Search in sources :

Example 11 with Requestable

use of eu.bcvsolutions.idm.core.api.domain.Requestable 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 12 with Requestable

use of eu.bcvsolutions.idm.core.api.domain.Requestable 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 13 with Requestable

use of eu.bcvsolutions.idm.core.api.domain.Requestable 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 14 with Requestable

use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testChangeRoleWithGuaranteesSkipApproving.

@Test
public void testChangeRoleWithGuaranteesSkipApproving() {
    // Create role with guarantee
    IdmIdentityDto guarantee = getHelper().createIdentity();
    IdmRoleDto changedRole = getHelper().createRole();
    getHelper().createRoleGuarantee(changedRole, guarantee);
    // Create request
    IdmRequestDto request = requestManager.createRequest(changedRole);
    Assert.assertNotNull(request);
    Assert.assertEquals(request.getOwnerType(), changedRole.getClass().getName());
    Assert.assertEquals(request.getOwnerId(), changedRole.getId());
    // Change role (without save)
    changedRole.setDescription(getHelper().createName());
    changedRole.setPriority(1000);
    // Create request item
    Requestable requestable = requestManager.post(request.getId(), changedRole);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
    // Is not same instance
    Assert.assertTrue(changedRole != roleFromRequest);
    // Has same values as new role
    Assert.assertEquals(changedRole.getPriority(), roleFromRequest.getPriority());
    Assert.assertEquals(changedRole.getDescription(), roleFromRequest.getDescription());
    IdmRoleDto currentRole = roleService.get(changedRole.getId());
    Assert.assertNotEquals(changedRole.getPriority(), currentRole.getPriority());
    Assert.assertNotEquals(changedRole.getDescription(), currentRole.getDescription());
    // Skip approving
    request.setExecuteImmediately(true);
    request = requestService.save(request);
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    // Role has guarantee, but approval process wasn't started because the request
    // skipped approving.
    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(changedRole.getCode(), executedRole.getCode());
    Assert.assertEquals(changedRole.getName(), executedRole.getName());
    Assert.assertEquals(changedRole.getPriority(), executedRole.getPriority());
    Assert.assertEquals(changedRole.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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 15 with Requestable

use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.

the class RequestApprovalProcessor method process.

@SuppressWarnings("unchecked")
@Override
public EventResult<IdmRequestDto> process(EntityEvent<IdmRequestDto> event) {
    IdmRequestDto dto = event.getContent();
    boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
    // 
    String ownerTyp = dto.getOwnerType();
    Assert.notNull(ownerTyp, "Owner type is rquired for start approval process!");
    Class<Requestable> ownerClass = null;
    try {
        ownerClass = (Class<Requestable>) Class.forName(ownerTyp);
    } catch (ClassNotFoundException e) {
        throw new CoreException(e);
    }
    String wfDefinition = requestConfiguration.getRequestApprovalProcessKey(ownerClass);
    if (Strings.isNullOrEmpty(wfDefinition)) {
        throw new ResultCodeException(CoreResultCode.REQUEST_NO_WF_DEF_FOUND, ImmutableMap.of("entityType", dto.getOwnerType()));
    }
    boolean approved = manager.startApprovalProcess(dto, checkRight, event, wfDefinition);
    DefaultEventResult<IdmRequestDto> result = new DefaultEventResult<>(event, this);
    result.setSuspended(!approved);
    return result;
}
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) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)

Aggregations

Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)28 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)13 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)13 Test (org.junit.Test)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)5 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)5 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)5 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)5 IOException (java.io.IOException)5 Strings (com.google.common.base.Strings)4 ImmutableList (com.google.common.collect.ImmutableList)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)4 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)4