Search in sources :

Example 1 with IdmExportImportDto

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

the class ExportImportDeleteProcessor method process.

@Override
public EventResult<IdmExportImportDto> process(EntityEvent<IdmExportImportDto> event) {
    IdmExportImportDto dto = event.getContent();
    // Internal delete
    service.deleteInternal(dto);
    return new DefaultEventResult<>(event, this);
}
Also used : IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 2 with IdmExportImportDto

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

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

the class DefaultImportManager method uploadImport.

@Override
@Transactional
public IdmExportImportDto uploadImport(String name, String fileName, InputStream inputStream, BasePermission... permission) {
    Assert.notNull(name, "Name cannot be null!");
    Assert.notNull(fileName, "File name cannot be null!");
    Assert.notNull(inputStream, "Input stream cannot be null!");
    LOG.info("Upload of a import [{}] starts ...", name);
    IdmExportImportDto batch = new IdmExportImportDto();
    batch.setName(name);
    batch.setType(ExportImportType.IMPORT);
    batch = exportImportService.save(batch, permission);
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setName(fileName);
    attachment.setMimetype(ExportManager.APPLICATION_ZIP);
    attachment.setInputData(inputStream);
    attachment.setOwnerType(lookupService.getOwnerType(IdmExportImportDto.class));
    attachment = attachmentManager.saveAttachment(batch, attachment);
    Path tempDirectory = null;
    try {
        tempDirectory = extractZip(attachment);
        IdmExportImportDto manifest = validate(tempDirectory);
        batch.setName(manifest.getName());
        batch.setExecutorName(manifest.getExecutorName());
        batch.setData(attachment.getId());
        batch = exportImportService.save(batch, permission);
    } finally {
        // Delete temp files.
        if (tempDirectory != null) {
            FileSystemUtils.deleteRecursively(tempDirectory.toFile());
        }
    }
    return batch;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Path(java.nio.file.Path) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmExportImportDto

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

the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleGuaranteeByRole.

@Test
public void testExportAndImportRoleGuaranteeByRole() {
    IdmRoleDto role = createRole();
    IdmRoleDto guaranteeRole = this.getHelper().createRole();
    IdmRoleGuaranteeRoleDto guarantee = this.getHelper().createRoleGuaranteeRole(role, guaranteeRole);
    // Make export, upload and import
    IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
    role = roleService.get(role.getId());
    Assert.assertNotNull(role);
    List<IdmRoleGuaranteeRoleDto> guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
    IdmRoleDto guaranteeRoleTwo = this.getHelper().createRole();
    this.getHelper().createRoleGuaranteeRole(role, guaranteeRoleTwo);
    guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(2, guarantees.size());
    // Execute import (check authoritative mode)
    importBatch = importManager.executeImport(importBatch, false);
    Assert.assertNotNull(importBatch);
    Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
    Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
    // Second guarantor had to be deleted!
    guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 5 with IdmExportImportDto

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

the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleGuaranteeByIdentity.

@Test
public void testExportAndImportRoleGuaranteeByIdentity() {
    IdmRoleDto role = createRole();
    IdmIdentityDto guaranteeIdentity = this.getHelper().createIdentity();
    IdmRoleGuaranteeDto guarantee = this.getHelper().createRoleGuarantee(role, guaranteeIdentity);
    // Make export, upload and import
    IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
    role = roleService.get(role.getId());
    Assert.assertNotNull(role);
    List<IdmRoleGuaranteeDto> guarantees = this.findGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
    IdmIdentityDto guaranteeIdentityTwo = this.getHelper().createIdentity();
    this.getHelper().createRoleGuarantee(role, guaranteeIdentityTwo);
    guarantees = this.findGuarantees(role);
    Assert.assertEquals(2, guarantees.size());
    // Execute import (check authoritative mode)
    importBatch = importManager.executeImport(importBatch, false);
    Assert.assertNotNull(importBatch);
    Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
    Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
    // Second guarantor had to be deleted!
    guarantees = this.findGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Aggregations

IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)31 AbstractExportBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest)18 Test (org.junit.Test)18 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)5 SysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)4 SysProvisioningBreakConfigDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)3 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)3 Path (java.nio.file.Path)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysProvisioningBreakRecipientDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto)2 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)2 ImportContext (eu.bcvsolutions.idm.core.api.dto.ImportContext)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2