Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Arvind Mishra
How to get current organization name
November 4, 2008 8:38 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 220

Join Date: February 13, 2008

Recent Posts

Hi

How can i get the current organization name .. in which i am right now .

Actually i want to sent to user the login page of the current orgnazation when he logs out of this organization

I have written this piece of code in LogoutPostAction.java
 1
 2                 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
 3          com.liferay.portal.model.Group currentGroup =  themeDisplay.getLayout().getGroup();
 4            if (currentGroup.isUser()) {
 5             // the group is a private user community
 6             // getting the userId of the group's owner is
 7              long userId = currentGroup.getClassPK();
 8              System.out.println("user group - user id :" +  userId );
 9            }
10            else if (currentGroup.isOrganization()) {
11              // the group is an Organization
12              long organizationId = currentGroup.getClassPK();
13              System.out.println("Organization group - organizationId  :" +  organizationId );
14            }
15            else {
16             // its a normal community
17                System.out.println("its a normal community");
18            }


but it prints

user group - user id :10134

Why its taking this organization as private user community .

thanks
arvind
Mallepula NarayanaGoud
RE: How to get current organizationId
September 22, 2010 8:15 AM
Answer

Mallepula NarayanaGoud

Rank: Junior Member

Posts: 95

Join Date: June 18, 2009

Recent Posts

Hi Arvind,

How can i get the current organizationId.. in which i am right now .

Actually i trying to build menu for individual organization, when user login to an organization menu is build.

But when an user is assign to multiple organizations, I want current organizationId of an organization were user is trying to login so that i can build menu.

Thanks in Advance.....

Thanks,
Narayana.
Arvind Mishra
RE: How to get current organizationId
September 22, 2010 11:34 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 220

Join Date: February 13, 2008

Recent Posts

Above mentioned code should work

Otherwise u can get group id from themeDisplay.getScopeGroupId(). if group is organization then scope group id is your organizationid
Apoorva Prakash
RE: How to get current organizationId
September 22, 2010 11:21 PM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Hello Arvind,
you are right... But please consider the following code snippet too...

1ThemeDisplay td = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
2User u=td.getUser();
3System.out.println(u.getOrganizationIds());


Thanks and regards...
Mallepula NarayanaGoud
RE: How to get current organizationId
September 23, 2010 12:51 AM
Answer

Mallepula NarayanaGoud

Rank: Junior Member

Posts: 95

Join Date: June 18, 2009

Recent Posts

Hi Arvind,

It is working fine!!!!!!
Thanks alot...

Thanks,
Narayana.
Mallepula NarayanaGoud
RE: How to get current organizationId
September 23, 2010 12:52 AM
Answer

Mallepula NarayanaGoud

Rank: Junior Member

Posts: 95

Join Date: June 18, 2009

Recent Posts

Hi Prakesh,

It is working fine!!!!!!
Thanks alot for Quick Response...

Thanks,
Narayana.
Apoorva Prakash
RE: How to get current organizationId
September 23, 2010 2:59 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Mallepula NarayanaGoud:
Hi Prakesh,

It is working fine!!!!!!
Thanks alot for Quick Response...

Thanks,
Narayana.


Welcome Narayana...
Arvind Mishra
RE: How to get current organizationId
September 23, 2010 7:09 AM
Answer

Arvind Mishra

Rank: Regular Member

Posts: 220

Join Date: February 13, 2008

Recent Posts

If you need to get the User , you can get it from HttpServletRequest itself.

User u = PortalUtil.getUser(request);
Gregg Archer
RE: How to get current organizationId
June 20, 2011 9:25 AM
Answer

Gregg Archer

Rank: New Member

Posts: 2

Join Date: June 20, 2011

Recent Posts

Arvind Mishra:
Otherwise u can get group id from themeDisplay.getScopeGroupId(). if group is organization then scope group id is your organizationid


