Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
gary b
Ho to uase SitesUtil.applyLayoutSetPrototypes
1. April 2013 05:39
Antwort

gary b

Rang: Junior Member

Nachrichten: 75

Eintrittsdatum: 2. Februar 2013

Neue Beiträge

Hi,

I want to apply the site template to an organization using code but when i am using below code:

SitesUtil.applyLayoutSetPrototypes(organization.getGroup(),123, 234,serviceContext);

its gives java.lang.NoClassDefFoundError because SitesUtil.java exist in portal-imp.jar so we can't access it in my portlet.
So I have created the ext and copy SitesUtil.jar in my ext and put that jar in my tomcat/lib/ext now I am not getting class not found error but getting below error.

 1viceBeanMethodInvocation.java:108)
 2        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanA
 3opProxy.java:211)
 4        at $Proxy28.importLayouts(Unknown Source)
 5        at com.liferay.portal.service.LayoutServiceUtil.importLayouts(LayoutServ
 6iceUtil.java:469)
 7        at com.liferay.portlet.sites.util.SitesUtil.copyLayoutSet(SitesUtil.java
 8:281)
 9        at com.liferay.portlet.sites.util.SitesUtil.applyLayoutSetPrototypes(Sit
10esUtil.java:225)
11        at com.eyepegasus.bean.NewUserBB.addOrganization(NewUserBB.java:489)
12        at com.eyepegasus.bean.NewUserBB.addUser(NewUserBB.java:325)
13        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.


Can any one help. I have seen many post but didn't found any solution.

My aim is to assign one default site to all organization at the time organization creation. If i will able to access SitesUtil I can directly do
SitesUtil.applyLayoutSetPrototypes(organization.getGroup(),123, 234,serviceContext);

Please help. Thanks in advance.
Peter Schübl
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
2. April 2013 00:35
Antwort

Peter Schübl

Rang: New Member

Nachrichten: 9

Eintrittsdatum: 24. November 2011

Neue Beiträge

Hi,

It is very unfortunate that the SitesUtil is not available as a service.

To use it you have to run it in the context of the portal (liferay core)

1MethodKey methodKey = new MethodKey("com.liferay.portlet.sites.util.SitesUtil",
2    "applyLayoutSetPrototypes", Group.class, long.class, long.class, ServiceContext.class);
3PortalClassInvoker.invoke(false, methodKey, organization.getGroup(), 123, 234, serviceContext);
gary b
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
2. April 2013 02:29
Antwort

gary b

Rang: Junior Member

Nachrichten: 75

Eintrittsdatum: 2. Februar 2013

Neue Beiträge

Hi,

I have already used the PortalClassInvoker.invoke() but getting the same above error.

After debugging the code we get to know that it is a permission related issue. So for assigning a site to organization we first need to login then my code will work properly.
So can any on tell me how we can login problematically using my code.

Thanks
Peter Schübl
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
2. April 2013 10:57
Antwort

Peter Schübl

Rang: New Member

Nachrichten: 9

Eintrittsdatum: 24. November 2011

Neue Beiträge

Well, that depends.

Where do you want to trigger the functionality from?

What you need to is a new ServiceContext.

Something like the following - not tested.
1ServiceContext serviceContext = new ServiceContext();
2serviceContext.setAddGroupPermissions(true);
3serviceContext.setAddGuestPermissions(true);
4serviceContext.setSignedIn(false);
5// set the following to an admin user / company or default user
6User user = UserLocalServiceUtil.getDefaultUser(companyId); // or any user that has the permissions
7serviceContext.setUserId(user.getUserId());
8serviceContext.setCompanyId(companyId);


And most likely you also have to setup the ThreadPermissionChecker
1PrincipalThreadLocal.setName(user.getUserId());
2PermissionChecker adminPermissionChecker = PermissionCheckerFactoryUtil.create(user, false);
3PermissionThreadLocal.setPermissionChecker(adminPermissionChecker);


Don't forget to reset the permission checker in a final block.

That should work. Fingers crossed.
xxz were
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
10. April 2013 01:30
Antwort

xxz were

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 9. April 2013

Neue Beiträge

