[ACCEPTED]-How to get global (company) group id in Liferay?-global
When you have only one Company
in your portal:
Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long globalGroupId = company.getGroup().getGroupId();
0
Extending yellow's answer, you can find the company
if 6 you know some value of the Portal Instance 5 (Company
):
If you know the
webId
of the Portal Instance, can 4 findcompany
by:String webId = "liferay.com"; // PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID) Company company = CompanyLocalServiceUtil.getCompanyByWebId(webId); long globalGroupId = company.getGroup().getGroupId();
If you know the
mail-domain
of the Portal 3 Instance, can findcompany
by:String mailDomain = "liferay.com"; Company company = CompanyLocalServiceUtil.getCompanyByMx(mailDomain); long globalGroupId = company.getGroup().getGroupId();
If you know the
virtual host
of 2 the Portal Instance, can findcompany
by:String virtualHost = "localhost"; Company company = CompanyLocalServiceUtil.getCompanyByVirtualHost(virtualHost); long globalGroupId = company.getGroup().getGroupId();
There are also other useful methods available to explore in CompanyLocalServiceUtil
, for those who are interested.
Thanks 1 Yellow for the lead, it was really helpful.
You can use the following :
GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId()).getGroupId();
0
If you need this info for Document Library, you 1 can use
public static long getDefaultCompanyId(){
long companyId = 0;
try{ companyId = getDefaultCompany().getCompanyId(); }
catch(Exception e){ System.out.println(e.getClass() + " " +e.getMessage()); }
return companyId;
}
public static long getDefaultGroupId (){
long companyId = getDefaultCompanyId();
long globalGroupId = 0L;
Group group = null;
try {
group = GroupLocalServiceUtil.getGroup(companyId, "Guest");
} catch (PortalException | SystemException e) {
e.printStackTrace();
return globalGroupId;
}
globalGroupId = group.getGroupId();
return globalGroupId;
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.