Message Boards

Can we get portletId and PlId without request object?

Mohamed Saleem, modified 4 Years ago.

Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
I want to get plId and portlet id in scheduler class. How can I get these Ids any one please help me?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Mohamed SaleemI want to get plId and portlet id in scheduler class. How can I get these Ids any one please help me?
a plid is associated with the page a portlet may be placed on. Thus it's not related to the portlet and there might be multiple plids for a single portlet - and they might all be spread across multiple portal instances (companyId in the API) and sites (scopeGroupId or groupId in API).

So - yes, you can find out, which pages your portlet is placed on, you'll most likely need to decide which of the potentially multiple ones you want to use.

For the portletId: It depends on which one you mean: There's the one hardcoded id that a portlet has (comes with your portlet), and in case you can add multiple portlets of the same kind on a page, they'll have their own instance Ids (not to confuse with "portal instance" or "companyId")

While this might have been a technically correct answer, I'm not sure it's too helpful. What do you want to do with them? How do you start your scheduler? What does it do? Maybe there's another solution than the one that you're thinking about?
Mohamed Saleem, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
Hi Olaf,
In scheduler I want to store the some value in Portlet Preference Table.

to acheive this i want portletPreference object. getting preference object i need plid and portletId.



thanks,
Saleem.
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Mohamed Saleem
In scheduler I want to store the some value in Portlet Preference Table.

to acheive this i want portletPreference object. getting preference object i need plid and portletId.
I'd recommend to store your scheduler's output somewhere else, where you can also access it from your portlet. This way your scheduler is only doing its business and has no ties into Liferay's API. Plus, it doesn't need to determine which of the potentially many portletPreferences to write to.

Your portlet and your scheduler then have a common backend, which they both access. Definitely a cleaner way to introduce those dependencies.
Mohamed Saleem, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
Hi Olaf,sorry for late reply, I have done this requirement.
* getting portletid from portletkeys file  and companyid from PortalUtil .
*Using Dynamicquery  with two property(portletId and companyId), I got the Portletpreference Object. Then I stored my data into it.
thanks,
Saleem
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Mohamed, That is certainly one way to do it and I'm glad you got it solved. I am curious though, what would the scheduler need to store? and why for a specific portlet on a specific page only?Normally scheduled tasks are supposed to represent system level functions, like CRON jobs on a unix system. I've done a lot of work with them and the message bus (in Liferay) over the years and I have never had occasion to do something like you are describing so I am curious to understand more of what you are doing. Can you shed some light?
Mohamed Saleem, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
Hi Andrew Jardine,I have one custom portlet and added in multiple pages, I n this portlet I have to show 5 pages links per portlet (not current pages) in current site using asset category based calculation. The calculated value should be more than 70% matching the category of the current page. Every day scheduler will run at the time calculation will do and storing the plids in Portlet Preferences. To achieve this I want Portlet preference object, so i am using the below code to get portlet preferences.
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
                com.liferay.portal.kernel.model.PortletPreferences.class, PortalClassLoaderUtil.getClassLoader());
        dynamicQuery
                .add(PropertyFactoryUtil.forName("portletId").like("%" + SamplePortletKeys.Sample + "%"));
        List<com.liferay.portal.kernel.model.PortletPreferences> portletPreferences = PortletPreferencesLocalServiceUtil
                .dynamicQuery(dynamicQuery);
and looping out the portlet preferences. 

Regards,Saleem.
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Mohammed,Thanks for getting back to me emoticon. That's an interesting scenario. So let's say your portlet is on page x. The scheduler runs today, does some calculations a d sets 5 plids (excluding page x) for the portlet -- sounds like related assets in a way. When the job runs again tomorrow does it change the 5 links for the portlet on page x? Or are those links set the one time only .. but you run the job daily incase that same portlet is added to a different page?
Mohamed Saleem, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
Hi Andrew,Yes , changes depends on asset category and admin added  portlet in some other pages. If admin added the portlet to some other pages or change the asset category in page configuration , next schedule it should change,  for every time page is added to the preference, we increasing count of linked page. initially linked count should be zero. based on calculation i mentioned above, we sorted the list by ascending order and added in the portlet prefernce. 

thanks,
Saleem. 
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Interesting -- how long does this calculation take to run for any given page? I am asking for two reasons --
1. If it is pretty quick, then why not run it on render so that the links are always up to date and accurate? (but I am guessing perhaps it takes too long to calculate to do this?)
2. I'm inclined to agree with Olaf. You have it working which is great, but it's an odd solution. The reason I say that is because you have both a process that is changing portlet settings, but a user can also change the settings. The process will (eventually) win every time of course, but that could be confusing for a user that doesn't know about the process. If the category is the driving factor for the links, I'd be inclined to use service builder to generate a table/entity that stored the metrics and then get the portlets to read that table on render.

With that said, I'm still not entirely sure i understand your use case so perhaps my approach has some shortfalls that I am not clear on.
Mohamed Saleem, modified 4 Years ago.

RE: Can we get portletId and PlId without request object?

Junior Member Posts: 37 Join Date: 12/16/15 Recent Posts
Hi Andrew,I have asked one question related to remote staging, i am strucking to get data from remote server. can you please help me. please go through this link https://liferay.dev/forums/-/message_boards/message/57220126