Example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getCompanyGroup

List of usage examples for com.liferay.portal.kernel.service GroupLocalServiceUtil getCompanyGroup

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getCompanyGroup.

Prototype

public static com.liferay.portal.kernel.model.Group getCompanyGroup(long companyId)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the company group.

Usage

From source file:com.liferay.exportimport.resources.importer.internal.util.BaseImporter.java

License:Open Source License

@Override
public void afterPropertiesSet() throws Exception {
    User user = UserLocalServiceUtil.getDefaultUser(companyId);

    userId = user.getUserId();/*from   ww w. j  ava  2 s  . c  om*/

    if (isCompanyGroup()) {
        return;
    }

    Group group = null;

    if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
        LayoutSetPrototype layoutSetPrototype = getLayoutSetPrototype(companyId, targetValue);

        if (layoutSetPrototype != null) {
            existing = true;
        } else {
            layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(userId, companyId,
                    getTargetValueMap(), new HashMap<Locale, String>(), true, true, new ServiceContext());
        }

        group = layoutSetPrototype.getGroup();

        targetClassPK = layoutSetPrototype.getLayoutSetPrototypeId();
    } else if (targetClassName.equals(Group.class.getName())) {
        if (targetValue.equals(GroupConstants.GLOBAL)) {
            group = GroupLocalServiceUtil.getCompanyGroup(companyId);
        } else if (targetValue.equals(GroupConstants.GUEST)) {
            group = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);

            List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false,
                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, false, 0, 1);

            if (!layouts.isEmpty()) {
                Layout layout = layouts.get(0);

                LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

                List<String> portletIds = layoutTypePortlet.getPortletIds();

                if (portletIds.size() != 2) {
                    existing = true;
                }

                for (String portletId : portletIds) {
                    if (!portletId.equals("47") && !portletId.equals("58")) {

                        existing = true;
                    }
                }
            }
        } else {
            group = GroupLocalServiceUtil.fetchGroup(companyId, targetValue);

            if (group != null) {
                int privateLayoutPageCount = group.getPrivateLayoutsPageCount();

                int publicLayoutPageCount = group.getPublicLayoutsPageCount();

                if ((privateLayoutPageCount != 0) || (publicLayoutPageCount != 0)) {

                    existing = true;
                }
            } else {
                group = GroupLocalServiceUtil.addGroup(userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
                        StringPool.BLANK, GroupConstants.DEFAULT_PARENT_GROUP_ID,
                        GroupConstants.DEFAULT_LIVE_GROUP_ID, getMap(targetValue), null,
                        GroupConstants.TYPE_SITE_OPEN, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
                        null, true, true, new ServiceContext());
            }
        }

        targetClassPK = group.getGroupId();
    }

    if (group != null) {
        groupId = group.getGroupId();
    }
}

From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java

License:Open Source License

@Test
public void testExportImportDisplayStyleFromGlobalScope() throws Exception {
    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(group.getCompanyId());

    testExportImportDisplayStyle(companyGroup.getGroupId(), "company");
}

From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java

License:Open Source License

protected void testExportImportDisplayStyle(long displayStyleGroupId, String scopeType) throws Exception {

    Portlet portlet = PortletLocalServiceUtil.getPortletById(group.getCompanyId(), getPortletId());

    if (portlet == null) {
        return;//from w ww  . java  2  s.  com
    }

    if (scopeType.equals("layout") && !portlet.isScopeable()) {
        Assert.assertTrue("This test does not apply", true);

        return;
    }

    TemplateHandler templateHandler = portlet.getTemplateHandlerInstance();

    if ((templateHandler == null) || !templateHandler.isDisplayTemplateHandler()) {

        Assert.assertTrue("This test does not apply", true);

        return;
    }

    String className = templateHandler.getClassName();
    long resourceClassNameId = PortalUtil
            .getClassNameId("com.liferay.portlet.display.template.PortletDisplayTemplate");

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(displayStyleGroupId,
            PortalUtil.getClassNameId(className), 0, resourceClassNameId);

    Map<String, String[]> preferenceMap = new HashMap<>();

    String displayStyle = PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX + ddmTemplate.getTemplateKey();

    preferenceMap.put("displayStyle", new String[] { displayStyle });

    preferenceMap.put("displayStyleGroupId", new String[] { String.valueOf(ddmTemplate.getGroupId()) });

    if (scopeType.equals("layout")) {
        preferenceMap.put("lfrScopeLayoutUuid", new String[] { this.layout.getUuid() });
    }

    preferenceMap.put("lfrScopeType", new String[] { scopeType });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    String importedDisplayStyle = portletPreferences.getValue("displayStyle", StringPool.BLANK);

    Assert.assertEquals(displayStyle, importedDisplayStyle);

    long importedDisplayStyleGroupId = GetterUtil
            .getLong(portletPreferences.getValue("displayStyleGroupId", null));

    long expectedDisplayStyleGroupId = importedGroup.getGroupId();

    if (scopeType.equals("company")) {
        Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(importedGroup.getCompanyId());

        expectedDisplayStyleGroupId = companyGroup.getGroupId();
    } else if (displayStyleGroupId != group.getGroupId()) {
        expectedDisplayStyleGroupId = displayStyleGroupId;
    }

    Assert.assertEquals(expectedDisplayStyleGroupId, importedDisplayStyleGroupId);
}

