Example usage for com.liferay.portal.kernel.service UserLocalServiceUtil addOrganizationUsers

List of usage examples for com.liferay.portal.kernel.service UserLocalServiceUtil addOrganizationUsers

Introduction

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

Prototype

public static void addOrganizationUsers(long organizationId, long[] userIds)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Usage

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

License:Open Source License

@Test
public void testDeleteOrganizationSiteOnlyRemovesSiteRoles() throws Exception {

    Organization organization = OrganizationLocalServiceUtil.addOrganization(TestPropsValues.getUserId(),
            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, RandomTestUtil.randomString(), true);

    Group organizationSite = GroupLocalServiceUtil.getOrganizationGroup(TestPropsValues.getCompanyId(),
            organization.getOrganizationId());

    organizationSite.setManualMembership(true);

    User user = UserTestUtil.addOrganizationOwnerUser(organization);

    UserLocalServiceUtil.addGroupUser(organizationSite.getGroupId(), user.getUserId());
    UserLocalServiceUtil.addOrganizationUsers(organization.getOrganizationId(),
            new long[] { user.getUserId() });

    Role siteRole = RoleTestUtil.addRole(RoleConstants.TYPE_SITE);

    UserGroupRoleLocalServiceUtil.addUserGroupRoles(user.getUserId(), organizationSite.getGroupId(),
            new long[] { siteRole.getRoleId() });

    GroupLocalServiceUtil.deleteGroup(organizationSite);

    Assert.assertEquals(1, UserGroupRoleLocalServiceUtil.getUserGroupRolesCount(user.getUserId(),
            organizationSite.getGroupId()));

    UserLocalServiceUtil.deleteUser(user);

    OrganizationLocalServiceUtil.deleteOrganization(organization);
}

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

License:Open Source License

@Test
public void testInactiveOrganizationGroup() throws Exception {
    _user = UserTestUtil.addUser();//from  w  w w .  ja v a2 s  . c om

    Organization organization = OrganizationTestUtil.addOrganization(true);

    _organizations.addFirst(organization);

    UserLocalServiceUtil.addOrganizationUsers(organization.getOrganizationId(),
            new long[] { _user.getUserId() });

    Group group = organization.getGroup();

    LayoutTestUtil.addLayout(group);

    group = GroupLocalServiceUtil.getGroup(group.getGroupId());

    group.setActive(false);

    GroupLocalServiceUtil.updateGroup(group);

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

    Assert.assertFalse(groups + " contains " + group, groups.contains(group));
}

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

License:Open Source License

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

    Organization parentOrganization = OrganizationTestUtil.addOrganization(true);

    Group parentOrganizationGroup = parentOrganization.getGroup();

    _organizations.addFirst(parentOrganization);

    Organization organization = OrganizationTestUtil.addOrganization(parentOrganization.getOrganizationId(),
            RandomTestUtil.randomString(), false);

    _organizations.addFirst(organization);

    UserLocalServiceUtil.addOrganizationUsers(organization.getOrganizationId(),
            new long[] { _user.getUserId() });

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

        Group organizationGroup = organization.getGroup();

        Assert.assertTrue(groups + " does not contain " + parentOrganizationGroup,
                groups.contains(parentOrganizationGroup));
        Assert.assertFalse(groups + " contains " + organizationGroup, groups.contains(organizationGroup));
    } finally {
        UserLocalServiceUtil.unsetOrganizationUsers(organization.getOrganizationId(),
                new long[] { _user.getUserId() });
    }
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

/**
 * Adds the users to the organization./*from   w ww .j av a  2 s . co m*/
 *
 * @param organizationId the primary key of the organization
 * @param userIds the primary keys of the users
 */
protected void addOrganizationUsers(long organizationId, long[] userIds) throws PortalException {

    UserLocalServiceUtil.addOrganizationUsers(organizationId, userIds);

    reindex(userIds);
}