use of eu.bcvsolutions.idm.core.api.dto.filter.IdmExportImportFilter 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.filter.IdmExportImportFilter in project CzechIdMng by bcvsolutions.
the class LongRunningTaskDeleteProcessor method process.
@Override
public EventResult<IdmLongRunningTaskDto> process(EntityEvent<IdmLongRunningTaskDto> event) {
IdmLongRunningTaskDto lrt = event.getContent();
//
attachmentManager.deleteAttachments(lrt);
//
IdmExportImportFilter filter = new IdmExportImportFilter();
filter.setLongRunningTaskId(lrt.getId());
exportImportService.find(filter, null).forEach(batch -> {
batch.setLongRunningTask(null);
//
exportImportService.save(batch);
});
//
service.deleteInternal(lrt);
//
return new DefaultEventResult<>(event, this);
}
Aggregations