use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class DefaultRealmPullResultHandler method delete.
private List<ProvisioningReport> delete(final SyncDelta delta, final List<String> keys) throws JobExecutionException {
if (!profile.getTask().isPerformDelete()) {
LOG.debug("PullTask not configured for delete");
finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to delete {}", keys);
List<ProvisioningReport> results = new ArrayList<>();
for (String key : keys) {
Object output;
Result resultStatus = Result.FAILURE;
ProvisioningReport result = new ProvisioningReport();
try {
result.setKey(key);
result.setOperation(ResourceOperation.DELETE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
Realm realm = realmDAO.find(key);
RealmTO before = binder.getRealmTO(realm, true);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Realm '%s' not found", key));
} else {
result.setName(before.getFullPath());
}
if (!profile.isDryRun()) {
for (PullActions action : profile.getActions()) {
action.beforeDelete(profile, delta, before);
}
try {
if (!realmDAO.findChildren(realm).isEmpty()) {
throw SyncopeClientException.build(ClientExceptionType.HasChildren);
}
Set<String> adminRealms = Collections.singleton(realm.getFullPath());
AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
keyCond.setSchema("key");
SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
if (users + groups + anyObjects > 0) {
SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
containedAnys.getElements().add(users + " user(s)");
containedAnys.getElements().add(groups + " group(s)");
containedAnys.getElements().add(anyObjects + " anyObject(s)");
throw containedAnys;
}
PropagationByResource propByRes = new PropagationByResource();
for (String resource : realm.getResourceKeys()) {
propByRes.add(ResourceOperation.DELETE, resource);
}
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
taskExecutor.execute(tasks, false);
realmDAO.delete(realm);
output = null;
resultStatus = Result.SUCCESS;
for (PullActions action : profile.getActions()) {
action.after(profile, delta, before, result);
}
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not delete {}", realm, e);
output = e;
}
finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta);
}
results.add(result);
} catch (DelegatedAdministrationException e) {
LOG.error("Not allowed to read Realm {}", key, e);
} catch (Exception e) {
LOG.error("Could not delete Realm {}", key, e);
}
}
return results;
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class DefaultRealmPullResultHandler method update.
private List<ProvisioningReport> update(final SyncDelta delta, final List<String> keys) throws JobExecutionException {
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PullTask not configured for update");
finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to update {}", keys);
List<ProvisioningReport> results = new ArrayList<>();
for (String key : keys) {
LOG.debug("About to update {}", key);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.UPDATE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setKey(key);
Realm realm = realmDAO.find(key);
RealmTO before = binder.getRealmTO(realm, true);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Realm '%s' not found", key));
} else {
result.setName(before.getFullPath());
}
if (!profile.isDryRun()) {
Result resultStatus;
Object output;
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
try {
for (PullActions action : profile.getActions()) {
action.beforeUpdate(profile, delta, before, null);
}
PropagationByResource propByRes = binder.update(realm, before);
realm = realmDAO.save(realm);
RealmTO updated = binder.getRealmTO(realm, true);
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
taskExecutor.execute(tasks, false);
for (PullActions action : profile.getActions()) {
action.after(profile, delta, updated, result);
}
output = updated;
resultStatus = Result.SUCCESS;
result.setName(updated.getFullPath());
LOG.debug("{} successfully updated", updated);
} 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 Realm {}", 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 Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
}
finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class PropagationTaskITCase method paginatedList.
@Test
public void paginatedList() {
PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(2).build());
assertNotNull(tasks);
assertEquals(2, tasks.getResult().size());
for (TaskTO task : tasks.getResult()) {
assertNotNull(task);
}
tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(2).size(2).build());
assertNotNull(tasks);
assertEquals(2, tasks.getPage());
assertEquals(2, tasks.getResult().size());
for (TaskTO task : tasks.getResult()) {
assertNotNull(task);
}
tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1000).size(2).build());
assertNotNull(tasks);
assertTrue(tasks.getResult().isEmpty());
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class PropagationTaskITCase method read.
@Test
public void read() {
PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, "316285cc-ae52-4ea2-a33b-7355e189ac3f", true);
assertNotNull(taskTO);
assertNotNull(taskTO.getExecutions());
assertTrue(taskTO.getExecutions().isEmpty());
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class PropagationTaskITCase method bulkAction.
@Test
public void bulkAction() {
// create user with testdb resource
UserTO userTO = UserITCase.getUniqueSampleTO("taskBulk@apache.org");
userTO.getResources().add(RESOURCE_NAME_TESTDB);
userTO = createUser(userTO).getEntity();
List<PropagationTaskTO> tasks = new ArrayList<>(taskService.<PropagationTaskTO>search(new TaskQuery.Builder(TaskType.PROPAGATION).anyTypeKind(AnyTypeKind.USER).entityKey(userTO.getKey()).build()).getResult());
assertFalse(tasks.isEmpty());
BulkAction bulkAction = new BulkAction();
bulkAction.setType(BulkAction.Type.DELETE);
tasks.forEach(taskTO -> bulkAction.getTargets().add(taskTO.getKey()));
taskService.bulk(bulkAction);
assertFalse(taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(100).build()).getResult().containsAll(tasks));
}
Aggregations