use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class AbstractExportBulkActionTest method executeExportAndImport.
/**
* Provides export and following import operation for supplied dto It accepts a map of methods in order to supply necessary operation between individual steps.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <DTO extends AbstractDto> IdmExportImportDto executeExportAndImport(List<DTO> dtos, Class dtoType, String actionName, Map<String, Consumer<DTO>> execute) {
String batchName = getHelper().createName();
Class<? extends BaseEntity> entityClass = getLookupService().getEntityClass(dtoType);
Set<UUID> ids = dtos.stream().map(AbstractDto::getId).collect(Collectors.toSet());
// Bulk action preparation
IdmBulkActionDto bulkAction = findBulkAction(entityClass, actionName);
bulkAction.setIdentifiers(ids);
bulkAction.getProperties().put(AbstractExportBulkAction.PROPERTY_NAME, batchName);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, (long) dtos.size(), null, null);
// Export batch is created
IdmExportImportFilter exportImportFilter = new IdmExportImportFilter();
exportImportFilter.setText(batchName);
List<IdmExportImportDto> batches = exportImportService.find(exportImportFilter, null).getContent();
Assert.assertEquals(1, batches.size());
IdmExportImportDto batch = batches.get(0);
Assert.assertEquals(OperationState.EXECUTED, batch.getResult().getState());
Assert.assertNotNull(batch.getData());
// Find export batch as attachment
List<IdmAttachmentDto> attachments = //
attachmentManager.getAttachments(batch.getId(), getLookupService().getEntityClass(IdmExportImportDto.class).getCanonicalName(), //
null).getContent();
Assert.assertEquals(1, attachments.size());
IdmAttachmentDto attachment = attachments.get(0);
// Upload import
IdmExportImportDto importBatch = importManager.uploadImport(attachment.getName(), attachment.getName(), attachmentManager.getAttachmentData(attachment.getId()));
Assert.assertNotNull(importBatch);
Assert.assertEquals(batch.getName(), importBatch.getName());
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
// Get a service corresponding to the DTO type
ReadWriteDtoService<BaseDto, BaseFilter> service = ((ReadWriteDtoService<BaseDto, BaseFilter>) getLookupService().getDtoService(dtoType));
dtos.forEach(dto -> {
// Execute supplied action before original dto deletion
if (execute != null && execute.containsKey(EXECUTE_BEFORE_DTO_DELETE)) {
execute.get(EXECUTE_BEFORE_DTO_DELETE).accept(dto);
}
// Original dto deletion
service.delete(dto);
Assert.assertNull(service.get(dto.getId()));
});
// Execute import
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(batch.getName(), importBatch.getName());
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
return importBatch;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class DefaultFormService method export.
@Override
public void export(IdmFormInstanceDto formInstanceDto, IdmExportImportDto batch) {
Assert.notNull(batch, "Export batch must exist!");
Assert.notNull(formInstanceDto, "Instance of cannot be null for export!");
// All confidential values will be removed from the export. We don't want change
// confidential value on a target IdM.
List<IdmFormValueDto> valuesWithoutConfidential = //
formInstanceDto.getValues().stream().filter(//
formValue -> !formValue.isConfidential()).collect(Collectors.toList());
formInstanceDto.setValues(valuesWithoutConfidential);
batch.getExportedDtos().add(formInstanceDto);
ExportDescriptorDto exportDescriptorDto = new ExportDescriptorDto(formInstanceDto.getClass());
if (!batch.getExportOrder().contains(exportDescriptorDto)) {
batch.getExportOrder().add(exportDescriptorDto);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class SystemExportProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto system = event.getContent();
Assert.notNull(system, "System have to be set.");
Assert.notNull(system.getId(), "System id has to be set.");
Map<String, Serializable> properties = event.getProperties();
Serializable batchProp = properties.get(SystemProcessor.EXPORT_BATCH_PROPERTY);
Assert.isTrue(batchProp instanceof IdmExportImportDto, "Export import batch has to be supplied.");
IdmExportImportDto batch = (IdmExportImportDto) batchProp;
vsSystemService.exportVsDefinition(system.getId(), batch);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class AbstractExportBulkAction method exportManifest.
/**
* Export batch as "manifest" contains basic batch information (name, creator
* ...)
*
* @param tempDirectory
* @throws IOException
*/
private void exportManifest(Path tempDirectory) throws IOException {
// Create copy of batch
IdmExportImportDto batchToExport = new IdmExportImportDto(batch.getId());
batchToExport.setName(batch.getName());
batchToExport.setType(batch.getType());
batchToExport.setResult(batch.getResult());
batchToExport.setExecutorName(batch.getExecutorName());
batchToExport.getExportOrder().addAll(batch.getExportOrder());
EntityUtils.copyAuditFields(batch, batchToExport);
exportManager.exportDto(batchToExport, batch);
Path source = Paths.get(tempDirectory.toString(), IdmExportImportDto.class.getSimpleName(), MessageFormat.format("{0}.{1}", batch.getId().toString(), ExportManager.EXTENSION_JSON));
Path target = Paths.get(tempDirectory.toString(), ExportManager.EXPORT_BATCH_FILE_NAME);
// Move main export batch (create "Manifest")
Files.move(source, target);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class ExportImportSaveProcessor method process.
@Override
public EventResult<IdmExportImportDto> process(EntityEvent<IdmExportImportDto> event) {
IdmExportImportDto dto = event.getContent();
dto = service.saveInternal(dto);
event.setContent(dto);
return new DefaultEventResult<>(event, this);
}
Aggregations