if (!syncTask.isPerformCreate()) {
LOG.debug("SyncTask not configured for create");
return Collections.<SyncResult>emptyList();
}
final SyncResult result = new SyncResult();
result.setOperation(ResourceOperation.CREATE);
result.setSubjectType(attrUtil.getType());
result.setStatus(SyncResult.Status.SUCCESS);
AbstractAttributableTO subjectTO = connObjectUtil.getAttributableTO(delta.getObject(), syncTask, attrUtil);
// Attributable transformation (if configured)
AbstractAttributableTO actual = attrTransformer.transform(subjectTO);
LOG.debug("Transformed: {}", actual);
if (dryRun) {
result.setId(0L);
if (actual instanceof UserTO) {
result.setName(((UserTO) actual).getUsername());
}
if (actual instanceof RoleTO) {
result.setName(((RoleTO) actual).getName());
}
} else {
delta = actions.beforeCreate(this, delta, actual);
Object output;
Result resultStatus;
try {
if (AttributableType.USER == attrUtil.getType()) {
Boolean enabled = readEnabled(delta.getObject());
WorkflowResult<Map.Entry<Long, Boolean>> created =
uwfAdapter.create((UserTO) actual, true, enabled);
List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
((UserTO) actual).getPassword(), actual.getVirtualAttributes(),
Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
actual = userDataBinder.getUserTO(created.getResult().getKey());
result.setId(created.getResult().getKey());
result.setName(((UserTO) actual).getUsername());
} else if (AttributableType.ROLE == attrUtil.getType()) {
WorkflowResult<Long> created = rwfAdapter.create((RoleTO) actual);
AttributeTO roleOwner = actual.getAttributeMap().get(StringUtils.EMPTY);
if (roleOwner != null) {
roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
}
EntitlementUtil.extendAuthContext(created.getResult());
List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
actual.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));
taskExecutor.execute(tasks);
actual = roleDataBinder.getRoleTO(created.getResult());
result.setId(created.getResult());
result.setName(((RoleTO) actual).getName());
}
output = actual;
resultStatus = Result.SUCCESS;
} catch (PropagationException e) {
// A propagation failure doesn't imply a synchronization failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
result.setStatus(SyncResult.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not create {} {} ", attrUtil.getType(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}