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

前端 未结 4 1213
爱一瞬间的悲伤
爱一瞬间的悲伤 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 05:03

    If you need this info for Document Library, you 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;
    }
    

提交回复
热议问题