in core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/LiveSyncJobDelegate.java [269:374]
protected void doLivesync() throws JobExecutionException {
profile.getResults().clear();
TaskExec<SchedTask> execution = initExecution();
execution.setTask(null);
String message;
String status;
OpEvent.Outcome result;
try {
if (!profile.isDryRun()) {
for (InboundActions action : profile.getActions()) {
action.beforeAll(profile);
}
}
infos.forEach(info -> {
setStatus("Live syncing " + info.objectClass().getObjectClassValue());
OperationOptions options = Optional.ofNullable(
latestSyncTokens.get(info.objectClass().getObjectClassValue())).
map(syncToken -> new OperationOptionsBuilder(info.options()).
setPagedResultsCookie(syncToken.getValue().toString()).build()).
orElseGet(() -> info.options());
profile.getConnector().livesync(
info.objectClass(),
liveSyncDelta -> {
try {
LOG.debug("LiveSyncDelta: {}", liveSyncDelta);
SyncDelta syncDelta = info.provision() == null
? mapper.map(liveSyncDelta, info.orgUnit())
: mapper.map(liveSyncDelta, info.provision());
LOG.debug("Mapped SyncDelta: {}", syncDelta);
return dispatcher.handle(syncDelta);
} catch (Exception e) {
LOG.error("While live syncing from {} with {}",
task.getResource().getKey(), liveSyncDelta, e);
return false;
}
},
options);
if (info.provision() != null && info.uidOnCreate() != null) {
AnyUtils anyUtils = anyUtilsFactory.getInstance(info.anyTypeKind());
profile.getResults().stream().
filter(r -> r.getUidValue() != null && r.getKey() != null
&& r.getOperation() == ResourceOperation.CREATE
&& r.getAnyType().equals(info.provision().getAnyType())).
forEach(r -> liveSyncTaskSaver.addAttr(
anyUtils,
validator,
r.getKey(),
info.uidOnCreate(),
r.getUidValue()));
}
if (info.anyTypeKind() == AnyTypeKind.GROUP) {
try {
setGroupOwners();
} catch (Exception e) {
LOG.error("While setting group owners", e);
}
}
});
if (!profile.isDryRun()) {
for (InboundActions action : profile.getActions()) {
action.afterAll(profile);
}
}
message = createReport(profile.getResults(), task.getResource(), profile.isDryRun());
status = TaskJob.Status.SUCCESS.name();
result = OpEvent.Outcome.SUCCESS;
} catch (Throwable t) {
LOG.error("While executing task {}", task.getKey(), t);
message = ExceptionUtils2.getFullStackTrace(t);
status = TaskJob.Status.FAILURE.name();
result = OpEvent.Outcome.FAILURE;
}
if (!profile.getResults().isEmpty()) {
liveSyncTaskSaver.save(task.getKey(), execution, message, status, result, this::hasToBeRegistered);
}
if (!profile.isDryRun()) {
boolean anySyncTokenChanged = false;
for (int i = 0; i < infos.size() && !anySyncTokenChanged; i++) {
if (infos.get(i).provision() != null) {
anySyncTokenChanged = syncTokenChanged(
infos.get(i).provision().getSyncToken(),
infos.get(i).objectClass().getObjectClassValue());
} else if (infos.get(i).orgUnit() != null) {
anySyncTokenChanged = syncTokenChanged(
infos.get(i).orgUnit().getSyncToken(),
infos.get(i).objectClass().getObjectClassValue());
}
}
if (anySyncTokenChanged) {
liveSyncTaskSaver.save(task.getResource().getKey(), latestSyncTokens);
}
}
}