private void TestThatQueryBuilderWithoutParametersBeingSetThrowsQueryBuildingException()
        {
            //we should have problems reading from the table valued function
            var qb = new QueryBuilder("", "");

            //table valued function should have 2 fields (chi and definitionID)
            Assert.AreEqual(2, _tvfCatalogue.GetAllExtractionInformation(ExtractionCategory.Any).Count());

            qb.AddColumnRange(_tvfCatalogue.GetAllExtractionInformation(ExtractionCategory.Any));

            var ex = Assert.Throws <QueryBuildingException>(() => Console.WriteLine(qb.SQL));

            Assert.AreEqual("No Value defined for Parameter @numberOfRecords", ex.Message);
        }
Пример #2
0
 public void Add(ICatalogue catalogue)
 {
     foreach (var ei in catalogue.GetAllExtractionInformation(ExtractionCategory.Any))
     {
         Add(ei);
     }
 }
Пример #3
0
        private IColumn GetExtractionIdentifierFrom(ICatalogue catalogue, ChooseWhichExtractionIdentifierToUseFromManyHandler resolveMultipleExtractionIdentifiers)
        {
            //the aggregate they are cloning does not have an extraction identifier but the dataset might still have one
            var catalogueCandidates = catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Where(e => e.IsExtractionIdentifier).ToArray();

            //if there are multiple IsExtractionInformation columns
            if (catalogueCandidates.Count() != 1)
            {
                if (resolveMultipleExtractionIdentifiers == null)//no delegate has been provided for resolving this
                {
                    throw new NotSupportedException("Cannot create AggregateConfiguration because the Catalogue " + catalogue + " has " + catalogueCandidates.Length + " IsExtractionIdentifier ExtractionInformations");
                }
                else
                {
                    //there is a delegate to resolve this, invoke it
                    var answer = resolveMultipleExtractionIdentifiers(catalogue, catalogueCandidates);

                    //the delegate returned null
                    if (answer == null)
                    {
                        throw new Exception("User did not pick a candidate ExtractionInformation column from those we offered");
                    }
                    else
                    {
                        return(answer);//the delegate picked one
                    }
                }
            }

            return(catalogueCandidates[0]);
        }
Пример #4
0
        private string GetSql(ICatalogue mainCata)
        {
            mainCata.ClearAllInjections();

            var qb = new QueryBuilder(null, null);

            qb.AddColumnRange(mainCata.GetAllExtractionInformation(ExtractionCategory.Any));
            return(qb.SQL);
        }
Пример #5
0
 private ExtractionInformation GetExtractionInformation(ICatalogue cata, string name)
 {
     try
     {
         return(cata.GetAllExtractionInformation(ExtractionCategory.Any).Single(ei => ei.GetRuntimeName().Equals(name, StringComparison.CurrentCultureIgnoreCase)));
     }
     catch
     {
         throw new Exception("Could not find an ExtractionInformation called '" + name + "' in dataset " + cata.Name);
     }
 }
        /// <summary>
        /// Change which column is the linkage identifier in a <see cref="Catalogue"/> either at a global level or for a specific <paramref name="inConfiguration"/>
        /// </summary>
        /// <param name="activator"></param>
        /// <param name="catalogue"></param>
        /// <param name="inConfiguration"></param>
        /// <param name="column"></param>
        public ExecuteCommandSetExtractionIdentifier(IBasicActivateItems activator,
                                                     [DemandsInitialization("The dataset you want to change the extraction identifier for")]
                                                     ICatalogue catalogue,

                                                     [DemandsInitialization("Optional - The specific extraction you want the change made in or Null for the Catalogue itself (will affect all future extractions)")]
                                                     IExtractionConfiguration inConfiguration,

                                                     [DemandsInitialization("Optional - The Column name(s) you want to select as the new linkage identifier(s).  Comma seperate multiple entries if needed")]
                                                     string column) : base(activator)
        {
            _catalogue       = catalogue;
            _inConfiguration = inConfiguration;
            _catalogue.ClearAllInjections();

            if (inConfiguration != null)
            {
                var allEds = inConfiguration.GetAllExtractableDataSets();
                var eds    = allEds.FirstOrDefault(sds => sds.Catalogue_ID == _catalogue.ID);
                if (eds == null)
                {
                    SetImpossible($"Catalogue '{_catalogue}' is not part of ExtractionConfiguration '{inConfiguration}'");
                    return;
                }

                _selectedDataSetColumns = inConfiguration.GetAllExtractableColumnsFor(eds);

                if (_selectedDataSetColumns.Length == 0)
                {
                    SetImpossible($"Catalogue '{_catalogue}' in '{inConfiguration}' does not have any extractable columns");
                    return;
                }

                _alreadyMarkedInConfiguration = _selectedDataSetColumns.Where(ei => ei.IsExtractionIdentifier).ToArray();
            }
            else
            {
                _extractionInformations = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any);

                if (_extractionInformations.Length == 0)
                {
                    SetImpossible("Catalogue does not have any extractable columns");
                    return;
                }

                _alreadyMarked = _extractionInformations.Where(ei => ei.IsExtractionIdentifier).ToArray();
            }

            if (!string.IsNullOrWhiteSpace(column))
            {
                toPick = column.Split(',', StringSplitOptions.RemoveEmptyEntries);
            }
        }
Пример #7
0
        private ExtractionInformation GetExtractionInformationFromCatalogue(ICatalogue catalogue)
        {

            var eis = catalogue.GetAllExtractionInformation(ExtractionCategory.Any);

            if (eis.Count(ei => ei.IsExtractionIdentifier) != 1)
            {
                SetImpossible("Catalogue must have a single IsExtractionIdentifier column");
                return null;
            }

            return eis.Single(e => e.IsExtractionIdentifier);
        }
Пример #8
0
        public void SetupValidationOnCatalogue()
        {
            Validator v  = new Validator();
            var       iv = new ItemValidator("chi");

            iv.PrimaryConstraint             = new Chi();
            iv.PrimaryConstraint.Consequence = Consequence.Wrong;

            v.AddItemValidator(iv, "chi", typeof(string));
            catalogue.ValidatorXML = v.SaveToXml();

            catalogue.TimeCoverage_ExtractionInformation_ID =
                catalogue.GetAllExtractionInformation(ExtractionCategory.Any)
                .Single(e => e.GetRuntimeName().Equals("dtCreated")).ID;

            catalogue.SaveToDatabase();
        }
Пример #9
0
        public void Test_FromCataloguesExtractionRequestFulfiller_NoFilterExtraction(DatabaseType databaseType, bool isNoFiltersExtraction)
        {
            DiscoveredDatabase db = GetCleanedServer(databaseType);

            var dt = new DataTable();

            dt.Columns.Add("StudyInstanceUID");
            dt.Columns.Add("SeriesInstanceUID");
            dt.Columns.Add("SOPInstanceUID");
            dt.Columns.Add("Extractable", typeof(bool));
            dt.Columns.Add(QueryToExecuteColumnSet.DefaultImagePathColumnName);
            dt.Rows.Add("1.1", "123.1", "1.1", true, "/images/1.dcm");
            dt.SetDoNotReType(true);

            DiscoveredTable tbl       = db.CreateTable("FromCataloguesExtractionRequestFulfillerTests", dt);
            ICatalogue      catalogue = Import(tbl);

            ExtractionInformation ei = catalogue.GetAllExtractionInformation(ExtractionCategory.Any).First();
            var filter = new ExtractionFilter(CatalogueRepository, "Extractable only", ei)
            {
                IsMandatory = true,
                WhereSQL    = "Extractable = 1"
            };

            filter.SaveToDatabase();
            var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { catalogue });

            fulfiller.Rejectors.Add(new RejectAll());

            var message = new ExtractionRequestMessage
            {
                KeyTag = "SeriesInstanceUID",
                ExtractionIdentifiers = new List <string>(new [] { "123.1" }),
                IsNoFilterExtraction  = isNoFiltersExtraction,
            };

            ExtractImageCollection[] matching = fulfiller.GetAllMatchingFiles(message, new NullAuditExtractions()).ToArray();

            int expected = isNoFiltersExtraction ? 1 : 0;

            Assert.AreEqual(1, matching.Length);
            Assert.AreEqual(expected, matching[0].Accepted.Count);
        }
Пример #10
0
        private void SetCatalogue(ICatalogue catalogue)
        {
            ResetImpossibleness();

            _catalogue = catalogue;

            if (catalogue == null)
            {
                SetImpossible("Catalogue cannot be null");
                return;
            }

            var status = _catalogue.GetExtractabilityStatus(BasicActivator.RepositoryLocator.DataExportRepository);

            if (status.IsProjectSpecific)
            {
                SetImpossible("Catalogue is already Project Specific");
            }

            if (!status.IsExtractable)
            {
                SetImpossible("Catalogue must first be made Extractable");
            }

            var ei = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any);

            if (!ei.Any())
            {
                SetImpossible("Catalogue has no extractable columns");
            }

            if (ei.Count(e => e.IsExtractionIdentifier) != 1)
            {
                SetImpossible("Catalogue must have exactly 1 IsExtractionIdentifier column");
            }

            if (ei.Any(e => e.ExtractionCategory != ExtractionCategory.Core && e.ExtractionCategory != ExtractionCategory.ProjectSpecific))
            {
                SetImpossible("All existing ExtractionInformations must be ExtractionCategory.Core");
            }
        }
