Search in sources :

Example 1 with ImportContext

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

the class DefaultImportManager method internalExecuteImport.

@Override
@Transactional
public ImportContext internalExecuteImport(IdmExportImportDto batch, boolean dryRun, AbstractLongRunningTaskExecutor<OperationResult> importTaskExecutor) {
    Assert.notNull(batch, "Batch cannot be null!");
    Assert.notNull(batch.getId(), "Batch ID cannot be null!");
    LOG.info("Internal import [{}, dry-run: {}] starts ...", batch.toString(), dryRun);
    // Delete all logs for this batch.
    IdmImportLogFilter logFilter = new IdmImportLogFilter();
    logFilter.setBatchId(batch.getId());
    // 
    importLogService.findIds(logFilter, null).getContent().forEach(logId -> importLogService.deleteById(logId));
    IdmAttachmentDto attachment = attachmentManager.get(batch.getData());
    Path tempDirectory = null;
    try {
        tempDirectory = extractZip(attachment);
        // Load manifest - batch contains order of import
        IdmExportImportDto manifest = validate(tempDirectory);
        ImportContext context = new ImportContext();
        // 
        context.setTempDirectory(tempDirectory).setManifest(// 
        manifest).setExportDescriptors(// 
        manifest.getExportOrder()).setDryRun(// 
        dryRun).setBatch(// 
        batch).setImportTaskExecutor(importTaskExecutor);
        // Set count of all files in the batch (minus manifest)
        long countOfFiles = countOfFiles(tempDirectory);
        context.getImportTaskExecutor().setCounter(0L);
        context.getImportTaskExecutor().setCount(countOfFiles - 1);
        // Import new and update exist DTOs.
        manifest.getExportOrder().forEach(descriptor -> this.executeImportForType(descriptor, context));
        // Delete redundant DTOs.
        Lists.reverse(manifest.getExportOrder()).forEach(descriptor -> this.removeRedundant(descriptor, context));
        return context;
    } finally {
        // Delete temp files.
        if (tempDirectory != null) {
            FileSystemUtils.deleteRecursively(tempDirectory.toFile());
        }
        LOG.info("Internal import [{}, dry-run: {}] ended", batch.toString(), dryRun);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Path(java.nio.file.Path) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) ImportContext(eu.bcvsolutions.idm.core.api.dto.ImportContext) IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ImportContext

use of eu.bcvsolutions.idm.core.api.dto.ImportContext 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 3 with ImportContext

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

the class DefaultImportManager method getParentDtoFromBatch.

/**
 * Find parent DTO in the batch by parent field in given DTO.
 *
 * @param dto
 * @param context
 * @return
 * @throws IOException
 */
private BaseDto getParentDtoFromBatch(BaseDto dto, ImportContext context) {
    ExportDescriptorDto descriptor = this.getDescriptor(context, dto.getClass());
    Assert.notNull(descriptor, "Descriptor cannot be null!");
    Set<String> parentFields = descriptor.getParentFields();
    if (parentFields.isEmpty()) {
        return null;
    }
    for (String parentField : parentFields) {
        try {
            UUID parentId = this.getFieldUUIDValue(parentField, dto, dto.getClass());
            Class<? extends AbstractDto> parentType = this.getDtoClassFromField(dto.getClass(), parentField);
            Assert.notNull(parentType, "Parent type cannot be null!");
            if (parentId == null) {
                continue;
            }
            Path dtoTypePath = Paths.get(context.getTempDirectory().toString(), parentType.getSimpleName());
            try (Stream<Path> paths = Files.walk(dtoTypePath)) {
                BaseDto parentDto = // 
                paths.filter(// 
                Files::isRegularFile).map(// 
                path -> convertFileToDto(path.toFile(), parentType, context)).filter(// 
                d -> parentId.equals(d.getId())).findFirst().orElse(null);
                if (parentDto != null) {
                    return parentDto;
                }
            }
        } catch (IOException ex) {
            throw new ResultCodeException(CoreResultCode.IMPORT_ZIP_EXTRACTION_FAILED, ex);
        }
    }
    return null;
}
Also used : ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) Path(java.nio.file.Path) 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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IOException(java.io.IOException) UUID(java.util.UUID) Files(java.nio.file.Files)

Example 4 with ImportContext

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

the class DefaultImportManager method convertStringToDto.

/**
 * Convert given DTO in string to the DTO
 *
 * @param dtoAsString
 * @param dtoClass
 * @param context
 * @return
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonParseException
 */
@SuppressWarnings("unchecked")
private <DTO> DTO convertStringToDto(String dtoAsString, Class<? extends BaseDto> dtoClass, ImportContext context) throws IOException {
    String replacedDtoAsString = dtoAsString;
    Map<UUID, UUID> replacedIDs = context.getReplacedIDs();
    // Find IDs to replace
    Set<UUID> idsToReplace = // 
    replacedIDs.keySet().stream().filter(// 
    oldId -> dtoAsString.contains(oldId.toString())).collect(// 
    Collectors.toSet());
    // Replace found IDs
    for (UUID idToReplace : idsToReplace) {
        replacedDtoAsString = replacedDtoAsString.replace(idToReplace.toString(), replacedIDs.get(idToReplace).toString());
    }
    return (DTO) mapper.readValue(replacedDtoAsString, dtoClass);
}
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) UUID(java.util.UUID)

Example 5 with ImportContext

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

the class DefaultImportManager method validate.

/**
 * Validate import batch
 *
 * @param tempDirectory
 * @return
 */
private IdmExportImportDto validate(Path tempDirectory) {
    Assert.notNull(tempDirectory, "Temp directory cannot be null!");
    File manifest = Paths.get(tempDirectory.toString(), ExportManager.EXPORT_BATCH_FILE_NAME).toFile();
    if (!manifest.exists()) {
        throw new ResultCodeException(CoreResultCode.IMPORT_VALIDATION_FAILED_NO_MANIFEST, ImmutableMap.of("manifest", manifest.getAbsoluteFile()));
    }
    return (IdmExportImportDto) convertFileToDto(manifest, IdmExportImportDto.class, new ImportContext());
}
Also used : IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) ImportContext(eu.bcvsolutions.idm.core.api.dto.ImportContext) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) File(java.io.File)

Aggregations

IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)5 ImportContext (eu.bcvsolutions.idm.core.api.dto.ImportContext)5 IdmImportLogFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)3 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)3 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)3 ExportImportType (eu.bcvsolutions.idm.core.api.domain.ExportImportType)3 Inheritable (eu.bcvsolutions.idm.core.api.domain.Inheritable)3 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)3 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)3 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)3