} 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);
// entitlements
Entitlement entitlement;
for (String entitlementName : roleTO.getEntitlements()) {
entitlement = entitlementDAO.find(entitlementName);
if (entitlement == null) {
LOG.warn("Ignoring invalid entitlement {}", entitlementName);
} else {
role.addEntitlement(entitlement);
}
}
// owner
if (roleTO.getUserOwner() != null) {
SyncopeUser owner = userDAO.find(roleTO.getUserOwner());
if (owner == null) {
LOG.warn("Ignoring invalid user specified as owner: {}", roleTO.getUserOwner());
} else {
role.setUserOwner(owner);
}
}
if (roleTO.getRoleOwner() != null) {
SyncopeRole owner = roleDAO.find(roleTO.getRoleOwner());
if (owner == null) {
LOG.warn("Ignoring invalid role specified as owner: {}", roleTO.getRoleOwner());
} else {
role.setRoleOwner(owner);
}