use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.
the class UserRestClient method suspend.
public BulkActionResult suspend(final String etag, final String userKey, final List<StatusBean> statuses) {
StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses, false);
statusPatch.setKey(userKey);
statusPatch.setType(StatusPatchType.SUSPEND);
BulkActionResult result;
synchronized (this) {
result = new BulkActionResult();
Map<String, BulkActionResult.Status> res = result.getResults();
UserService service = getService(etag, UserService.class);
@SuppressWarnings("unchecked") ProvisioningResult<UserTO> provisions = (ProvisioningResult<UserTO>) service.status(statusPatch).readEntity(ProvisioningResult.class);
if (statusPatch.isOnSyncope()) {
res.put(StringUtils.capitalize(Constants.SYNCOPE), "suspended".equalsIgnoreCase(provisions.getEntity().getStatus()) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
}
for (PropagationStatus status : provisions.getPropagationStatuses()) {
res.put(status.getResource(), BulkActionResult.Status.valueOf(status.getStatus().name()));
}
resetClient(UserService.class);
}
return result;
}
use of org.apache.syncope.common.lib.to.BulkActionResult 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());
}
use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.
the class ReportITCase method deleteExecutions.
@Test
public void deleteExecutions() {
Date start = new Date();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
reportTO.setKey(null);
reportTO.setName("deleteExecutions" + getUUIDString());
reportTO.getExecutions().clear();
reportTO = createReport(reportTO);
assertNotNull(reportTO);
String execKey = execReport(reportTO.getKey());
assertNotNull(execKey);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
Date end = new Date();
BulkActionResult result = reportService.deleteExecutions(new BulkExecDeleteQuery.Builder().key(reportTO.getKey()).startedAfter(start).endedBefore(end).build());
assertNotNull(result);
assertEquals(1, result.getResults().size());
assertEquals(execKey, result.getResults().keySet().iterator().next());
assertEquals(BulkActionResult.Status.SUCCESS, result.getResults().entrySet().iterator().next().getValue());
}
use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.
the class AbstractAnyService method associate.
@Override
public Response associate(final AssociationPatch patch) {
Date etagDate = findLastChange(patch.getKey());
checkETag(String.valueOf(etagDate.getTime()));
ProvisioningResult<TO> updated;
switch(patch.getAction()) {
case LINK:
updated = new ProvisioningResult<>();
updated.setEntity(getAnyLogic().link(patch.getKey(), patch.getResources()));
break;
case ASSIGN:
updated = getAnyLogic().assign(patch.getKey(), patch.getResources(), patch.getValue() != null, patch.getValue(), isNullPriorityAsync());
break;
case PROVISION:
updated = getAnyLogic().provision(patch.getKey(), patch.getResources(), patch.getValue() != null, patch.getValue(), isNullPriorityAsync());
break;
default:
updated = new ProvisioningResult<>();
updated.setEntity(getAnyLogic().read(patch.getKey()));
}
BulkActionResult result = new BulkActionResult();
if (patch.getAction() == ResourceAssociationAction.LINK) {
patch.getResources().forEach(resource -> {
result.getResults().put(resource, updated.getEntity().getResources().contains(resource) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
});
} else {
updated.getPropagationStatuses().forEach(propagationStatusTO -> result.getResults().put(propagationStatusTO.getResource(), BulkActionResult.Status.valueOf(propagationStatusTO.getStatus().toString())));
}
return modificationResponse(result);
}
use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.
the class AbstractAnyService method bulk.
@Override
public Response bulk(final BulkAction bulkAction) {
AbstractAnyLogic<TO, P> logic = getAnyLogic();
BulkActionResult result = new BulkActionResult();
switch(bulkAction.getType()) {
case MUSTCHANGEPASSWORD:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
try {
final UserPatch userPatch = new UserPatch();
userPatch.setKey(key);
userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(true).build());
result.getResults().put(((UserLogic) logic).update(userPatch, false).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing delete for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
case DELETE:
bulkAction.getTargets().forEach(key -> {
try {
result.getResults().put(logic.delete(key, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing delete for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
break;
case SUSPEND:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
StatusPatch statusPatch = new StatusPatch.Builder().key(key).type(StatusPatchType.SUSPEND).onSyncope(true).build();
try {
result.getResults().put(((UserLogic) logic).status(statusPatch, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing suspend for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
case REACTIVATE:
if (logic instanceof UserLogic) {
bulkAction.getTargets().forEach(key -> {
StatusPatch statusPatch = new StatusPatch.Builder().key(key).type(StatusPatchType.REACTIVATE).onSyncope(true).build();
try {
result.getResults().put(((UserLogic) logic).status(statusPatch, isNullPriorityAsync()).getEntity().getKey(), BulkActionResult.Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing reactivate for user {}", key, e);
result.getResults().put(key, BulkActionResult.Status.FAILURE);
}
});
} else {
throw new BadRequestException();
}
break;
default:
}
return modificationResponse(result);
}
Aggregations