Search in sources :

Example 46 with AbstractDto

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

the class SystemExportBulkActionIntegrationTest method testExportAndImportConnectorConfigsForTwoSystems.

@Test
public void testExportAndImportConnectorConfigsForTwoSystems() {
    SysSystemDto systemOne = createSystem();
    SysSystemDto systemTwo = createSystem();
    // Load configurations
    IcConnectorConfiguration originalConnectorConfigurationOne = systemService.getConnectorConfiguration(systemOne);
    Assert.assertNotNull(originalConnectorConfigurationOne);
    Assert.assertTrue(originalConnectorConfigurationOne.getConfigurationProperties().getProperties().size() > 0);
    IcConnectorConfiguration originalConnectorConfigurationTwo = systemService.getConnectorConfiguration(systemTwo);
    Assert.assertNotNull(originalConnectorConfigurationTwo);
    Assert.assertTrue(originalConnectorConfigurationTwo.getConfigurationProperties().getProperties().size() > 0);
    ArrayList<AbstractDto> systems = Lists.newArrayList(systemOne, systemTwo);
    // Make export, upload, delete system and import
    executeExportAndImport(systems, SysSystemDto.class, SystemExportBulkAction.NAME, null);
    systemOne = systemService.get(systemOne.getId());
    Assert.assertNotNull(systemOne);
    systemTwo = systemService.get(systemTwo.getId());
    Assert.assertNotNull(systemTwo);
    checkConnectorConfiguration(systemOne, originalConnectorConfigurationOne);
    checkConnectorConfiguration(systemTwo, originalConnectorConfigurationTwo);
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 47 with AbstractDto

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

the class RequestManagerTest method testDeleteRequestIntegrityWithWf.

@Test
public void testDeleteRequestIntegrityWithWf() {
    // 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);
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    executedRequest = requestService.get(executedRequest.getId());
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    String processId = executedRequest.getWfProcessId();
    Assert.assertNotNull(processId);
    // Wf process is in progress
    WorkflowProcessInstanceDto processInstace = workflowProcessInstanceService.get(processId);
    Assert.assertNotNull(processInstace);
    // Two items should be created
    Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
    // Delete the request
    requestService.delete(executedRequest);
    IdmRequestDto requestDeleted = requestService.get(executedRequest.getId());
    Assert.assertNull(requestDeleted);
    // Process should be deleted (canceled)
    processInstace = workflowProcessInstanceService.get(processId);
    Assert.assertNull(processInstace);
}
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) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 48 with AbstractDto

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

the class RequestManagerTest method testBasicItemIntegrity.

@Test
public void testBasicItemIntegrity() {
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    // null -> DELETE
    // Create delete 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);
    // DELETE -> CHANGE
    // Create change request item
    role.setDescription(getHelper().createName());
    Requestable requestablePost = requestManager.post(request.getId(), requestable);
    IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
    // In one request can exists only one item for same owner -> change item must be
    // same (updated) as in delete cause.
    Assert.assertEquals(requestItem.getId(), changeRequestItem.getId());
    // CHANGE -> null
    // Create delete request item (again)
    requestable = requestManager.delete(request.getId(), requestablePost);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    // Previous item was deleted
    List<IdmRequestItemDto> items = requestManager.findRequestItems(request.getId(), null);
    Assert.assertEquals(0, items.size());
    // null -> DELETE
    // Create delete request item
    requestable = requestManager.delete(request.getId(), requestable);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
    // DELETE -> null
    // Again delete same DTO. In this situation should be previous item (delete)
    // deleted.
    requestable = requestManager.delete(request.getId(), requestable);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
    IdmRoleDto newRole = new IdmRoleDto();
    newRole.setCode(getHelper().createName());
    newRole.setName(newRole.getCode());
    // null -> ADD
    Requestable newRequestable = requestManager.post(request.getId(), newRole);
    Assert.assertNotNull(newRequestable);
    Assert.assertNotNull(newRequestable.getRequestItem());
    IdmRequestItemDto newRequestItem = DtoUtils.getEmbedded((AbstractDto) newRequestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.ADD, newRequestItem.getOperation());
    // One item must exists now
    Assert.assertEquals(1, requestManager.findRequestItems(request.getId(), null).size());
    // ADD -> null
    // Delete of DTO, which is not created in DB causes his deleting.
    requestable = requestManager.delete(request.getId(), newRequestable);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    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) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 49 with AbstractDto

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

