Foros de discusión

importing guest layouts from a larfile in startup Hook

Gandhi Rai, modificado hace 11 años.

importing guest layouts from a larfile in startup Hook

New Member Mensajes: 4 Fecha de incorporación: 8/02/13 Mensajes recientes
Hi,
I am trying to import some guest layouts from a larFile(exported from another instance) in to a liferay instance (can be an already installed_and_configured OR can be a fresh installation) by creating a class which extends SimpleAction in a Start up Hook ( ) and then pointing 'application.startup.events' to this class in the portal-ext.properties file. I want this to run every time the server starts as my larFile version may change over the time. My Code is as follows...

File larFile=new File("/Users/grai001/Desktop/default_guest_public_new_light.lar");

//using absolute path for now -need help in accessing the relative path to ${liferay.home}??

Group guestGroup = GroupLocalServiceUtil.getGroup(1, GroupConstants.GUEST);
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), false, new HashMap<String,String[]>(), larFile);


//I want them to be a public layouts which are visible to every one even when a user is not logged in - like the default WHAT-WE-DO kind of
pages in liferay6.1 - I am using 6.1GA2 at both ends


How ever this is giving me null pointer exception and the stack trace is as below..

com.liferay.portal.kernel.exception.SystemException: java.lang.NullPointerException
at com.liferay.portal.service.impl.LayoutLocalServiceImpl.importLayouts(LayoutLocalServiceImpl.java:1398)
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:122)
at com.liferay.portal.service.impl.LayoutLocalServiceVirtualLayoutsAdvice.invoke(LayoutLocalServiceVirtualLayoutsAdvice.java:197)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.invoke(LayoutLocalServiceStagingAdvice.java:107)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy27.importLayouts(Unknown Source)
at com.liferay.portal.service.LayoutLocalServiceUtil.importLayouts(LayoutLocalServiceUtil.java:1037)
at com.walmart.services.mpportal.liferay.startup.StartupHook.run(StartupHook.java:88)
at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:106)
at com.liferay.portal.events.EventsProcessorImpl.process(EventsProcessorImpl.java:58)
at com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:53)
at com.liferay.portal.util.PortalInstances._initCompany(PortalInstances.java:462)
at com.liferay.portal.util.PortalInstances.initCompany(PortalInstances.java:92)
at com.liferay.portal.servlet.MainServlet.initCompanies(MainServlet.java:798)
at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:355)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
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:680)
Caused by: java.lang.NullPointerException
at com.liferay.portal.kernel.util.ParamUtil.getLong(ParamUtil.java:616)
at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.deleteLayout(LayoutLocalServiceStagingAdvice.java:70)
at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.invoke(LayoutLocalServiceStagingAdvice.java:113)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy27.deleteLayout(Unknown Source)
at com.liferay.portal.service.LayoutLocalServiceUtil.deleteLayout(LayoutLocalServiceUtil.java:435)
at com.liferay.portal.lar.LayoutImporter.deleteMissingLayouts(LayoutImporter.java:196)
at com.liferay.portal.lar.LayoutImporter.doImportLayouts(LayoutImporter.java:774)
at com.liferay.portal.lar.LayoutImporter.importLayouts(LayoutImporter.java:147)
at com.liferay.portal.service.impl.LayoutLocalServiceImpl.importLayouts(LayoutLocalServiceImpl.java:1382)
... 50 more




And now doing LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), true, new HashMap<String,String[]>(), larFile);

ie...importing them as private layouts is working fine - unfortunately I want them to be public and be visible to every one. Also logging in as portal adminstrator and
importing from the UI as public layouts is working well and good. How ever I want this to be done in an automated way.


Trying to solve this problem of mine from the past 1 week - did enough research - but still couldn't. Any kind of help is appreciated..! emoticon

Thanks in advance,
-Gandhi
thumbnail
meera prince, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Hi

LayoutSetPrototype layoutSetPrototype =
LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
publicLayoutSetPrototypeId);
Map<String, String[]> parameterMap = getLayoutSetPrototypeParameters(actionRequest);
try {
file = LayoutLocalServiceUtil.exportLayoutsAsFile(layoutSetPrototype.getLayoutSet().getGroupId(), layoutSetPrototype.getLayoutSet().isPrivateLayout(),
null, parameterMap, null, null);
LayoutLocalServiceUtil.importLayouts(themeDisplay.getUserId(),publicLayoutSet.getGroupId(), publicLayoutSet.isPrivateLayout(),parameterMap, file);
}catch(Exception e){
e.printStrackTrace();
}

===============

