Search in sources :

Example 1 with IdmExportImportFilter

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;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmExportImportFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmExportImportFilter) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) UUID(java.util.UUID)

Example 2 with IdmExportImportFilter

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);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmExportImportFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmExportImportFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Aggregations

IdmExportImportFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmExportImportFilter)2 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)1 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)1 BaseFilter (eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)1 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)1 UUID (java.util.UUID)1