use of com.liferay.portal.NoSuchRoleException in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultRoles.
/**
* Adds the user to the default roles, unless the user already has these
* roles. The default roles can be specified in
* <code>portal.properties</code> with the key
* <code>admin.default.role.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
public void addDefaultRoles(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> roleIdSet = new HashSet<Long>();
String[] defaultRoleNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ROLE_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ROLE_NAMES);
for (String defaultRoleName : defaultRoleNames) {
try {
Role role = rolePersistence.findByC_N(user.getCompanyId(), defaultRoleName);
if (!userPersistence.containsRole(userId, role.getRoleId())) {
roleIdSet.add(role.getRoleId());
}
} catch (NoSuchRoleException nsre) {
}
}
long[] roleIds = ArrayUtil.toArray(roleIdSet.toArray(new Long[roleIdSet.size()]));
roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
userPersistence.addRoles(userId, roleIds);
}
Aggregations