role.setInheritAccountPolicy(roleTO.isInheritAccountPolicy());
SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
// name and parent
SyncopeClientException invalidRoles = new SyncopeClientException(SyncopeClientExceptionType.InvalidRoles);
if (roleTO.getName() == null) {
LOG.error("No name specified for this role");
invalidRoles.addElement("No name specified for this role");
} else {
role.setName(roleTO.getName());
}
Long parentRoleId = null;
if (roleTO.getParent() != 0) {
SyncopeRole parentRole = roleDAO.find(roleTO.getParent());
if (parentRole == null) {
LOG.error("Could not find role with id " + roleTO.getParent());
invalidRoles.addElement(String.valueOf(roleTO.getParent()));
scce.addException(invalidRoles);
} else {
role.setParent(parentRole);
parentRoleId = role.getParent().getId();
}
}
SyncopeRole otherRole = roleDAO.find(roleTO.getName(), parentRoleId);
if (otherRole != null) {
LOG.error("Another role exists with the same name " + "and the same parent role: " + otherRole);
invalidRoles.addElement(roleTO.getName());
}
// attributes, derived attributes, virtual attributes and resources
fill(role, roleTO, AttributableUtil.getInstance(AttributableType.ROLE), scce);