Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Tanaji Londhe
How to get OrganizationId after login?
12. Juli 2012 00:08
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi,

How to access organizationId in my porltet class after successful login.

Thanks,
Tanaji.
Amit Doshi
RE: How to get OrganizationId after login?
12. Juli 2012 00:41
Antwort

Amit Doshi

Rang: Liferay Master

Nachrichten: 544

Eintrittsdatum: 29. Dezember 2010

Neue Beiträge

Hi Tanaji,

You can check using below code snippet.

ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
if(themeDisplay.isSignedIn())
{
// Check the OrganizationLocalServiceUtil Class and use the method that meets your requirement.
}

Hope it helps.

Thanks & Regards,
Amit Doshi
Jitendra Rajput
RE: How to get OrganizationId after login?
12. Juli 2012 01:18
Antwort

Jitendra Rajput

Rang: Liferay Master

Nachrichten: 709

Eintrittsdatum: 7. Januar 2011

Neue Beiträge

If you need current Group/organization/community id then you can directly get it using ThemeDisplay

1
2ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
3themeDisplay.getScopeGroupId()
Tanaji Londhe
RE: How to get OrganizationId after login?
13. Juli 2012 03:18
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Amit Doshi:
Hi Tanaji,

You can check using below code snippet.

ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
if(themeDisplay.isSignedIn())
{
// Check the OrganizationLocalServiceUtil Class and use the method that meets your requirement.
}

Hope it helps.

Thanks & Regards,
Amit Doshi


Hi Amit,
If I use this code OrganizationLocalServiceUtil.getOrganizationId(companyId, name) what is second String name parameter.

Thanks,
Tanaji.
Tanaji Londhe
RE: How to get OrganizationId after login?
13. Juli 2012 03:22
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Jitendra Rajput:
If you need current Group/organization/community id then you can directly get it using ThemeDisplay

1
2ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
3themeDisplay.getScopeGroupId()



Hi Jitendra,

It doesnt give me OrgnizationId. It gives another id becuse I check in db table.

Thanks,
Tanaji
Jignesh Vachhani
RE: How to get OrganizationId after login?
13. Juli 2012 04:49
Antwort

Jignesh Vachhani

Rang: Liferay Master

Nachrichten: 780

Eintrittsdatum: 10. März 2008

Neue Beiträge

you can use below code to get organization id of logged in user :


1ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
2themeDisplay.getUser().getOrganizations();


Here you will get list of organization ids for login user.
Tejas Kanani
RE: How to get OrganizationId after login?
13. Juli 2012 04:39
Antwort

Tejas Kanani

Rang: Liferay Master

Nachrichten: 653

Eintrittsdatum: 6. Januar 2009

Neue Beiträge

This might help,

1
2ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
3Group group = themeDisplay.getScopeGroup();
4long organizationId = 0;
5if(group.isOrganization()) {
6     organizationId = group.getOrganizationId();
7}
Tanaji Londhe
RE: How to get OrganizationId after login?
13. Juli 2012 05:41
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi,
Hi Tejas I use your code but it gives me 0 value.

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
List<Organization> list = OrganizationLocalServiceUtil.getUserOrganizations(userId) ;
Iterator<Organization> iterator = list.iterator();
while(iterator.hasNext()) {
organizationId = iterator.next().getOrganizationId();
}

I use this code.

This method is also useful as Amit said in above post "OrganizationLocalServiceUtil.getOrganizationId(companyId, name)" .
Tejas Kanani
RE: How to get OrganizationId after login?
13. Juli 2012 06:08
Antwort

Tejas Kanani

Rang: Liferay Master

Nachrichten: 653

Eintrittsdatum: 6. Januar 2009

Neue Beiträge

It's good that its working for you now.
And if you have created any organization(not Site) and if you put your portlet in any of its page.
If you try to get organizationId using my code, ideally it should return you desired organizationId.
Tanaji Londhe
RE: How to get OrganizationId after login?
13. Juli 2012 23:22
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hi Tejas,

As you said, I create 1 Organization and 1 user as a Admin for the that org.
I use following code snippet
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
Group group = themeDisplay.getScopeGroup();
long organizationId = 0;
if(group.isOrganization()) {
organizationId = group.getOrganizationId();
System.out.println("-----------------> organizationId = "+organizationId);
}

Still it will give me orgId=0. I think my organization is not a group. Thats why it gives me zero value.
Hitoshi Ozawa
RE: How to get OrganizationId after login?
14. Juli 2012 01:48
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7990

Eintrittsdatum: 23. März 2010

Neue Beiträge

How to access organizationId in my porltet class after successful login.


If you only want to get organizationId of user who logged in, just get the user from themeDisplay and get organizationId.

User user2 = themeDisplay.getUser();
long[] orgId = user2.getOrganizationIds();
Tanaji Londhe
RE: How to get OrganizationId after login?
14. Juli 2012 03:04
Antwort

Tanaji Londhe

Rang: Regular Member

Nachrichten: 196

Eintrittsdatum: 25. April 2012

Neue Beiträge

Hitoshi Ozawa:
How to access organizationId in my porltet class after successful login.


If you only want to get organizationId of user who logged in, just get the user from themeDisplay and get organizationId.

User user2 = themeDisplay.getUser();
long[] orgId = user2.getOrganizationIds();



Hi Hitoshi,

Thanks its working properly.

Thanks,
Tanaji
Jignesh Vachhani
RE: How to get OrganizationId after login?
15. Juli 2012 22:49
Antwort

Jignesh Vachhani

Rang: Liferay Master

Nachrichten: 780

Eintrittsdatum: 10. März 2008

Neue Beiträge

Doesn't look like the same code which i provided ?

ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay.getUser().getOrganizations();