Search in sources :

Example 6 with BulkActionResult

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;
}
Also used : PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Example 7 with BulkActionResult

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());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) BulkAction(org.apache.syncope.common.lib.to.BulkAction) Test(org.junit.jupiter.api.Test)

Example 8 with BulkActionResult

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());
}
Also used : ReportTO(org.apache.syncope.common.lib.to.ReportTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) BulkExecDeleteQuery(org.apache.syncope.common.rest.api.beans.BulkExecDeleteQuery) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with BulkActionResult

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);
}
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 10 with BulkActionResult

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);
}
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

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