Search in sources :

Example 1 with IdmImportLogFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter 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 IdmImportLogFilter

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

the class IdmImportLogController method toFilter.

@Override
protected IdmImportLogFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmImportLogFilter filter = new IdmImportLogFilter(parameters);
    // If parent property contains ID of IdmImportLog, then we need to change filter to DTO id.
    if (filter.getParent() != null) {
        IdmImportLogDto logDto = getService().get(filter.getParent());
        if (logDto != null) {
            filter.setParent(logDto.getDtoId());
            filter.setBatchId(logDto.getBatch());
        }
    }
    return filter;
}
Also used : IdmImportLogDto(eu.bcvsolutions.idm.core.api.dto.IdmImportLogDto) IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter)

Example 3 with IdmImportLogFilter

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

the class DefaultIdmImportLogService method saveDistinct.

@Override
@Transactional
public IdmImportLogDto saveDistinct(IdmImportLogDto dto, BasePermission... permission) {
    if (this.isNew(dto)) {
        Assert.notNull(dto.getBatch(), "Batch ID must be filled for distinct save!");
        Assert.notNull(dto.getDtoId(), "DTO ID must be filled for distinct save!");
        IdmImportLogFilter filter = new IdmImportLogFilter();
        filter.setBatchId(dto.getBatch());
        filter.setDtoId(dto.getDtoId());
        // If exists import-log for same batch and DTO ID, then is used his ID (prevent creation of duplicated logs).
        if (this.count(filter) > 0) {
            IdmImportLogDto originalLog = this.find(filter, null).getContent().get(0);
            dto.setId(originalLog.getId());
        }
    }
    return super.save(dto, permission);
}
Also used : IdmImportLogDto(eu.bcvsolutions.idm.core.api.dto.IdmImportLogDto) IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmImportLogFilter

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

the class DefaultIdmImportLogService method toDto.

@Override
protected IdmImportLogDto toDto(IdmImportLog entity, IdmImportLogDto dto, IdmImportLogFilter filter) {
    dto = super.toDto(entity, dto, filter);
    if (dto != null && dto.getDtoId() != null) {
        // Set count of children
        IdmImportLogFilter childrenFilter = new IdmImportLogFilter();
        childrenFilter.setParent(dto.getDtoId());
        childrenFilter.setBatchId(dto.getBatch());
        dto.setChildrenCount(this.count(childrenFilter));
    }
    return dto;
}
Also used : IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter)

Example 5 with IdmImportLogFilter

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

the class DefaultIdmExportImportService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmExportImportDto dto) {
    Assert.notNull(dto, "Batch cannot be null for delete!");
    Assert.notNull(dto.getId(), "Batch ID cannot be null for delete!");
    // delete attachments
    attachmentManager.deleteAttachments(dto);
    // Delete all logs for this batch.
    IdmImportLogFilter logFilter = new IdmImportLogFilter();
    logFilter.setBatchId(dto.getId());
    // 
    importLogService.findIds(logFilter, null).getContent().forEach(logId -> {
        importLogService.deleteById(logId);
    });
    super.deleteInternal(dto);
}
Also used : IdmImportLogFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmImportLogFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmImportLogFilter)5 Transactional (org.springframework.transaction.annotation.Transactional)3 IdmImportLogDto (eu.bcvsolutions.idm.core.api.dto.IdmImportLogDto)2 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)1 ImportContext (eu.bcvsolutions.idm.core.api.dto.ImportContext)1 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)1 Path (java.nio.file.Path)1