in core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/DefaultUserPushResultHandler.java [212:353]
protected void doHandle(final LinkedAccount account, final Provision provision) throws JobExecutionException {
ProvisioningReport result = new ProvisioningReport();
profile.getResults().add(result);
result.setKey(account.getKey());
result.setAnyType(MatchType.LINKED_ACCOUNT.name());
result.setUidValue(account.getConnObjectKeyValue());
result.setName(account.getConnObjectKeyValue());
LOG.debug("Pushing linked account {} towards {}", account.getKey(), profile.getTask().getResource());
// Try to read remote object BEFORE any actual operation
Optional<ConnectorObject> connObj = MappingUtils.getConnObjectKeyItem(provision).
flatMap(connObjectKeyItem -> outboundMatcher.matchByConnObjectKeyValue(
profile.getConnector(),
connObjectKeyItem,
account.getConnObjectKeyValue(),
profile.getTask().getResource(),
provision,
Optional.empty()));
LOG.debug("Match found for linked account {} as {}: {}", account, provision.getObjectClass(), connObj);
ConnectorObject beforeObj = connObj.orElse(null);
if (profile.isDryRun()) {
if (beforeObj == null) {
result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
} else {
result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
}
result.setStatus(ProvisioningReport.Status.SUCCESS);
} else {
Boolean enable = profile.getTask().isSyncStatus()
? BooleanUtils.negate(account.isSuspended())
: null;
try {
if (beforeObj == null) {
result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
switch (profile.getTask().getUnmatchingRule()) {
case ASSIGN:
case PROVISION:
for (PushActions action : profile.getActions()) {
if (profile.getTask().getUnmatchingRule() == UnmatchingRule.ASSIGN) {
action.beforeAssign(profile, account);
} else {
action.beforeProvision(profile, account);
}
}
if (!profile.getTask().isPerformCreate()) {
LOG.debug("PushTask not configured for create");
result.setStatus(ProvisioningReport.Status.IGNORE);
} else {
provision(account, enable, result);
}
break;
case UNLINK:
LOG.warn("{} not applicable to linked accounts, ignoring",
profile.getTask().getUnmatchingRule());
break;
case IGNORE:
result.setStatus(ProvisioningReport.Status.IGNORE);
break;
default:
// do nothing
}
} else {
result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
switch (profile.getTask().getMatchingRule()) {
case UPDATE:
for (PushActions action : profile.getActions()) {
action.beforeUpdate(profile, account);
}
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PushTask not configured for update");
result.setStatus(ProvisioningReport.Status.IGNORE);
} else {
update(account, enable, beforeObj, ResourceOperation.UPDATE, result);
}
break;
case UNASSIGN:
case DEPROVISION:
for (PushActions action : profile.getActions()) {
if (profile.getTask().getMatchingRule() == MatchingRule.UNASSIGN) {
action.beforeUnassign(profile, account);
} else {
action.beforeDeprovision(profile, account);
}
}
if (!profile.getTask().isPerformDelete()) {
LOG.debug("PushTask not configured for delete");
result.setStatus(ProvisioningReport.Status.IGNORE);
} else {
update(account, enable, beforeObj, ResourceOperation.DELETE, result);
}
break;
case LINK:
case UNLINK:
LOG.warn("{} not applicable to linked accounts, ignoring",
profile.getTask().getMatchingRule());
break;
case IGNORE:
result.setStatus(ProvisioningReport.Status.IGNORE);
break;
default:
// do nothing
}
}
for (PushActions action : profile.getActions()) {
action.after(profile, account, result);
}
if (result.getStatus() == null) {
result.setStatus(ProvisioningReport.Status.SUCCESS);
}
} catch (IgnoreProvisionException e) {
throw e;
} catch (Exception e) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.warn("Error pushing linked account {} towards {}", account, profile.getTask().getResource(), e);
for (PushActions action : profile.getActions()) {
action.onError(profile, account, result, e);
}
throw new JobExecutionException(e);
}
}
}