Tips and Tricks for programming in Liferay Extended Environment – Part 1

Share

Hi there,

As my journey with Liferay continues I thought it would be a good idea to write down some.. let’s say, miscellaneous stuff that were apparently trivial, but turned out to consume much more time than expected. So, there is one for today (actually happened last week) and I will keep updating this blog with new ones that I find (or remember 😛 ).

Use EntityLocalServiceUtil instead of EntityUtil wherever possible

For example use UserLocalServiceUtil instead of UserUtil if you need to programmatically update user details.

Explanation: I wrote a feature for Liferay that automatically synchronizes Liferay’s internal users with an external source. So, basically wrote a class for Liferay in Extended Environment that periodically checks the user that exist (or don’t exist any more) in this external source. Each time a new user appears there, it is also created as a new user inside of Liferay and when a new user is deleted from the external source, its Liferay corespondent must be deactivated . (If it was already created).

So I thought this will do the trick:

bla bla bla
bla bla bla
user.setActive(false);
UserUtil.update(user, true);
// it has the same effect for this operation no matter if you user true of false for the merge parameter

rest of the bla

but it does it only half way.

While in updates the status internally (checked the database), the user still somehow remains active because it is still displayed in the active users in Control Panel. (It should be displayed if you filter by inactive users). And also, while it is displayed as active, it has the reactivate option in its context menu. I did not check if this inconsistency (guess I can call it that) disappears after restarting Liferay because it would not be a solution.

To fix this I changed the code into:
bla bla bla
bla bla bla
user.setActive(false);
UserLocalServiceUtil.updateActive(user.getUserId(), false);
// the second parameter tell whether you want to activate or deactivate it. I want to deactivate now

even more bla

This way it is updated correctly everywhere and works just fine.

Another example of the same kind would be to use
UserLocalServiceUtil.addUserGroupUsers(group.getUserGroupId(), new long[] {user.getUserId()});

instead of
UserGroupUtil.addUser(group.getUserGroupId(), user);

with the before and after bla, if you like to programmatically add a user in a user group. Same thing here. The second call adds the user internally but the operation is not visible when looking in the Assign Members area of a user group. The first call does the trick all the way.

Stay tuned for more.

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close