@PreAuthorize("(hasRole('USER_DELETE') and #bulkAction.operation == #bulkAction.operation.DELETE) or "
+ "(hasRole('USER_UPDATE') and "
+ "(#bulkAction.operation == #bulkAction.operation.REACTIVATE or "
+ "#bulkAction.operation == #bulkAction.operation.SUSPEND))")
public BulkActionResult bulk(final BulkAction bulkAction) {
BulkActionResult res = new BulkActionResult();
switch (bulkAction.getOperation()) {
case DELETE:
for (String userId : bulkAction.getTargets()) {
try {
res.add(delete(Long.valueOf(userId)).getId(), Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing delete for user {}", userId, e);
res.add(userId, Status.FAILURE);
}
}
break;
case SUSPEND:
for (String userId : bulkAction.getTargets()) {
StatusMod statusMod = new StatusMod();
statusMod.setId(Long.valueOf(userId));
statusMod.setType(StatusMod.ModType.SUSPEND);
try {
res.add(status(statusMod).getId(), Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing suspend for user {}", userId, e);
res.add(userId, Status.FAILURE);
}
}
break;
case REACTIVATE:
for (String userId : bulkAction.getTargets()) {
StatusMod statusMod = new StatusMod();
statusMod.setId(Long.valueOf(userId));
statusMod.setType(StatusMod.ModType.REACTIVATE);
try {
res.add(status(statusMod).getId(), Status.SUCCESS);
} catch (Exception e) {
LOG.error("Error performing reactivate for user {}", userId, e);
res.add(userId, Status.FAILURE);
}
}
break;
default: