Search in sources :

Example 11 with ExportDescriptorDto

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

the class DefaultSysSystemMappingService method export.

@Override
public void export(UUID id, IdmExportImportDto batch) {
    super.export(id, batch);
    // Tree-type will be searching by code (advanced paring by treeType field)
    ExportDescriptorDto descriptorDto = getExportManager().getDescriptor(batch, this.getDtoClass());
    descriptorDto.getAdvancedParingFields().add(SysSystemMapping_.treeType.getName());
    // Export mapped attributes
    SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
    filter.setSystemMappingId(id);
    List<SysSystemAttributeMappingDto> attributes = this.getAttributeMappingService().find(filter, null).getContent();
    if (attributes.isEmpty()) {
        this.getAttributeMappingService().export(ExportManager.BLANK_UUID, batch);
    }
    attributes.forEach(systemAttributeMapping -> {
        this.getAttributeMappingService().export(systemAttributeMapping.getId(), batch);
    });
    // Set parent field -> set authoritative mode.
    getExportManager().setAuthoritativeMode(SysSystemAttributeMapping_.systemMapping.getName(), "systemId", SysSystemAttributeMappingDto.class, batch);
}
Also used : ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)

Example 12 with ExportDescriptorDto

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

the class DefaultIdmRoleGuaranteeRoleService method export.

@Override
public void export(UUID id, IdmExportImportDto batch) {
    Assert.notNull(batch, "Export batch must exist!");
    super.export(id, batch);
    // Advanced pairing
    ExportDescriptorDto descriptorDto = getExportManager().getDescriptor(batch, this.getDtoClass());
    descriptorDto.getAdvancedParingFields().add(IdmRoleGuaranteeRole_.guaranteeRole.getName());
}
Also used : ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)

Example 13 with ExportDescriptorDto

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

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

the class DefaultImportManager method getSuperParentDtoClass.

private Class<? extends AbstractDto> getSuperParentDtoClass(ExportDescriptorDto descriptor, ImportContext context) {
    Class<? extends BaseDto> dtoClass = descriptor.getDtoClass();
    Set<String> parentFields = descriptor.getParentFields();
    if (!CollectionUtils.isEmpty(parentFields)) {
        String parentField = parentFields.toArray(new String[0])[0];
        Class<? extends AbstractDto> superParentDtoClass = null;
        while (superParentDtoClass == null) {
            Class<? extends AbstractDto> parentDtoClass = this.getDtoClassFromField(dtoClass, parentField);
            ExportDescriptorDto parentDescriptor = getDescriptor(context, parentDtoClass);
            Assert.notNull(parentDescriptor, "Descriptor was not found!");
            if (CollectionUtils.isEmpty(parentDescriptor.getParentFields())) {
                superParentDtoClass = parentDtoClass;
            } else {
                dtoClass = parentDtoClass;
                parentField = parentDescriptor.getParentFields().toArray(new String[0])[0];
            }
        }
        return superParentDtoClass;
    }
    return null;
}
Also used : ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)

Example 15 with ExportDescriptorDto

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

the class DefaultImportManager method excludeFields.

/**
 * Resolve excluded fields. If some fields for this DTO class are excluded,
 * then will be sets to a value from the current DTO (or set to the null, if current DTO does not exist).
 *
 * @param dto
 * @param currentDto
 * @param context
 * @return
 */
private BaseDto excludeFields(BaseDto dto, BaseDto currentDto, ImportContext context) {
    if (dto == null) {
        return null;
    }
    ExportDescriptorDto descriptor = this.getDescriptor(context, dto.getClass());
    Assert.notNull(descriptor, "Descriptor cannot be null here!");
    descriptor.getExcludedFields().forEach(excludedField -> {
        Object currentFieldValue = null;
        if (currentDto != null) {
            currentFieldValue = this.getDtoFieldValue(currentDto, excludedField);
        }
        this.setDtoFieldValue(dto, excludedField, currentFieldValue);
    });
    return dto;
}
Also used : ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)

Aggregations

ExportDescriptorDto (eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)20 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)4 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)4 UUID (java.util.UUID)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Lists (com.google.common.collect.Lists)3 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)3 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)3 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)3 EmbeddedDto (eu.bcvsolutions.idm.core.api.dto.EmbeddedDto)3 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)3 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)3 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)3 IntrospectionException (java.beans.IntrospectionException)3 PropertyDescriptor (java.beans.PropertyDescriptor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2