Search in sources :

Example 1 with UserLogic

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);
}
Also used : UserLogic(org.apache.syncope.core.logic.UserLogic) BadRequestException(javax.ws.rs.BadRequestException) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyTO(org.apache.syncope.common.lib.to.AnyTO) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Aggregations

BadRequestException (javax.ws.rs.BadRequestException)1 BooleanReplacePatchItem (org.apache.syncope.common.lib.patch.BooleanReplacePatchItem)1 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 AnyTO (org.apache.syncope.common.lib.to.AnyTO)1 AttrTO (org.apache.syncope.common.lib.to.AttrTO)1 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)1 UserLogic (org.apache.syncope.core.logic.UserLogic)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1