RE: Multiple Organization creation Process takes time

pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
we have one portlet , In that we are getting Organisation name and email Id from the Excel sheet and we creating Organization .For creating 1 Organisation it will take 2-3 minutes , thats not good for the end user experience . so we decided to use Multithreading but there also we getting Deadlock situation while creating multiple organisation .
while creating Organisation when we applying site template for Organisation that process it taking more time 
below is the method for applying site Template .
SitesUtil.updateLayoutSetPrototypesLinks(organization.getGroup(), publicLayoutSetPrototypeId,privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled,
                    privateLayoutSetPrototypeLinkEnabled);
we have any other approach to apply site template or any other solution that make Organisation creation process fast ?


  
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,  You can try background process  for reading excel and updating  organization site template
May be u can refer below url https://liferay.dev/blogs/-/blogs/background-task-a-k-a-the-secret-weapon-behind-the-new-asynchronous-staging
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed 
   Thanks for quick reply , I will check document 
Amos Fong, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed,
  I am trying this approach but BackgroundTaskLocalServiceUtil  this class not finding Liferay 
so , I  am getting ClassNotFoundException for this class
for reference purpose I am using below document 
http://liferaytutorial.blogspot.com/2015/08/executing-background-task.html

Thanks and Regards ,
​​​​​​​  Pradip 

thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
which version of liferay your using ?
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed,
I am trying that approach using docs reference code 
But while deployment I am getting 
java.lang.IllegalArgumentException: Property "background.task.executor.class.name" is not set for com.vy.testExecutor.MyTestExecutor@5ffd2a64

you have any idea on this issue , for reference purpose I am sending snap of the my test class
Thanks and regards,
​​​​​​​ Pradip
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Can you please  share complete error and java code
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed ,
Thanks for giving your valuable time for sharing knowledge 
I updated my code But i am unable to calling execute method .
and I am attaching sample code .
Getting exception as like below -

​​​​​​​13:49:02,544 INFO  [http-nio-7095-exec-9][BackgroundTaskPortlet:65] BackgroundTaskPortlet.doView()============
13:49:30,491 ERROR [http-nio-7095-exec-9][status_jsp:950] com.liferay.portal.kernel.portlet.PortletContainerException: com.liferay.portal.kernel.portlet.PortletContainerException: javax.servlet.ServletException: java.lang.StackOverflowError

It looks taskContextMap taking only wrapper class object  values only , If we creating our own pojo class with serializable and passing in the map object . It will throwing same object.
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts

It looks taskContextMap taking only wrapper class object  values only , If we creating our own pojo class with serializable and passing in the map object . It will throwing same object.

Hi Pradip , 
  As per my understanding your setting your Serialized Pojo class in taskContextMap ? I would suggest you  if its entity of service builder you could add the primary key  of that entity object in taskContextMap  and use that reference in your TaskExecutor . In case you want to have  just pojo in  taskContextMap  then you can also make use of json utiltity of liferay and build  json and save the json string something like below.
JSONObject jsonObject JSONFactoryUtil.createJSONObject();
jsonObject.put("abc", "xyz");
jsonObject.toJSONString();[code]

​​​​​​​
But if in case you wanted to use Serialized Pojo only then also i think it should work if your Pojo is  serializable may be you can refer below to make you class serializable https://www.vogella.com/tutorials/JavaSerialization/article.html
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed,
Thanks again .. continuously you are giving your time 
so, as per suggestion I am creating 1 json in that I am putting all values and while setting in taskContextMap I am converting it into serializable and I am sending . 
But actually , we need ThemeDisplay obj , PortletPreference , ResourceRequest , ResourceResponse this object also in execute method . But they comes as null or getting ClassCastException for some object 
so , again we getting wrapper class object values only 

Thanks and Regards, 
​​​​​​​ Pradip Choudhari 
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Ok can you please tell me the exact use of Themedisplay and other objects in background executor ?
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Thanks Mohammed, 
for continuing giving feedback..
​​​​​​​
I want those object while creation of the organisation that code execute backgroundly  and it placed in execute() method.
means like when execute() method called by container , In that I will get all data from Map object like orgName,OrgEmail ,themeDisplay and other Object and I will use those object to creation of the Organisation

thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Ideally you will be requiring service context object for creating Organization  in background task executor as you dont have request object you need to create service context object and update the object with required attribute for your useYou can use like this and use the service context object .ServiceContext  serviceContext = new ServiceContext();
serviceContext.setCompanyId(companyId);
serviceContext.setScopeGroupId(scopeGroupId);
       
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed , 
Thanks for guidence purpose .
I tried ThemDisplay obj getting from ServletContext but it giving null .
I am attaching snap below .
(Note :In doView method instead of backgroundTaskmanager.addBackGroundTask(---) , I am using BackgroundTaskManagerUtil.addBackgroundTask(---)  in below snap)
​​​​​​​
Thanks And Regards, 
Pradip
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,    As i told service context which you are creating using servicecontext contructor will give a plain servicecontext wihtout themedisplay ,request object ,etc . And in Background executor you will not have themedisplay object as you don't have Request Object for that .  Can you please share the use of themedisplay in your code as we can find alternate for that .
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed,

I am using themeDisplay in below schenerious ,
superAdminIds=UserLocalServiceUtil.getRoleUserIds(RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), RoleConstants.ADMINISTRATOR).getRoleId());

if(themeDisplay.isSignedIn()){
                 parentOrgAdminEmailId=themeDisplay.getUser().getEmailAddress();
             }else{
                 parentOrgAdminEmailId=themeDisplay.getDefaultUser().getEmailAddress();
             }

If we get requeset , response object also in execute method , that is also useful for us becoz using request we can get themeDisplay object in execute method , but we are not getting request , response object also .

Thanks & Regards, 
Pradip
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Ok in this case as your running a background process it does not  have anything as signed in or signed out ? You can directly user UserLocalServiceUtil.getDefaultUser(PortalUtil.getDefaultCompanyId()) but still you want to capture when user triggered this was he signed in or not then you can actually save themeDisplay.isSignedIn() value in taskcontextmap and retrieve it here 
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed , 
This is actually good approach , 
I will try this case .

Thanks & Regards , 
Pradip
pradip choudhari, modified 6 Years ago. Junior Member Posts: 59 Join Date: 5/10/19 Recent Posts
Hello Mohammed , 
Thanks for your continuous suggestion .
This approach worked for me . 

Thanks and Regards, 
​​​​​​​Pradip