use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class CreateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (actual instanceof UserTO) {
WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyTO) {
WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
if (actual instanceof GroupTO && isPull()) {
Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
if (groupOwner.isPresent()) {
groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
}
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), null));
} else {
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
}
}
}
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class AbstractPullResultHandler method provision.
protected List<ProvisioningReport> provision(final SyncDelta delta, final Provision provision, final AnyUtils anyUtils) throws JobExecutionException {
if (!profile.getTask().isPerformCreate()) {
LOG.debug("PullTask not configured for create");
finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
AnyTO anyTO = connObjectUtils.getAnyTO(delta.getObject(), profile.getTask(), provision, anyUtils);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.CREATE);
result.setAnyType(provision.getAnyType().getKey());
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setName(getName(anyTO));
if (profile.isDryRun()) {
result.setKey(null);
finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
} else {
for (PullActions action : profile.getActions()) {
action.beforeProvision(profile, delta, anyTO);
}
create(anyTO, delta, UnmatchingRule.toEventName(UnmatchingRule.PROVISION), provision, result);
}
return Collections.singletonList(result);
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class AbstractPullResultHandler method assign.
protected List<ProvisioningReport> assign(final SyncDelta delta, final Provision provision, final AnyUtils anyUtils) throws JobExecutionException {
if (!profile.getTask().isPerformCreate()) {
LOG.debug("PullTask not configured for create");
finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
AnyTO anyTO = connObjectUtils.getAnyTO(delta.getObject(), profile.getTask(), provision, anyUtils);
anyTO.getResources().add(profile.getTask().getResource().getKey());
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.CREATE);
result.setAnyType(provision.getAnyType().getKey());
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setName(getName(anyTO));
if (profile.isDryRun()) {
result.setKey(null);
finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
} else {
for (PullActions action : profile.getActions()) {
action.beforeAssign(profile, delta, anyTO);
}
create(anyTO, delta, UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), provision, result);
}
return Collections.singletonList(result);
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class AbstractPullResultHandler method deprovision.
protected List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean unlink) throws JobExecutionException {
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PullTask not configured for update");
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to deprovision {}", anyKeys);
final List<ProvisioningReport> results = new ArrayList<>();
for (String key : anyKeys) {
LOG.debug("About to unassign resource {}", key);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.DELETE);
result.setAnyType(provision.getAnyType().getKey());
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setKey(key);
AnyTO before = getAnyTO(key);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key));
}
if (!profile.isDryRun()) {
Object output;
Result resultStatus;
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
result.setName(getName(before));
try {
if (unlink) {
for (PullActions action : profile.getActions()) {
action.beforeUnassign(profile, delta, before);
}
} else {
for (PullActions action : profile.getActions()) {
action.beforeDeprovision(profile, delta, before);
}
}
PropagationByResource propByRes = new PropagationByResource();
propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
taskExecutor.execute(propagationManager.getDeleteTasks(provision.getAnyType().getKind(), key, propByRes, null), false);
AnyPatch anyPatch = null;
if (unlink) {
anyPatch = newPatch(key);
anyPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(profile.getTask().getResource().getKey()).build());
}
if (anyPatch == null) {
output = getAnyTO(key);
} else {
output = doUpdate(before, anyPatch, delta, result);
}
for (PullActions action : profile.getActions()) {
action.after(profile, delta, AnyTO.class.cast(output), result);
}
resultStatus = Result.SUCCESS;
LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key);
} catch (PropagationException e) {
// A propagation failure doesn't imply a pull failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not update {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
}
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
use of org.apache.syncope.common.lib.to.AnyTO in project syncope by apache.
the class AbstractPushResultHandler method provision.
protected void provision(final Any<?> any, final Boolean enabled, final ProvisioningReport result) {
AnyTO before = getAnyTO(any.getKey());
List<String> noPropResources = new ArrayList<>(before.getResources());
noPropResources.remove(profile.getTask().getResource().getKey());
PropagationByResource propByRes = new PropagationByResource();
propByRes.add(ResourceOperation.CREATE, profile.getTask().getResource().getKey());
PropagationReporter reporter = taskExecutor.execute(propagationManager.getCreateTasks(any.getType().getKind(), any.getKey(), propByRes, before.getVirAttrs(), noPropResources), false);
reportPropagation(result, reporter);
}
Aggregations