use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter 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.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.
the class DeleteProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
String key = exchange.getIn().getBody(String.class);
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (null != getAnyTypeKind()) {
List<PropagationTaskTO> tasks;
PropagationReporter propagationReporter;
switch(getAnyTypeKind()) {
case USER:
PropagationByResource propByRes = new PropagationByResource();
propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceKeys(key));
// Note here that we can only notify about "delete", not any other
// task defined in workflow process definition: this because this
// information could only be available after uwfAdapter.delete(), which
// will also effectively remove user from db, thus making virtually
// impossible by NotificationManager to fetch required user information
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
case GROUP:
tasks = new ArrayList<>();
// resources only because of the reason being deleted (see SYNCOPE-357)
for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) {
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.USER, entry.getKey(), entry.getValue(), excludedResources));
}
for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) {
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, entry.getKey(), entry.getValue(), excludedResources));
}
// Generate propagation tasks for deleting this group from resources
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, null, null));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
case ANY_OBJECT:
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, null, excludedResources);
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
default:
break;
}
}
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.
the class DeprovisionProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
String key = exchange.getIn().getBody(String.class);
List<String> resources = exchange.getProperty("resources", List.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (null != getAnyTypeKind()) {
PropagationByResource propByRes = new PropagationByResource();
List<PropagationTaskTO> tasks;
PropagationReporter propagationReporter;
switch(getAnyTypeKind()) {
case USER:
propByRes.set(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, userDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
case GROUP:
propByRes.addAll(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, propByRes, groupDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
case ANY_OBJECT:
propByRes.addAll(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, propByRes, anyObjectDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
default:
break;
}
}
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.
the class StatusProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if (getAnyTypeKind() == AnyTypeKind.USER && isPull()) {
WorkflowResult<Map.Entry<UserPatch, Boolean>> updated = (WorkflowResult<Entry<UserPatch, Boolean>>) exchange.getIn().getBody();
Boolean enabled = exchange.getProperty("enabled", Boolean.class);
String key = exchange.getProperty("key", String.class);
if (enabled != null) {
User user = userDAO.find(key);
WorkflowResult<String> enableUpdate = null;
if (user.isSuspended() == null) {
enableUpdate = uwfAdapter.activate(key, null);
} else if (enabled && user.isSuspended()) {
enableUpdate = uwfAdapter.reactivate(key);
} else if (!enabled && !user.isSuspended()) {
enableUpdate = uwfAdapter.suspend(key);
}
if (enableUpdate != null) {
if (enableUpdate.getPropByRes() != null) {
updated.getPropByRes().merge(enableUpdate.getPropByRes());
updated.getPropByRes().purge();
}
updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
}
}
} else if (getAnyTypeKind() == AnyTypeKind.USER) {
WorkflowResult<Long> updated = (WorkflowResult<Long>) exchange.getIn().getBody();
StatusPatch statusPatch = exchange.getProperty("statusPatch", StatusPatch.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
PropagationByResource propByRes = new PropagationByResource();
propByRes.addAll(ResourceOperation.UPDATE, statusPatch.getResources());
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(AnyTypeKind.USER, statusPatch.getKey(), false, statusPatch.getType() != StatusPatchType.SUSPEND, propByRes, null, null);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
}
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.
the class UpdateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
if (actual instanceof UserPatch || isPull()) {
WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks;
if (isPull()) {
boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
} else {
tasks = getPropagationManager().getUserUpdateTasks(updated);
}
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyPatch) {
WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
}
}
}
Aggregations