找到你要的答案

Q:Liferay: How to create a organization programatically?

Q:Liferay:如何创建一个组织程序吗?

I am well versed with the liferay portal. But i dont know how do i create a organization when it comes to programming through liferay developer studio. Can it be done through a hook?. For now i have a project available in which i have created a hook. Which interface should i implement and what all classes should i be using it. What i have done till now? I have gone through this link which makes us understand about the methods but the approach required is missing. I couldnt find it anywhere(basics and approach of creating org through program). What are the entries that i have to make in liferay-hook.xml?

I am a beginner and any guidance is much appreciated. Many thanks in advance.

I am well versed with the liferay portal. But i dont know how do i create a organization when it comes to programming through liferay developer studio. Can it be done through a hook?. For now i have a project available in which i have created a hook. Which interface should i implement and what all classes should i be using it. What i have done till now? I have gone through this link which makes us understand about the methods but the approach required is missing. I couldnt find it anywhere(basics and approach of creating org through program). What are the entries that i have to make in liferay-hook.xml?

我是一个初学者,任何指导是非常赞赏。提前多谢。

answer1: 回答1:

Liferay provides Utility classes, which are usable/callable outside the ROOT context of the server.

Generally you can find those classes with following post-fix: entity-name-ServiceUtil

For Organization you have OrganizationLocalServiceUtil, which have related methods e.g. OrganizationLocalServiceUtil.addOrganization(...) to add the organization.

If you want to try this thing out, create a simple liferay portlet and check the method.

One can use these methods in HOOK, Portlet or Ext depending on the use-case.

提供实用工具类,即可用/可服务器根上下文之外。

通常你可以找到这些类与后固定:实体名称serviceutil

For Organization you have OrganizationLocalServiceUtil, which have related methods e.g. OrganizationLocalServiceUtil.addOrganization(...) to add the organization.

如果你想尝试这件事,创建一个简单的Liferay的portlet和检查方法。

一个可以在钩子的使用这些方法,portlet或Ext视使用情况。

answer2: 回答2:

@Shirish You can use liferay utility classes anywhere like inside hook,ext ...etc.

Here you want to create organization inside hook, which you can accomplish using utility class OrganizationServiceUtil in following way.

ServiceContext serviceContext = ServiceContextFactory.getInstance(request); //or null
Organization organization = OrganizationServiceUtil.addOrganization(
                OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID,
                organizationName,
                OrganizationConstants.TYPE_REGULAR_ORGANIZATION,
                RegionConstants.DEFAULT_REGION_ID,
                CountryConstants.DEFAULT_COUNTRY_ID,
                ListTypeConstants.ORGANIZATION_STATUS_DEFAULT,
                "",
                false,
                serviceContext
        );

You can also create organization using Utility class 'OrganiztionLocalServiceUtil' in following way.

OrganiztionLocalServiceUtil.addOrganization(
    long userId, long parentOrganizationId, String name, String type,
    boolean recursable, long regionId, long countryId, int statusId,
    String comments, boolean site, ServiceContext serviceContext);

“Shirish可以使用Liferay实用类内钩的地方,Ext…等。

在这里,你想创建组织内钩,你可以使用实用程序类organizationserviceutil以下方式。

ServiceContext serviceContext = ServiceContextFactory.getInstance(request); //or null
Organization organization = OrganizationServiceUtil.addOrganization(
                OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID,
                organizationName,
                OrganizationConstants.TYPE_REGULAR_ORGANIZATION,
                RegionConstants.DEFAULT_REGION_ID,
                CountryConstants.DEFAULT_COUNTRY_ID,
                ListTypeConstants.ORGANIZATION_STATUS_DEFAULT,
                "",
                false,
                serviceContext
        );

你也可以创建组织利用工具类的organiztionlocalserviceutil在以下方式。

OrganiztionLocalServiceUtil.addOrganization(
    long userId, long parentOrganizationId, String name, String type,
    boolean recursable, long regionId, long countryId, int statusId,
    String comments, boolean site, ServiceContext serviceContext);
java  liferay  liferay-6