コード例 #1
0
        public void RelatedCatalogueTest_OneCatalogue(bool createExtractionInformation)
        {
            TableInfo  t = new TableInfo(Repository, "MyTable");
            ColumnInfo c = new ColumnInfo(Repository, "MyCol", "varchar(10)", t);

            Catalogue     cata = new Catalogue(Repository, "MyCata");
            CatalogueItem ci   = new CatalogueItem(Repository, cata, "MyCataItem");

            try
            {
                if (createExtractionInformation)
                {
                    new ExtractionInformation(Repository, ci, c, "dbo.SomeFunc('Bob') as MySelectLine");
                }
                else
                {
                    ci.SetColumnInfo(c);
                }

                var catas = t.GetAllRelatedCatalogues();
                Assert.AreEqual(1, catas.Length);
                Assert.AreEqual(cata, catas[0]);
            }
            finally
            {
                ci.DeleteInDatabase();
                cata.DeleteInDatabase();
                t.DeleteInDatabase();
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: LinkerTests.cs プロジェクト: HicServices/RDMP
        public void AddLinkBetween_createNewLink_pass()
        {
            ///////////////Create the things that we are going to create relationships between /////////////////
            var predator        = new Catalogue(CatalogueRepository, "Predator");
            var lazor           = new CatalogueItem(CatalogueRepository, predator, "QuadlzorVelocity");
            var highEnergyTable = new TableInfo(CatalogueRepository, "HighEnergyShizzle");
            var velocityColumn  = new ColumnInfo(CatalogueRepository, "Velocity Of Matter", "int", highEnergyTable);

            ////////////Check the creation worked ok
            Assert.IsNotNull(predator); //catalogue
            Assert.IsNotNull(lazor);

            Assert.IsNotNull(highEnergyTable); //underlying table stuff
            Assert.IsNotNull(velocityColumn);

            ////////////// Create links between stuff and check they were created successfully //////////////

            //create a link between catalogue item lazor and velocity column
            lazor.SetColumnInfo(velocityColumn);
            Assert.IsTrue(lazor.ColumnInfo.ID == velocityColumn.ID);

            ////////////////cleanup ---- Delete everything that we created -------- //////////////
            velocityColumn.DeleteInDatabase(); //delete causes CASCADE: CatalogueItem no longer associated with ColumnInfo because ColumnInfo died

            lazor.RevertToDatabaseState();

            Assert.IsNull(lazor.ColumnInfo);//involves a database query so won't actually invalidate the below

            predator.DeleteInDatabase();

            highEnergyTable.DeleteInDatabase();
        }
コード例 #4
0
ファイル: DependencyTests.cs プロジェクト: HicServices/RDMP
        public void ExtractionInformationTriangle()
        {
            var t   = new TableInfo(CatalogueRepository, "t");
            var col = new ColumnInfo(CatalogueRepository, "mycol", "varchar(10)", t);

            var cat = new Catalogue(CatalogueRepository, "MyCat");
            var ci  = new CatalogueItem(CatalogueRepository, cat, "myci");


            try
            {
                //col depends on tr
                Assert.Contains(t, col.GetObjectsThisDependsOn());
                Assert.Contains(col, t.GetObjectsDependingOnThis());

                //catalogue depends on catalogue items existing (slightly counter intuitive but think of it as data flow out of technical low level data through transforms into datasets - and then into researchers and research projects)
                Assert.Contains(cat, ci.GetObjectsDependingOnThis());
                Assert.Contains(ci, cat.GetObjectsThisDependsOn());

                //catalogue item should not be relying on anything currently (no link to underlying technical data)
                Assert.IsNull(ci.GetObjectsThisDependsOn());

                //now they are associated so the ci should be dependent on the col
                ci.SetColumnInfo(col);
                Assert.Contains(col, ci.GetObjectsDependingOnThis());
            }
            finally
            {
                t.DeleteInDatabase();
                cat.DeleteInDatabase();
            }
        }
コード例 #5
0
ファイル: LinkerTests.cs プロジェクト: HicServices/RDMP
        public void AddSameLinkTwice()
        {
            Catalogue     predator        = null;
            CatalogueItem lazor           = null;
            TableInfo     highEnergyTable = null;
            ColumnInfo    velocityColumn  = null;

            try
            {
                ///////////////Create the things that we are going to create relationships between /////////////////
                predator        = new Catalogue(CatalogueRepository, "Predator");
                lazor           = new CatalogueItem(CatalogueRepository, predator, "QuadlzorVelocity");
                highEnergyTable = new TableInfo(CatalogueRepository, "HighEnergyShizzle");
                velocityColumn  = new ColumnInfo(CatalogueRepository, "Velocity Of Matter", "int", highEnergyTable);

                //now you can add as many links as you want, it just skips them
                lazor.SetColumnInfo(velocityColumn);
                Assert.AreEqual(lazor.ColumnInfo, velocityColumn);
            }
            finally
            {
                lazor.DeleteInDatabase();           //delete child
                predator.DeleteInDatabase();        //delete parent

                velocityColumn.DeleteInDatabase();  //delete child
                highEnergyTable.DeleteInDatabase(); //delete parent
            }
        }
コード例 #6
0
        public void CreateTask()
        {
            _lmd = new LoadMetadata(CatalogueRepository);

            _dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "ProcessTaskCheckingTests"));
            _dir.Create();

            var hicdir = LoadDirectory.CreateDirectoryStructure(_dir, "ProjDir", true);

            _lmd.LocationOfFlatFiles = hicdir.RootPath.FullName;
            _lmd.SaveToDatabase();

            Catalogue     c  = new Catalogue(CatalogueRepository, "c");
            CatalogueItem ci = new CatalogueItem(CatalogueRepository, c, "ci");
            TableInfo     t  = new TableInfo(CatalogueRepository, "t");

            t.Server   = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name;
            t.Database = "mydb";
            t.SaveToDatabase();
            ColumnInfo col = new ColumnInfo(CatalogueRepository, "col", "bit", t);

            ci.SetColumnInfo(col);
            c.LoadMetadata_ID = _lmd.ID;
            c.SaveToDatabase();

            _task    = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles);
            _checker = new ProcessTaskChecks(_lmd);
        }
