public void ImportCatalogueWithMultipleMandatoryFilters() { //First mandatory var filter1 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]); filter1.IsMandatory = true; filter1.WhereSQL = "There Be Dragons"; filter1.SaveToDatabase(); //Second mandatory var filter2 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[1]); filter2.IsMandatory = true; filter2.WhereSQL = "And Months"; filter2.SaveToDatabase(); //Then one that is not mandatory var filter3 = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[2]); filter3.IsMandatory = false; filter3.WhereSQL = "But Can Also Be Flies"; filter3.SaveToDatabase(); //ensure that both are picked up as mandatory filters by catalogue var mandatoryFilters = testData.catalogue.GetAllMandatoryFilters(); Assert.AreEqual(2, mandatoryFilters.Length); AggregateConfiguration importedAggregate = null; try { //import the Catalogue importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container Assert.IsNotNull(importedAggregateFilterContainer); //the AND container should be there Assert.AreEqual(FilterContainerOperation.AND, importedAggregateFilterContainer.Operation); //the filters should both be there (See above test for WHERE SQL, ID etc checking) var importedFilters = importedAggregateFilterContainer.GetFilters(); Assert.AreEqual(2, importedFilters.Length); } finally { filter1.DeleteInDatabase(); filter2.DeleteInDatabase(); filter3.DeleteInDatabase(); if (importedAggregate != null) { importedAggregate.RootFilterContainer.DeleteInDatabase(); importedAggregate.DeleteInDatabase(); } } }
private void AddParameterValueSet(ExtractionFilter filter) { var parameterSet = new ExtractionFilterParameterSet(RepositoryLocator.CatalogueRepository, filter); parameterSet.CreateNewValueEntries(); Publish(filter); Activate(parameterSet); }
public void test_creating_ExtractionFilter() { ExtractionInformation extractInfo = null; ExtractionFilter filterFastThings = null; ExtractionFilterParameter parameter = null; try { //define extraction information extractInfo = new ExtractionInformation(CatalogueRepository, cataItem, columnInfo, "ROUND(VelocityOfMatter,2) VelocityOfMatterRounded"); //define filter and parameter filterFastThings = new ExtractionFilter(CatalogueRepository, "FastThings", extractInfo) { WhereSQL = "VelocityOfMatter > @X", Description = "Query to identify things that travel faster than X miles per hour!" }; filterFastThings.SaveToDatabase(); Assert.AreEqual(filterFastThings.Name, "FastThings"); parameter = new ExtractionFilterParameter(CatalogueRepository, "DECLARE @X INT", filterFastThings); Assert.IsNotNull(parameter); Assert.AreEqual(parameter.ParameterName, "@X"); parameter.Value = "500"; parameter.SaveToDatabase(); ExtractionFilterParameter afterSave = CatalogueRepository.GetObjectByID <ExtractionFilterParameter>(parameter.ID); Assert.AreEqual(afterSave.Value, "500"); ExtractionFilter filterFastThings_NewCopyFromDB = CatalogueRepository.GetObjectByID <ExtractionFilter>(filterFastThings.ID); Assert.AreEqual(filterFastThings.ID, filterFastThings_NewCopyFromDB.ID); Assert.AreEqual(filterFastThings.Description, filterFastThings_NewCopyFromDB.Description); Assert.AreEqual(filterFastThings.Name, filterFastThings_NewCopyFromDB.Name); Assert.AreEqual(filterFastThings.WhereSQL, filterFastThings_NewCopyFromDB.WhereSQL); } finally { if (parameter != null) { parameter.DeleteInDatabase(); } //filters are children of extraction info with CASCADE DELETE so have to delete this one first if we want to test it programatically (although we could just skip deleting it since SQL will handle it anyway) if (filterFastThings != null) { filterFastThings.DeleteInDatabase(); } if (extractInfo != null) { extractInfo.DeleteInDatabase(); } } }
public ExecuteCommandAddNewExtractionFilterParameterSet(IBasicActivateItems activator, ExtractionFilter filter) : base(activator) { _filter = filter; if (!_filter.GetAllParameters().Any()) { SetImpossible("Filter has no parameters"); } }
public void ImportCatalogueWithMandatoryFilter() { var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]); filter.IsMandatory = true; filter.WhereSQL = "There Be Dragons"; filter.SaveToDatabase(); //ensure that it is picked up var mandatoryFilters = testData.catalogue.GetAllMandatoryFilters(); Assert.AreEqual(1, mandatoryFilters.Length); Assert.AreEqual(filter, mandatoryFilters[0]); AggregateConfiguration importedAggregate = null; try { importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); Assert.AreEqual(ChangeDescription.NoChanges, importedAggregate.HasLocalChanges().Evaluation); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container Assert.IsNotNull(importedAggregateFilterContainer); //With an AND operation Assert.AreEqual(FilterContainerOperation.AND, importedAggregateFilterContainer.Operation); var importedFilters = importedAggregateFilterContainer.GetFilters(); Assert.AreEqual(1, importedFilters.Length); //they are not the same object Assert.AreNotEqual(filter, importedFilters[0]); //the deployed filter knows it's parent it was cloned from Assert.AreEqual(filter.ID, importedFilters[0].ClonedFromExtractionFilter_ID); //the WHERE SQL of the filters should be the same Assert.AreEqual(filter.WhereSQL, importedFilters[0].WhereSQL); } finally { filter.DeleteInDatabase(); if (importedAggregate != null) { importedAggregate.RootFilterContainer.DeleteInDatabase(); importedAggregate.DeleteInDatabase(); } } }
private IFilter CreateFilter(Catalogue cata, string name, string parentExtractionInformation, string whereSql, string desc) { var filter = new ExtractionFilter(_repos.CatalogueRepository, name, GetExtractionInformation(cata, parentExtractionInformation)); filter.WhereSQL = whereSql; filter.Description = desc; filter.SaveToDatabase(); var parameterCreator = new ParameterCreator(filter.GetFilterFactory(), null, null); parameterCreator.CreateAll(filter, null); return(filter); }
public void GatherAndShare_ExtractionFilter_Test() { //Setup some objects under Catalogue var cata = new Catalogue(CatalogueRepository, "Cata"); cata.Periodicity = Catalogue.CataloguePeriodicity.BiMonthly; cata.SaveToDatabase(); var catalogueItem1 = new CatalogueItem(CatalogueRepository, cata, "Ci1"); var tableInfo = new TableInfo(CatalogueRepository, "Myt"); var colInfo = new ColumnInfo(CatalogueRepository, "[Mt].[C1]", "varchar(10)", tableInfo); catalogueItem1.ColumnInfo_ID = colInfo.ID; catalogueItem1.SaveToDatabase(); //Setup a Filter under this extractable column (the filter is what we will share) var ei = new ExtractionInformation(CatalogueRepository, catalogueItem1, colInfo, "UPPER(C1) as Fish"); var filter = new ExtractionFilter(CatalogueRepository, "My Filter", ei); filter.Description = "amagad"; filter.WhereSQL = "UPPER(C1) = @a"; //Give the filter a parameter @a just to make things interesting var declaration = filter.GetQuerySyntaxHelper().GetParameterDeclaration("@a", new DatabaseTypeRequest(typeof(string), 1)); var param = filter.GetFilterFactory().CreateNewParameter(filter, declaration); //Also create a 'known good value' set i.e. recommended value for the parameter to achive some goal (you can have multiple of these - this will not be shared) var set = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Fife"); var val = new ExtractionFilterParameterSetValue(CatalogueRepository, set, (ExtractionFilterParameter)param); val.Value = "'FISH'"; //Gather the dependencies (this is what we are testing) var gatherer = new Gatherer(RepositoryLocator); Assert.IsTrue(gatherer.CanGatherDependencies(filter)); var gathered = gatherer.GatherDependencies(filter); //gatherer should have gathered the filter and the parameter (but not the ExtractionFilterParameterSet sets) Assert.AreEqual(1, gathered.Children.Count); Assert.AreEqual(param, gathered.Children[0].Object); //Cleanup val.DeleteInDatabase(); set.DeleteInDatabase(); cata.DeleteInDatabase(); }
public ExtractionFilterUIOptions(ExtractionFilter masterCatalogueFilter) : base(masterCatalogueFilter) { var c = masterCatalogueFilter.ExtractionInformation.CatalogueItem.Catalogue; var colInfo = masterCatalogueFilter.GetColumnInfoIfExists(); if (colInfo == null) { throw new MissingColumnInfoException("No ColumnInfo found for filter '" + masterCatalogueFilter + "'"); } _globals = colInfo.TableInfo.GetAllParameters(); _tables = c.GetTableInfoList(false); _columns = c.GetAllExtractionInformation(ExtractionCategory.Any); }
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); }
public SimpleFilterUI(IActivateItems activator, ExtractionFilter filter) { _activator = activator; _filter = filter; InitializeComponent(); lblFilterName.Text = filter.Name; pbFlter.Image = activator.CoreIconProvider.GetImage(RDMPConcept.Filter); var parameters = filter.ExtractionFilterParameters.ToArray(); SetupKnownGoodValues(); for (int i = 0; i < parameters.Length; i++) { var currentRowPanel = new Panel(); currentRowPanel.Bounds = new Rectangle(0, 0, tableLayoutPanel1.Width, rowHeight); currentRowPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; currentRowPanel.Margin = Padding.Empty; var p = new SimpleParameterUI(activator, parameters[i]); currentRowPanel.Controls.Add(p); p.tbValue.TextChanged += (s, e) => { //we are here because user is selecting a value from the dropdown not because he is editting the text field manually if (_settingAKnownGoodValue) { return; } //user is manually editting a Parameters so it no longer matches a Known value ddKnownGoodValues.SelectedItem = ""; }; parameterUis.Add(p); tableLayoutPanel1.Controls.Add(currentRowPanel, 0, i + 1); tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; } Height = 35 + (parameters.Length * rowHeight); }
private ExtractionFilter GetFilterWithParameterSet() { var cata = new Catalogue(CatalogueRepository, "myCata"); var cataItem = new CatalogueItem(CatalogueRepository, cata, "MyCol"); var table = new TableInfo(CatalogueRepository, "myTbl"); var col = new ColumnInfo(CatalogueRepository, "myCol", "varchar(10)", table); var ei = new ExtractionInformation(CatalogueRepository, cataItem, col, "[myTbl].[mycol]"); var filter = new ExtractionFilter(CatalogueRepository, "Age", ei); filter.WhereSQL = "Age >= @age"; new ExtractionFilterParameter(CatalogueRepository, "DECLARE @age int", filter); var paramSet = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Old"); paramSet.CreateNewValueEntries(); return(filter); }
private SimpleFilterUI AddFilter(ExtractionFilter f) { var filterUI = new SimpleFilterUI(_activator, f); filterUI.RequestDeletion += () => RemoveFilter(filterUI); filterUI.Width = tableLayoutPanel1.Width; filterUI.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; tableLayoutPanel1.Controls.Add(filterUI, tableLayoutPanel1.RowCount - 1, 0); //this array always seems to be 1 element long.. tableLayoutPanel1.RowStyles[0].SizeType = SizeType.AutoSize; _filterUIs.Add(filterUI); //if there are 2+ filters then user can specify AND / OR to combine them ddAndOr.Enabled = _filterUIs.Count >= 2; return(filterUI); }
public void FromCataloguesExtractionRequestFulfiller_MandatoryFilter(DatabaseType databaseType) { var 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.Rows.Add("1.1", "123.1", "2.1", false, "/images/2.dcm"); dt.Rows.Add("1.1", "1234.1", "3.1", false, "/images/3.dcm"); dt.Rows.Add("1.1", "1234.1", "4.1", true, "/images/4.dcm"); dt.SetDoNotReType(true); var tbl = db.CreateTable("FromCataloguesExtractionRequestFulfillerTests", dt); var catalogue = Import(tbl); var ei = catalogue.GetAllExtractionInformation(ExtractionCategory.Any).First(); var filter = new ExtractionFilter(CatalogueRepository, "Extractable only", ei); filter.IsMandatory = true; filter.WhereSQL = "Extractable = 1"; filter.SaveToDatabase(); var fulfiller = new FromCataloguesExtractionRequestFulfiller(new[] { catalogue }); var matching = fulfiller.GetAllMatchingFiles(new ExtractionRequestMessage() { KeyTag = "SeriesInstanceUID", ExtractionIdentifiers = new List <string>(new string[] { "123.1" }), }, new NullAuditExtractions()).ToArray(); Assert.AreEqual(1, matching.Length); Assert.AreEqual(1, matching[0].Accepted.Count); Assert.AreEqual(1, matching[0].Accepted.Count(f => f.FilePathValue.Equals("/images/1.dcm"))); }
public void ExtractionFilterParameterSet_Deleting() { var cata = new Catalogue(CatalogueRepository, "myCata"); var cataItem = new CatalogueItem(CatalogueRepository, cata, "MyCol"); var table = new TableInfo(CatalogueRepository, "myTbl"); var col = new ColumnInfo(CatalogueRepository, "myCol", "varchar(10)", table); var ei = new ExtractionInformation(CatalogueRepository, cataItem, col, "[myTbl].[mycol]"); var filter = new ExtractionFilter(CatalogueRepository, "Age", ei); filter.WhereSQL = "Age >= @age"; new ExtractionFilterParameter(CatalogueRepository, "DECLARE @age int", filter); var paramSet = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Old"); var vals = paramSet.CreateNewValueEntries(); Assert.AreEqual(1, vals.Length); Assert.IsTrue(vals[0].Exists()); paramSet.DeleteInDatabase(); Assert.IsFalse(paramSet.Exists()); Assert.IsFalse(vals[0].Exists()); }
public void Test_DatabaseTypeQueryWithParameter_IntParameter(DatabaseType dbType) { //Pick the destination server var tableName = TestDatabaseNames.GetConsistentName("tbl"); //make sure there's a database ready to receive the data var db = GetCleanedServer(dbType); db.Create(true); //this is the table we are uploading var dt = new DataTable(); dt.Columns.Add("numbercol"); dt.Rows.Add(10); dt.Rows.Add(15); dt.Rows.Add(20); dt.Rows.Add(25); dt.TableName = tableName; try { ///////////////////////UPLOAD THE DataTable TO THE DESTINATION//////////////////////////////////////////// var uploader = new DataTableUploadDestination(); uploader.PreInitialize(db, new ThrowImmediatelyDataLoadJob()); uploader.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()); uploader.Dispose(new ThrowImmediatelyDataLoadJob(), null); var tbl = db.ExpectTable(tableName); var importer = new TableInfoImporter(CatalogueRepository, tbl); importer.DoImport(out var ti, out var ci); var engineer = new ForwardEngineerCatalogue(ti, ci, true); engineer.ExecuteForwardEngineering(out var cata, out var cis, out var ei); ///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////THE ACTUAL PROPER TEST//////////////////////////////////// //create an extraction filter var extractionInformation = ei.Single(); var filter = new ExtractionFilter(CatalogueRepository, "Filter by numbers", extractionInformation); filter.WhereSQL = extractionInformation.SelectSQL + " = @n"; filter.SaveToDatabase(); //create the parameters for filter (no globals, masters or scope adjacent parameters) new ParameterCreator(filter.GetFilterFactory(), null, null).CreateAll(filter, null); var p = filter.GetAllParameters().Single(); Assert.AreEqual("@n", p.ParameterName); p.ParameterSQL = p.ParameterSQL.Replace("varchar(50)", "int"); //make it int p.Value = "20"; p.SaveToDatabase(); var qb = new QueryBuilder(null, null); qb.AddColumn(extractionInformation); qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, new[] { filter }, FilterContainerOperation.AND); using (var con = db.Server.GetConnection()) { con.Open(); string sql = qb.SQL; var cmd = db.Server.GetCommand(sql, con); var r = cmd.ExecuteReader(); Assert.IsTrue(r.Read()); Assert.AreEqual( 20, r[extractionInformation.GetRuntimeName()]); } /////////////////////////////////////////////////////////////////////////////////////// } finally { db.Drop(); } }
private ExtractionFilterParameterSet AdvertiseAvailableFilterParameterSetsIfAny(ExtractionFilter extractionFilterOrNull) { if (extractionFilterOrNull == null) { return(null); } var parameterSets = extractionFilterOrNull.Repository.GetAllObjectsWithParent <ExtractionFilterParameterSet>(extractionFilterOrNull); if (parameterSets.Any()) { if (MessageBox.Show("Filter " + extractionFilterOrNull + " has some preconfigured values for parameters that represent useful configurations for this filter, would you use one of these? If you change your mind you can still choose 'Select Null'", "Use curated parameter set values?", MessageBoxButtons.YesNo) == DialogResult.Yes) { var dialog = new SelectIMapsDirectlyToDatabaseTableDialog(parameterSets, true, false); if (dialog.ShowDialog() == DialogResult.OK) { return(dialog.Selected as ExtractionFilterParameterSet); } } } return(null); }
private CohortIdentificationConfiguration CreateCohortIdentificationConfiguration(ExtractionFilter inclusionFilter1) { //Create the top level configuration object var cic = new CohortIdentificationConfiguration(_repos.CatalogueRepository, "Tayside Lung Cancer Cohort"); //create a UNION container for Inclusion Criteria var container = new CohortAggregateContainer(_repos.CatalogueRepository, SetOperation.UNION); container.Name = "Inclusion Criteria"; container.SaveToDatabase(); cic.RootCohortAggregateContainer_ID = container.ID; cic.SaveToDatabase(); //Create a new cohort set to the 'Inclusion Criteria' based on the filters Catalogue var cata = inclusionFilter1.ExtractionInformation.CatalogueItem.Catalogue; var ac = cic.CreateNewEmptyConfigurationForCatalogue(cata, (a, b) => { throw new Exception("Problem encountered with chi column(s)"); }, false); container.AddChild(ac, 0); //Add the filter to the WHERE logic of the cohort set var whereContainer = new AggregateFilterContainer(_repos.CatalogueRepository, FilterContainerOperation.OR); ac.Name = "People with " + inclusionFilter1.Name; ac.RootFilterContainer_ID = whereContainer.ID; cic.EnsureNamingConvention(ac); //this will put cicx at the front and cause implicit SaveToDatabase FilterImporter filterImporter = new FilterImporter(new AggregateFilterFactory(_repos.CatalogueRepository), null); var cloneFilter = filterImporter.ImportFilter(inclusionFilter1, null); whereContainer.AddChild(cloneFilter); return(cic); }
public void CloneWithFilters(bool introduceOrphanExtractionInformation) { if (introduceOrphanExtractionInformation) { IntroduceOrphan(); } Assert.IsEmpty(_configuration.ReleaseLog); var filter = new ExtractionFilter(CatalogueRepository, "FilterByFish", _extractionInformations[0]); try { //setup a filter with a parameter filter.WhereSQL = "Fish = @fish"; new ParameterCreator(new ExtractionFilterFactory(_extractionInformations[0]), null, null).CreateAll(filter, null); filter.SaveToDatabase(); Assert.IsTrue(filter.ExtractionFilterParameters.Count() == 1); //create a root container var container = new FilterContainer(DataExportRepository); _selectedDataSet.RootFilterContainer_ID = container.ID; _selectedDataSet.SaveToDatabase(); //create a deployed filter var importer = new FilterImporter(new DeployedExtractionFilterFactory(DataExportRepository), null); var deployedFilter = (DeployedExtractionFilter)importer.ImportFilter(filter, null); deployedFilter.FilterContainer_ID = container.ID; deployedFilter.Name = "FilterByFishDeployed"; deployedFilter.SaveToDatabase(); var param = deployedFilter.ExtractionFilterParameters[0]; param.Value = "'jormungander'"; param.SaveToDatabase(); ExtractDatasetCommand request = new ExtractDatasetCommand(_configuration, new ExtractableDatasetBundle(_extractableDataSet)); request.GenerateQueryBuilder(); Assert.AreEqual( CollapseWhitespace( string.Format( @"DECLARE @fish AS varchar(50); SET @fish='jormungander'; /*The ID of the cohort in [{0}CohortDatabase]..[Cohort]*/ DECLARE @CohortDefinitionID AS int; SET @CohortDefinitionID=-599; /*The project number of project {0}ExtractionConfiguration*/ DECLARE @ProjectNumber AS int; SET @ProjectNumber=1; SELECT DISTINCT [{0}CohortDatabase]..[Cohort].[ReleaseID] AS ReleaseID, [{0}ScratchArea].[dbo].[TestTable].[Name], [{0}ScratchArea].[dbo].[TestTable].[DateOfBirth] FROM [{0}ScratchArea].[dbo].[TestTable] INNER JOIN [{0}CohortDatabase]..[Cohort] ON [{0}ScratchArea].[dbo].[TestTable].[PrivateID]=[{0}CohortDatabase]..[Cohort].[PrivateID] WHERE ( /*FilterByFishDeployed*/ Fish = @fish ) AND [{0}CohortDatabase]..[Cohort].[cohortDefinition_id]=-599 " , TestDatabaseNames.Prefix)) , CollapseWhitespace(request.QueryBuilder.SQL)); ExtractionConfiguration deepClone = _configuration.DeepCloneWithNewIDs(); Assert.AreEqual(deepClone.Cohort_ID, _configuration.Cohort_ID); Assert.AreNotEqual(deepClone.ID, _configuration.ID); try { ExtractDatasetCommand request2 = new ExtractDatasetCommand(deepClone, new ExtractableDatasetBundle(_extractableDataSet)); request2.GenerateQueryBuilder(); Assert.AreEqual(request.QueryBuilder.SQL, request2.QueryBuilder.SQL); } finally { deepClone.DeleteInDatabase(); } } finally { filter.DeleteInDatabase(); } }
public void ImportCatalogueWithSingleFilterThatHasAParameter(bool createAGlobalOverrideBeforeHand) { string parameterSQL = "DECLARE @dragonCount as varchar(100)"; var filter = new ExtractionFilter(CatalogueRepository, "MyMandatoryFilter", testData.extractionInformations[0]); filter.IsMandatory = true; filter.WhereSQL = "There Be Dragons AND @dragonCount = 1"; filter.SaveToDatabase(); //Should result in the creation of a parameter new ParameterCreator(new ExtractionFilterFactory(testData.extractionInformations[0]), null, null).CreateAll(filter, null); var filterParameters = filter.ExtractionFilterParameters.ToArray(); Assert.AreEqual(1, filterParameters.Length); filterParameters[0].ParameterSQL = parameterSQL; filterParameters[0].Value = "'No More than 300 Dragons Please'"; filterParameters[0].SaveToDatabase(); AnyTableSqlParameter global = null; if (createAGlobalOverrideBeforeHand) { global = new AnyTableSqlParameter(CatalogueRepository, cohortIdentificationConfiguration, parameterSQL); global.Value = "'At Least 1000 Dragons'"; global.SaveToDatabase(); } //ensure that it is picked up var mandatoryFilters = testData.catalogue.GetAllMandatoryFilters(); Assert.AreEqual(1, mandatoryFilters.Length); Assert.AreEqual(filter, mandatoryFilters[0]); AggregateConfiguration importedAggregate = null; try { importedAggregate = cohortIdentificationConfiguration.CreateNewEmptyConfigurationForCatalogue(testData.catalogue, null); var importedAggregateFilterContainer = importedAggregate.RootFilterContainer; //Must have a root container Assert.IsNotNull(importedAggregateFilterContainer); //With an AND operation Assert.AreEqual(FilterContainerOperation.AND, importedAggregateFilterContainer.Operation); var importedFilters = importedAggregateFilterContainer.GetFilters(); Assert.AreEqual(1, importedFilters.Length); //Because the configuration already has a parameter with the same declaration it should not bother to import the parameter from the underlying filter if (createAGlobalOverrideBeforeHand) { Assert.AreEqual(0, importedFilters[0].GetAllParameters().Length); } else { //Because there is no global we should be creating a clone of the parameter too var paramClones = importedFilters[0].GetAllParameters(); Assert.AreEqual(1, paramClones.Length); //clone should have same SQL and Value Assert.AreEqual(parameterSQL, paramClones[0].ParameterSQL); Assert.AreEqual(filterParameters[0].ParameterSQL, paramClones[0].ParameterSQL); Assert.AreEqual(filterParameters[0].Value, paramClones[0].Value); //but not be the same object in database Assert.AreNotEqual(filterParameters[0], paramClones[0]); } } finally { if (global != null) { global.DeleteInDatabase(); } filter.DeleteInDatabase(); if (importedAggregate != null) { importedAggregate.RootFilterContainer.DeleteInDatabase(); importedAggregate.DeleteInDatabase(); } } }