* @param original original RoleTO
* @param incremental perform incremental diff (without removing existing info)
* @return RoleMod containing differences
*/
public static RoleMod diff(final RoleTO updated, final RoleTO original, final boolean incremental) {
RoleMod result = new RoleMod();
diff(updated, original, result, incremental);
// 1. inheritance
result.setInheritOwner(updated.isInheritOwner());
result.setInheritAccountPolicy(updated.isInheritAccountPolicy());
result.setInheritPasswordPolicy(updated.isInheritPasswordPolicy());
result.setInheritAttributes(updated.isInheritAttributes());
result.setInheritDerivedAttributes(updated.isInheritDerivedAttributes());
result.setInheritVirtualAttributes(updated.isInheritVirtualAttributes());
// 2. policies
result.setAccountPolicy(new ReferenceMod(updated.getAccountPolicy()));
result.setPasswordPolicy(new ReferenceMod(updated.getPasswordPolicy()));
// 3. name
if (!original.getName().equals(updated.getName())) {
result.setName(updated.getName());
}
// 4. entitlements
Set<String> updatedEnts = new HashSet<String>(updated.getEntitlements());
Set<String> originalEnts = new HashSet<String>(original.getEntitlements());
if (updatedEnts.equals(originalEnts)) {
result.setEntitlements(null);
} else {
result.setEntitlements(updated.getEntitlements());
}
// 5. owner
result.setUserOwner(new ReferenceMod(updated.getUserOwner()));
result.setRoleOwner(new ReferenceMod(updated.getRoleOwner()));
return result;
}