Search in sources :

Example 16 with IdmExportImportDto

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;
}
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 17 with IdmExportImportDto

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);
    }
}
Also used : AbstractFormValue_(eu.bcvsolutions.idm.core.eav.entity.AbstractFormValue_) Order(org.springframework.data.domain.Sort.Order) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) FormProjectionManager(eu.bcvsolutions.idm.core.eav.api.service.FormProjectionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Matcher(java.util.regex.Matcher) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) FormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter) Method(java.lang.reflect.Method) ImmutableMap(com.google.common.collect.ImmutableMap) ConfigurationClassProperty(eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) PropertyDescriptor(java.beans.PropertyDescriptor) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Lazy(org.springframework.context.annotation.Lazy) Pattern(java.util.regex.Pattern) PageImpl(org.springframework.data.domain.PageImpl) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormAttribute_(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute_) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) FormAttributeRendererDto(eu.bcvsolutions.idm.core.eav.api.dto.FormAttributeRendererDto) OrderAwarePluginRegistry(org.springframework.plugin.core.OrderAwarePluginRegistry) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Introspector(java.beans.Introspector) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CollectionUtils(org.apache.commons.collections.CollectionUtils) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IdmFormDefinition_(eu.bcvsolutions.idm.core.eav.entity.IdmFormDefinition_) FormAttributeRenderer(eu.bcvsolutions.idm.core.eav.api.service.FormAttributeRenderer) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) ObjectUtils(org.springframework.util.ObjectUtils) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) IdmForm(eu.bcvsolutions.idm.core.eav.entity.IdmForm) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Comparator(java.util.Comparator) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)

Example 18 with IdmExportImportDto

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);
}
Also used : Serializable(java.io.Serializable) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 19 with IdmExportImportDto

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);
}
Also used : Path(java.nio.file.Path) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)

Example 20 with IdmExportImportDto

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

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