use of org.apache.syncope.core.logic.UserLogic 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