public OperationDefinitionController(
            IMediator mediator,
            IOptions <OperationsConfiguration> operationsConfig,
            IOptions <FeatureConfiguration> featureConfig)
        {
            EnsureArg.IsNotNull(mediator, nameof(mediator));
            EnsureArg.IsNotNull(operationsConfig?.Value, nameof(operationsConfig));
            EnsureArg.IsNotNull(featureConfig?.Value, nameof(featureConfig));

            _mediator = mediator;
            _operationConfiguration = operationsConfig.Value;
            _featureConfiguration   = featureConfig.Value;
        }
        public virtual OperationsConfiguration Build()
        {
            var configuration = new OperationsConfiguration
            {
                OperationFactoryFactoryMethod            = OperationFactoryFactoryMethod,
                OperationScopeFactoryFactoryMethod       = OperationScopeFactoryFactoryMethod,
                OperationContextFactoryFactoryMethod     = OperationContextFactoryFactoryMethod,
                RootOperationTrackerFactoryFactoryMethod = RootOperationTrackerFactoryFactoryMethod,
                Trackers = _trackers.AsReadOnly()
            };

            return(configuration);
        }
Exemple #3
0
        public OperationsCapabilityProvider(
            IOptions <OperationsConfiguration> operationConfiguration,
            IOptions <FeatureConfiguration> featureConfiguration,
            IUrlResolver urlResolver)
        {
            EnsureArg.IsNotNull(operationConfiguration?.Value, nameof(operationConfiguration));
            EnsureArg.IsNotNull(featureConfiguration?.Value, nameof(featureConfiguration));
            EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));

            _operationConfiguration = operationConfiguration.Value;
            _featureConfiguration   = featureConfiguration.Value;
            _urlResolver            = urlResolver;
        }
        private ConvertDataController GetController(ConvertDataConfiguration convertDataConfiguration)
        {
            var operationConfig = new OperationsConfiguration()
            {
                ConvertData = convertDataConfiguration,
            };

            IOptions <OperationsConfiguration> optionsOperationConfiguration = Substitute.For <IOptions <OperationsConfiguration> >();

            optionsOperationConfiguration.Value.Returns(operationConfig);

            return(new ConvertDataController(
                       _mediator,
                       optionsOperationConfiguration,
                       NullLogger <ConvertDataController> .Instance));
        }
        public OperationsCapabilityProvider(
            IOptions <OperationsConfiguration> operationConfiguration,
            IOptions <FeatureConfiguration> featureConfiguration,
            IUrlResolver urlResolver,
            Func <IScoped <ISearchService> > searchServiceFactory)
        {
            EnsureArg.IsNotNull(operationConfiguration?.Value, nameof(operationConfiguration));
            EnsureArg.IsNotNull(featureConfiguration?.Value, nameof(featureConfiguration));
            EnsureArg.IsNotNull(urlResolver, nameof(urlResolver));
            EnsureArg.IsNotNull(searchServiceFactory, nameof(searchServiceFactory));

            _operationConfiguration = operationConfiguration.Value;
            _featureConfiguration   = featureConfiguration.Value;
            _urlResolver            = urlResolver;
            _searchServiceFactory   = searchServiceFactory;
        }
Exemple #6
0
        private ExportController GetController(ExportConfiguration exportConfig)
        {
            var operationConfig = new OperationsConfiguration()
            {
                Export = exportConfig,
            };

            IOptions <OperationsConfiguration> optionsOperationConfiguration = Substitute.For <IOptions <OperationsConfiguration> >();

            optionsOperationConfiguration.Value.Returns(operationConfig);

            return(new ExportController(
                       Substitute.For <IFhirRequestContextAccessor>(),
                       optionsOperationConfiguration,
                       NullLogger <ExportController> .Instance));
        }
        private ReindexController GetController(ReindexJobConfiguration reindexConfig)
        {
            var operationConfig = new OperationsConfiguration()
            {
                Reindex = reindexConfig,
            };

            IOptions <OperationsConfiguration> optionsOperationConfiguration = Substitute.For <IOptions <OperationsConfiguration> >();

            optionsOperationConfiguration.Value.Returns(operationConfig);

            return(new ReindexController(
                       _mediator,
                       optionsOperationConfiguration,
                       _urlResolver,
                       NullLogger <ReindexController> .Instance));
        }
Exemple #8
0
        private static ValidateExportRequestFilterAttribute GetFilter(ExportJobConfiguration exportJobConfig = null)
        {
            if (exportJobConfig == null)
            {
                exportJobConfig         = new ExportJobConfiguration();
                exportJobConfig.Enabled = true;
                exportJobConfig.SupportedDestinations.Add(SupportedDestinationType);
            }

            var opConfig = new OperationsConfiguration()
            {
                Export = exportJobConfig,
            };

            IOptions <OperationsConfiguration> options = Substitute.For <IOptions <OperationsConfiguration> >();

            options.Value.Returns(opConfig);

            return(new ValidateExportRequestFilterAttribute(options));
        }