コード例 #7
0
        private Catalogue SetupATestCatalogue(SqlConnectionStringBuilder builder, string database, string table)
        {
            //create a new catalogue for test data (in the test data catalogue)
            var cat = new Catalogue(CatalogueRepository, "DeleteMe");
            TableInfoImporter importer = new TableInfoImporter(CatalogueRepository, builder.DataSource, database, table, DatabaseType.MicrosoftSQLServer, builder.UserID, builder.Password);
            importer.DoImport(out var tableInfo, out var columnInfos);

            toCleanUp.Push(cat);

            //push the credentials if there are any
            var creds = (DataAccessCredentials)tableInfo.GetCredentialsIfExists(DataAccessContext.InternalDataProcessing);
            if (creds != null)
                toCleanUp.Push(creds);

            //and the TableInfo
            toCleanUp.Push(tableInfo);

            //for each column we will add a new one to the
            foreach (ColumnInfo col in columnInfos)
            {
                //create it with the same name
                var cataItem = new CatalogueItem(CatalogueRepository, cat, col.Name.Substring(col.Name.LastIndexOf(".") + 1).Trim('[', ']', '`'));
                toCleanUp.Push(cataItem);

                cataItem.SetColumnInfo(col);

                toCleanUp.Push(col);
            }

            return cat;
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: CatalogueItemTests.cs プロジェクト: lulzzz/RDMP
        public void TestSettingColumnInfoToNull()
        {
            var parent = new Catalogue(CatalogueRepository, "GROG");

            CatalogueItem child1 = new CatalogueItem(CatalogueRepository, parent, "GROG_ITEM1");

            child1.SetColumnInfo(null);

            Assert.IsNull(child1.ColumnInfo_ID);
            child1.DeleteInDatabase();
            parent.DeleteInDatabase();
        }
コード例 #10
0
        /// <inheritdoc/>
        public override void Execute()
        {
            base.Execute();

            foreach (var descCol in _lookupDescriptionColumns)
            {
                Lookup lookup = new Lookup(_catalogueRepository, descCol, _fkToPkTuples.First().Item1, _fkToPkTuples.First().Item2, ExtractionJoinType.Left, _collation);

                foreach (var supplementalKeyPair in _fkToPkTuples.Skip(1))
                {
                    new LookupCompositeJoinInfo(_catalogueRepository, lookup, supplementalKeyPair.Item1, supplementalKeyPair.Item2, _collation);
                }

                if (_alsoCreateExtractionInformations)
                {
                    string proposedName;

                    if (_lookupDescriptionColumns.Length == 1)
                    {
                        proposedName = _foreignKeyExtractionInformation.GetRuntimeName() + "_Desc";
                    }
                    else
                    {
                        proposedName = _foreignKeyExtractionInformation.GetRuntimeName() + "_" + descCol.GetRuntimeName();
                    }

                    var newCatalogueItem = new CatalogueItem(_catalogueRepository, _catalogue, proposedName);
                    newCatalogueItem.SetColumnInfo(descCol);

                    //bump everyone down 1
                    foreach (var toBumpDown in _allExtractionInformations.Where(e => e.Order > _foreignKeyExtractionInformation.Order))
                    {
                        toBumpDown.Order++;
                        toBumpDown.SaveToDatabase();
                    }

                    var newExtractionInformation = new ExtractionInformation(_catalogueRepository, newCatalogueItem, descCol, descCol.ToString());
                    newExtractionInformation.ExtractionCategory = ExtractionCategory.Supplemental;
                    newExtractionInformation.Alias = newCatalogueItem.Name;
                    newExtractionInformation.Order = _foreignKeyExtractionInformation.Order + 1;
                    newExtractionInformation.SaveToDatabase();
                }
            }

            _catalogue.ClearAllInjections();
        }
コード例 #11
0
        public void RelatedCatalogueTest_TwoCatalogues_TwoColumnsEach(bool createExtractionInformation)
        {
            TableInfo  t  = new TableInfo(Repository, "MyTable");
            ColumnInfo c1 = new ColumnInfo(Repository, "MyCol1", "varchar(10)", t);
            ColumnInfo c2 = new ColumnInfo(Repository, "MyCol2", "varchar(10)", t);

            Catalogue     cata1 = new Catalogue(Repository, "cata1");
            CatalogueItem ci1_1 = new CatalogueItem(Repository, cata1, "MyCataItem1_1");
            CatalogueItem ci1_2 = new CatalogueItem(Repository, cata1, "MyCataItem1_2");

            Catalogue     cata2 = new Catalogue(Repository, "cata2");
            CatalogueItem ci2_1 = new CatalogueItem(Repository, cata2, "MyCataItem2_1");
            CatalogueItem ci2_2 = new CatalogueItem(Repository, cata2, "MyCataItem2_2");

            try
            {
                if (createExtractionInformation)
                {
                    new ExtractionInformation(Repository, ci1_1, c1, "dbo.SomeFunc('Bob') as MySelectLine");
                    new ExtractionInformation(Repository, ci1_2, c2, "dbo.SomeFunc('Bob') as MySelectLine");
                    new ExtractionInformation(Repository, ci2_1, c2, "dbo.SomeFunc('Bob') as MySelectLine");
                    new ExtractionInformation(Repository, ci2_2, c1, "dbo.SomeFunc('Bob') as MySelectLine");
                }
                else
                {
                    ci1_1.SetColumnInfo(c1);
                    ci1_2.SetColumnInfo(c2);
                    ci2_1.SetColumnInfo(c2);
                    ci2_2.SetColumnInfo(c1);
                }



                var catas = t.GetAllRelatedCatalogues();
                Assert.AreEqual(2, catas.Length);
                Assert.IsTrue(catas.Contains(cata1));
                Assert.IsTrue(catas.Contains(cata2));
            }
            finally
            {
                cata1.DeleteInDatabase();
                cata2.DeleteInDatabase();
                t.DeleteInDatabase();
            }
        }
コード例 #12
0
ファイル: HICPipelineTests.cs プロジェクト: HicServices/RDMP
            public void Create(CatalogueRepository repository, DiscoveredDatabase database,
                               ILoadDirectory directory)
            {
                TableInfo = new TableInfo(repository, "TestData")
                {
                    Server   = database.Server.Name,
                    Database = database.GetRuntimeName()
                };
                TableInfo.SaveToDatabase();

                if (!string.IsNullOrWhiteSpace(database.Server.ExplicitUsernameIfAny))
                {
                    Credentials = new DataAccessCredentialsFactory(repository).Create(TableInfo,
                                                                                      database.Server.ExplicitUsernameIfAny, database.Server.ExplicitPasswordIfAny,
                                                                                      DataAccessContext.Any);
                }


                ColumnInfo = new ColumnInfo(repository, "Col1", "int", TableInfo)
                {
                    IsPrimaryKey = true
                };
                ColumnInfo.SaveToDatabase();

                LoadMetadata = new LoadMetadata(repository, "HICLoadPipelineTests")
                {
                    LocationOfFlatFiles = directory.RootPath.FullName
                };
                LoadMetadata.SaveToDatabase();

                Catalogue = new Catalogue(repository, "HICLoadPipelineTests")
                {
                    LoggingDataTask = "Test",
                    LoadMetadata_ID = LoadMetadata.ID
                };
                Catalogue.SaveToDatabase();

                var catalogueItem = new CatalogueItem(repository, Catalogue, "Test");

                catalogueItem.SetColumnInfo(ColumnInfo);

                SetupLoadProcessTasks(repository);
            }
コード例 #13
0
        public void SetupExtraction()
        {
            cata       = new Catalogue(CatalogueRepository, "ExtractionInformationTestsCatalogue");
            cataItem   = new CatalogueItem(CatalogueRepository, cata, "QuadlzorVelocity");
            ti         = new TableInfo(CatalogueRepository, "HighEnergyShizzle");
            columnInfo = new ColumnInfo(CatalogueRepository, "VelocityOfMatter", "int", ti);

            ////////////Check the creation worked ok
            Assert.IsNotNull(cata); //catalogue
            Assert.IsNotNull(cataItem);

            Assert.IsNotNull(ti); //underlying table stuff
            Assert.IsNotNull(columnInfo);

            ////////////// Create links between stuff and check they were created successfully //////////////

            //create a link between catalogue item lazor and velocity column
            cataItem.SetColumnInfo(columnInfo);
        }
コード例 #14
0
        public void TestGetTablesAndLookupTables()
        {
            //One catalogue
            Catalogue cata = new Catalogue(Repository, "TestGetTablesAndLookupTables");

            //6 virtual columns
            CatalogueItem ci1 = new CatalogueItem(Repository, cata, "Col1");
            CatalogueItem ci2 = new CatalogueItem(Repository, cata, "Col2");
            CatalogueItem ci3 = new CatalogueItem(Repository, cata, "Col3");
            CatalogueItem ci4 = new CatalogueItem(Repository, cata, "Col4");
            CatalogueItem ci5 = new CatalogueItem(Repository, cata, "Description");
            CatalogueItem ci6 = new CatalogueItem(Repository, cata, "Code");

            //2 columns come from table 1
            TableInfo  t1    = new TableInfo(Repository, "Table1");
            ColumnInfo t1_c1 = new ColumnInfo(Repository, "Col1", "varchar(10)", t1);
            ColumnInfo t1_c2 = new ColumnInfo(Repository, "Col2", "int", t1);

            //2 columns come from table 2
            TableInfo  t2    = new TableInfo(Repository, "Table2");
            ColumnInfo t2_c1 = new ColumnInfo(Repository, "Col3", "varchar(10)", t2);
            ColumnInfo t2_c2 = new ColumnInfo(Repository, "Col4", "int", t2);

            //2 columns come from the lookup table
            TableInfo  t3    = new TableInfo(Repository, "Table3");
            ColumnInfo t3_c1 = new ColumnInfo(Repository, "Description", "varchar(10)", t3);
            ColumnInfo t3_c2 = new ColumnInfo(Repository, "Code", "int", t3);

            //wire SetUp virtual columns to underlying columns
            ci1.SetColumnInfo(t1_c1);
            ci2.SetColumnInfo(t1_c2);
            ci3.SetColumnInfo(t2_c1);
            ci4.SetColumnInfo(t2_c2);
            ci5.SetColumnInfo(t3_c1);
            ci6.SetColumnInfo(t3_c2);

            //configure the lookup relationship
            var lookup = new Lookup(Repository, t3_c1, t1_c2, t3_c2, ExtractionJoinType.Left, "");

            try
            {
                var allTables = cata.GetTableInfoList(true).ToArray();
                Assert.Contains(t1, allTables);
                Assert.Contains(t2, allTables);
                Assert.Contains(t3, allTables);

                var normalTablesOnly = cata.GetTableInfoList(false).ToArray();
                Assert.AreEqual(2, normalTablesOnly.Length);
                Assert.Contains(t1, normalTablesOnly);
                Assert.Contains(t2, normalTablesOnly);

                var lookupTablesOnly = cata.GetLookupTableInfoList();
                Assert.AreEqual(1, lookupTablesOnly.Length);
                Assert.Contains(t3, lookupTablesOnly);

                List <ITableInfo> normalTables, lookupTables;
                cata.GetTableInfos(out normalTables, out lookupTables);
                Assert.AreEqual(2, normalTables.Count);
                Assert.AreEqual(1, lookupTables.Count);

                Assert.Contains(t1, normalTables);
                Assert.Contains(t2, normalTables);
                Assert.Contains(t3, lookupTables);
            }
            finally
            {
                lookup.DeleteInDatabase();

                t1.DeleteInDatabase();
                t2.DeleteInDatabase();
                t3.DeleteInDatabase();

                cata.DeleteInDatabase();
            }
        }
コード例 #15
0
 public void DeleteInDatabase()
 {
     CatalogueItem.SetColumnInfo(null);
 }
コード例 #16
0
        public void ExtractableColumnTest()
        {
            ExtractableDataSet      dataSet       = null;
            ExtractionConfiguration configuration = null;
            Project project = null;

            Catalogue     cata     = null;
            CatalogueItem cataItem = null;
            ColumnInfo    column   = null;
            TableInfo     table    = null;

            ExtractionInformation extractionInformation = null;
            ExtractableColumn     extractableColumn     = null;

            try
            {
                //setup catalogue side of things
                cata     = new Catalogue(CatalogueRepository, "unit_test_ExtractableColumnTest_Cata");
                cataItem = new CatalogueItem(CatalogueRepository, cata, "unit_test_ExtractableColumnTest_CataItem");
                table    = new TableInfo(CatalogueRepository, "DaveTable");
                column   = new ColumnInfo(CatalogueRepository, "Name", "string", table);
                cataItem.SetColumnInfo(column);

                extractionInformation = new ExtractionInformation(CatalogueRepository, cataItem, column, "Hashme(Name)");

                //setup extractor side of things
                dataSet = new ExtractableDataSet(DataExportRepository, cata);
                project = new Project(DataExportRepository, "unit_test_ExtractableColumnTest_Proj");

                configuration = new ExtractionConfiguration(DataExportRepository, project);

                extractableColumn = new ExtractableColumn(DataExportRepository, dataSet, configuration, extractionInformation, 0, "Hashme2(Name)");
                Assert.AreEqual(configuration.GetAllExtractableColumnsFor(dataSet).Length, 1);
            }
            finally
            {
                if (extractionInformation != null)
                {
                    extractionInformation.DeleteInDatabase();
                }

                if (column != null)
                {
                    column.DeleteInDatabase();
                }

                if (table != null)
                {
                    table.DeleteInDatabase();
                }

                if (cataItem != null)
                {
                    cataItem.DeleteInDatabase();
                }

                if (configuration != null)
                {
                    configuration.DeleteInDatabase();
                }

                if (project != null)
                {
                    project.DeleteInDatabase();
                }

                if (dataSet != null)
                {
                    dataSet.DeleteInDatabase();
                }

                if (cata != null)
                {
                    cata.DeleteInDatabase();
                }
            }
        }