Foren

Assign known site template to a organization programitically

Aryan sds, geändert vor 10 Jahren.

Assign known site template to a organization programitically

Junior Member Beiträge: 57 Beitrittsdatum: 24.04.12 Neueste 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.


@Override
	public void run(HttpServletRequest request, HttpServletResponse response)
			throws ActionException {
		// TODO Auto-generated method stub
		System.out.println("in hook ");
    	
	
		_log.debug("Perform Post Login");
		 
		        // Redirect to user organization private space
		        long userId = PortalUtil.getUserId(request);
		    	ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
		      
		        
		        try {
		            List<organization> userOrganizations = OrganizationLocalServiceUtil
		                    .getUserOrganizations(userId);
		
		            if (userOrganizations != null &amp;&amp; userOrganizations.size() &gt; 0) {
		               
		            
				        
				       
		            	Organization org = userOrganizations.get(0);
		
		                
		                if(org.getPrivateLayoutsPageCount()&gt;0){
		                
		                	
		                
		                String path = PortalUtil.getPathFriendlyURLPrivateGroup()
		                        + org.getGroup().getFriendlyURL();
		
		                
		                response.sendRedirect(path);
		                
		                
		                }
		                
		               
		                else if(org.getPrivateLayoutsPageCount()&lt;0 || org.getPrivateLayoutsPageCount()==0 &amp;&amp; userId!=0){
		                	
		                	               	
		                	
		                	
		                	System.out.println("in new site template ");
		                	
		                	long userids[] = { userId };
		                	ServiceContext serviceContext = new ServiceContext();
		                	long templateId=14525;// site template layoutSetPrototypeId
						      	
		                	Group  g=org.getGroup();
							SitesUtil.applyLayoutSetPrototypes(g
									,templateId,
									0, serviceContext);
		                	
							System.out.println(" site template assigned");
							
							
							Role role= RoleLocalServiceUtil.getRole(
							d.getCompanyId(), "Administrator");
							
							Role role1= RoleLocalServiceUtil.getRole(
							d.getCompanyId(), "Organization Administrator");
							
							
							Role role2 = RoleLocalServiceUtil.getRole(
							d.getCompanyId(), "User");
							
							
							UserLocalServiceUtil.deleteRoleUser(role.getRoleId(),userId);
							
							UserLocalServiceUtil.addRoleUsers(role1.getRoleId(), userids);
							UserLocalServiceUtil.addRoleUsers(role2.getRoleId(), userids);
							
							 String path = PortalUtil.getPathFriendlyURLPrivateGroup()
				                        + org.getGroup().getFriendlyURL();
							 
							 
								System.out.println(" Path"+path);
				
				                response.sendRedirect(path);
		                }
		                
		            }
		            
		            
		          
		        } catch (Exception e) {
		            _log.warn("Unable to redirect to organization page, userId="
		                    + userId, e);
		        }
		
		
	}</organization>





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.
thumbnail
Antoine Comble, geändert vor 10 Jahren.

RE: Assign known site template to a organization programitically

Regular Member Beiträge: 232 Beitrittsdatum: 07.09.12 Neueste Beiträge
Hi,

You can try this :


LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroupId, true);
layoutSet.setLayoutSetPrototypeLinkEnabled(true);
layoutSet.setLayoutSetPrototypeUuid(yourlayoutSetPrototype.getUuid());
LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(pharmacieGroupId, true, true,	yourlayoutSetPrototype.getUuid());


Antoine