Пример #11
0
        /// <summary>
        /// Generates a column set based on columns found in <paramref name="catalogue"/> (using the default expected column names
        /// e.g. <see cref="DefaultSeriesIdColumnName"/>).  Returns null if the <paramref name="catalogue"/> does not have all the required
        /// columns
        /// </summary>
        /// <param name="catalogue"></param>
        /// <param name="requireFilePath"></param>
        public static QueryToExecuteColumnSet Create(ICatalogue catalogue, bool requireFilePath)
        {
            if (catalogue == null)
            {
                throw new ArgumentNullException(nameof(catalogue));
            }

            var eis = catalogue.GetAllExtractionInformation(ExtractionCategory.Any);

            var filePathColumn    = eis.SingleOrDefault(ei => ei.GetRuntimeName().Equals(DefaultImagePathColumnName, StringComparison.CurrentCultureIgnoreCase));
            var studyTagColumn    = eis.SingleOrDefault(ei => ei.GetRuntimeName().Equals(DefaultStudyIdColumnName, StringComparison.CurrentCultureIgnoreCase));
            var seriesTagColumn   = eis.SingleOrDefault(ei => ei.GetRuntimeName().Equals(DefaultSeriesIdColumnName, StringComparison.CurrentCultureIgnoreCase));
            var instanceTagColumn = eis.SingleOrDefault(ei => ei.GetRuntimeName().Equals(DefaultInstanceIdColumnName, StringComparison.CurrentCultureIgnoreCase));

            if (filePathColumn == null && requireFilePath)
            {
                return(null);
            }

            return(new QueryToExecuteColumnSet(catalogue, filePathColumn, studyTagColumn, seriesTagColumn, instanceTagColumn, requireFilePath));
        }
Пример #12
0
        public QueryToExecuteColumnSet(ICatalogue catalogue,
                                       ExtractionInformation filePathColumn,
                                       ExtractionInformation studyTagColumn,
                                       ExtractionInformation seriesTagColumn,
                                       ExtractionInformation instanceTagColumn,
                                       bool requireFilePath = true)
        {
            Catalogue = catalogue ?? throw new ArgumentNullException(nameof(catalogue));

            AllColumns = new ReadOnlyCollection <ExtractionInformation>(Catalogue.GetAllExtractionInformation(ExtractionCategory.Any)); Catalogue.GetAllExtractionInformation(ExtractionCategory.Any);

            if (filePathColumn == null && requireFilePath)
            {
                throw new ArgumentNullException(nameof(filePathColumn));
            }

            FilePathColumn    = filePathColumn;
            StudyTagColumn    = studyTagColumn;
            SeriesTagColumn   = seriesTagColumn;
            InstanceTagColumn = instanceTagColumn;
        }
Пример #13
0
        public override void Execute()
        {
            if (_catalogue == null)
            {
                SetCatalogue(SelectOne <Catalogue>(BasicActivator.RepositoryLocator.CatalogueRepository));
            }

            if (_project == null)
            {
                _project = SelectOne <Project>(BasicActivator.RepositoryLocator.DataExportRepository);
            }

            if (_project == null || _catalogue == null)
            {
                return;
            }

            base.Execute();

            var eds = BasicActivator.RepositoryLocator.DataExportRepository.GetAllObjectsWithParent <ExtractableDataSet>(_catalogue).SingleOrDefault();

            IExtractionConfiguration alreadyInConfiguration = eds.ExtractionConfigurations.FirstOrDefault(ec => ec.Project_ID != _project.ID);

            if (alreadyInConfiguration != null)
            {
                throw new Exception("Cannot make " + _catalogue + " Project Specific because it is already a part of ExtractionConfiguration " + alreadyInConfiguration + " (Project=" + alreadyInConfiguration.Project + ") and possibly others");
            }

            eds.Project_ID = _project.ID;
            foreach (ExtractionInformation ei in _catalogue.GetAllExtractionInformation(ExtractionCategory.Any))
            {
                ei.ExtractionCategory = ExtractionCategory.ProjectSpecific;
                ei.SaveToDatabase();
            }
            eds.SaveToDatabase();

            Publish(_catalogue);
        }