How to get global (company) group id in Liferay?

前端 未结 4 1307
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 04:27

How to get the global (company) group id in Liferay without accessing ThemeDisplay?

P.S.: with ThemeDisplay it is simple: themeDisplay.ge

4条回答
  •  轮回少年
    2021-02-08 04:51

    Extending yellow's answer, you can find the company if you know some value of the Portal Instance (Company):

    1. If you know the webId of the Portal Instance, can find company by:

      String webId = "liferay.com"; // PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID)
      Company company = CompanyLocalServiceUtil.getCompanyByWebId(webId);
      long globalGroupId = company.getGroup().getGroupId();
      
    2. If you know the mail-domain of the Portal Instance, can find company by:

      String mailDomain = "liferay.com";
      Company company = CompanyLocalServiceUtil.getCompanyByMx(mailDomain);
      long globalGroupId = company.getGroup().getGroupId();
      
    3. If you know the virtual host of the Portal Instance, can find company 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 Yellow for the lead, it was really helpful.

提交回复
热议问题