use of org.apache.syncope.core.provisioning.api.WorkflowResult in project syncope by apache.
the class CamelUserProvisioningManager method update.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
@SuppressWarnings("unchecked")
public Pair<UserPatch, List<PropagationStatus>> update(final UserPatch userPatch, final ProvisioningReport result, final Boolean enabled, final Set<String> excludedResources, final boolean nullPriorityAsync) {
PollingConsumer pollingConsumer = getConsumer("direct:updateInPullPort");
Map<String, Object> props = new HashMap<>();
props.put("key", userPatch.getKey());
props.put("result", result);
props.put("enabled", enabled);
props.put("excludedResources", excludedResources);
props.put("nullPriorityAsync", nullPriorityAsync);
sendMessage("direct:updateUserInPull", userPatch, props);
Exchange exchange = pollingConsumer.receive();
Exception ex = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
if (ex != null) {
LOG.error("Update of user {} failed, trying to pull its status anyway (if configured)", nullPriorityAsync, ex);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage("Update failed, trying to pull status anyway (if configured)\n" + ex.getMessage());
WorkflowResult<Pair<UserPatch, Boolean>> updated = new WorkflowResult<>(Pair.of(userPatch, false), new PropagationByResource(), new HashSet<>());
sendMessage("direct:userInPull", updated, props);
exchange = pollingConsumer.receive();
}
return exchange.getIn().getBody(Pair.class);
}
use of org.apache.syncope.core.provisioning.api.WorkflowResult in project syncope by apache.
the class CamelUserProvisioningManager method activate.
@Override
@SuppressWarnings("unchecked")
public Pair<String, List<PropagationStatus>> activate(final StatusPatch statusPatch, final boolean nullPriorityAsync) {
PollingConsumer pollingConsumer = getConsumer("direct:statusPort");
Map<String, Object> props = new HashMap<>();
props.put("token", statusPatch.getToken());
props.put("key", statusPatch.getKey());
props.put("statusPatch", statusPatch);
props.put("nullPriorityAsync", nullPriorityAsync);
if (statusPatch.isOnSyncope()) {
sendMessage("direct:activateUser", statusPatch.getKey(), props);
} else {
WorkflowResult<String> updated = new WorkflowResult<>(statusPatch.getKey(), null, statusPatch.getType().name().toLowerCase());
sendMessage("direct:userStatusPropagation", updated, props);
}
Exchange exchange = pollingConsumer.receive();
if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
}
return exchange.getIn().getBody(Pair.class);
}
use of org.apache.syncope.core.provisioning.api.WorkflowResult 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.WorkflowResult 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.WorkflowResult 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