Search in sources :

Example 26 with IdmConceptRoleRequestDto

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

the class ModelMapperConfig method modelMapper.

@SuppressWarnings("unchecked")
@Bean
public ModelMapper modelMapper() {
    ModelMapper modeler = new ModelMapper();
    // We want use STRICT matching strategy ... others can be ambiguous
    modeler.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    // Convert BaseEntity to UIID (get ID)
    Converter<? extends BaseEntity, UUID> entityToUiid = new EntityToUuidConverter(modeler, applicationContext);
    // Convert UIID to Entity
    Converter<UUID, ? extends BaseEntity> uiidToEntity = new UuidToEntityConverter(applicationContext);
    // This converter must be set for only one purpose... workaround fixed
    // error in ModelMapper.
    // When is in DTO field (applicant for example) with type UUID (with
    // conversion to IdmIdentity) and other UUID field (for example
    // modifierId), but with same value as first field, then mapper will be
    // set converted value from first field (applicant) to second field (IdmIdentity to UUID) ->
    // Class cast exception will be throw.
    // + Additionally this converter allows load DTO (by UUID) and put him to embedded map.
    Converter<UUID, UUID> uuidToUiid = new UuidToUuidConverter(applicationContext);
    modeler.createTypeMap(UUID.class, UUID.class).setConverter(uuidToUiid);
    // Converter for resolve problem with 0x00 character in Postgress.
    modeler.createTypeMap(String.class, String.class).setConverter(new StringToStringConverter());
    // Converter OperationResult for resolve problem with 0x00 character in Postgress.
    modeler.createTypeMap(OperationResult.class, OperationResult.class).setConverter(new OperationResultConverter(modeler));
    // Condition for property ... if is property list and dto is trimmed,
    // then will be not used (set null)
    // or if is property list and have parent dto, then will be to set null
    // (only two levels are allowed).
    Condition<Object, Object> trimmListCondition = new Condition<Object, Object>() {

        @Override
        public boolean applies(MappingContext<Object, Object> context) {
            if (List.class.isAssignableFrom(context.getDestinationType())) {
                MappingContext<?, ?> parentContext = context.getParent();
                MappingContext<?, ?> superContext = parentContext != null ? parentContext.getParent() : null;
                if (superContext != null) {
                    if (parentContext != null && parentContext.getDestination() instanceof AbstractDto) {
                        ((AbstractDto) parentContext.getDestination()).setTrimmed(true);
                    }
                    return false;
                }
                if (parentContext != null && parentContext.getDestination() instanceof AbstractDto && ((AbstractDto) parentContext.getDestination()).isTrimmed()) {
                    return false;
                }
            }
            return true;
        }
    };
    modeler.getConfiguration().setPropertyCondition(trimmListCondition);
    // entity to uiid converters will be set for all entities
    entityManager.getMetamodel().getEntities().forEach(entityType -> {
        if (entityType.getJavaType() == null) {
            return;
        }
        @SuppressWarnings("rawtypes") TypeMap typeMapEntityToUiid = modeler.createTypeMap(entityType.getJavaType(), UUID.class);
        typeMapEntityToUiid.setConverter(entityToUiid);
        @SuppressWarnings("rawtypes") TypeMap typeMapUiidToEntity = modeler.createTypeMap(UUID.class, entityType.getJavaType());
        typeMapUiidToEntity.setConverter(uiidToEntity);
    });
    // configure default type map for entities
    // this behavior must be placed in this class, not in toDto methods (getEmbedded use mapper for map entity to dto)
    // identity role and backward compatibility with automatic role
    TypeMap<IdmIdentityRole, IdmIdentityRoleDto> typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
    if (typeMapIdentityRole == null) {
        modeler.createTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole.addMappings(new PropertyMap<IdmIdentityRole, IdmIdentityRoleDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(this.source.getAutomaticRole() != null);
            }
        });
    }
    // concept role request and automatic role backward compatibility
    TypeMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto> typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
    if (typeMapRoleConcept == null) {
        modeler.createTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept.addMappings(new PropertyMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    return modeler;
}
Also used : IdmConceptRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) OperationResultConverter(eu.bcvsolutions.idm.core.config.domain.OperationResultConverter) EntityToUuidConverter(eu.bcvsolutions.idm.core.config.domain.EntityToUuidConverter) MappingContext(org.modelmapper.spi.MappingContext) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) UuidToUuidConverter(eu.bcvsolutions.idm.core.config.domain.UuidToUuidConverter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) UuidToEntityConverter(eu.bcvsolutions.idm.core.config.domain.UuidToEntityConverter) Condition(org.modelmapper.Condition) ModelMapper(org.modelmapper.ModelMapper) StringToStringConverter(eu.bcvsolutions.idm.core.config.domain.StringToStringConverter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) TypeMap(org.modelmapper.TypeMap) Bean(org.springframework.context.annotation.Bean)

Example 27 with IdmConceptRoleRequestDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method duplicatedRequestExceptionTest.

@Test()
@Transactional()
public void duplicatedRequestExceptionTest() {
    loginAsAdmin(USER_TEST_A);
    IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
    IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
    IdmRoleRequestDto request = new IdmRoleRequestDto();
    request.setApplicant(testA.getId());
    request.setExecuteImmediately(false);
    request.setRequestedByType(RoleRequestedByType.MANUALLY);
    IdmRoleRequestDto requestA = roleRequestService.save(request);
    Assert.assertEquals(RoleRequestState.CONCEPT, requestA.getState());
    LocalDate validFrom = new LocalDate().minusDays(1);
    LocalDate validTill = new LocalDate().plusMonths(1);
    IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
    conceptA.setRoleRequest(requestA.getId());
    conceptA.setOperation(ConceptRoleRequestOperation.ADD);
    conceptA.setRole(roleA.getId());
    conceptA.setValidFrom(validFrom);
    conceptA.setValidTill(validTill);
    conceptA.setIdentityContract(contractA.getId());
    conceptRoleRequestService.save(conceptA);
    roleRequestService.startRequestInternal(requestA.getId(), true);
    requestA = roleRequestService.get(requestA.getId());
    Assert.assertEquals(RoleRequestState.IN_PROGRESS, requestA.getState());
    IdmRoleRequestDto requestB = roleRequestService.save(request);
    conceptA.setRoleRequest(requestB.getId());
    conceptRoleRequestService.save(conceptA);
    // We expect duplication exception
    roleRequestService.startRequestInternal(requestB.getId(), true);
    requestB = roleRequestService.get(requestB.getId());
    Assert.assertEquals(RoleRequestState.DUPLICATED, requestB.getState());
    Assert.assertEquals(requestA.getId(), requestB.getDuplicatedToRequest());
    // We change only description (remove duplicity)
    requestB.setDescription("-----");
    roleRequestService.save(requestB);
    // We expect correct start
    roleRequestService.startRequestInternal(requestB.getId(), true);
    requestB = roleRequestService.get(requestB.getId());
    Assert.assertEquals(RoleRequestState.IN_PROGRESS, requestB.getState());
    Assert.assertEquals(null, requestB.getDuplicatedToRequest());
}
Also used : IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) LocalDate(org.joda.time.LocalDate) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with IdmConceptRoleRequestDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method noSameApplicantExceptionTest.

@Test(expected = RoleRequestException.class)
@Transactional()
public void noSameApplicantExceptionTest() {
    IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
    IdmIdentityDto testB = identityService.getByUsername(USER_TEST_B);
    IdmIdentityContractDto contractB = identityContractService.getPrimeContract(testB.getId());
    IdmRoleRequestDto request = new IdmRoleRequestDto();
    request.setApplicant(testA.getId());
    request.setExecuteImmediately(true);
    request.setRequestedByType(RoleRequestedByType.MANUALLY);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
    conceptA.setRoleRequest(request.getId());
    conceptA.setOperation(ConceptRoleRequestOperation.ADD);
    conceptA.setRole(roleA.getId());
    // Contract from
    conceptA.setIdentityContract(contractB.getId());
    // applicant B
    conceptA = conceptRoleRequestService.save(conceptA);
    // excepted ROLE_REQUEST_APPLICANTS_NOT_SAME exception
    roleRequestService.startRequestInternal(request.getId(), true);
}
Also used : IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with IdmConceptRoleRequestDto

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

the class DefaultIdmRoleRequestServiceIntegrationTest method addPermissionViaRoleRequestTest.

