Search in sources :

Example 1 with NoSuchUserGroupException

use of com.liferay.portal.NoSuchUserGroupException in project liferay-ide by liferay.

the class UserLocalServiceImpl method addDefaultUserGroups.

/**
 * Adds the user to the default user groups, unless the user is already in
 * these user groups. The default user groups can be specified in
 * <code>portal.properties</code> with the property
 * <code>admin.default.user.group.names</code>.
 *
 * @param  userId the primary key of the user
 * @throws PortalException if a user with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
@SuppressWarnings("deprecation")
public void addDefaultUserGroups(long userId) throws PortalException, SystemException {
    User user = userPersistence.findByPrimaryKey(userId);
    Set<Long> userGroupIdSet = new HashSet<Long>();
    String[] defaultUserGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_USER_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_USER_GROUP_NAMES);
    for (String defaultUserGroupName : defaultUserGroupNames) {
        try {
            UserGroup userGroup = userGroupPersistence.findByC_N(user.getCompanyId(), defaultUserGroupName);
            if (!userPersistence.containsUserGroup(userId, userGroup.getUserGroupId())) {
                userGroupIdSet.add(userGroup.getUserGroupId());
            }
        } catch (NoSuchUserGroupException nsuge) {
        }
    }
    long[] userGroupIds = ArrayUtil.toArray(userGroupIdSet.toArray(new Long[userGroupIdSet.size()]));
    if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
        for (long userGroupId : userGroupIds) {
            userGroupLocalService.copyUserGroupLayouts(userGroupId, userId);
        }
    }
    userPersistence.addUserGroups(userId, userGroupIds);
}
Also used : User(com.liferay.portal.model.User) NoSuchUserGroupException(com.liferay.portal.NoSuchUserGroupException) HashSet(java.util.HashSet) UserGroup(com.liferay.portal.model.UserGroup)

Aggregations

NoSuchUserGroupException (com.liferay.portal.NoSuchUserGroupException)1 User (com.liferay.portal.model.User)1 UserGroup (com.liferay.portal.model.UserGroup)1 HashSet (java.util.HashSet)1