Search in sources :

Example 1 with Team

use of com.liferay.portal.model.Team in project liferay-ide by liferay.

the class UserLocalServiceImpl method unsetGroupTeamsUsers.

/**
 * Removes the users from the teams of a group.
 *
 * @param  groupId the primary key of the group
 * @param  userIds the primary keys of the users
 * @throws PortalException if a portal exception occurred
 * @throws SystemException if a system exception occurred
 */
@Override
public void unsetGroupTeamsUsers(long groupId, long[] userIds) throws PortalException, SystemException {
    List<Team> teams = teamPersistence.findByGroupId(groupId);
    for (Team team : teams) {
        unsetTeamUsers(team.getTeamId(), userIds);
    }
    PermissionCacheUtil.clearCache();
}
Also used : Team(com.liferay.portal.model.Team)

Example 2 with Team

use of com.liferay.portal.model.Team in project liferay-ide by liferay.

the class UserLocalServiceImpl method addDefaultRolesAndTeams.

protected void addDefaultRolesAndTeams(long groupId, long[] userIds) throws PortalException, SystemException {
    List<Role> defaultSiteRoles = new ArrayList<Role>();
    Group group = groupLocalService.getGroup(groupId);
    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();
    long[] defaultSiteRoleIds = StringUtil.split(typeSettingsProperties.getProperty("defaultSiteRoleIds"), 0L);
    for (long defaultSiteRoleId : defaultSiteRoleIds) {
        Role defaultSiteRole = rolePersistence.fetchByPrimaryKey(defaultSiteRoleId);
        if (defaultSiteRole == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find role " + defaultSiteRoleId);
            }
            continue;
        }
        defaultSiteRoles.add(defaultSiteRole);
    }
    List<Team> defaultTeams = new ArrayList<Team>();
    long[] defaultTeamIds = StringUtil.split(typeSettingsProperties.getProperty("defaultTeamIds"), 0L);
    for (long defaultTeamId : defaultTeamIds) {
        Team defaultTeam = teamPersistence.findByPrimaryKey(defaultTeamId);
        if (defaultTeam == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find team " + defaultTeamId);
            }
            continue;
        }
        defaultTeams.add(defaultTeam);
    }
    for (long userId : userIds) {
        Set<Long> userRoleIdsSet = new HashSet<Long>();
        for (Role role : defaultSiteRoles) {
            if (!userPersistence.containsRole(userId, role.getRoleId())) {
                userRoleIdsSet.add(role.getRoleId());
            }
        }
        long[] userRoleIds = ArrayUtil.toArray(userRoleIdsSet.toArray(new Long[userRoleIdsSet.size()]));
        userGroupRoleLocalService.addUserGroupRoles(userId, groupId, userRoleIds);
        Set<Long> userTeamIdsSet = new HashSet<Long>();
        for (Team team : defaultTeams) {
            if (!userPersistence.containsTeam(userId, team.getTeamId())) {
                userTeamIdsSet.add(team.getTeamId());
            }
        }
        long[] userTeamIds = ArrayUtil.toArray(userTeamIdsSet.toArray(new Long[userTeamIdsSet.size()]));
        userPersistence.addTeams(userId, userTeamIds);
    }
}
Also used : Role(com.liferay.portal.model.Role) UserGroupRole(com.liferay.portal.model.UserGroupRole) Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ArrayList(java.util.ArrayList) Team(com.liferay.portal.model.Team) HashSet(java.util.HashSet)

Aggregations

Team (com.liferay.portal.model.Team)2 UnicodeProperties (com.liferay.portal.kernel.util.UnicodeProperties)1 Group (com.liferay.portal.model.Group)1 Role (com.liferay.portal.model.Role)1 UserGroup (com.liferay.portal.model.UserGroup)1 UserGroupRole (com.liferay.portal.model.UserGroupRole)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1