Search in sources :

Example 6 with AbstractDto

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

the class EntityGenerateValuesProcessor method process.

@Override
public EventResult<AbstractDto> process(EntityEvent<AbstractDto> event) {
    AbstractDto entityDto = event.getContent();
    if (valueGeneratorManager.supportsGenerating(entityDto)) {
        LOG.info("Start generating for entity id [{}] and class [{}].", entityDto.getId(), entityDto.getClass().getCanonicalName());
        entityDto = valueGeneratorManager.generate(entityDto);
        event.setContent(entityDto);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 7 with AbstractDto

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

the class DefaultImportManager method makeAdvancedPairing.

/**
 * Make advanced paring
 *
 * @param dto
 * @param context
 * @param dtoClass
 * @return
 */
private BaseDto makeAdvancedPairing(BaseDto dto, ImportContext context, Class<? extends BaseDto> dtoClass) {
    ExportDescriptorDto descriptor = this.getDescriptor(context, dtoClass);
    for (String advancedParingField : descriptor.getAdvancedParingFields()) {
        try {
            Class<? extends AbstractDto> dtoClassField = this.getDtoClassFromField(dtoClass, advancedParingField);
            if (dtoClassField == null) {
                throw new ResultCodeException(CoreResultCode.IMPORT_FIELD_EMBEDDED_ANNOTATION_MISSING, ImmutableMap.of("field", advancedParingField));
            }
            UUID id = this.getFieldUUIDValue(advancedParingField, dto, dtoClass);
            if (id == null) {
                // ID is null -> no relation exists -> continues
                continue;
            }
            // Get service for DTO in field.
            Class<? extends BaseDto> serviceDtoClass = dtoClassField;
            if (dtoClassField.isAnnotationPresent(Inheritable.class)) {
                serviceDtoClass = dto.getClass().getAnnotation(Inheritable.class).dtoService();
            }
            ReadWriteDtoService<BaseDto, ?> dtoServiceForField = getDtoService(serviceDtoClass);
            BaseDto currentFieldDto = dtoServiceForField.get(id);
            if (currentFieldDto != null) {
                // DTO exists -> no change is necessary.
                continue;
            }
            // DTO not found by ID, we will try find it by code.
            if (dto instanceof AbstractDto) {
                Path dtoPath = Paths.get(context.getTempDirectory().toString(), dtoClass.getSimpleName(), MessageFormat.format("{0}.{1}", dto.getId().toString(), ExportManager.EXTENSION_JSON));
                EmbeddedDto embeddedDto = (EmbeddedDto) this.convertFileToDto(dtoPath.toFile(), EmbeddedDto.class, context);
                JsonNode batchFieldDtoAsString = embeddedDto.getEmbedded().get(advancedParingField);
                if (batchFieldDtoAsString == null) {
                    if (descriptor.isOptional()) {
                        return null;
                    } else {
                        Assert.notNull(batchFieldDtoAsString, MessageFormat.format("Embedded map must contains DTO for advanced paring field [{0}]", advancedParingField));
                    }
                }
                BaseDto batchFieldDto;
                try {
                    batchFieldDto = this.convertStringToDto(batchFieldDtoAsString.toString(), dtoClassField, context);
                    String code = null;
                    if (batchFieldDto instanceof Codeable) {
                        code = ((Codeable) batchFieldDto).getCode();
                        if (Strings.isNotEmpty(code)) {
                            currentFieldDto = lookupService.lookupDto(serviceDtoClass, code);
                        }
                    } else if (batchFieldDto != null) {
                        // Find target DTO by example source DTO (typically by more then one filter field).
                        code = batchFieldDto.toString();
                        EmbeddedDto fieldEmbeddedDto = (EmbeddedDto) this.convertStringToDto(batchFieldDtoAsString.toString(), EmbeddedDto.class, context);
                        currentFieldDto = this.findByExample(batchFieldDto, fieldEmbeddedDto, context);
                    }
                    if (currentFieldDto != null) {
                        // DTO for given code exists -> replace ID by this new in given DTO.
                        // 
                        new PropertyDescriptor(advancedParingField, dtoClass).getWriteMethod().invoke(dto, currentFieldDto.getId());
                        // Save old and new ID for next DTOs.
                        context.getReplacedIDs().put(id, (UUID) currentFieldDto.getId());
                        continue;
                    } else {
                        // If is DTO set as optional, we will only skip this DTO.
                        if (descriptor.isOptional()) {
                            throw new ResultCodeException(CoreResultCode.IMPORT_ADVANCED_PARING_NOT_FOUND_OPTIONAL, ImmutableMap.of("field", advancedParingField, "dto", dto.toString(), "notFoundDto", batchFieldDto.toString(), "code", code));
                        }
                        throw new ResultCodeException(CoreResultCode.IMPORT_ADVANCED_PARING_FAILED_NOT_FOUND, ImmutableMap.of("field", advancedParingField, "dto", dto.toString(), "notFoundDto", batchFieldDto.toString(), "code", code));
                    }
                } catch (IOException e) {
                    throw new ResultCodeException(CoreResultCode.IMPORT_CONVERT_TO_DTO_FAILED, ImmutableMap.of("file", "Converted from String.", "dto", dtoClass), e);
                }
            }
            // (skip this DTO).
            if (descriptor.isOptional()) {
                return null;
            }
        } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
            throw new ResultCodeException(CoreResultCode.EXPORT_IMPORT_REFLECTION_FAILED, e);
        }
    }
    return dto;
}
Also used : Path(java.nio.file.Path) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) PropertyDescriptor(java.beans.PropertyDescriptor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IntrospectionException(java.beans.IntrospectionException) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) EmbeddedDto(eu.bcvsolutions.idm.core.api.dto.EmbeddedDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) UUID(java.util.UUID)

