Search in sources :

Example 6 with Requestable

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

the class DefaultRequestManager method resolveItem.

private void resolveItem(IdmRequestItemDto item) throws ClassNotFoundException, IOException {
    Assert.notNull(item, "Item is mandatory!");
    RequestOperationType type = item.getOperation();
    // Get DTO service
    @SuppressWarnings("unchecked") Class<? extends Requestable> dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
    // Get service
    @SuppressWarnings("unchecked") ReadWriteDtoService<Requestable, BaseFilter> dtoService = (ReadWriteDtoService<Requestable, BaseFilter>) this.getServiceByItem(item, dtoClass);
    // Create or Update DTO
    if (RequestOperationType.ADD == type || RequestOperationType.UPDATE == type) {
        Requestable dto = this.convertItemToDto(item, dtoClass);
        // confidential storage
        if (dto instanceof IdmFormValueDto) {
            IdmFormValueDto formValueDto = (IdmFormValueDto) dto;
            if (formValueDto.isConfidential()) {
                formValueDto.setValue(this.getConfidentialPersistentValue(item));
            }
        }
        // Save without check a permissions
        dto = dtoService.save(dto);
        item.setResult(new OperationResultDto(OperationState.EXECUTED));
        item.setState(RequestState.EXECUTED);
        requestItemService.save(item);
        return;
    }
    // Delete DTO
    if (RequestOperationType.REMOVE == type) {
        Assert.notNull(item.getOwnerId(), "Id in item is required for delete!");
        Requestable dtoToDelete = dtoService.get(item.getOwnerId());
        if (dtoToDelete == null) {
            item.setResult(new // 
            OperationResultDto.Builder(// 
            OperationState.NOT_EXECUTED).setException(new ResultCodeException(CoreResultCode.NOT_FOUND, // 
            ImmutableMap.of("entity", item.getOriginalCreatorId()))).build());
            requestItemService.save(item);
            return;
        }
        // Delete without check a permissions
        dtoService.deleteById(dtoToDelete.getId());
        item.setResult(new OperationResultDto(OperationState.EXECUTED));
        item.setState(RequestState.EXECUTED);
        requestItemService.save(item);
        return;
    }
}
Also used : Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter)

Example 7 with Requestable

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

the class RequestManagerTest method testGetChangesOnCreateRoleByRequest.

@Test
public void testGetChangesOnCreateRoleByRequest() {
    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);
    IdmRequestItemChangesDto changes = requestManager.getChanges(requestItemService.get(requestable.getRequestItem()));
    Assert.assertNotNull(changes);
    List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
    attributes.forEach(attribute -> {
        Assert.assertEquals(RequestOperationType.ADD, attribute.getValue().getChange());
    });
}
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) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 8 with Requestable

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

the class RequestManagerTest method testDeleteRequestable.

@Test
public void testDeleteRequestable() {
    // Create role
    IdmRoleDto changedRole = getHelper().createRole();
    // 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());
    Assert.assertNotNull(requestItemService.get(requestable.getRequestItem()));
    // Delete the role
    roleService.delete(changedRole);
    // Request item must be canceled
    IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
    Assert.assertNotNull(requestItem);
    Assert.assertEquals(RequestState.CANCELED, requestItem.getState());
    // Request must be canceled
    request = requestService.get(request.getId());
    Assert.assertNotNull(request);
    Assert.assertEquals(RequestState.CANCELED, request.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 9 with Requestable

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

the class RequestManagerTest method testChangeRoleWithGuaranteesApprove.

@Test
public void testChangeRoleWithGuaranteesApprove() {
    // 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());
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    loginAsNoAdmin(guarantee.getUsername());
    try {
        completeTasksFromUsers(guarantee.getId().toString(), "approve");
    } catch (ResultCodeException e) {
        fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
    } catch (Exception e) {
        fail("Some problem: " + e.getLocalizedMessage());
    }
    // Reload the request (after approving)
    executedRequest = requestService.get(executedRequest.getId());
    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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 10 with Requestable

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

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