final Set<Attribute> attributes = new HashSet<Attribute>(task.getAttributes());
if (before != null) {
// 1. check if rename is really required
final Name newName = (Name) AttributeUtil.find(Name.NAME, attributes);
LOG.debug("Rename required with value {}", newName);
if (newName != null && newName.equals(before.getName())
&& !before.getUid().getUidValue().equals(newName.getNameValue())) {
LOG.debug("Remote object name unchanged");
attributes.remove(newName);
}
LOG.debug("Attributes to be replaced {}", attributes);
// 2. update with a new "normalized" attribute set
connector.update(task.getPropagationMode(), ObjectClass.ACCOUNT, before.getUid(),
attributes, null, propagationAttempted);
} else {
// 1. get accountId
final String accountId = task.getAccountId();
// 2. get name
final Name name = (Name) AttributeUtil.find(Name.NAME, attributes);
// 3. check if:
// * accountId is not blank;
// * accountId is not equal to Name.
if (StringUtils.hasText(accountId)
&& (name == null || !accountId.equals(name.getNameValue()))) {
// 3.a retrieve uid
final Uid uid = (Uid) AttributeUtil.find(Uid.NAME, attributes);
// 3.b add Uid if not provided