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);
}
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);
}
}
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;
}
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());
}
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());
}
Aggregations