From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java

License:Open Source License

protected void initImport(Group exportGroup, Group importGroup) throws Exception {

    userIdStrategy = new TestUserIdStrategy();

    zipReader = ZipReaderFactoryUtil.getZipReader(zipWriter.getFile());

    String xml = zipReader.getEntryAsString("/manifest.xml");

    if (xml == null) {
        Document document = SAXReaderUtil.createDocument();

        Element rootElement = document.addElement("root");

        rootElement.addElement("header");

        zipWriter.addEntry("/manifest.xml", document.asXML());

        zipReader = ZipReaderFactoryUtil.getZipReader(zipWriter.getFile());
    }//from w  w  w .  ja va 2  s.co m

    portletDataContext = PortletDataContextFactoryUtil.createImportPortletDataContext(
            importGroup.getCompanyId(), importGroup.getGroupId(), getParameterMap(), userIdStrategy, zipReader);

    portletDataContext.setExportImportProcessId(BaseStagedModelDataHandlerTestCase.class.getName());
    portletDataContext.setImportDataRootElement(rootElement);

    Element missingReferencesElement = rootElement.element("missing-references");

    if (missingReferencesElement == null) {
        missingReferencesElement = rootElement.addElement("missing-references");
    }

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    Group sourceCompanyGroup = GroupLocalServiceUtil.getCompanyGroup(exportGroup.getCompanyId());

    portletDataContext.setSourceCompanyGroupId(sourceCompanyGroup.getGroupId());

    portletDataContext.setSourceCompanyId(exportGroup.getCompanyId());
    portletDataContext.setSourceGroupId(exportGroup.getGroupId());
}

From source file:com.liferay.journal.service.test.BaseJournalServiceTestCase.java

License:Open Source License

protected long getCompanyGroupId() throws Exception {
    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(companyId);

    return companyGroup.getGroupId();
}

From source file:com.liferay.microblogs.web.internal.asset.MicroblogsEntryAssetRenderer.java

License:Open Source License

@Override
public long getGroupId() {
    try {//from  www. j  ava2  s  .  c  o  m
        Group group = GroupLocalServiceUtil.getCompanyGroup(_entry.getCompanyId());

        return group.getGroupId();
    } catch (Exception e) {
    }

    return 0;
}

From source file:com.liferay.mobile.device.rules.service.persistence.impl.MDRRuleGroupFinderImpl.java

License:Open Source License

protected void setGroupIds(QueryPos qPos, long groupId, Map<String, Object> params) throws PortalException {

    Boolean includeGlobalScope = (Boolean) params.get("includeGlobalScope");

    if ((includeGlobalScope != null) && includeGlobalScope) {
        qPos.add(groupId);//  www  .j  a  v  a 2s  . co  m

        Group group = GroupLocalServiceUtil.getGroup(groupId);

        Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(group.getCompanyId());

        qPos.add(companyGroup.getGroupId());
    } else {
        qPos.add(groupId);
    }
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.test.RoleStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected void initExport() throws Exception {
    super.initExport();

    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

    rootElement.addAttribute("company-group-id", String.valueOf(companyGroup.getGroupId()));

    Group userPersonalSiteGroup = GroupLocalServiceUtil
            .getUserPersonalSiteGroup(portletDataContext.getCompanyId());

    rootElement.addAttribute("user-personal-site-group-id", String.valueOf(userPersonalSiteGroup.getGroupId()));
}

From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java

License:Open Source License

@Test
public void testAddCompanyStagingGroup() throws Exception {
    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(TestPropsValues.getCompanyId());

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAttribute("staging", Boolean.TRUE);

    Group companyStagingGroup = GroupLocalServiceUtil.addGroup(TestPropsValues.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID, companyGroup.getClassName(), companyGroup.getClassPK(),
            companyGroup.getGroupId(), companyGroup.getNameMap(), companyGroup.getDescriptionMap(),
            companyGroup.getType(), companyGroup.isManualMembership(), companyGroup.getMembershipRestriction(),
            companyGroup.getFriendlyURL(), false, companyGroup.isActive(), serviceContext);

    try {/*from   w w  w .ja va2  s .  c  o m*/
        Assert.assertTrue(companyStagingGroup.isCompanyStagingGroup());

        Assert.assertEquals(companyGroup.getGroupId(), companyStagingGroup.getLiveGroupId());
    } finally {
        GroupLocalServiceUtil.deleteGroup(companyStagingGroup);
    }
}

From source file:com.liferay.site.service.persistence.test.GroupServiceUserSitesGroupsTest.java

License:Open Source License

@Test
public void testCompanyGroup() throws Exception {
    _user = UserTestUtil.addUser();//from w  w  w . j a v  a 2  s. c  o  m

    List<Group> groups = GroupServiceUtil.getUserSitesGroups(_user.getUserId(), null, QueryUtil.ALL_POS);

    Group group = GroupLocalServiceUtil.getCompanyGroup(_user.getCompanyId());

    Assert.assertTrue(groups + " does not contain " + group, groups.contains(group));
}