Search in sources :

Example 1 with BulkActionResult

use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.

the class AbstractAnyService method deassociate.

@Override
public Response deassociate(final DeassociationPatch patch) {
    Date etagDate = findLastChange(patch.getKey());
    checkETag(String.valueOf(etagDate.getTime()));
    ProvisioningResult<TO> updated;
    switch(patch.getAction()) {
        case UNLINK:
            updated = new ProvisioningResult<>();
            updated.setEntity(getAnyLogic().unlink(patch.getKey(), patch.getResources()));
            break;
        case UNASSIGN:
            updated = getAnyLogic().unassign(patch.getKey(), patch.getResources(), isNullPriorityAsync());
            break;
        case DEPROVISION:
            updated = getAnyLogic().deprovision(patch.getKey(), patch.getResources(), isNullPriorityAsync());
            break;
        default:
            updated = new ProvisioningResult<>();
            updated.setEntity(getAnyLogic().read(patch.getKey()));
    }
    BulkActionResult result = new BulkActionResult();
    if (patch.getAction() == ResourceDeassociationAction.UNLINK) {
        patch.getResources().forEach(resource -> {
            result.getResults().put(resource, updated.getEntity().getResources().contains(resource) ? BulkActionResult.Status.FAILURE : BulkActionResult.Status.SUCCESS);
        });
    } else {
        updated.getPropagationStatuses().forEach(propagationStatusTO -> result.getResults().put(propagationStatusTO.getResource(), BulkActionResult.Status.valueOf(propagationStatusTO.getStatus().toString())));
    }
    return modificationResponse(result);
}
Also used : BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyTO(org.apache.syncope.common.lib.to.AnyTO) Date(java.util.Date)

Example 2 with BulkActionResult

use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.

the class TaskServiceImpl method bulk.

@Override
public BulkActionResult bulk(final BulkAction bulkAction) {
    BulkActionResult result = new BulkActionResult();
    switch(bulkAction.getType()) {
        case DELETE:
            for (String key : bulkAction.getTargets()) {
                try {
                    result.getResults().put(logic.delete(null, key).getKey(), BulkActionResult.Status.SUCCESS);
                } catch (Exception e) {
                    LOG.error("Error performing delete for task {}", key, e);
                    result.getResults().put(key, BulkActionResult.Status.FAILURE);
                }
            }
            break;
        case DRYRUN:
            for (String key : bulkAction.getTargets()) {
                try {
                    logic.execute(key, null, true);
                    result.getResults().put(key, BulkActionResult.Status.SUCCESS);
                } catch (Exception e) {
                    LOG.error("Error performing dryrun for task {}", key, e);
                    result.getResults().put(key, BulkActionResult.Status.FAILURE);
                }
            }
            break;
        case EXECUTE:
            for (String key : bulkAction.getTargets()) {
                try {
                    logic.execute(key, null, false);
                    result.getResults().put(key, BulkActionResult.Status.SUCCESS);
                } catch (Exception e) {
                    LOG.error("Error performing execute for task {}", key, e);
                    result.getResults().put(key, BulkActionResult.Status.FAILURE);
                }
            }
            break;
        default:
    }
    return result;
}
Also used : BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) BadRequestException(javax.ws.rs.BadRequestException)

Example 3 with BulkActionResult

use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.

the class AbstractAnyRestClient method provision.

public BulkActionResult provision(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses);
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(key).action(ResourceAssociationAction.PROVISION).onSyncope(statusPatch.isOnSyncope()).resources(statusPatch.getResources()).build();
        result = service.associate(associationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch)

Example 4 with BulkActionResult

use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.

the class AbstractAnyRestClient method assign.

public BulkActionResult assign(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses);
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(key).action(ResourceAssociationAction.ASSIGN).onSyncope(statusPatch.isOnSyncope()).resources(statusPatch.getResources()).build();
        result = service.associate(associationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch)

Example 5 with BulkActionResult

use of org.apache.syncope.common.lib.to.BulkActionResult in project syncope by apache.

the class AbstractAnyRestClient method deprovision.

public BulkActionResult deprovision(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(key).action(ResourceDeassociationAction.DEPROVISION).resources(StatusUtils.buildStatusPatch(statuses).getResources()).build();
        result = service.deassociate(deassociationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Aggregations

BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)18 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)6 Date (java.util.Date)3 AssociationPatch (org.apache.syncope.common.lib.patch.AssociationPatch)3 DeassociationPatch (org.apache.syncope.common.lib.patch.DeassociationPatch)3 AnyTO (org.apache.syncope.common.lib.to.AnyTO)3 AttrTO (org.apache.syncope.common.lib.to.AttrTO)3 UserTO (org.apache.syncope.common.lib.to.UserTO)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 BadRequestException (javax.ws.rs.BadRequestException)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)2 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)2 UserService (org.apache.syncope.common.rest.api.service.UserService)2 Test (org.junit.jupiter.api.Test)2 SchedulerException (org.quartz.SchedulerException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 NotSupportedException (javax.ws.rs.NotSupportedException)1 BooleanReplacePatchItem (org.apache.syncope.common.lib.patch.BooleanReplacePatchItem)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1