Search in sources :

Example 11 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testDeleteRequestIntegrity.

@Test
public void testDeleteRequestIntegrity() {
    // Log as admin, but not user 'admin' (we don't want to skip WF)
    IdmIdentityDto adminUser = getHelper().createIdentity();
    loginAsAdmin(adminUser.getUsername());
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    // Create guarantee
    IdmIdentityDto guarantee = getHelper().createIdentity();
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    Requestable requestablePost = requestManager.post(request.getId(), roleGuarantee);
    IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
    Assert.assertTrue(requestablePost instanceof IdmRoleGuaranteeDto);
    // Change role (without save)
    role.setDescription(getHelper().createName());
    role.setPriority(1000);
    // Create request item
    Requestable requestable = requestManager.post(request.getId(), role);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    // Request should be in concept state
    request = requestService.get(request.getId());
    Assert.assertEquals(RequestState.CONCEPT, request.getState());
    // Two items should be created
    Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
    // Delete the request
    requestService.delete(request);
    IdmRequestDto requestDeleted = requestService.get(request.getId());
    Assert.assertNull(requestDeleted);
    // All items should be deleted
    Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 12 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testCreateRoleByRequest.

@Test
public void testCreateRoleByRequest() {
    IdmRoleDto newRole = new IdmRoleDto();
    newRole.setCode(getHelper().createName());
    newRole.setName(newRole.getCode());
    newRole.setPriority(10);
    newRole.setDescription(getHelper().createName());
    IdmRequestDto request = requestManager.createRequest(newRole);
    Assert.assertNotNull(request);
    Requestable requestable = requestManager.post(request.getId(), newRole);
    Assert.assertNotNull(requestable);
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not same instance
    Assert.assertTrue(newRole != roleFromRequest);
    // Has same values as new role
    Assert.assertEquals(newRole.getCode(), roleFromRequest.getCode());
    Assert.assertEquals(newRole.getName(), roleFromRequest.getName());
    Assert.assertEquals(newRole.getPriority(), roleFromRequest.getPriority());
    Assert.assertEquals(newRole.getDescription(), roleFromRequest.getDescription());
    // Role not exists yet
    Assert.assertNull(roleService.get(roleFromRequest.getId()));
    IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
    Assert.assertNotNull(executedRequest);
    Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
    IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
    // Role must exists now
    Assert.assertNotNull(executedRole);
    // Has same values as new role
    Assert.assertEquals(newRole.getCode(), executedRole.getCode());
    Assert.assertEquals(newRole.getName(), executedRole.getName());
    Assert.assertEquals(newRole.getPriority(), executedRole.getPriority());
    Assert.assertEquals(newRole.getDescription(), executedRole.getDescription());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 13 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testDeleteRoleByRequest.

@Test
public void testDeleteRoleByRequest() {
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    Assert.assertEquals(request.getOwnerType(), role.getClass().getName());
    Assert.assertEquals(request.getOwnerId(), role.getId());
    // Create request item
    Requestable requestable = requestManager.delete(request.getId(), role);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    IdmRequestItemDto requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not deleted yet
    IdmRoleDto currentRole = roleService.get(role.getId());
    Assert.assertNotNull(currentRole);
    // Start request
    IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
    Assert.assertNotNull(executedRequest);
    Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
    // Role have to be deleted
    IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
    Assert.assertNull(executedRole);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 14 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testThrowExceptionFromRequest.

@Test
public void testThrowExceptionFromRequest() {
    IdmRoleDto newRole = new IdmRoleDto();
    newRole.setCode(getHelper().createName());
    newRole.setName(newRole.getCode());
    newRole.setPriority(10);
    newRole.setDescription(getHelper().createName());
    IdmRequestDto request = requestManager.createRequest(newRole);
    Assert.assertNotNull(request);
    Requestable requestable = requestManager.post(request.getId(), newRole);
    Assert.assertNotNull(requestable);
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not same instance
    Assert.assertTrue(newRole != roleFromRequest);
    // Has same values as new role
    Assert.assertEquals(newRole.getCode(), roleFromRequest.getCode());
    Assert.assertEquals(newRole.getName(), roleFromRequest.getName());
    Assert.assertEquals(newRole.getPriority(), roleFromRequest.getPriority());
    Assert.assertEquals(newRole.getDescription(), roleFromRequest.getDescription());
    // Role not exists yet
    Assert.assertNull(roleService.get(roleFromRequest.getId()));
    // We break the item (we want throw exception)
    IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
    requestItem.setOwnerType("TO BREAK IT");
    requestItemService.save(requestItem);
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    Assert.assertEquals(RequestState.EXCEPTION, executedRequest.getState());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 15 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class AbstractRemoveBulkAction method processDto.

@Override
protected OperationResult processDto(DTO dto) {
    try {
        if (dto instanceof Requestable && requestConfiguration.isRequestModeEnabled(dto.getClass())) {
            // Request mode is enabled for that DTO
            Requestable requestable = (Requestable) dto;
            IdmRequestDto request = requestManager.deleteRequestable(requestable, false);
            if (RequestState.IN_PROGRESS == request.getState()) {
                throw new AcceptedException(request.getId().toString());
            }
            if (RequestState.EXCEPTION == request.getState()) {
                throw new CoreException(ExceptionUtils.resolveException(request.getResult().getException()));
            }
            return new OperationResult.Builder(request.getResult().getState()).setCause(request.getResult().getException()).build();
        }
        this.getService().delete(dto);
        return new OperationResult.Builder(OperationState.EXECUTED).build();
    } catch (AcceptedException ex) {
        return new OperationResult.Builder(OperationState.RUNNING).setException(ex).build();
    } catch (ResultCodeException ex) {
        return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
    } catch (Exception ex) {
        Throwable resolvedException = ExceptionUtils.resolveException(ex);
        if (resolvedException instanceof ResultCodeException) {
            return // 
            new OperationResult.Builder(OperationState.EXCEPTION).setException(// 
            (ResultCodeException) resolvedException).build();
        }
        return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Aggregations

IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)47 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)25 Test (org.junit.Test)24 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)23 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)23 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)18 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)18 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)11 UUID (java.util.UUID)11 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)9 Transactional (org.springframework.transaction.annotation.Transactional)9 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)8 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)8 IdmRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter)8 IdmRequestService (eu.bcvsolutions.idm.core.api.service.IdmRequestService)8 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)8 Lists (com.google.common.collect.Lists)7 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)7