the class AbstractReadDtoService method toDtos.

/**
 * Converts list of entities to list of DTOs.
 * Method check returned value from method {@link AbstractReadDtoService#supportsToDtoWithFilter()}.
 * If the method {@link AbstractReadDtoService#supportsToDtoWithFilter()} return true
 * the method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto, BaseFilter)} will be called.
 * Otherwise will be called method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto)}.
 *
 * @param entities
 * @param trimmed
 * @param filter
 * @return
 */
protected List<DTO> toDtos(List<E> entities, boolean trimmed, F filter) {
    if (entities == null) {
        return null;
    }
    List<DTO> dtos = new ArrayList<>();
    entities.forEach(entity -> {
        try {
            DTO newDto = this.getDtoClass(entity).getDeclaredConstructor().newInstance();
            if (newDto instanceof AbstractDto) {
                ((AbstractDto) newDto).setTrimmed(trimmed);
            }
            DTO dto = null;
            // Check if service support filter mapping and use it for transform entity to DTO
            if (supportsToDtoWithFilter()) {
                dto = this.toDto(entity, newDto, filter);
            } else {
                dto = this.toDto(entity, newDto);
            }
            dtos.add(dto);
        } catch (ReflectiveOperationException ex) {
            throw new CoreException(ex);
        }
    });
    return dtos;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ArrayList(java.util.ArrayList)

Example 50 with AbstractDto

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

the class ModelMapperConfig method modelMapper.

@SuppressWarnings("unchecked")
@Bean
public ModelMapper modelMapper() {
    ModelMapper modeler = new ModelMapper();
    modeler.getConfiguration().setMatchingStrategy(// We want use STRICT matching strategy ... others can be ambiguous.
    MatchingStrategies.STRICT).setSkipNullEnabled(// prevent to skip null property values
    false);
    // Convert BaseEntity to UIID (get ID)
    // FIXME: Fix EntityToUuidConditionalConverter field resolving and use conditional converter instead this.
    Converter<? extends BaseEntity, UUID> entityToUuid = new EntityToUuidConverter(modeler, applicationContext);
    // Convert UIID to Entity
    // Conditional converter is using here, because ModelMapper contains bug with
    // skipping converter if source value is null. More here https://redmine.czechidm.com/issues/2271.
    modeler.getConfiguration().getConverters().add(new UuidToEntityConditionalConverter(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> uuidToUuid = new UuidToUuidConverter(applicationContext);
    modeler.createTypeMap(UUID.class, UUID.class).setConverter(uuidToUuid);
    // 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 PostgreSQL.
    modeler.createTypeMap(OperationResult.class, OperationResult.class).setConverter(new OperationResultConverter(modeler));
    // Simple ConfigurationMap converter - map without template is not provided by model mapper out of box.
    modeler.createTypeMap(ConfigurationMap.class, ConfigurationMap.class).setConverter(new ConfigurationMapToConfigurationMapConverter());
    // 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> trimListCondition = 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(trimListCondition);
    // entity to uuid converters will be set for all entities
    entityManager.getMetamodel().getEntities().forEach(entityType -> {
        if (entityType.getJavaType() == null) {
            return;
        }
        @SuppressWarnings("rawtypes") TypeMap typeMapEntityToUuid = modeler.createTypeMap(entityType.getJavaType(), UUID.class);
        typeMapEntityToUuid.setConverter(entityToUuid);
    });
    // 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(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 : UuidToEntityConditionalConverter(eu.bcvsolutions.idm.core.config.domain.UuidToEntityConditionalConverter) 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) Condition(org.modelmapper.Condition) ModelMapper(org.modelmapper.ModelMapper) StringToStringConverter(eu.bcvsolutions.idm.core.config.domain.StringToStringConverter) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) ConfigurationMapToConfigurationMapConverter(eu.bcvsolutions.idm.core.config.domain.ConfigurationMapToConfigurationMapConverter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) TypeMap(org.modelmapper.TypeMap) Bean(org.springframework.context.annotation.Bean)

Aggregations

AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)54 UUID (java.util.UUID)28 Test (org.junit.Test)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)15 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)13 HashMap (java.util.HashMap)12 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Assert (org.springframework.util.Assert)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 Map (java.util.Map)10 Service (org.springframework.stereotype.Service)10 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IntrospectionException (java.beans.IntrospectionException)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ImmutableMap (com.google.common.collect.ImmutableMap)8