Example 8 with AbstractDto

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

the class DefaultImportManager method removeRedundant.

/**
 * Ensures delete redundant entities in target IdM. Deletes DTOs are within
 * golden DTO type (super parent = typically system, role, ...).
 *
 * @param descriptor
 * @param context
 */
private void removeRedundant(ExportDescriptorDto descriptor, ImportContext context) {
    Class<? extends BaseDto> dtoClass = descriptor.getDtoClass();
    // Does this DTO support the authoritative mode?
    boolean supportsAuthoritativeMode = descriptor.isSupportsAuthoritativeMode();
    if (!supportsAuthoritativeMode) {
        return;
    }
    String superParentFilterProperty = descriptor.getSuperParentFilterProperty();
    Assert.notNull(superParentFilterProperty, "For authoritative mode must be superParentFilterProperty defined!");
    // Find super parent (gold) DTO (typically it is DTO for system, role ...)
    Class<? extends AbstractDto> superParentDtoClass = getSuperParentDtoClass(descriptor, context);
    Assert.notNull(superParentDtoClass, "Supper parent cannot be null here!");
    Path superParentDtoTypePath = Paths.get(context.getTempDirectory().toString(), superParentDtoClass.getSimpleName());
    try {
        // Find all super parent IDs for this DTO type in batch.
        Set<UUID> superParentIdsInBatch;
        try (Stream<Path> paths = Files.walk(superParentDtoTypePath)) {
            superParentIdsInBatch = // 
            paths.filter(// 
            Files::isRegularFile).map(path -> {
                BaseDto dto = convertFileToDto(path.toFile(), superParentDtoClass, context);
                return (UUID) dto.getId();
            }).collect(Collectors.toSet());
        }
        Set<Class<? extends BaseDto>> inheritedClasses = getInheritedClasses(dtoClass, context.getManifest());
        // Find all IDs for all children classes
        Set<Serializable> childrenIdsInBatch = Sets.newHashSet();
        for (Class<? extends BaseDto> inheritedClass : inheritedClasses) {
            // Find all IDs for this DTO type in batch.
            Path dtoTypePath = Paths.get(context.getTempDirectory().toString(), inheritedClass.getSimpleName());
            try (Stream<Path> paths = Files.walk(dtoTypePath)) {
                Set<Serializable> childrenIds = // 
                paths.filter(// 
                Files::isRegularFile).map(// 
                path -> convertFileToDto(path.toFile(), inheritedClass, context)).map(dto -> {
                    // If ID has been replaced, then we need to also replace it.
                    if (context.getReplacedIDs().containsKey((UUID) dto.getId())) {
                        return context.getReplacedIDs().get((UUID) dto.getId());
                    }
                    return dto.getId();
                }).collect(Collectors.toSet());
                childrenIdsInBatch.addAll(childrenIds);
            }
        }
        superParentIdsInBatch.forEach(superParentId -> {
            try {
                Class<? extends BaseDto> serviceDtoClass = dtoClass;
                if (dtoClass.isAnnotationPresent(Inheritable.class)) {
                    serviceDtoClass = dtoClass.getAnnotation(Inheritable.class).dtoService();
                }
                ReadWriteDtoService<BaseDto, BaseFilter> dtoService = getDtoService(serviceDtoClass);
                BaseFilter filterBase = dtoService.getFilterClass().getDeclaredConstructor().newInstance();
                // Fill super-parent-property by superParentId (call setter = check if filter is
                // implemented).
                new PropertyDescriptor(superParentFilterProperty, dtoService.getFilterClass()).getWriteMethod().invoke(filterBase, superParentId);
                // Load all IDs in IdM for this parent ID.
                List<UUID> childrenIdsInIdM = // 
                dtoService.find(filterBase, null).getContent().stream().map(// 
                childDto -> ((AbstractDto) childDto).getId()).collect(Collectors.toList());
                // IDs to delete = entities missing in the batch.
                Set<UUID> idsToDelete = // 
                childrenIdsInIdM.stream().filter(// 
                idmId -> !childrenIdsInBatch.contains(idmId)).collect(Collectors.toSet());
                idsToDelete.forEach(id -> {
                    BaseDto baseDto = dtoService.get(id);
                    IdmImportLogDto dtoLog = new IdmImportLogDto(context.getBatch(), baseDto, RequestOperationType.REMOVE, superParentId);
                    if (!context.isDryRun()) {
                        dtoService.delete(baseDto);
                        dtoLog.setResult(new OperationResultDto(OperationState.EXECUTED));
                    } else {
                        dtoLog.setResult(new OperationResultDto.Builder(OperationState.NOT_EXECUTED).setModel(// 
                        new DefaultResultModel(CoreResultCode.IMPORT_EXECUTED_AS_DRYRUN)).build());
                    }
                    importLogService.saveDistinct(dtoLog);
                });
            } catch (ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
                throw new ResultCodeException(CoreResultCode.EXPORT_IMPORT_REFLECTION_FAILED, e);
            }
        });
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.EXPORT_IMPORT_IO_FAILED, e);
    }
}
Also used : Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) ImportContext(eu.bcvsolutions.idm.core.api.dto.ImportContext) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmImportLogDto(eu.bcvsolutions.idm.core.api.dto.IdmImportLogDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) AttachmentConfiguration(eu.bcvsolutions.idm.core.ecm.api.config.AttachmentConfiguration) Path(java.nio.file.Path) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ImmutableMap(com.google.common.collect.ImmutableMap) ImportTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor) IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Set(java.util.Set) IdmExportImportService(eu.bcvsolutions.idm.core.api.service.IdmExportImportService) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileSystemUtils(org.springframework.util.FileSystemUtils) Sets(com.google.common.collect.Sets) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Inheritable(eu.bcvsolutions.idm.core.api.domain.Inheritable) Objects(java.util.Objects) EmbeddedDto(eu.bcvsolutions.idm.core.api.dto.EmbeddedDto) List(java.util.List) Stream(java.util.stream.Stream) PropertyDescriptor(java.beans.PropertyDescriptor) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) Strings(org.apache.logging.log4j.util.Strings) ExportImportType(eu.bcvsolutions.idm.core.api.domain.ExportImportType) ZipUtils(eu.bcvsolutions.idm.core.api.utils.ZipUtils) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ExportManager(eu.bcvsolutions.idm.core.api.service.ExportManager) ImportManager(eu.bcvsolutions.idm.core.api.service.ImportManager) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) AttachableEntity(eu.bcvsolutions.idm.core.ecm.api.entity.AttachableEntity) Session(org.hibernate.Session) MessageFormat(java.text.MessageFormat) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmImportLogService(eu.bcvsolutions.idm.core.api.service.IdmImportLogService) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) Files(java.nio.file.Files) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) Field(java.lang.reflect.Field) File(java.io.File) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) Paths(java.nio.file.Paths) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Serializable(java.io.Serializable) IntrospectionException(java.beans.IntrospectionException) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmImportLogDto(eu.bcvsolutions.idm.core.api.dto.IdmImportLogDto) UUID(java.util.UUID) Path(java.nio.file.Path) PropertyDescriptor(java.beans.PropertyDescriptor) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IOException(java.io.IOException)