Could you tell me the possible values that publicLayoutSetPrototypeId and privateLayoutSetPrototypeId can take and its meaning?
Peter Schübl
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
10. April 2013 04:02
Antwort

Peter Schübl

Rang: New Member

Nachrichten: 9

Eintrittsdatum: 24. November 2011

Neue Beiträge

public/privateLayoutSetPrototypeId are IDs of LayoutSetPrototype instances.

A LayoutSetPrototype is the entity for a Site Template.

Use LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypes(-1, -1) to get a list of Site Templates.
Jing Guo
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
10. April 2013 08:10
Antwort

Jing Guo

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 22. Oktober 2012

Neue Beiträge

Hi,

I think you could probably try to use LayoutSetPrototypeLocalServiceUtil and LayoutSetLocalServiceUtil class, I am attaching some of my code here:

 1
 2   //following code is based on my requirement, change it to meet yours.
 3   //get all layout prototype
 4   List<LayoutSetPrototype> layouts = LayoutSetPrototypeLocalServiceUtil
 5                    .getLayoutSetPrototypes(-1, -1);
 6            LayoutSetPrototype publicLayoutSetPrototype = null;
 7            LayoutSetPrototype privateLayoutSetPrototype = null;
 8   //find the right prototype
 9    for (int i = 0; i < layouts.size(); i++) {
10                if (layouts.get(i).getNameCurrentValue()
11                        .equals(publicLayoutName)) {
12                    publicLayoutSetPrototype = layouts.get(i);
13                } else if (layouts.get(i).getNameCurrentValue()
14                        .equals(privateLayoutName)) {
15                    privateLayoutSetPrototype = layouts.get(i);
16
17                }
18
19            }
20      
21    LayoutSet publicLayoutset = LayoutSetLocalServiceUtil.getLayoutSet(
22                    group.getGroupId(), false);
23
24            LayoutSet privateLayoutset = LayoutSetLocalServiceUtil
25                    .getLayoutSet(group.getGroupId(), true);
26
27            publicLayoutset.setLayoutSetPrototypeUuid(publicLayoutSetPrototype
28                    .getUuid());
29
30            privateLayoutset
31                    .setLayoutSetPrototypeUuid(privateLayoutSetPrototype
32                            .getUuid());
33
34publicLayoutset.setLayoutSetPrototypeLinkEnabled(true);
35
36            privateLayoutset.setLayoutSetPrototypeLinkEnabled(true);
37
38            LayoutSetLocalServiceUtil.updateLayoutSet(publicLayoutset);
39
40            LayoutSetLocalServiceUtil.updateLayoutSet(privateLayoutset);
41    


I hope this helps

Jing Guo
Sunil Kulkarni
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
10. April 2013 09:23
Antwort

Sunil Kulkarni

Rang: Junior Member

Nachrichten: 94

Eintrittsdatum: 24. Juni 2011

Neue Beiträge

I was facing the same problem for assigning the site template for organization site.

http://www.liferay.com/community/forums/-/message_boards/message/18392329

It might be not a valid way.
gary b
RE: Ho to uase SitesUtil.applyLayoutSetPrototypes
18. April 2013 05:58
Antwort

gary b

Rang: Junior Member

Nachrichten: 75

Eintrittsdatum: 2. Februar 2013

Neue Beiträge

Hi All,

Here is the solution.

To assign site template to an organization you must be logged in so we have created a hook for postlogin and put the below code in postlogin method..
First you need to assign the admin role to user and must initialize permission checker otherwise you will get " permission checker is not initialized" error .
 1
 2Role adminRole = RoleLocalServiceUtil.getRole(10153,"Administrator");
 3 List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
 4                            
 5                             PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
 6                             PermissionChecker permissionChecker =PermissionCheckerFactoryUtil.create(adminUsers.get(0), true);
 7                             PermissionThreadLocal.setPermissionChecker(permissionChecker);
 8                            
 9                           
10                        
11                            MethodKey key = new MethodKey("com.liferay.portlet.sites.util.SitesUtil", "applyLayoutSetPrototypes",
12                                                              Group.class, long.class, long.class, ServiceContext.class );
13                                                   
14                                    PortalClassInvoker.invoke(true, key, org.getGroup(), 13825, 13825, serviceContext);