Fórum

Creating sites programmatically?

thumbnail
Arnold Wenger, modificado 9 Anos atrás.

Creating sites programmatically?

New Member Postagens: 9 Data de Entrada: 15/09/14 Postagens Recentes
Hi guys,

I'm trying to create an simplified version of the create site page in the control panel.
But to achieve this I would like to know how liferay creates a site programmatically.
Which interface are being uses and can I access/use them as well?
Got tips/trick how to achieve this?
I have already looked at de API document’s but it’s like looking for a needle in a haystack.

Thank you for your help in this matter.
Oliver Bayer, modificado 9 Anos atrás.

RE: Creating sites programmatically?

Liferay Master Postagens: 894 Data de Entrada: 18/02/09 Postagens Recentes
Hi Arnold,

are you referring to site as "pages" or "website"?
Pages can be added/ deleted/ updated etc by using LayoutLocalServiceUtil.* methods.
Sites - internally called group - can be modified using the GroupLocalServiceUtil.* methods.

HTH Oli
thumbnail
Arnold Kevin Wenger, modificado 9 Anos atrás.

RE: Creating sites programmatically?

New Member Postagens: 9 Data de Entrada: 15/09/14 Postagens Recentes
Oliver Bayer:
Hi Arnold,

are you referring to site as "pages" or "website"?
Pages can be added/ deleted/ updated etc by using LayoutLocalServiceUtil.* methods.
Sites - internally called group - can be modified using the GroupLocalServiceUtil.* methods.

HTH Oli


Thx for the quick response.

I’m referring to the site that you can create at :Admin/Control panel/Site.(If you login in liferay.)
Aren’t the classes you mentions there to create site layouts and user groups ??
Oliver Bayer, modificado 9 Anos atrás.

RE: Creating sites programmatically?

Liferay Master Postagens: 894 Data de Entrada: 18/02/09 Postagens Recentes
Hi Arnold,

a site like e.g. the guest community (friendly url = /guest) is -historically- called a group. Just take a look at the group_ table of your liferay database for reference. So you can use the GroupLocalServiceUtil methods to create a new group = new site. You must set the boolean attribute "site" to true if you want to create a new site. Now if you want to create new pages for your site you should use the LayoutLocalServiceUtil methods. Pages are connected to a site by the groupId attribute (of your previously created site).

Greets Oli
thumbnail
Arnold Kevin Wenger, modificado 9 Anos atrás.

RE: Creating sites programmatically?

New Member Postagens: 9 Data de Entrada: 15/09/14 Postagens Recentes
Thanks for the help. I will look in to it.
emoticon
thumbnail
Muhammed Shafeek V, modificado 9 Anos atrás.

RE: Creating sites programmatically? (Resposta)

Regular Member Postagens: 140 Data de Entrada: 22/07/13 Postagens Recentes
Hi,

For creating site and assigning temlates. try this,,


Group group = null;
int type = GroupConstants.TYPE_SITE_OPEN;
long publicLayoutSetPrototypeId = 0;
long privateLayoutSetPrototypeId = 0;
boolean privateLayout = false;

try {
List<LayoutSetPrototype> layoutSetPrototypes;

group = GroupServiceUtil.addGroup(0,
name, description, type, StringPool.BLANK, true, true,
serviceContext);


layoutSetPrototypes = LayoutSetPrototypeServiceUtil.search(
serviceContext.getThemeDisplay().getCompanyId(),
Boolean.TRUE, null);

for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
if (layoutSetPrototype.getDescription().equalsIgnoreCase(
"travel community")) { //here choose the template description, that you wish to assign to your site.

publicLayoutSetPrototypeId = layoutSetPrototype
.getLayoutSetPrototypeId();

PortalClassInvoker.invoke(true,
_updateLayoutSetPrototypesMethodKey, group,
publicLayoutSetPrototypeId,
privateLayoutSetPrototypeId, !privateLayout,
privateLayout);

LayoutSet layoutSet = LayoutSetLocalServiceUtil
.getLayoutSet(group.getGroupId(), false);

PortalClassInvoker.invoke(true,
_mergeLayoutSetPrototypeLayoutsMethodKey,
group, layoutSet);

log.info("site is created>>>>>>>>>>>>>>");

break;
}
}
}
} catch (DuplicateGroupException e) {

} catch (PortalException e1) {

} catch (com.liferay.portal.kernel.exception.SystemException e1) {

}
private static final String _CLASS_NAME = "com.liferay.portlet.sites.util.SitesUtil";
private static MethodKey _mergeLayoutSetPrototypeLayoutsMethodKey = new MethodKey(
_CLASS_NAME, "mergeLayoutSetProtypeLayouts", Group.class,
LayoutSet.class);

private static MethodKey _updateLayoutSetPrototypesMethodKey = new MethodKey(
_CLASS_NAME, "updateLayoutSetPrototypesLinks", Group.class,
long.class, long.class, boolean.class, boolean.class);


Kind regards,
M Shafeek V
thumbnail
Arnold Kevin Wenger, modificado 9 Anos atrás.

RE: Creating sites programmatically?

New Member Postagens: 9 Data de Entrada: 15/09/14 Postagens Recentes
Awesome. Thanks for the code.

I just have a few questions
What is ? :
• _mergeLayoutSetPrototypeLayoutsMethodKey
• _updateLayoutSetPrototypesMethodKey
and what is it good for?

p.s. Sorry if I’m asking amateur questions.
I’m fairly new to Liferay(4 weeks).
But everyone got to start somewhere.
thumbnail
Jitendra Rajput, modificado 9 Anos atrás.

RE: Creating sites programmatically?

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Arnold Kevin Wenger:
Awesome. Thanks for the code.

I just have a few questions
What is ? :
• _mergeLayoutSetPrototypeLayoutsMethodKey
• _updateLayoutSetPrototypesMethodKey
and what is it good for?

p.s. Sorry if I’m asking amateur questions.
I’m fairly new to Liferay(4 weeks).
But everyone got to start somewhere.


We can not directly access any class of portal-impl.jar in plugin project. Using PortalClassInvoker we can access portal-impl.jar we have to specify details like which method you want to access , what are the argument for that method etc. MethodKey is nothing but fully qualified name of the class.

You can add site using GroupServiceUtil.addGroup() but there are some post action once group is created. If you have portal source code then you can check updateGroup() method of EditGroupAction.java
thumbnail
Arnold Kevin Wenger, modificado 9 Anos atrás.

RE: Creating sites programmatically?

New Member Postagens: 9 Data de Entrada: 15/09/14 Postagens Recentes
it's works! I optimized it a bit and gave the user right's to make sites and it works Great.
THANK YOU!