Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Aryan sds
Assign known site template to a organization programitically
3. April 2013 06:49
Antwort

Aryan sds

Rang: Junior Member

Nachrichten: 57

Eintrittsdatum: 24. April 2012

Neue Beiträge

Hello I have created user & organization pragmatically using addUser() & addOrganization() methods respectively.

I am also able to add users to this organization using addOrganizationUsers() method.

Now I have created a site template from liferay control panel.

As we know , we can create a site for organization, and while creating a site we have options to select a site template for public & private pages.


So I want to create a organization site with private pages only so it will be seen by only organization members .

So How we can create a organization site & assign him particular site template(means all process
of creating a site for organization should get done programitically )once we create a organization?


I am using liferay 6.1.0-ce-ga1. version

I am trying in this way .

Step 1. Able to create a user using addUser() method.
step 2. Able to assign admin role to created user using UserLocalServiceUtil.addRoleUsers() method.
step 3. Able to create organization using OrganizationLocalServiceUtil.addOrganization() method.
step 4. Able to assign users to created organization using UserLocalServiceUtil.addOrganizationUsers() method.
step 5 Now I have created a hook for LoginPostAction.java file .I am overriding run() method in this way.

(As we know that site template can be assigned to a organization only if admin is logged in.)
So that's why I am following this way.

 1
 2@Override
 3    public void run(HttpServletRequest request, HttpServletResponse response)
 4            throws ActionException {
 5        // TODO Auto-generated method stub
 6        System.out.println("in hook ");
 7       
 8   
 9        _log.debug("Perform Post Login");
10         
11                // Redirect to user organization private space
12                long userId = PortalUtil.getUserId(request);
13                ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
14             
15               
16                try {
17                    List<Organization> userOrganizations = OrganizationLocalServiceUtil
18                            .getUserOrganizations(userId);
19       
20                    if (userOrganizations != null && userOrganizations.size() > 0) {
21                      
22                   
23                        
24                      
25                        Organization org = userOrganizations.get(0);
26       
27                        
28                        if(org.getPrivateLayoutsPageCount()>0){
29                        
30                           
31                        
32                        String path = PortalUtil.getPathFriendlyURLPrivateGroup()
33                                + org.getGroup().getFriendlyURL();
34       
35                        
36                        response.sendRedirect(path);
37                        
38                        
39                        }
40                        
41                      
42                        else if(org.getPrivateLayoutsPageCount()<0 || org.getPrivateLayoutsPageCount()==0 && userId!=0){
43                           
44                                              
45                           
46                           
47                            System.out.println("in new site template ");
48                           
49                            long userids[] = { userId };
50                            ServiceContext serviceContext = new ServiceContext();
51                            long templateId=14525;// site template layoutSetPrototypeId
52                                 
53                            Group  g=org.getGroup();
54                            SitesUtil.applyLayoutSetPrototypes(g
55                                    ,templateId,
56                                    0, serviceContext);
57                           
58                            System.out.println(" site template assigned");
59                           
60                           
61                            Role role= RoleLocalServiceUtil.getRole(
62                            d.getCompanyId(), "Administrator");
63                           
64                            Role role1= RoleLocalServiceUtil.getRole(
65                            d.getCompanyId(), "Organization Administrator");
66                           
67                           
68                            Role role2 = RoleLocalServiceUtil.getRole(
69                            d.getCompanyId(), "User");
70                           
71                           
72                            UserLocalServiceUtil.deleteRoleUser(role.getRoleId(),userId);
73                           
74                            UserLocalServiceUtil.addRoleUsers(role1.getRoleId(), userids);
75                            UserLocalServiceUtil.addRoleUsers(role2.getRoleId(), userids);
76                           
77                             String path = PortalUtil.getPathFriendlyURLPrivateGroup()
78                                        + org.getGroup().getFriendlyURL();
79                            
80                            
81                                System.out.println(" Path"+path);
82               
83                                response.sendRedirect(path);
84                        }
85                        
86                    }
87                   
88                   
89                  
90                } catch (Exception e) {
91                    _log.warn("Unable to redirect to organization page, userId="
92                            + userId, e);
93                }
94       
95       
96    }





But still I am unable to assign a site template to that organization.
I am getting error as ...PermissionChecker not initialized.
and error log is


com.liferay.portal.security.auth.PrincipalException: PermissionChecker NOT initialized
AT com.liferay.portal.service.base.PrincipalBean.getPermissionChecker(PrincipalBean.java:81)
AT com.liferay.portal.service.impl.LayoutServiceImpl.importLayouts(LayoutServiceImpl.java:624)
AT sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
AT sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
AT sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
AT java.lang.reflect.Method.invoke(Method.java:597)
AT com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
AT com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
AT com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
AT com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
AT com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
AT com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
AT com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
AT com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
AT $Proxy34.importLayouts(UNKNOWN Source)
AT com.liferay.portal.service.LayoutServiceUtil.importLayouts(LayoutServiceUtil.java:469)
AT com.liferay.portlet.sites.util.SitesUtil.copyLayoutSet(SitesUtil.java:281)
AT com.liferay.portlet.sites.util.SitesUtil.applyLayoutSetPrototypes(SitesUtil.java:211)
AT com.LoginPostAction.run(LoginPostAction.java:163)
AT com.liferay.portal.kernel.events.InvokerAction.run(InvokerAction.java:41)
AT com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:81)
AT com.liferay.portal.events.EventsProcessorImpl.process(EventsProcessorImpl.java:68)
AT com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:53)
AT com.liferay.portal.servlet.MainServlet.loginUser(MainServlet.java:1035)
AT com.liferay.portal.servlet.MainServlet.service(MainServlet.java:454)
AT javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
AT org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
AT org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
AT com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
AT com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:304)
AT com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
AT com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
AT com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
AT com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
AT com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
AT com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
AT com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
AT com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
AT com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
AT com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
AT org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
AT com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
AT org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
AT org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
AT org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
AT org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
AT org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
AT org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
AT org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
AT org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
AT org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
AT org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
AT org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
AT org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
AT org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
AT java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
AT java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
AT java.lang.Thread.run(Thread.java:619)

So anybody give me suggestions how should I overcome with this error? Or Is there any other method which I can override .
I have created hook for LoginPostAction.java file because as we know when any user gets login , it goes finally to redirect section, So if it's going redirect section it means that user is logged in and here I am assigning a site template for his organization.
Please if anybody has any other good way other than this , let me know.
My main intention is to assign known site template to organization, for that we need to be logged in as a Admin. So how can I use liferay's own inbuilt methods or Api's to achieve this.

error.


Thank you,
Arayn sds.
Antoine Comble
RE: Assign known site template to a organization programitically
15. Juni 2013 13:54
Antwort

Antoine Comble

Rang: Regular Member

Nachrichten: 204

Eintrittsdatum: 7. September 2012

Neue Beiträge

Hi,

You can try this :

1
2LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroupId, true);
3layoutSet.setLayoutSetPrototypeLinkEnabled(true);
4layoutSet.setLayoutSetPrototypeUuid(yourlayoutSetPrototype.getUuid());
5LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
6LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(pharmacieGroupId, true, true,    yourlayoutSetPrototype.getUuid());


Antoine