use of org.apache.syncope.common.lib.to.BulkAction in project syncope by apache.
the class UserSyncopeOperations method bulkDelete.
private Map<String, BulkActionResult.Status> bulkDelete(final AnyQuery query) {
query.setPage(0);
query.setSize(0);
int count = userService.search(query).getTotalCount();
BulkAction bulkAction = new BulkAction();
bulkAction.setType(BulkAction.Type.DELETE);
query.setSize(PAGE_SIZE);
for (int page = 1; page <= (count / PAGE_SIZE) + 1; page++) {
query.setPage(page);
bulkAction.getTargets().addAll(userService.search(query).getResult().stream().map(EntityTO::getKey).collect(Collectors.toList()));
}
return userService.bulk(bulkAction).readEntity(BulkActionResult.class).getResults();
}
use of org.apache.syncope.common.lib.to.BulkAction 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));
}
use of org.apache.syncope.common.lib.to.BulkAction in project syncope by apache.
the class UserITCase method bulkActions.
@Test
public void bulkActions() {
BulkAction bulkAction = new BulkAction();
for (int i = 0; i < 10; i++) {
UserTO userTO = getUniqueSampleTO("bulk_" + i + "@apache.org");
bulkAction.getTargets().add(String.valueOf(createUser(userTO).getEntity().getKey()));
}
// check for a fail
bulkAction.getTargets().add(String.valueOf(Long.MAX_VALUE));
assertEquals(11, bulkAction.getTargets().size());
bulkAction.setType(BulkAction.Type.SUSPEND);
BulkActionResult res = userService.bulk(bulkAction).readEntity(BulkActionResult.class);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
assertEquals("suspended", userService.read(res.getResultByStatus(Status.SUCCESS).get(3)).getStatus());
bulkAction.setType(BulkAction.Type.REACTIVATE);
res = userService.bulk(bulkAction).readEntity(BulkActionResult.class);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
assertEquals("active", userService.read(res.getResultByStatus(Status.SUCCESS).get(3)).getStatus());
bulkAction.setType(BulkAction.Type.DELETE);
res = userService.bulk(bulkAction).readEntity(BulkActionResult.class);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
}
Aggregations