Example 9 with AbstractDto

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

the class DefaultRequestManager method getChanges.

@Override
public List<IdmRequestItemAttributeDto> getChanges(AbstractDto currentDto, AbstractDto changedDto, RequestOperationType itemOperation) {
    List<IdmRequestItemAttributeDto> resultAttributes = new ArrayList<>();
    Map<String, Object> currentFieldsValues = this.dtoToMap(currentDto);
    Map<String, Object> changedFieldsValues = this.dtoToMap(changedDto);
    // First add all new attributes
    changedFieldsValues.keySet().stream().forEach(changedAttribute -> {
        if (!currentFieldsValues.containsKey(changedAttribute)) {
            Object value = changedFieldsValues.get(changedAttribute);
            IdmRequestItemAttributeDto attribute = new IdmRequestItemAttributeDto(changedAttribute, value instanceof List, true);
            if (attribute.isMultivalue()) {
                if (value instanceof List) {
                    ((List<?>) value).forEach(v -> {
                        attribute.getValues().add(new IdmRequestAttributeValueDto(v, null, RequestOperationType.ADD));
                    });
                }
            } else {
                attribute.setValue(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
            }
            resultAttributes.add(attribute);
        }
    });
    // Second add all already exists attributes
    currentFieldsValues.keySet().forEach(currentAttribute -> {
        Object changedValue = changedFieldsValues.get(currentAttribute);
        IdmRequestItemAttributeDto attribute;
        Object currentValue = currentFieldsValues.get(currentAttribute);
        attribute = new IdmRequestItemAttributeDto(currentAttribute, changedValue instanceof List, false);
        if (attribute.isMultivalue()) {
            if (changedValue instanceof List) {
                ((List<?>) changedValue).forEach(value -> {
                    if (currentValue instanceof List && ((List<?>) currentValue).contains(value)) {
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, null));
                    } else {
                        attribute.setChanged(true);
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
                    }
                });
            }
            if (currentValue instanceof List) {
                ((List<?>) currentValue).forEach(value -> {
                    if (changedValue == null || !((List<?>) changedValue).contains(value)) {
                        attribute.setChanged(true);
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, RequestOperationType.REMOVE));
                    }
                });
            }
        } else {
            if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentValue)) || (currentValue != null && currentValue.equals(changedValue))) {
                attribute.setChanged(RequestOperationType.UPDATE == itemOperation ? false : true);
                attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, RequestOperationType.UPDATE == itemOperation ? null : itemOperation));
            } else {
                attribute.setChanged(true);
                attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, itemOperation));
            }
        }
        resultAttributes.add(attribute);
    });
    // Make all values nicer
    // 
    resultAttributes.stream().filter(// 
    attribute -> attribute.getValue() != null).forEach(attribute -> {
        // 
        attribute.getValue().setValue(this.makeNiceValue(attribute.getValue().getValue()));
        attribute.getValue().setOldValue(this.makeNiceValue(attribute.getValue().getOldValue()));
        List<IdmRequestAttributeValueDto> attributeValues = attribute.getValues();
        attributeValues.forEach(attributeValue -> {
            attributeValue.setValue(this.makeNiceValue(attributeValue.getValue()));
            attributeValue.setOldValue(this.makeNiceValue(attributeValue.getOldValue()));
        });
    });
    return resultAttributes;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto)