@Test
@Transactional()
public void addPermissionViaRoleRequestTest() {
    IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
    IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
    IdmRoleRequestDto request = new IdmRoleRequestDto();
    request.setApplicant(testA.getId());
    request.setExecuteImmediately(true);
    request.setRequestedByType(RoleRequestedByType.MANUALLY);
    // can not be saved (after
    request.setState(RoleRequestState.EXECUTED);
    // create must be
    // CONCEPT)
    request = roleRequestService.save(request);
    Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
    LocalDate validFrom = new LocalDate().minusDays(1);
    LocalDate validTill = new LocalDate().plusMonths(1);
    IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
    conceptA.setRoleRequest(request.getId());
    // can not be saved (after
    conceptA.setState(RoleRequestState.EXECUTED);
    // create must be
    // CONCEPT)
    conceptA.setOperation(ConceptRoleRequestOperation.ADD);
    conceptA.setRole(roleA.getId());
    conceptA.setValidFrom(validFrom);
    conceptA.setValidTill(validTill);
    conceptA.setIdentityContract(contractA.getId());
    conceptA = conceptRoleRequestService.save(conceptA);
    Assert.assertEquals(RoleRequestState.CONCEPT, conceptA.getState());
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(testA.getId());
    Assert.assertEquals(1, identityRoles.size());
    Assert.assertEquals(validFrom, identityRoles.get(0).getValidFrom());
    Assert.assertEquals(validTill, identityRoles.get(0).getValidTill());
    Assert.assertEquals(contractA.getId(), identityRoles.get(0).getIdentityContract());
    Assert.assertEquals(roleA.getId(), identityRoles.get(0).getRole());
}
Also used : IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) LocalDate(org.joda.time.LocalDate) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with IdmConceptRoleRequestDto

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

the class DefaultIdmConceptRoleRequestService method toEntity.

@Override
@Transactional(readOnly = true)
public IdmConceptRoleRequest toEntity(IdmConceptRoleRequestDto dto, IdmConceptRoleRequest entity) {
    if (dto == null) {
        return null;
    }
    // TODO: Create converter for skip fields mark as read only
    if (dto.getId() != null) {
        IdmConceptRoleRequestDto dtoPersisited = this.get(dto.getId());
        if (dto.getState() == null) {
            dto.setState(dtoPersisited.getState());
        }
        if (dto.getLog() == null) {
            dto.setLog(dtoPersisited.getLog());
        }
        if (dto.getWfProcessId() == null) {
            dto.setWfProcessId(dtoPersisited.getWfProcessId());
        }
    } else {
        dto.setState(RoleRequestState.CONCEPT);
    }
    // 
    // field automatic role exists in entity but not in dto
    TypeMap<IdmConceptRoleRequestDto, IdmConceptRoleRequest> typeMap = modelMapper.getTypeMap(getDtoClass(), getEntityClass());
    if (typeMap == null) {
        modelMapper.createTypeMap(getDtoClass(), getEntityClass());
        typeMap = modelMapper.getTypeMap(getDtoClass(), getEntityClass());
        typeMap.addMappings(new PropertyMap<IdmConceptRoleRequestDto, IdmConceptRoleRequest>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    // 
    if (entity != null) {
        modelMapper.map(dto, entity);
    } else {
        entity = modelMapper.map(dto, getEntityClass(dto));
    }
    // set additional automatic role
    if (entity != null) {
        if (dto.getAutomaticRole() != null) {
            // it isn't possible use lookupService entity lookup
            IdmAutomaticRole automaticRole = automaticRoleRepository.findOne(dto.getAutomaticRole());
            entity.setAutomaticRole(automaticRole);
        } else {
            // relation was removed
            entity.setAutomaticRole(null);
        }
    }
    return entity;
}
Also used : IdmConceptRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest) IdmAutomaticRole(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)56 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)50 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)48 Test (org.junit.Test)47 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)45 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)45 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)36 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)35 List (java.util.List)26 ArrayList (java.util.ArrayList)25 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)24 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)24 Transactional (org.springframework.transaction.annotation.Transactional)19 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)6 IdmConceptRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter)4 LocalDate (org.joda.time.LocalDate)4 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)3