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

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

Introduction

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

Prototype

public static com.liferay.portal.kernel.model.Group addGroup(long userId, long parentGroupId, String className,
            long classPK, long liveGroupId, java.util.Map<java.util.Locale, String> nameMap,
            java.util.Map<java.util.Locale, String> descriptionMap, int type, boolean manualMembership,
            int membershipRestriction, String friendlyURL, boolean site, boolean active,
            ServiceContext serviceContext) throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Usage

From source file:com.liferay.asset.service.test.AssetTagFinderTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    _group = GroupTestUtil.addGroup();/*w ww. j a  v a  2s  .co m*/

    Layout layout = LayoutTestUtil.addLayout(_group);

    Map<Locale, String> nameMap = new HashMap<>();

    String name = RandomTestUtil.randomString();

    nameMap.put(LocaleUtil.getDefault(), name);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    _scopeGroup = GroupLocalServiceUtil.addGroup(TestPropsValues.getUserId(), _group.getParentGroupId(),
            Layout.class.getName(), layout.getPlid(), GroupConstants.DEFAULT_LIVE_GROUP_ID, nameMap,
            RandomTestUtil.randomLocaleStringMap(), GroupConstants.TYPE_SITE_OPEN, true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(name), false, true, serviceContext);
}

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   w  w w .ja  v a2  s  .  c o  m*/

    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.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 v  a 2 s  .co  m
        Assert.assertTrue(companyStagingGroup.isCompanyStagingGroup());

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

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

License:Open Source License

@Test
public void testScopes() throws Exception {
    Group group = GroupTestUtil.addGroup();

    Layout layout = LayoutTestUtil.addLayout(group);

    Assert.assertFalse(layout.hasScopeGroup());

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getDefault(), layout.getName(LocaleUtil.getDefault()));

    Group scope = GroupLocalServiceUtil.addGroup(TestPropsValues.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID, Layout.class.getName(), layout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID, nameMap, (Map<Locale, String>) null, 0, true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false, true, null);

    Assert.assertFalse(scope.isRoot());/*  www.  ja v  a2 s .  co m*/
    Assert.assertEquals(scope.getParentGroupId(), group.getGroupId());

    GroupLocalServiceUtil.deleteGroup(scope);

    GroupLocalServiceUtil.deleteGroup(group);
}

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

License:Open Source License

protected Group addScopeGroup(Group group) throws Exception {
    Layout scopeLayout = LayoutTestUtil.addLayout(group);

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString());

    return GroupLocalServiceUtil.addGroup(TestPropsValues.getUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(), scopeLayout.getPlid(), GroupConstants.DEFAULT_LIVE_GROUP_ID, nameMap,
            (Map<Locale, String>) null, 0, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false,
            true, null);/*from w  ww.j  a va2s .  c  om*/
}

From source file:com.liferay.trash.service.test.TrashEntryLocalServiceCheckEntriesTest.java

License:Open Source License

protected Group createLayoutGroup(Group group) throws Exception {
    User user = UserTestUtil.getAdminUser(group.getCompanyId());
    Layout layout = LayoutTestUtil.addLayout(group);

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getDefault(), String.valueOf(layout.getPlid()));

    return GroupLocalServiceUtil.addGroup(user.getUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(), layout.getPlid(), GroupConstants.DEFAULT_LIVE_GROUP_ID, nameMap,
            (Map<Locale, String>) null, 0, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false,
            true, null);// ww w .  j a va2 s  . c  o m
}