Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gwowen Fu
How to get UserID in BasePortletDataHandler.importData()?
June 20, 2012 9:12 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

Hi,

Based on the Sample-lar-portlet project, I have a class extending BasePortletDataHandler to add UserGroup when exportData() is called during Import.

I am calling UserGroupLocalServiceUtil.addUserGroup(userId, companyId, name, description) to add a user group but it requires a userId.

How could I get the current user's user id inside importData?
public String exportData(PortletDataContext context, String portletId, PortletPreferences preferences) throws PortletDataException;

I see context.getUserIdStrategy() can return UserIdStrategy which can return userId by providing userUuid;
How could I get the UUID?

Is there ant way I can get user ID?

Thanks!
Gwowen
David H Nebinger
RE: How to get UserID in BasePortletDataHandler.importData()?
June 20, 2012 9:19 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 12529

Join Date: September 1, 2006

Recent Posts

Don't you have these concepts kinda reversed?

On export, you'd be exporting the user group information so you'd have the user id available.

On import, here's where you'd call the UserGroupLocalServiceUtil.addUserGroup() method because you're importing a user group and the import has the user id to use...
Gwowen Fu
RE: How to get UserID in BasePortletDataHandler.importData()?
June 20, 2012 9:39 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

David H Nebinger:

On export, you'd be exporting the user group information so you'd have the user id available.

There is no user id when I exporting UserGroup. UserGroup table doesn't have user id. It only has "userGroupId", "companyId", "parentUserGroupId", "name", "description", "addedByLDAPImport".

I don't understand why user id is needed for inserting UserGroup. Is there any other table involved?

Thanks!
Gwowen
David H Nebinger
RE: How to get UserID in BasePortletDataHandler.importData()?
June 20, 2012 10:06 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 12529

Join Date: September 1, 2006

Recent Posts

Sure, adding a user group at least involves adding a group, adding resources, adding permissions, ...

Check out the logic in the source for com.liferay.portal.service.impl.UserGroupLocalServiceImpl to trace through everything that happens...
Gwowen Fu
RE: How to get UserID in BasePortletDataHandler.importData()?
June 21, 2012 2:26 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

David H Nebinger:
Sure, adding a user group at least involves adding a group, adding resources, adding permissions, ...

Check out the logic in the source for com.liferay.portal.service.impl.UserGroupLocalServiceImpl to trace through everything that happens...


Thanks, I found the answer there.