Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Anil T
How to check id is user id or group id ?
February 20, 2013 7:16 AM
Answer

Anil T

Rank: Expert

Posts: 294

Join Date: January 14, 2012

Recent Posts

Hi,

I have a string array which has user ids and group ids. So how can we separate the group ids and user ids ?
Hitoshi Ozawa
RE: How to check id is user id or group id ?
February 20, 2013 1:56 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

I have a string array which has user ids and group ids. So how can we separate the group ids and user ids ?


Liferay doesn't mix user ids with group ids. Rewrite your program so user ids and group ids are in different String array.
Samuel Kong
RE: How to check id is user id or group id ?
February 21, 2013 12:31 AM
Answer

Samuel Kong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1476

Join Date: March 10, 2008

Recent Posts

I agree with Hitoshi's suggestion. But if you must,

1Group group = GroupLocalServiceUtil.getGroup(id);
2if (group.isUser()) {
3    ...
4}
5else if (group.isUserGroup()) {
6    ...
7}
Meera Prince
RE: How to check id is user id or group id ?
February 21, 2013 1:47 AM
Answer

Meera Prince

Rank: Liferay Legend

Posts: 1110

Join Date: February 8, 2011

Recent Posts

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
com.liferay.portal.model.Group currentGroup = themeDisplay.getLayout().getGroup();
if (currentGroup.isOrganization()){
................
}
if (currentGroup.isCommunity() {
............
}

if (currentGroup .isUser()) {
.........................
}

if (currentGroup .isUserGroup()) {

....................
}

Regards
Meera Prince
Hitoshi Ozawa
RE: How to check id is user id or group id ?
February 21, 2013 2:15 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Well, he has an array of String so he'll have to convert a String to a long too. Not very efficient.
Anil T
RE: How to check id is user id or group id ?
February 21, 2013 7:11 AM
Answer

Anil T

Rank: Expert

Posts: 294

Join Date: January 14, 2012

Recent Posts

Thanks for your response Hitoshi. I have a string array which have either user id or group id. I have written the below code for this,

try {
GroupLocalServiceUtil.getGroup(id);
communityId =id;
} catch(Exception e){
userId = id;
}

I have handled the case like the above, but I need some other ways to handle the same case. And suggest me that can I write the code like this code ? Is there any problem with above code ?
Siby Mathew
RE: How to check id is user id or group id ?
February 21, 2013 8:32 AM
Answer

Siby Mathew

Rank: Expert

Posts: 267

Join Date: March 4, 2011

Recent Posts

Hi Anil,
Can you please elaborate on your functionality.
Who populates this string array of userid+groupId ? Why is it grouped together in the first place ?
Also these ids can change if the same user/group gets deleted and added.

Thanks,
Siby