Forums de discussion

Combine hook and Service Builder

Lee Chamberlain, modifié il y a 7 années.

Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
Is it possible / straightforward to combine a hook and a service builder.

I'm creating a feedback forum to be filled on on logout, so I need to hook to create a pre logout event, but need the service builder to store the response in the database.

Thanks
Lee
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Combine hook and Service Builder

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Honestly no.

Under 6.x you could combine a portlet and a hook into a single plugin, under 7 this is not possible (well, if you use the legacy sdk maybe it can still be created, but the new OSGi module approach does not support it), but at runtime it just won't work.

JSP hooks apply to the ROOT context which does not have access to the service jar to invoke the service.

Under 6.x you'd have to push the service jar into the global class loader (introducing deployment issues) so the service is available within the ROOT context. In this scenario you can either bundle the hook w/ the SB portlet or not (doesn't matter).

Under 7 you can do a JSP hook via a bundle fragment but you still can't define a dependency on a service. You could, however, dynamically look up a service reference to use for a call, but even this can get a little murky (what do you do if you can't get a service instance, what is the overhead in repeating the lookup, ...).





Come meet me at the LSNA!
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
We're using 6.2
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
Could I do this by building a hook and a service builder separately?

1/Write a hook which redirects to a portlet on logout.
2/Temporarily retain the variables I need from a logged in user (email address, username etc..) after logout
3/Use the service builder to save the info I've collected in the feedback form.
4/Redirect to logout page after form submission.


Also I'd need to bipass the form if it's been filled in within a specified period of time, but I'm assuming if I can do 4/ then this wouldn't be a problem.
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Combine hook and Service Builder

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
It will not be easy to pass this info around. Logout itself invalidates the session, so session storage becomes questionable (I think session has already been whacked by the time a post login hook is invoked, but I haven't checked the sequencing lately).

Doing things on logout has always been tricky since a session timeout or closed browser or dropped internet connection all result in a logout, but there's no UI available to show the user anything or ask questions or ...

If I were building this, I'd probably continue w/ the post login hook but I'd be adding parameters for the redirect that would send user to a specific page; the params would be user id and whatever else needed to be passed. On that page would be my portlet that used the params for populating the form details and form submit to the portlet can invoke the SB to store the data. Since user has just logged out, you'd have to ensure that guest has all necessary permissions to see the portlet and add the record.






Come meet me at the LSNA!
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
Thanks, if I do a pre logout rather than a post logout will that change things?

I'm currently building into my run method a redirect which I'm hoping to pass the parameters to the next page (early days yet)


		PortletURL redirectURL = PortletURLFactoryUtil.create(request, portletId, plid, lifecycle)
		redirectURL.setParameter("email","");


Will my parameters still apply after a logout?
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Combine hook and Service Builder

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Params will not have anything to do w/ logout, they're URL parameters and their scope is the lifetime of the request.

Note that if you are redirecting on a pre-logout hook, you're basically preventing logout. You'll have to allow some mechanism for the pre logout hook to identify that the form has already been completed and not do the redirect otherwise you'll be stuck in an exit loop.





Come meet me at the LSNA!
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
I'll pseudo code my idea


if logout
show feedback form
complete logout on form submission

if logout and feedback form has been completed within 1 month
Don't show the form, and automatically complete logout

if no email or screenname params
redirect to home page (to prevent someone just accessing the page by typing in the URL)


I suppose the second part is the hardest part. Would passing some sort of boolean to confirm whether the form portlet has been viewed (in either the first or second part above) work?
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Combine hook and Service Builder

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
2nd part isn't that hard. You have the user id who is logging out, you can get the last form date through your SB code to see if it has been completed within a specific time frame and decide from there.







Come meet me at the LSNA!
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
Thanks


Will it be possible to get email address and other info about the user in the run method of a customprelogout or will that have been killed once logout was initiated?
thumbnail
David H Nebinger, modifié il y a 7 années.

RE: Combine hook and Service Builder

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
All you need is user id. When you have that, you can always pull up the User model object to access other fields.




Come meet me at the LSNA!
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
Thanks

Is it possible to write code that will log out a user as I need to? (just thinking of ways to avoid a loop).

Is it possible to kill a login session and then write a redirect without calling existing sign_out code?

Thanks
L
Lee Chamberlain, modifié il y a 7 années.

RE: Combine hook and Service Builder

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
If I redirect to /c/portal/logout , will that send me around a loop if I've got a redirect to the feedback in the prelogoutaction, or will the loop only occur if I've logged out using the sign_out in the theme?