Thanks to Arvind's tip about getScopeGroupId(), I found that #theme_display.getScopeGroupName() was exactly what I needed to put the current org's name into a page title.
Hiran Chaudhuri
RE: How to get current organizationId
October 12, 2011 2:50 AM
Answer

Hiran Chaudhuri

Rank: Regular Member

Posts: 174

Join Date: September 1, 2010

Recent Posts

Arvind Mishra:
Above mentioned code should work

Otherwise u can get group id from themeDisplay.getScopeGroupId(). if group is organization then scope group id is your organizationid

Hello, Arvind.

I do have the same problem, and your response sounds promising.
The scope group in my page looke like this (toString called):
{groupId=18, companyId=1, creatorUserId=5, classNameId=9, classPK=18, parentGroupId=0, liveGroupId=0, name=Guest, description=, type=1, typeSettings=, friendlyURL=/guest, active=true}

Now how would I detect from that whether I have an organization, a community or a private user page?
Sandeep Nair
RE: How to get current organizationId
October 12, 2011 3:10 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1692

Join Date: November 5, 2008

Recent Posts

Use GroupLocalServiceUtil for example

GroupLocalServiceUtil.getGroup(groupId).isOrganization() --> tells whether its Organization
GroupLocalServiceUtil.getGroup(groupId).isCommunity() --> tells whether its Community
GroupLocalServiceUtil.getGroup(groupId).isUser() --> tells whether its Usr

Regards,
Sandeep
Hiran Chaudhuri
RE: How to get current organization name
October 12, 2011 3:19 AM
Answer

Hiran Chaudhuri

Rank: Regular Member

Posts: 174

Join Date: September 1, 2010

Recent Posts

Thank you for that quick help, Sandeep.

At the same time I also found http://www.liferay.com/community/forums/-/message_boards/message/10790380, in which they say you can simply use

Group currentGroup = themeDisplay.getLayout().getGroup();
currentGroup.isCommunity(), .isOrganization(), .isUser()
Juan Camilo Carrillo Casas
RE: How to get current organization name
March 7, 2013 8:34 AM
Answer

Juan Camilo Carrillo Casas

Rank: New Member

Posts: 1

Join Date: March 7, 2013

Recent Posts

To get the Site/Group Name always and not "Guest" use this:

group.getDescriptiveName()

I found the use of this method in the source code of Liferay, in dockbar view.jsp code you can see the use of them:

/portal-web/docroot/html/portlet/dockbar/view.jsp

Look at this fragment of code in line 22.

 1
 2<%
 3            String refererGroupDescriptiveName = null;
 4            String backURL = null;
 5
 6            if (themeDisplay.getRefererPlid() > 0) {
 7                Layout refererLayout = LayoutLocalServiceUtil.fetchLayout(themeDisplay.getRefererPlid());
 8
 9                if (refererLayout != null) {
10                    Group refererGroup = refererLayout.getGroup();
11
12                    if (refererGroup.isUserGroup()) {
13                        Group scopeGroup = themeDisplay.getScopeGroup();
14
15                        if (scopeGroup.isUser()) {
16                            refererGroup = scopeGroup;
17
18                            refererLayout = new VirtualLayout(refererLayout, refererGroup);
19                        }
20                    }
21
22                    refererGroupDescriptiveName = refererGroup.getDescriptiveName(locale);
23
24                    if (refererGroup.isUser() && (refererGroup.getClassPK() == user.getUserId())) {
25                        if (refererLayout.isPublicLayout()) {
26                            refererGroupDescriptiveName = LanguageUtil.get(pageContext, "my-public-pages");
27                        }
28                        else {
29                            refererGroupDescriptiveName = LanguageUtil.get(pageContext, "my-private-pages");
30                        }
31                    }
32
33                    backURL = PortalUtil.getLayoutURL(refererLayout, themeDisplay);
34
35                    if (!CookieKeys.hasSessionId(request)) {
36                        backURL = PortalUtil.getURLWithSessionId(backURL, session.getId());
37                    }
38                }
39            }
40%>