public void update_changeAllPropertiesOfCatalogueItem_passes() { Catalogue parent = new Catalogue(CatalogueRepository, "KONGOR"); CatalogueItem child = new CatalogueItem(CatalogueRepository, parent, "KONGOR_SUPERKING") { Agg_method = "Adding SetUp", Comments = "do not change amagad super secret!", Limitations = "Extreme limitaitons", Description = "Exciting things are going down in the streets of new your this time of year it would be a great idea if you were to go there", Name = "KONGOR_MINIMAN", Periodicity = Catalogue.CataloguePeriodicity.Monthly, Research_relevance = "Highly relevant to all fields of subatomic particle study", Statistical_cons = "Dangerous cons frequent the areas that this stats is happening, be afraid", Topic = "nothing much, lots of stuff" }; child.SaveToDatabase(); CatalogueItem childAfter = CatalogueRepository.GetObjectByID <CatalogueItem>(child.ID); Assert.IsTrue(child.Name == childAfter.Name); Assert.IsTrue(child.Agg_method == childAfter.Agg_method); Assert.IsTrue(child.Comments == childAfter.Comments); Assert.IsTrue(child.Limitations == childAfter.Limitations); Assert.IsTrue(child.Description == childAfter.Description); Assert.IsTrue(child.Periodicity == childAfter.Periodicity); Assert.IsTrue(child.Research_relevance == childAfter.Research_relevance); Assert.IsTrue(child.Statistical_cons == childAfter.Statistical_cons); Assert.IsTrue(child.Topic == childAfter.Topic); child.DeleteInDatabase(); parent.DeleteInDatabase(); }
private void Setup2Catalogues(out Catalogue c1, out Catalogue c2) { c1 = WhenIHaveA <Catalogue>(); c1.Name = "ffff"; c1.Description = "A cool dataset with interesting stuff"; c1.SaveToDatabase(); var c1ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col1"); c1ci1.Description = "some info about column 1"; c1ci1.SaveToDatabase(); var c1ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col2"); c1ci2.Description = "some info about column 2"; c1ci2.SaveToDatabase(); c2 = WhenIHaveA <Catalogue>(); c2.Name = "Demog"; c2.Description = "This is expensive dataset: $30 to use"; c2.SaveToDatabase(); var c2ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Name"); c2ci1.Description = "Name of the patient"; c2ci1.SaveToDatabase(); var c2ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Address"); c2ci2.Description = "Where they live"; c2ci2.SaveToDatabase(); var c2ci3 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Postcode"); c2ci3.Description = "Patients postcode"; c2ci3.SaveToDatabase(); }
public override void Execute() { base.Execute(); if (_columnInfo == null) { _columnInfo = SelectOne <ColumnInfo>(Activator.RepositoryLocator.CatalogueRepository, _catalogueItem.Name); } if (_columnInfo == null) { return; } _catalogueItem.SetColumnInfo(_columnInfo); //if it did not have a name before if (_catalogueItem.Name.StartsWith("New CatalogueItem")) { //give it one _catalogueItem.Name = _columnInfo.GetRuntimeName(); _catalogueItem.SaveToDatabase(); } //Either way refresh the catalogue item Publish(_catalogueItem); }
public override void Execute() { base.Execute(); //if we have not got an explicit one to import let the user pick one if (_columnInfos.Length == 0) { string text; //get them to pick a column info var columnInfo = (ColumnInfo)BasicActivator.SelectOne(new DialogArgs { TaskDescription = "Select which column the new CatalogueItem will describe/extract", WindowTitle = "Choose underlying Column" }, BasicActivator.CoreChildProvider.AllColumnInfos); if (columnInfo == null) { return; } //get them to type a name for it (based on the ColumnInfo if picked) if (TypeText("Name", "Type a name for the new CatalogueItem", 500, columnInfo?.GetRuntimeName(), out text)) { var ci = new CatalogueItem(BasicActivator.RepositoryLocator.CatalogueRepository, _catalogue, "New CatalogueItem " + Guid.NewGuid()); ci.Name = text; //set the associated column if they did pick it if (columnInfo != null) { ci.SetColumnInfo(columnInfo); } ci.SaveToDatabase(); Publish(_catalogue); Emphasise(ci, int.MaxValue); } } else { foreach (ColumnInfo columnInfo in _columnInfos) { if (AlreadyInCatalogue(columnInfo)) { continue; } var ci = new CatalogueItem(BasicActivator.RepositoryLocator.CatalogueRepository, _catalogue, columnInfo.Name); ci.SetColumnInfo(columnInfo); ci.SaveToDatabase(); } Publish(_catalogue); } }
public void SourceRead_ToTable_IgnoringSuperflousColumn_LoadMetadata() { var repo = new MemoryCatalogueRepository(); var lmd = new LoadMetadata(repo, "MyLoad"); var cata1 = new Catalogue(repo, "PatientCatalogue"); var ci1 = new CatalogueItem(repo, cata1, "PatientAge"); var ti1 = new TableInfo(repo, "PatientTableInfo"); var colInfo1 = new ColumnInfo(repo, "PatientAge", "varchar(100)", ti1); ci1.ColumnInfo_ID = colInfo1.ID; ci1.SaveToDatabase(); cata1.LoadMetadata_ID = lmd.ID; cata1.SaveToDatabase(); var cata2 = new Catalogue(repo, "FileCatalogue"); var ci2 = new CatalogueItem(repo, cata2, "RelFileName"); var ti2 = new TableInfo(repo, "FileTableInfo"); var colInfo2 = new ColumnInfo(repo, "RelFileName", "varchar(100)", ti2); ci2.ColumnInfo_ID = colInfo2.ID; ci2.SaveToDatabase(); cata2.LoadMetadata_ID = lmd.ID; cata2.SaveToDatabase(); var source = new DicomDatasetCollectionSource(); source.InvalidDataHandlingStrategy = InvalidDataHandling.ThrowException; var ds = new DicomDataset(); ds.Add(DicomTag.PatientAge, "123Y"); var sequence = new DicomSequence(DicomTag.AcquisitionContextSequence, new DicomDataset() { { DicomTag.WedgeAngleFloat, "3.40282347e+038" } }); ds.Add(sequence); var worklist = new ExplicitListDicomDatasetWorklist(new[] { ds }, "fish.dcm"); source.PreInitialize(worklist, new ThrowImmediatelyDataLoadEventListener()); source.FilenameField = "RelFileName"; source.UseAllTableInfoInLoadAsFieldMap = lmd; var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()); Assert.AreEqual("123Y", dt.Rows[0]["PatientAge"]); Assert.AreEqual("fish.dcm", dt.Rows[0]["RelFileName"]); Assert.AreEqual(2, dt.Columns.Count); }
public void TestNewlineSubstitution_FullTemplate() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "ffff"; cata.Description = @"A cool dataset with interesting stuff"; cata.SaveToDatabase(); var cataItem1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "Col1"); cataItem1.Description = "some info about column 1"; cataItem1.SaveToDatabase(); var cataItem2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, cata, "Col2"); cataItem2.Description = @"some info about column 2"; cataItem2.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description | Column | Description | $foreach CatalogueItem | $Name | $Description | $end"); var cmd = new ExecuteCommandExtractMetadata(new ThrowImmediatelyActivator(RepositoryLocator), new[] { cata }, outDir, template, "$Name.md", false, "<br/>"); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "ffff.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"## ffff A cool<br/>dataset with interesting stuff | Column | Description | | Col1 | some info about column 1 | | Col2 | some info <br/>about column 2 |", resultText.TrimEnd()); }
public void clone_CloneCatalogueItemWithIDIntoCatalogue_passes() { Catalogue parent = new Catalogue(CatalogueRepository, "KONGOR"); Catalogue parent2 = new Catalogue(CatalogueRepository, "KONGOR2"); CatalogueItem child = new CatalogueItem(CatalogueRepository, parent, "KONGOR_SUPERKING") { Agg_method = "Adding SetUp", Comments = "do not change amagad super secret!", Limitations = "Extreme limitaitons", Description = "Exciting things are going down in the streets of new your this time of year it would be a great idea if you were to go there", Name = "KONGOR_MINIMAN", Periodicity = Catalogue.CataloguePeriodicity.Monthly, Research_relevance = "Highly relevant to all fields of subatomic particle study", Statistical_cons = "Dangerous cons frequent the areas that this stats is happening, be afraid", Topic = "nothing much, lots of stuff" }; CatalogueItem cloneChild = null; try { child.SaveToDatabase(); cloneChild = child.CloneCatalogueItemWithIDIntoCatalogue(parent2); //get the clone that was returned Assert.AreEqual(cloneChild.Catalogue_ID, parent2.ID); //it is in the second one Assert.AreNotEqual(cloneChild.Catalogue_ID, parent.ID); //it is not in the first one Assert.AreNotEqual(cloneChild.ID, child.ID); //it has a new ID Assert.AreEqual(cloneChild.Limitations, child.Limitations); Assert.AreEqual(cloneChild.Description, child.Description); Assert.AreEqual(cloneChild.Name, child.Name); Assert.AreEqual(cloneChild.Periodicity, child.Periodicity); Assert.AreEqual(cloneChild.Research_relevance, child.Research_relevance); Assert.AreEqual(cloneChild.Statistical_cons, child.Statistical_cons); Assert.AreEqual(cloneChild.Topic, child.Topic); } finally { if (cloneChild != null) { cloneChild.DeleteInDatabase(); } child.DeleteInDatabase(); parent.DeleteInDatabase(); parent2.DeleteInDatabase(); } }
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(); }
private ExtractionInformation CreateExtractionInformation(Catalogue catalogue, string name, string columnInfoName, string selectSQL) { var col = catalogue.GetTableInfoList(false).SelectMany(t => t.ColumnInfos).SingleOrDefault(c => c.GetRuntimeName() == columnInfoName); if (col == null) { throw new Exception("Could not find ColumnInfo called '" + columnInfoName + "' in Catalogue " + catalogue); } var ci = new CatalogueItem(_repos.CatalogueRepository, catalogue, name); ci.ColumnInfo_ID = col.ID; ci.SaveToDatabase(); return(new ExtractionInformation(_repos.CatalogueRepository, ci, col, selectSQL)); }
/// <inheritdoc cref="ExecuteForwardEngineering()"/> public void ExecuteForwardEngineering(Catalogue intoExistingCatalogue, out Catalogue catalogue, out CatalogueItem[] catalogueItems, out ExtractionInformation[] extractionInformations) { var repo = _tableInfo.CatalogueRepository; //if user did not specify an existing catalogue to supplement if (intoExistingCatalogue == null) { //create a new (empty) catalogue and treat that as the new target intoExistingCatalogue = new Catalogue(repo, _tableInfo.GetRuntimeName()); } catalogue = intoExistingCatalogue; List <CatalogueItem> catalogueItemsCreated = new List <CatalogueItem>(); List <ExtractionInformation> extractionInformationsCreated = new List <ExtractionInformation>(); int order = 0; //for each column we will add a new one to the foreach (ColumnInfo col in _columnInfos) { order++; //create it with the same name CatalogueItem cataItem = new CatalogueItem(repo, intoExistingCatalogue, col.Name.Substring(col.Name.LastIndexOf(".") + 1).Trim('[', ']', '`', '"')); catalogueItemsCreated.Add(cataItem); if (_markAllExtractable) { var newExtractionInfo = new ExtractionInformation(repo, cataItem, col, col.Name); newExtractionInfo.Order = order; newExtractionInfo.SaveToDatabase(); extractionInformationsCreated.Add(newExtractionInfo); } else { cataItem.ColumnInfo_ID = col.ID; cataItem.SaveToDatabase(); } } extractionInformations = extractionInformationsCreated.ToArray(); catalogueItems = catalogueItemsCreated.ToArray(); }
public override void Execute() { var available = BasicActivator.CoreChildProvider.AllCatalogueItems.Except(new[] { _toPopulate }).ToList(); string initialSearchText = null; //if we have a CatalogueItem other than us that has same Name maybe that's the one they want if (available.Any(a => a.Name.Equals(_toPopulate.Name, StringComparison.CurrentCultureIgnoreCase))) { initialSearchText = _toPopulate.Name; } if (SelectOne(available, out CatalogueItem selected, initialSearchText, false)) { CopyNonIDValuesAcross(selected, _toPopulate, true); _toPopulate.SaveToDatabase(); Publish(_toPopulate); } base.Execute(); }
public override void Execute() { var available = Activator.CoreChildProvider.AllCatalogueItems.Except(new[] { _toPopulate }).ToArray(); var dialog = new SelectIMapsDirectlyToDatabaseTableDialog(available, false, false); //if we have a CatalogueItem other than us that has same Name maybe that's the one they want if (available.Any(a => a.Name.Equals(_toPopulate.Name, StringComparison.CurrentCultureIgnoreCase))) { dialog.SetInitialFilter(_toPopulate.Name); } if (dialog.ShowDialog() == DialogResult.OK) { var chosen = (CatalogueItem)dialog.Selected; CopyNonIDValuesAcross(chosen, _toPopulate, true); _toPopulate.SaveToDatabase(); Publish(_toPopulate); } base.Execute(); }
public void TestCustomMetadataReport_TwoCataloguesWithItems() { var c1 = WhenIHaveA <Catalogue>(); c1.Name = "ffff"; c1.Description = "A cool dataset with interesting stuff"; c1.SaveToDatabase(); var c1ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col1"); c1ci1.Description = "some info about column 1"; c1ci1.SaveToDatabase(); var c1ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c1, "Col2"); c1ci2.Description = "some info about column 2"; c1ci2.SaveToDatabase(); var c2 = WhenIHaveA <Catalogue>(); c2.Name = "Demog"; c2.Description = "This is expensive dataset: $30 to use"; c2.SaveToDatabase(); var c2ci1 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Name"); c2ci1.Description = "Name of the patient"; c2ci1.SaveToDatabase(); var c2ci2 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Address"); c2ci2.Description = "Where they live"; c2ci2.SaveToDatabase(); var c2ci3 = new CatalogueItem(RepositoryLocator.CatalogueRepository, c2, "Postcode"); c2ci3.Description = "Patients postcode"; c2ci3.SaveToDatabase(); var template = new FileInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "template.md")); var outDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "outDir")); if (outDir.Exists) { outDir.Delete(true); } outDir.Create(); File.WriteAllText(template.FullName, @"## $Name $Description Price: $30 | Column | Description | $foreach CatalogueItem | $Name | $Description | $end"); var cmd = new ExecuteCommandExtractMetadata(null, new[] { c1, c2 }, outDir, template, "Datasets.md", true, null); cmd.Execute(); var outFile = Path.Combine(outDir.FullName, "Datasets.md"); FileAssert.Exists(outFile); var resultText = File.ReadAllText(outFile); StringAssert.AreEqualIgnoringCase(@"## ffff A cool dataset with interesting stuff Price: $30 | Column | Description | | Col1 | some info about column 1 | | Col2 | some info about column 2 | ## Demog This is expensive dataset: $30 to use Price: $30 | Column | Description | | Name | Name of the patient | | Address | Where they live | | Postcode | Patients postcode |", resultText.TrimEnd()); }
public override void Execute() { base.Execute(); var db = SelectDatabase(false, "Import all Tables form Database..."); if (db == null) { return; } ShareManager shareManager = new ShareManager(Activator.RepositoryLocator, LocalReferenceGetter); List <ICatalogue> catalogues = new List <ICatalogue>(); //don't do any double importing! var existing = Activator.RepositoryLocator.CatalogueRepository.GetAllObjects <TableInfo>(); var ignoredTables = new List <TableInfo>(); if (YesNo("Would you also like to import ShareDefinitions (metadata)?", "Import Metadata From File(s)")) { OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true }; ofd.Filter = "Share Definitions|*.sd"; if (ofd.ShowDialog() == DialogResult.OK) { foreach (var f in ofd.FileNames) { using (var stream = File.Open(f, FileMode.Open)) { var newObjects = shareManager.ImportSharedObject(stream); if (newObjects != null) { catalogues.AddRange(newObjects.OfType <ICatalogue>()); } } } } } bool generateCatalogues = false; if (YesNo("Would you like to try to guess non-matching Catalogues by Name?", "Guess by name")) { catalogues.AddRange(Activator.RepositoryLocator.CatalogueRepository.GetAllObjects <Catalogue>()); } else if (YesNo("Would you like to generate empty Catalogues for non-matching tables instead?", "Generate New Catalogues")) { generateCatalogues = true; } var married = new Dictionary <CatalogueItem, ColumnInfo>(); TableInfo anyNewTable = null; foreach (DiscoveredTable discoveredTable in db.DiscoverTables(includeViews: false)) { var collide = existing.FirstOrDefault(t => t.Is(discoveredTable)); if (collide != null) { ignoredTables.Add(collide); continue; } var importer = new TableInfoImporter(Activator.RepositoryLocator.CatalogueRepository, discoveredTable); TableInfo ti; ColumnInfo[] cis; //import the table importer.DoImport(out ti, out cis); anyNewTable = anyNewTable ?? ti; //find a Catalogue of the same name (possibly imported from Share Definition) var matchingCatalogues = catalogues.Where(c => c.Name.Equals(ti.GetRuntimeName(), StringComparison.CurrentCultureIgnoreCase)).ToArray(); //if there's 1 Catalogue with the same name if (matchingCatalogues.Length == 1) { //we know we want to import all these ColumnInfos var unmatched = new List <ColumnInfo>(cis); //But hopefully most already have orphan CatalogueItems we can hook them together to foreach (var cataItem in matchingCatalogues[0].CatalogueItems) { if (cataItem.ColumnInfo_ID == null) { var matches = cataItem.GuessAssociatedColumn(cis, allowPartial: false).ToArray(); if (matches.Length == 1) { cataItem.SetColumnInfo(matches[0]); unmatched.Remove(matches[0]); //we married them together married.Add(cataItem, matches[0]); } } } //is anyone unmarried? i.e. new ColumnInfos that don't have CatalogueItems with the same name foreach (ColumnInfo columnInfo in unmatched) { var cataItem = new CatalogueItem(Activator.RepositoryLocator.CatalogueRepository, (Catalogue)matchingCatalogues[0], columnInfo.GetRuntimeName()); cataItem.ColumnInfo_ID = columnInfo.ID; cataItem.SaveToDatabase(); married.Add(cataItem, columnInfo); } } else if (generateCatalogues) { new ForwardEngineerCatalogue(ti, cis).ExecuteForwardEngineering(); } } if (married.Any() && YesNo("Found " + married.Count + " columns, make them all extractable?", "Make Extractable")) { foreach (var kvp in married) { //yup thats how we roll, the database is main memory! var ei = new ExtractionInformation(Activator.RepositoryLocator.CatalogueRepository, kvp.Key, kvp.Value, kvp.Value.Name); } } if (ignoredTables.Any()) { WideMessageBox.Show("Ignored some tables", "Ignored " + ignoredTables.Count + " tables because they already existed as TableInfos:" + string.Join(Environment.NewLine, ignoredTables.Select(ti => ti.GetRuntimeName()))); } if (anyNewTable != null) { Publish(anyNewTable); Emphasise(anyNewTable); } }
public void GatherAndShare_Catalogue_Test(bool goViaJson) { //Setup some objects under Catalogue that we can share var cata = new Catalogue(CatalogueRepository, "Cata"); cata.Periodicity = Catalogue.CataloguePeriodicity.BiMonthly; cata.SaveToDatabase(); var catalogueItem1 = new CatalogueItem(CatalogueRepository, cata, "Ci1"); var catalogueItem2 = new CatalogueItem(CatalogueRepository, cata, "Ci2"); var tableInfo = new TableInfo(CatalogueRepository, "Myt"); var colInfo = new ColumnInfo(CatalogueRepository, "[Mt].[C1]", "varchar(10)", tableInfo); catalogueItem1.ColumnInfo_ID = colInfo.ID; catalogueItem1.SaveToDatabase(); var ei = new ExtractionInformation(CatalogueRepository, catalogueItem1, colInfo, "UPPER(C1) as Fish"); //the logging server has a system default so should have been populated Assert.IsNotNull(cata.LiveLoggingServer_ID); //Catalogue sharing should be allowed Gatherer g = new Gatherer(RepositoryLocator); Assert.IsTrue(g.CanGatherDependencies(cata)); //gather the objects depending on Catalogue as a tree var gObj = g.GatherDependencies(cata); Assert.AreEqual(2, gObj.Children.Count); //both cata items var lmd = new LoadMetadata(CatalogueRepository); cata.LoadMetadata_ID = lmd.ID; cata.SaveToDatabase(); //get the share definition var shareManager = new ShareManager(RepositoryLocator); var shareDefinition = gObj.ToShareDefinitionWithChildren(shareManager); if (goViaJson) { var json = shareDefinition.Select(s => JsonConvertExtensions.SerializeObject(s, RepositoryLocator)).ToList(); shareDefinition = json.Select( j => JsonConvertExtensions.DeserializeObject(j, typeof(ShareDefinition), RepositoryLocator)) .Cast <ShareDefinition>() .ToList(); } //make a local change cata.Name = "fishfish"; cata.SubjectNumbers = "123"; cata.LoadMetadata_ID = null; cata.Periodicity = Catalogue.CataloguePeriodicity.Unknown; cata.SaveToDatabase(); lmd.DeleteInDatabase(); //import the saved copy shareManager.ImportSharedObject(shareDefinition); //revert the memory copy and check it got overwritten with the original saved values cata.RevertToDatabaseState(); Assert.AreEqual("Cata", cata.Name); var exports = CatalogueRepository.GetAllObjects <ObjectExport>(); Assert.IsTrue(exports.Any()); //now delete and report foreach (var d in exports) { d.DeleteInDatabase(); } //make a local change including Name cata.Name = "fishfish"; cata.SaveToDatabase(); //test importing the Catalogue properties only shareManager.ImportPropertiesOnly(cata, shareDefinition[0]); //import the defined properties but not name Assert.AreEqual("fishfish", cata.Name); Assert.AreEqual(Catalogue.CataloguePeriodicity.BiMonthly, cata.Periodicity); //reset this though Assert.IsNull(cata.LoadMetadata_ID); cata.SaveToDatabase(); cata.DeleteInDatabase(); //none of these should now exist thanks to cascade deletes Assert.IsFalse(cata.Exists()); Assert.IsFalse(catalogueItem1.Exists()); Assert.IsFalse(catalogueItem2.Exists()); //import the saved copy var newObjects = shareManager.ImportSharedObject(shareDefinition).ToArray(); Assert.AreEqual("Cata", ((Catalogue)newObjects[0]).Name); Assert.AreEqual("Ci1", ((CatalogueItem)newObjects[1]).Name); Assert.AreEqual("Ci2", ((CatalogueItem)newObjects[2]).Name); }
private void CreateLookupsEtc() { //an extractable file var filename = Path.Combine(TestContext.CurrentContext.WorkDirectory, "bob.txt"); File.WriteAllText(filename, "fishfishfish"); var doc = new SupportingDocument(CatalogueRepository, _catalogue, "bob"); doc.URL = new Uri("file://" + filename); doc.Extractable = true; doc.SaveToDatabase(); //an extractable global file (comes out regardless of datasets) var filename2 = Path.Combine(TestContext.CurrentContext.WorkDirectory, "bob2.txt"); File.WriteAllText(filename2, "fishfishfish2"); var doc2 = new SupportingDocument(CatalogueRepository, _catalogue, "bob2"); doc2.URL = new Uri("file://" + filename2); doc2.Extractable = true; doc2.IsGlobal = true; doc2.SaveToDatabase(); //an supplemental table in the database (not linked against cohort) var tbl = CreateDataset <Biochemistry>(Database, 500, 1000, new Random(50)); var sql = new SupportingSQLTable(CatalogueRepository, _catalogue, "Biochem"); var server = new ExternalDatabaseServer(CatalogueRepository, "myserver", null); server.SetProperties(tbl.Database); sql.ExternalDatabaseServer_ID = server.ID; sql.SQL = "SELECT * FROM " + tbl.GetFullyQualifiedName(); sql.Extractable = true; sql.SaveToDatabase(); //an supplemental (global) table in the database (not linked against cohort) var tbl2 = CreateDataset <HospitalAdmissions>(Database, 500, 1000, new Random(50)); var sql2 = new SupportingSQLTable(CatalogueRepository, _catalogue, "Hosp"); sql2.ExternalDatabaseServer_ID = server.ID; sql2.SQL = "SELECT * FROM " + tbl2.GetFullyQualifiedName(); sql2.Extractable = true; sql2.IsGlobal = true; sql2.SaveToDatabase(); DataTable dtLookup = new DataTable(); dtLookup.Columns.Add("C"); dtLookup.Columns.Add("D"); dtLookup.Rows.Add("F", "Female"); dtLookup.Rows.Add("M", "Male"); dtLookup.Rows.Add("NB", "Non Binary"); var lookupTbl = tbl2.Database.CreateTable("z_fff", dtLookup); Import(lookupTbl, out TableInfo ti, out ColumnInfo[] columnInfos); var lookup = new Lookup(CatalogueRepository, columnInfos[0], _columnToTransform, columnInfos[1], ExtractionJoinType.Left, null); //we need a CatalogueItem for the description in order to pick SetUp the Lookup as associated with the Catalogue var ci = new CatalogueItem(CatalogueRepository, _catalogue, "SomeDesc"); ci.ColumnInfo_ID = columnInfos[1].ID; ci.SaveToDatabase(); }
protected override void SetUp() { base.SetUp(); string sql = @"CREATE TABLE [dbo].[Tests]( [chi] [varchar](10) NULL, [Date] [datetime] NULL, [hb_extract] [varchar](1) NULL, [TestId] [int] NOT NULL, CONSTRAINT [PK_Tests] PRIMARY KEY CLUSTERED ( [TestId] ASC ) ) GO CREATE TABLE [dbo].[Results]( [TestId] [int] NOT NULL, [Measure] [varchar](10) NOT NULL, [Value] [int] NULL, CONSTRAINT [PK_Results] PRIMARY KEY CLUSTERED ( [TestId] ASC, [Measure] ASC ) ) GO ALTER TABLE [dbo].[Results] WITH CHECK ADD CONSTRAINT [FK_Results_Tests] FOREIGN KEY([TestId]) REFERENCES [dbo].[Tests] ([TestId]) GO"; var server = From.Server; using (var con = server.GetConnection()) { con.Open(); UsefulStuff.ExecuteBatchNonQuery(sql, con); } var importer1 = new TableInfoImporter(CatalogueRepository, From.ExpectTable("Tests")); var importer2 = new TableInfoImporter(CatalogueRepository, From.ExpectTable("Results")); importer1.DoImport(out t1, out c1); importer2.DoImport(out t2, out c2); var engineer1 = new ForwardEngineerCatalogue(t1, c1, true); var engineer2 = new ForwardEngineerCatalogue(t2, c2, true); engineer1.ExecuteForwardEngineering(out cata1, out cataItems1, out eis1); engineer2.ExecuteForwardEngineering(out cata2, out cataItems2, out eis2); new JoinInfo(CatalogueRepository, c1.Single(e => e.GetRuntimeName().Equals("TestId")), c2.Single(e => e.GetRuntimeName().Equals("TestId")), ExtractionJoinType.Left, null); _anoTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOTes", "T"); _anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 10; _anoTable.SaveToDatabase(); _anoTable.PushToANOServerAsNewTable("int", new ThrowImmediatelyCheckNotifier()); _comboCata = new Catalogue(CatalogueRepository, "Combo Catalogue"); //pk var ciTestId = new CatalogueItem(CatalogueRepository, _comboCata, "TestId"); var colTestId = c1.Single(c => c.GetRuntimeName().Equals("TestId")); ciTestId.ColumnInfo_ID = colTestId.ID; ciTestId.SaveToDatabase(); var eiTestId = new ExtractionInformation(CatalogueRepository, ciTestId, colTestId, colTestId.Name); //Measure var ciMeasure = new CatalogueItem(CatalogueRepository, _comboCata, "Measuree"); var colMeasure = c2.Single(c => c.GetRuntimeName().Equals("Measure")); ciMeasure.ColumnInfo_ID = colMeasure.ID; ciMeasure.SaveToDatabase(); var eiMeasure = new ExtractionInformation(CatalogueRepository, ciMeasure, colMeasure, colMeasure.Name); //Date var ciDate = new CatalogueItem(CatalogueRepository, _comboCata, "Dat"); var colDate = c1.Single(c => c.GetRuntimeName().Equals("Date")); ciDate.ColumnInfo_ID = colDate.ID; ciDate.SaveToDatabase(); var eiDate = new ExtractionInformation(CatalogueRepository, ciDate, colDate, colDate.Name); _destinationDatabase = To; }