Exemple #9
0
        private ExportController GetController(ExportJobConfiguration exportConfig)
        {
            var operationConfig = new OperationsConfiguration()
            {
                Export = exportConfig,
            };

            IOptions <OperationsConfiguration> optionsOperationConfiguration = Substitute.For <IOptions <OperationsConfiguration> >();

            optionsOperationConfiguration.Value.Returns(operationConfig);

            var features = new FeatureConfiguration();
            IOptions <FeatureConfiguration> optionsFeatures = Substitute.For <IOptions <FeatureConfiguration> >();

            optionsFeatures.Value.Returns(features);

            return(new ExportController(
                       _mediator,
                       _fhirRequestContextAccessor,
                       _urlResolver,
                       optionsOperationConfiguration,
                       optionsFeatures,
                       NullLogger <ExportController> .Instance));
        }
        private static async Task VerifyBulkImporterBehaviourAsync(Channel <ImportResource> inputs, long expectedSucceedCount, long expectedFailedCount, long expectedEndIndex, int maxResourceCountInBatch, int checkpointBatchCount, int maxConcurrentCount)
        {
            DataTable table1   = new DataTable();
            DataTable table2   = new DataTable();
            DataTable dupTable = new DataTable();
            List <SqlBulkCopyDataWrapper> importedResources = new List <SqlBulkCopyDataWrapper>();

            ISqlImportOperation testFhirDataBulkOperation = Substitute.For <ISqlImportOperation>();

            testFhirDataBulkOperation
            .When(t => t.BulkCopyDataAsync(Arg.Any <DataTable>(), Arg.Any <CancellationToken>()))
            .Do(call =>
            {
                DataTable table = (DataTable)call[0];
                if (table.TableName.Equals("Table1"))
                {
                    table1.Merge(table);
                }
                else if (table.TableName.Equals("Table2"))
                {
                    table2.Merge(table);
                }
                else if (table.TableName.Equals("Dup"))
                {
                    dupTable.Merge(table);
                }
            });
            testFhirDataBulkOperation
            .BulkMergeResourceAsync(Arg.Any <IEnumerable <SqlBulkCopyDataWrapper> >(), Arg.Any <CancellationToken>())
            .Returns(call =>
            {
                IEnumerable <SqlBulkCopyDataWrapper> resources = (IEnumerable <SqlBulkCopyDataWrapper>)call[0];
                importedResources.AddRange(resources);

                return(resources);
            });

            IImportErrorSerializer         errorSerializer    = Substitute.For <IImportErrorSerializer>();
            ISqlBulkCopyDataWrapperFactory dataWrapperFactory = Substitute.For <ISqlBulkCopyDataWrapperFactory>();

            dataWrapperFactory.CreateSqlBulkCopyDataWrapper(Arg.Any <ImportResource>())
            .Returns((callInfo) =>
            {
                ImportResource resource = (ImportResource)callInfo[0];
                return(new SqlBulkCopyDataWrapper()
                {
                    ResourceSurrogateId = resource.Id,
                });
            });

            List <TableBulkCopyDataGenerator> generators = new List <TableBulkCopyDataGenerator>()
            {
                new TestDataGenerator("Table1", 1),
                new TestDataGenerator("Table2", 2),
                new TestDupDataGenerator("Dup"),
            };

            IOptions <OperationsConfiguration> operationsConfiguration = Substitute.For <IOptions <OperationsConfiguration> >();
            OperationsConfiguration            operationsConfig        = new OperationsConfiguration();

            operationsConfig.Import.SqlBatchSizeForImportResourceOperation = maxResourceCountInBatch;
            operationsConfig.Import.SqlMaxImportOperationConcurrentCount   = maxConcurrentCount;
            operationsConfig.Import.SqlImportBatchSizeForCheckpoint        = checkpointBatchCount;
            operationsConfiguration.Value.Returns(operationsConfig);

            SqlResourceBulkImporter importer = new SqlResourceBulkImporter(testFhirDataBulkOperation, dataWrapperFactory, errorSerializer, generators, operationsConfiguration, NullLogger <SqlResourceBulkImporter> .Instance);

            List <string>     errorLogs        = new List <string>();
            IImportErrorStore importErrorStore = Substitute.For <IImportErrorStore>();

            importErrorStore.When(t => t.UploadErrorsAsync(Arg.Any <string[]>(), Arg.Any <CancellationToken>()))
            .Do(call =>
            {
                string[] errors = (string[])call[0];
                errorLogs.AddRange(errors);
            });
            (Channel <ImportProcessingProgress> progressChannel, Task importTask) = importer.Import(inputs, importErrorStore, CancellationToken.None);
            ImportProcessingProgress finalProgress = new ImportProcessingProgress();

            await foreach (ImportProcessingProgress progress in progressChannel.Reader.ReadAllAsync())
            {
                Assert.True(finalProgress.CurrentIndex <= progress.CurrentIndex);
                finalProgress = progress;
            }

            await importTask;

            Assert.Equal(expectedSucceedCount, finalProgress.SucceedImportCount);
            Assert.Equal(expectedFailedCount, finalProgress.FailedImportCount);
            Assert.Equal(expectedEndIndex, finalProgress.CurrentIndex);

            Assert.Equal(expectedSucceedCount, importedResources.Count);
            Assert.Equal(expectedSucceedCount, table1.Rows.Count);
            Assert.Equal(expectedSucceedCount * 2, table2.Rows.Count);
            Assert.Equal(expectedSucceedCount, dupTable.Rows.Count);
            Assert.Equal(expectedFailedCount, errorLogs.Count);
        }