public void configUserRole(Long userId, List<Long> roleIds,
String userRepoRef, String scopeId, boolean clearRoles) {
logger.debug("userId: {}, roleIds: {}", userId, roleIds);
UserStatus userStatus = userStatusManager.get(userId);
if (userStatus == null) {
logger.warn("cannot find UserStatus : {}", userId);
return;
}
if (clearRoles) {
List<Role> roles = new ArrayList<Role>();
roles.addAll(userStatus.getRoles());
for (Role role : roles) {
userStatus.getRoles().remove(role);
}
}
if (roleIds == null) {
roleIds = Collections.emptyList();
}
for (Long roleId : roleIds) {
Role role = roleManager.get(roleId);
boolean skip = false;
if (role == null) {
logger.warn("role is null, roleId : {}", roleId);
continue;
}
for (Role r : userStatus.getRoles()) {
logger.debug("r.getId() : {}, role.getId() : {}", r.getId(),
role.getId());
if (r.getId().equals(role.getId())) {
skip = true;
break;
}
}
if (skip) {
continue;
}
userStatus.getRoles().add(role);
}
userStatusManager.save(userStatus);
}