public static Map<String, String[]> getLayoutSetPrototypeParameters(ActionRequest actionRequest ) throws SystemException {
Map<String, String[]> parameterMap =
new LinkedHashMap<String, String[]>();
PortletPreferences oneClickSitePreferences = actionRequest.getPreferences();
String portletResource = ParamUtil.getString(actionRequest,"portletResource");
if (Validator.isNotNull(portletResource)) {
oneClickSitePreferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
}
parameterMap.put(PortletDataHandlerKeys.CATEGORIES,new String[] {oneClickSitePreferences.getValue(PortletDataHandlerKeys.CATEGORIES,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.DATA_STRATEGY,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.DATA_STRATEGY,"DATA_STRATEGY_MIRROR")});
parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.DELETE_PORTLET_DATA,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.DELETE_PORTLET_DATA,Boolean.FALSE.toString())});
parameterMap.put(PortletDataHandlerKeys.PERMISSIONS,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PERMISSIONS,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_DATA,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.PORTLET_SETUP,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_SETUP,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.THEME,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.THEME,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.USER_ID_STRATEGY,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.USER_ID_STRATEGY,"CURRENT_USER_ID")});
parameterMap.put(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,Boolean.TRUE.toString())});
parameterMap.put("permissionsAssignedToRoles",new String[]{oneClickSitePreferences.getValue("permissionsAssignedToRoles",Boolean.FALSE.toString())});
parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA_ALL,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.PORTLET_DATA_ALL,Boolean.TRUE.toString())});
parameterMap.put(PortletDataHandlerKeys.USER_PERMISSIONS,new String[]{oneClickSitePreferences.getValue(PortletDataHandlerKeys.USER_PERMISSIONS,Boolean.FALSE.toString())});
return parameterMap;
}
===============================
Gandhi Rai, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

New Member Mensajes: 4 Fecha de incorporación: 8/02/13 Mensajes recientes
Hi Meera,
Thanks for the response. As I mentioned right now I am just having a class extending SimpleAction and then overriding the run(String[] arg0) method. So I don't have any reference to themeDisplay/any request_or_response.

Thanks & Regards,
-Gandhi
Gandhi Rai, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

New Member Mensajes: 4 Fecha de incorporación: 8/02/13 Mensajes recientes
Any help from anyone?? emoticon
thumbnail
meera prince, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Hi Gandhi Rai.

Your task is import some layouts from existing LAR file.

Let me clear some thing like

Where did you get the LAR file.?
Have Exported already?
Where you kept this LAR file?

Please make sure file object is created for LAR file with give path... please give abosolute path some thing like this D://somefolder/your.lar

in the import method
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), false, new HashMap<String,String[]>(), larFile);

give userId ad Admin Id i.e 10169 i.e liferay test admin id you can hard code as of now.

new HashMap<String,String[]>() for this prepare this may from i sent you in the previous forum. there you have different option please make sure which options required and which not required.

Here my point is first make sure file object is getting or not for you given path.
if possible send your hook so that i can understand and i will solve if i got solution.
Regards,
Meera Prince
Gandhi Rai, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

New Member Mensajes: 4 Fecha de incorporación: 8/02/13 Mensajes recientes
Hi Meera,
Thanks for the response.I exported the LARFile from a different liferay server of the same version which is 6.1.1-ga2. As I already mentioned I don't think there is any issue with my File Object as the same piece of code is working when imported as private layouts. Anyways I'll try with the adminId and will let you know. My StartUp hook is pretty simple and can be seen below.

public class StartupHook extends SimpleAction{

@Override
public void run(String[] arg0) throws ActionException{


File larFile=new File("/Users/grai001/Desktop/default_guest_public_new.lar");
HashMap<String,String[]> parameterMap = new HashMap<String,String[]>();

parameterMap.put(
PortletDataHandlerKeys.PERMISSIONS,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_DATA,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_SETUP,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.USER_PERMISSIONS,
new String[] {Boolean.FALSE.toString()});

try {
boolean isPrivateLayouts = false; //Exception in the below line doesn't occur when this boolean is turned on.
Group guestGroup = GroupLocalServiceUtil.getGroup(1, GroupConstants.GUEST);
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), isPrivateLayouts, parameterMap, larFile);

} catch (Exception e) {
e.printStackTrace();
}
}
}
thumbnail
meera prince, modificado hace 11 años.

RE: importing guest layouts from a larfile in startup Hook

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Hi Gandhi Rai

Please observe following options in Map object.

ortletDataHandlerKeys.USER_ID_STRATEGY CURRENT_USER_ID / ALWAYS_CURRENT_USER_ID
PortletDataHandlerKeys.DATA_STRATEGY DATA_STRATEGY_COPY_AS_NEW / DATA_STRATEGY_MIRROR/
PortletDataHandlerKeys.USER_PERMISSIONS
PortletDataHandlerKeys.PERMISSIONS,

above all properties effect export and import so please change the values and test your application then it might work.,

prefer DATA_STRATEGY_COPY_AS_NEW instead of DATA_STRATEGY_MIRROR