@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public RoleTO getRoleTO(final SyncopeRole role) {
connObjectUtil.retrieveVirAttrValues(role, AttributableUtil.getInstance(AttributableType.ROLE));
RoleTO roleTO = new RoleTO();
roleTO.setId(role.getId());
roleTO.setName(role.getName());
roleTO.setInheritOwner(role.isInheritOwner());
roleTO.setInheritAttributes(role.isInheritAttributes());
roleTO.setInheritDerivedAttributes(role.isInheritDerivedAttributes());
roleTO.setInheritVirtualAttributes(role.isInheritVirtualAttributes());
roleTO.setInheritPasswordPolicy(role.isInheritPasswordPolicy());
roleTO.setInheritAccountPolicy(role.isInheritAccountPolicy());
if (role.getParent() != null) {
roleTO.setParent(role.getParent().getId());
}
if (role.getUserOwner() != null) {
roleTO.setUserOwner(role.getUserOwner().getId());
}
if (role.getRoleOwner() != null) {
roleTO.setRoleOwner(role.getRoleOwner().getId());
}
// -------------------------
// Retrieve all [derived/virtual] attributes (inherited and not)
// -------------------------
final List<RAttr> allAttributes = role.findInheritedAttributes();
allAttributes.addAll((List<RAttr>) role.getAttributes());
final List<RDerAttr> allDerAttributes = role.findInheritedDerivedAttributes();
allDerAttributes.addAll((List<RDerAttr>) role.getDerivedAttributes());
final List<RVirAttr> allVirAttributes = role.findInheritedVirtualAttributes();
allVirAttributes.addAll((List<RVirAttr>) role.getVirtualAttributes());
// -------------------------
fillTO(roleTO, allAttributes, allDerAttributes, allVirAttributes, role.getResources());
for (Entitlement entitlement : role.getEntitlements()) {
roleTO.addEntitlement(entitlement.getName());
}
roleTO.setPasswordPolicy(role.getPasswordPolicy() == null
? null
: role.getPasswordPolicy().getId());
roleTO.setAccountPolicy(role.getAccountPolicy() == null
? null
: role.getAccountPolicy().getId());
return roleTO;
}