Example 10 with AbstractDto

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

the class DefaultRequestManager method dtoToMap.

private Map<String, Object> dtoToMap(AbstractDto dto) {
    Map<String, Object> results = new HashMap<>();
    if (dto == null) {
        return results;
    }
    try {
        List<PropertyDescriptor> descriptors = Lists.newArrayList(Introspector.getBeanInfo(dto.getClass()).getPropertyDescriptors());
        List<Field> fields = // 
        Lists.newArrayList(dto.getClass().getDeclaredFields()).stream().filter(// 
        field -> !Requestable.REQUEST_ITEM_FIELD.equals(field.getName())).filter(// 
        field -> !Requestable.REQUEST_FIELD.equals(field.getName())).filter(// 
        field -> !field.isAnnotationPresent(JsonIgnore.class)).collect(// 
        Collectors.toList());
        // Embedded objects
        // 
        fields.stream().filter(// 
        field -> field.isAnnotationPresent(Embedded.class)).forEach(field -> {
            results.put(field.getName(), dto.getEmbedded().get(field.getName()));
        });
        // Others objects
        // 
        fields.stream().filter(// 
        field -> !field.isAnnotationPresent(Embedded.class)).forEach(field -> {
            try {
                PropertyDescriptor fieldDescriptor = // 
                descriptors.stream().filter(// 
                descriptor -> field.getName().equals(descriptor.getName())).findFirst().orElse(// 
                null);
                if (fieldDescriptor != null) {
                    Object value = fieldDescriptor.getReadMethod().invoke(dto);
                    results.put(field.getName(), value);
                }
            } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
                throw new CoreException(e);
            }
        });
    } catch (IntrospectionException e) {
        throw new CoreException(e);
    }
    return results;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) PropertyDescriptor(java.beans.PropertyDescriptor) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) IntrospectionException(java.beans.IntrospectionException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded)

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