Exemple #1
0
        public void MigrationOfOldPasswordsTest()
        {
            //cleanup
            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(c => c.Name.Equals("frankieFran")))
            {
                c.DeleteInDatabase();
            }

            //create a new credentials
            DataAccessCredentials creds = new DataAccessCredentials(CatalogueRepository, "frankieFran");

            try
            {
                //update the database to an unencrypted password (like would be the case before software patch)
                using (var con = CatalogueRepository.GetConnection())
                {
                    var cmd = DatabaseCommandHelper.GetCommand("UPDATE DataAccessCredentials set Password = '******' where Name='frankieFran'", con.Connection, con.Transaction);
                    Assert.AreEqual(1, cmd.ExecuteNonQuery());
                }

                DataAccessCredentials newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(creds.ID);

                Assert.AreEqual("fish", newCopy.GetDecryptedPassword());
                Assert.AreNotEqual("fish", newCopy.Password);
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
Exemple #2
0
        /// <summary>
        /// Tests that the logging database for the load is reachable and that it has an appropriate logging task for the load (if not a new task will be created 'Loading X')
        /// </summary>
        /// <param name="catalogue"></param>
        public void EnsureLoggingWorksFor(ICatalogue catalogue)
        {
            //if there's no logging task / logging server set them up with the same name as the lmd
            IExternalDatabaseServer loggingServer;

            if (catalogue.LiveLoggingServer_ID == null)
            {
                loggingServer = CatalogueRepository.GetServerDefaults().GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID);

                if (loggingServer != null)
                {
                    catalogue.LiveLoggingServer_ID = loggingServer.ID;
                }
                else
                {
                    throw new NotSupportedException("You do not yet have any logging servers configured so cannot create data loads");
                }
            }
            else
            {
                loggingServer = Repository.GetObjectByID <ExternalDatabaseServer>(catalogue.LiveLoggingServer_ID.Value);
            }

            //if there's no logging task yet and there's a logging server
            if (string.IsNullOrWhiteSpace(catalogue.LoggingDataTask))
            {
                var lm = new LogManager(loggingServer);
                var loggingTaskName = Name;

                lm.CreateNewLoggingTaskIfNotExists(loggingTaskName);
                catalogue.LoggingDataTask = loggingTaskName;
                catalogue.SaveToDatabase();
            }
        }
Exemple #3
0
        public void MultiEncryptingShouldntBreakIt()
        {
            //cleanup
            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(c => c.Name.Equals("frankieFran")))
            {
                c.DeleteInDatabase();
            }

            DataAccessCredentials creds = new DataAccessCredentials(CatalogueRepository, "frankieFran");

            try
            {
                //as soon as you set a password it should be encrypted by the credentials class in memory
                creds.Password = "******";

                Assert.AreNotEqual("fish", creds.Password);
                Assert.AreEqual("fish", creds.GetDecryptedPassword()); //but we should still be able to decrypt it

                //set the password to the encrypted password
                creds.Password = creds.Password;

                //should still work
                Assert.AreNotEqual("fish", creds.Password);
                Assert.AreEqual("fish", creds.GetDecryptedPassword()); //but we should still be able to decrypt it
            }
            finally
            {
                creds.DeleteInDatabase();
            }
        }
Exemple #4
0
        public void TearDown()
        {
            //delete all joins
            foreach (JoinInfo j in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                j.DeleteInDatabase();
            }

            //delete everything from data export
            foreach (var t in new Type[] { typeof(ExtractionConfiguration), typeof(ExternalCohortTable), typeof(ExtractableDataSet) })
            {
                foreach (IDeleteable o in DataExportRepository.GetAllObjects(t))
                {
                    o.DeleteInDatabase();
                }
            }

            //delete everything from catalogue
            foreach (var t in new Type[] { typeof(Catalogue), typeof(TableInfo), typeof(LoadMetadata), typeof(Pipeline) })
            {
                foreach (IDeleteable o in CatalogueRepository.GetAllObjects(t))
                {
                    o.DeleteInDatabase();
                }
            }
        }
        public void TestGenerateSqlForThreeLevelJoinPath_TimePeriodIsGrandparent()
        {
            ThreeTableSetupWhereTimePeriodIsGrandparent();

            var ciTimePeriodicity = CatalogueRepository.GetAllObjects <ColumnInfo>().SingleOrDefault(c => c.GetRuntimeName().Equals("HeaderDate"));

            if (ciTimePeriodicity == null)
            {
                throw new InvalidOperationException("Could not find TimePeriodicity column");
            }

            var sqlHelper = new BackfillSqlHelper(ciTimePeriodicity, From, To);

            var tiHeader  = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Headers"));
            var tiSamples = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Samples"));
            var tiResults = CatalogueRepository.GetAllObjects <TableInfo>().Single(t => t.GetRuntimeName().Equals("Results"));

            var joinInfos = CatalogueRepository.GetAllObjects <JoinInfo>();
            var joinPath  = new List <JoinInfo>
            {
                joinInfos.Single(info => info.PrimaryKey.TableInfo_ID == tiHeader.ID),
                joinInfos.Single(info => info.PrimaryKey.TableInfo_ID == tiSamples.ID)
            };

            var sql = sqlHelper.CreateSqlForJoinToTimePeriodicityTable("CurrentTable", tiResults, "TimePeriodicityTable", From, joinPath);



            Assert.AreEqual(string.Format(@"SELECT CurrentTable.*, TimePeriodicityTable.HeaderDate AS TimePeriodicityField 
FROM [{0}]..[Results] CurrentTable
LEFT JOIN [{0}]..[Samples] j1 ON j1.ID = CurrentTable.SampleID
LEFT JOIN [{0}]..[Headers] TimePeriodicityTable ON TimePeriodicityTable.ID = j1.HeaderID",
                                          From.GetRuntimeName()), sql);
        }
Exemple #6
0
        public void CreateNewColumnInfoInDatabase_NewColumns_NewColumnsAreEqualAfterSave()
        {
            TableInfo  parent = null;
            ColumnInfo child  = null;

            try
            {
                parent = new TableInfo(CatalogueRepository, "CHI");
                child  = new ColumnInfo(CatalogueRepository, "chi", "varchar(10)", parent)
                {
                    Description     = "The community health index, 10 digits of which the first 6 are date of birth",
                    Status          = ColumnInfo.ColumnStatus.Active,
                    RegexPattern    = "\\d*",
                    ValidationRules = "Last digit must be odd for gents and even for ladies"
                };

                child.SaveToDatabase();

                ColumnInfo childAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(child.ID);

                Assert.AreEqual(child.Name, childAfter.Name);
                Assert.AreEqual(child.Description, childAfter.Description);
                Assert.AreEqual(child.Status, childAfter.Status);
                Assert.AreEqual(child.RegexPattern, childAfter.RegexPattern);
                Assert.AreEqual(child.ValidationRules, childAfter.ValidationRules);
            }
            finally
            {
                child.DeleteInDatabase();
                parent.DeleteInDatabase();
            }
        }
        public void TestPruning()
        {
            Catalogue c  = new Catalogue(CatalogueRepository, "Catapault");
            var       ci = new CatalogueItem(CatalogueRepository, c, "string");

            Catalogue c2  = new Catalogue(CatalogueRepository, "Catapault (Import)");
            var       ci2 = new CatalogueItem(CatalogueRepository, c2, "string (Import)");

            Assert.AreEqual(CatalogueRepository.GetAllObjects <ObjectExport>().Count(), 0);
            var ec  = _share.GetNewOrExistingExportFor(c);
            var eci = _share.GetNewOrExistingExportFor(ci);

            _share.GetImportAs(ec.SharingUID, c2);
            _share.GetImportAs(eci.SharingUID, ci2);

            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectExport>().Count());
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());//successive calls shouldhn't generate extra entries since they are same obj
            Assert.AreEqual(2, CatalogueRepository.GetAllObjects <ObjectImport>().Count());

            //cannot delete the shared object
            Assert.Throws <Exception>(c.DeleteInDatabase);

            //can delete the import because that's ok
            Assert.DoesNotThrow(c2.DeleteInDatabase);

            //now that we deleted the import it should have deleted everything else including the CatalogueItem import which magically disapeared when we deleted the Catalogue via database level cascade events
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <ObjectImport>().Count());

            _share.GetImportAs(eci.SharingUID, ci2);
        }
Exemple #8
0
        public void SupportsValidation_NoDQE()
        {
            IServerDefaults defaults = CatalogueRepository.GetServerDefaults();
            var             before   = defaults.GetDefaultFor(PermissableDefaults.DQE);

            //cannot run test because it didn't have a value to clear!
            Assert.IsNotNull(before);

            //clear the default value
            defaults.ClearDefault(PermissableDefaults.DQE);

            try
            {
                CatalogueConstraintReport report = new CatalogueConstraintReport(_catalogue, SpecialFieldNames.DataLoadRunID);

                var e = Assert.Throws <Exception>(() => report.Check(new ThrowImmediatelyCheckNotifier()));
                Assert.IsTrue(
                    e.Message.StartsWith(
                        "Failed to create DQE Repository, possibly there is no DataQualityEngine Reporting Server (ExternalDatabaseServer).  You will need to create/set one in CatalogueManager")
                    );
            }
            finally
            {
                defaults.SetDefault(PermissableDefaults.DQE, before);
            }
        }
Exemple #9
0
        public void update_changeAllProperties_pass()
        {
            TableInfo  parent = new TableInfo(CatalogueRepository, "Rokkits");
            ColumnInfo column = new ColumnInfo(CatalogueRepository, "ExplosiveVol", "varchar(1000)", parent)
            {
                Digitisation_specs = "Highly digitizable",
                Format             = "Jpeg",
                Name      = "mycol",
                Source    = "Bazooka",
                Data_type = "Whatever"
            };

            column.SaveToDatabase();

            ColumnInfo columnAfter = CatalogueRepository.GetObjectByID <ColumnInfo>(column.ID);

            Assert.IsTrue(columnAfter.Digitisation_specs == "Highly digitizable");
            Assert.IsTrue(columnAfter.Format == "Jpeg");
            Assert.IsTrue(columnAfter.Name == "mycol");
            Assert.IsTrue(columnAfter.Source == "Bazooka");
            Assert.IsTrue(columnAfter.Data_type == "Whatever");

            columnAfter.DeleteInDatabase();
            parent.DeleteInDatabase();
        }
Exemple #10
0
        public void CreateNew_UseConstraint()
        {
            // Clean up any existing regexes
            CatalogueRepository.GetAllObjects <StandardRegex>("WHERE ConceptName = 'Fish'").ToList().ForEach(r => r.DeleteInDatabase());

            var regex = new StandardRegex(CatalogueRepository);

            try
            {
                Assert.IsNotNull(regex.ConceptName);
                Assert.IsTrue(string.IsNullOrEmpty(regex.Description));

                regex.ConceptName = "Fish";
                regex.Regex       = "^(Fish)$";
                regex.SaveToDatabase();

                StandardRegexConstraint constraint = new StandardRegexConstraint(CatalogueRepository);

                constraint.CatalogueStandardRegex = regex;

                Assert.IsNull(constraint.Validate("Fish", null, null));
                ValidationFailure failure = constraint.Validate("FishFingers", null, null);
                Assert.IsNotNull(failure);
            }
            finally
            {
                regex.DeleteInDatabase();
            }
        }
Exemple #11
0
        public void SupportsValidation_NoLoggingServer()
        {
            IServerDefaults defaults = CatalogueRepository.GetServerDefaults();
            var             before   = defaults.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID);

            //cannot run test because it didn't have a value to clear!
            Assert.IsNotNull(before);

            //clear the default value
            defaults.ClearDefault(PermissableDefaults.LiveLoggingServer_ID);

            try
            {
                CatalogueConstraintReport report = new CatalogueConstraintReport(_catalogue, SpecialFieldNames.DataLoadRunID);

                var e = Assert.Throws <Exception>(() => report.Check(new ThrowImmediatelyCheckNotifier()));
                Assert.IsTrue(
                    e.Message.StartsWith(
                        "Failed to setup logging of DQE runs")
                    );
            }
            finally
            {
                defaults.SetDefault(PermissableDefaults.LiveLoggingServer_ID, before);
            }
        }
        private void CleanCatalogueDatabase()
        {
            if (_catalogue != null)
            {
                _catalogue.DeleteInDatabase();
            }

            // ensure the database is cleared of test remnants
            foreach (var ji in CatalogueRepository.GetAllObjects <JoinInfo>())
            {
                ji.DeleteInDatabase();
            }

            // column infos don't appear to delete
            foreach (var ci in CatalogueRepository.GetAllObjects <ColumnInfo>())
            {
                ci.DeleteInDatabase();
            }

            foreach (var ti in CatalogueRepository.GetAllObjects <TableInfo>())
            {
                ti.DeleteInDatabase();
            }

            foreach (var credentials in CatalogueRepository.GetAllObjects <DataAccessCredentials>())
            {
                credentials.DeleteInDatabase();
            }
        }
Exemple #13
0
        public void SaveAndReloadCredentials()
        {
            var originalCredentials = new DataAccessCredentials(CatalogueRepository, "bob");

            try
            {
                originalCredentials.Name     = "bob1";
                originalCredentials.Username = "******";
                originalCredentials.Password = "******";
                originalCredentials.SaveToDatabase();

                var newCopy = CatalogueRepository.GetObjectByID <DataAccessCredentials>(originalCredentials.ID);
                Assert.AreEqual(originalCredentials.Name, newCopy.Name);
                Assert.AreEqual(originalCredentials.Username, newCopy.Username);
                Assert.AreEqual(originalCredentials.Password, newCopy.Password);

                //test overridden Equals
                Assert.AreEqual(originalCredentials, newCopy);
                originalCredentials.Password = "******";
                Assert.AreEqual(originalCredentials, newCopy);//they are still equal because IDs are the same
            }
            finally
            {
                originalCredentials.DeleteInDatabase();
            }
        }
 public ForwardEngineerANOCatalogueEngine(IRDMPPlatformRepositoryServiceLocator repositoryLocator, ForwardEngineerANOCataloguePlanManager planManager)
 {
     _catalogueRepository = (CatalogueRepository)repositoryLocator.CatalogueRepository;
     _shareManager        = new ShareManager(repositoryLocator);
     _planManager         = planManager;
     _allColumnsInfos     = _catalogueRepository.GetAllObjects <ColumnInfo>();
 }
Exemple #15
0
        public FilterManagerFromChildProvider(CatalogueRepository repository, ICoreChildProvider childProvider) : base(repository)
        {
            _containersToFilters =
                childProvider.AllAggregateFilters.Where(f => f.FilterContainer_ID.HasValue)
                .GroupBy(f => f.FilterContainer_ID.Value)
                .ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());

            var server = repository.DiscoveredServer;

            using (var con = repository.GetConnection())
            {
                var r = server.GetCommand("SELECT [AggregateFilterContainer_ParentID],[AggregateFilterContainer_ChildID]  FROM [AggregateFilterSubContainer]", con).ExecuteReader();
                while (r.Read())
                {
                    var parentId       = Convert.ToInt32(r["AggregateFilterContainer_ParentID"]);
                    var subcontainerId = Convert.ToInt32(r["AggregateFilterContainer_ChildID"]);

                    if (!_subcontainers.ContainsKey(parentId))
                    {
                        _subcontainers.Add(parentId, new List <AggregateFilterContainer>());
                    }

                    _subcontainers[parentId].Add(childProvider.AllAggregateContainersDictionary[subcontainerId]);
                }
                r.Close();
            }
        }
Exemple #16
0
        public void Container_Subcontainering()
        {
            var container = new CohortAggregateContainer(CatalogueRepository, SetOperation.UNION);

            var container2 = new CohortAggregateContainer(CatalogueRepository, SetOperation.INTERSECT);

            try
            {
                Assert.AreEqual(0, container.GetSubContainers().Length);


                Assert.AreEqual(0, container.GetSubContainers().Length);

                //set container to parent
                container.AddChild(container2);

                //container 1 should now contain container 2
                Assert.AreEqual(1, container.GetSubContainers().Length);
                Assert.Contains(container2, container.GetSubContainers());

                //container 2 should not have any children
                Assert.AreEqual(0, container2.GetSubContainers().Length);
            }
            finally
            {
                container.DeleteInDatabase();

                //container 2 was contained within container 1 so should have also been deleted
                Assert.Throws <KeyNotFoundException>(
                    () => CatalogueRepository.GetObjectByID <CohortAggregateContainer>(container2.ID));
            }
        }
Exemple #17
0
        private void RemovePreExistingReference()
        {
            //There will likely be an old reference to the external database server
            var preExisting = CatalogueRepository.GetAllObjects <ExternalDatabaseServer>().SingleOrDefault(e => e.Name.Equals(ANOStore_DatabaseName));

            if (preExisting == null)
            {
                return;
            }

            //Some child tests will likely create ANOTables that reference this server so we need to cleanup those for them so that we can cleanup the old server reference too
            foreach (var lingeringTablesReferencingServer in CatalogueRepository.GetAllObjects <ANOTable>().Where(a => a.Server_ID == preExisting.ID))
            {
                //unhook the anonymisation transform from any ColumnInfos using it
                foreach (ColumnInfo colWithANOTransform in CatalogueRepository.GetAllObjects <ColumnInfo>().Where(c => c.ANOTable_ID == lingeringTablesReferencingServer.ID))
                {
                    Console.WriteLine("Unhooked ColumnInfo " + colWithANOTransform + " from ANOTable " + lingeringTablesReferencingServer);
                    colWithANOTransform.ANOTable_ID = null;
                    colWithANOTransform.SaveToDatabase();
                }

                TruncateANOTable(lingeringTablesReferencingServer);
                lingeringTablesReferencingServer.DeleteInDatabase();
            }

            //now delete the old server reference
            preExisting.DeleteInDatabase();
        }
Exemple #18
0
        public DatabaseTests()
        {
            var opts = new PlatformDatabaseCreationOptions()
            {
                ServerName = TestDatabaseSettings.ServerName,
                Prefix     = TestDatabaseNames.Prefix,
                Username   = TestDatabaseSettings.Username,
                Password   = TestDatabaseSettings.Password
            };


            RepositoryLocator = new PlatformDatabaseCreationRepositoryFinder(opts);


            Console.WriteLine("Expecting Unit Test Catalogue To Be At Server=" + CatalogueRepository.DiscoveredServer.Name + " Database=" + CatalogueRepository.DiscoveredServer.GetCurrentDatabase());
            Assert.IsTrue(CatalogueRepository.DiscoveredServer.Exists(), "Catalogue database does not exist, run 'rdmp.exe install ...' to create it (Ensure that servername and prefix in TestDatabases.txt match those you provide to CreateDatabases.exe e.g. 'rdmp.exe install localhost\\sqlexpress TEST_')");
            Console.WriteLine("Found Catalogue");

            Console.WriteLine("Expecting Unit Test Data Export To Be At Server=" + DataExportRepository.DiscoveredServer.Name + " Database= " + DataExportRepository.DiscoveredServer.GetCurrentDatabase());
            Assert.IsTrue(DataExportRepository.DiscoveredServer.Exists(), "Data Export database does not exist, run 'rdmp.exe install ...' to create it (Ensure that servername and prefix in TestDatabases.txt match those you provide to CreateDatabases.exe e.g. 'rdmp.exe install localhost\\sqlexpress TEST_')");
            Console.WriteLine("Found DataExport");

            Console.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            RunBlitzDatabases(RepositoryLocator);

            var defaults = CatalogueRepository.GetServerDefaults();

            DataQualityEngineConnectionString = CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, PlatformDatabaseCreation.DefaultDQEDatabaseName, PermissableDefaults.DQE, new DataQualityEnginePatcher());
            UnitTestLoggingConnectionString   = CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, PlatformDatabaseCreation.DefaultLoggingDatabaseName, PermissableDefaults.LiveLoggingServer_ID, new LoggingDatabasePatcher());
            DiscoveredServerICanCreateRandomDatabasesAndTablesOn = new DiscoveredServer(CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, null, PermissableDefaults.RAWDataLoadServer, null));

            _discoveredSqlServer = new DiscoveredServer(TestDatabaseSettings.ServerName, null, DatabaseType.MicrosoftSQLServer, TestDatabaseSettings.Username, TestDatabaseSettings.Password);

            if (TestDatabaseSettings.MySql != null)
            {
                var builder = new MySqlConnectionStringBuilder(TestDatabaseSettings.MySql);

                foreach (string k in builder.Keys)
                {
                    if (k == "server" || k == "database" || k == "user id" || k == "password")
                    {
                        continue;
                    }

                    new ConnectionStringKeyword(CatalogueRepository, DatabaseType.MySql, k, builder[k].ToString());
                }
                _discoveredMySqlServer = new DiscoveredServer(builder);
            }

            if (TestDatabaseSettings.Oracle != null)
            {
                _discoveredOracleServer = new DiscoveredServer(TestDatabaseSettings.Oracle, DatabaseType.Oracle);
            }

            if (TestDatabaseSettings.PostgreSql != null)
            {
                _discoveredPostgresServer = new DiscoveredServer(TestDatabaseSettings.PostgreSql, DatabaseType.PostgreSql);
            }
        }
Exemple #19
0
 public void FinalTearDown()
 {
     //clear anostore default
     CatalogueRepository.GetServerDefaults().ClearDefault(PermissableDefaults.ANOStore);
     //delete the external server reference
     ANOStore_ExternalDatabaseServer.DeleteInDatabase();
 }
Exemple #20
0
        public void LoadProgress_Equals()
        {
            var loadMetadata = new LoadMetadata(CatalogueRepository);


            LoadProgress progress     = new LoadProgress(CatalogueRepository, loadMetadata);
            LoadProgress progressCopy = CatalogueRepository.GetObjectByID <LoadProgress>(progress.ID);

            progressCopy.Name       = "fish";
            progressCopy.OriginDate = new DateTime(2001, 01, 01);

            try
            {
                //values are different
                Assert.AreNotEqual(progressCopy.OriginDate, progress.OriginDate);
                Assert.AreNotEqual(progressCopy.Name, progress.Name);

                //IDs are the same
                Assert.AreEqual(progressCopy.ID, progress.ID);

                //therefore objects are the same
                Assert.IsTrue(progressCopy.Equals(progress));
            }
            finally
            {
                progress.DeleteInDatabase();
                loadMetadata.DeleteInDatabase();
            }
        }
        public void Test_ExampleDatasetsCreation()
        {
            //Should be empty RDMP metadata database
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <Catalogue>().Length);
            Assert.AreEqual(0, CatalogueRepository.GetAllObjects <AggregateConfiguration>().Length);

            //create the pipelines
            var pipes = new CataloguePipelinesAndReferencesCreation(RepositoryLocator, null, null);

            pipes.CreatePipelines();

            //create all the stuff
            var db      = GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer);
            var creator = new ExampleDatasetsCreation(new ThrowImmediatelyActivator(RepositoryLocator), RepositoryLocator);

            creator.Create(db, new ThrowImmediatelyCheckNotifier(), new PlatformDatabaseCreationOptions()
            {
                Seed = 500, DropDatabases = true
            });

            //should be at least 2 views (marked as view)
            var views = CatalogueRepository.GetAllObjects <TableInfo>().Count(ti => ti.IsView);

            Assert.GreaterOrEqual(views, 2);

            //should have at least created some catalogues, graphs etc
            Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects <Catalogue>().Length, 4);
            Assert.GreaterOrEqual(CatalogueRepository.GetAllObjects <AggregateConfiguration>().Length, 4);
        }
Exemple #22
0
        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();
        }
Exemple #23
0
        public IActionResult Get()
        {
            var repo = new CatalogueRepository();
            var c    = repo.GetAllCatalogues();

            return(Ok(c));
        }
        public void TestEncryptedPasswordHostArgumentType()
        {
            LoadMetadata        lmd = null;
            ProcessTaskArgument pta = null;

            try
            {
                pta = CreateNewProcessTaskArgumentInDatabase(out lmd);
                pta.SetType(typeof(EncryptedString));
                pta.SetValue(new EncryptedString(CatalogueRepository)
                {
                    Value = "test123"
                });
                pta.SaveToDatabase();

                var loadedPta = CatalogueRepository.GetObjectByID <ProcessTaskArgument>(pta.ID);
                var value     = loadedPta.GetValueAsSystemType() as EncryptedString;
                Assert.NotNull(value);
                Assert.AreEqual("test123", value.GetDecryptedValue());
            }
            finally
            {
                if (pta != null)
                {
                    var processTask = CatalogueRepository.GetObjectByID <ProcessTask>(pta.ProcessTask_ID);
                    processTask.DeleteInDatabase();
                }

                if (lmd != null)
                {
                    lmd.DeleteInDatabase();
                }
            }
        }
Exemple #25
0
        public IActionResult Filter(string n)
        {
            var repo = new CatalogueRepository();
            var c    = repo.GetCatalogueByName(n);

            return(Ok(c));
        }
Exemple #26
0
        public void GetAllTableInfos_moreThan1_pass()
        {
            var tableInfo = new TableInfo(CatalogueRepository, "AMAGAD!!!");

            Assert.IsTrue(CatalogueRepository.GetAllObjects <TableInfo>().Any());
            tableInfo.DeleteInDatabase();
        }
Exemple #27
0
        public void TestGettingConnectionStrings()
        {
            foreach (TableInfo tbl in CatalogueRepository.GetAllObjects <TableInfo>().Where(table => table.Name.ToLower().Equals("bob")))
            {
                tbl.DeleteInDatabase();
            }

            foreach (var c in CatalogueRepository.GetAllObjects <DataAccessCredentials>().Where(cred => cred.Name.ToLower().Equals("bob")))
            {
                c.DeleteInDatabase();
            }

            //test it with TableInfos
            TableInfo t = new TableInfo(CatalogueRepository, "Bob");

            try
            {
                t.Server   = "fish";
                t.Database = "bobsDatabase";
                t.SaveToDatabase();

                //t has no credentials
                var server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                Assert.AreEqual(true, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);

                var creds = new DataAccessCredentials(CatalogueRepository, "Bob");
                try
                {
                    t.SetCredentials(creds, DataAccessContext.InternalDataProcessing, true);
                    creds.Username = "******";
                    creds.Password = "******";
                    creds.SaveToDatabase();


                    ////t has some credentials now
                    server = DataAccessPortal.GetInstance().ExpectServer(t, DataAccessContext.InternalDataProcessing);

                    Assert.AreEqual(typeof(SqlConnectionStringBuilder), server.Builder.GetType());
                    Assert.AreEqual("fish", ((SqlConnectionStringBuilder)server.Builder).DataSource);
                    Assert.AreEqual("bobsDatabase", ((SqlConnectionStringBuilder)server.Builder).InitialCatalog);
                    Assert.AreEqual("frank", ((SqlConnectionStringBuilder)server.Builder).UserID);
                    Assert.AreEqual("bobsPassword", ((SqlConnectionStringBuilder)server.Builder).Password);
                    Assert.AreEqual(false, ((SqlConnectionStringBuilder)server.Builder).IntegratedSecurity);
                }
                finally
                {
                    var linker = new TableInfoCredentialsManager(CatalogueRepository);
                    linker.BreakAllLinksBetween(creds, t);
                    creds.DeleteInDatabase();
                }
            }
            finally
            {
                t.DeleteInDatabase();
            }
        }
Exemple #28
0
        public void CreateNewCredentialsThenGetByUsernamePasswordCombo()
        {
            var newCredentials = new DataAccessCredentials(CatalogueRepository, "bob");

            newCredentials.Username = "******";
            newCredentials.Password = "******";
            newCredentials.SaveToDatabase();

            var newCopy = CatalogueRepository.GetAllObjects <DataAccessCredentials>("WHERE Username='******'").SingleOrDefault();

            Assert.IsNotNull(newCopy);

            try
            {
                Assert.NotNull(newCopy);
                Assert.AreEqual(newCredentials.ID, newCopy.ID);
                Assert.AreEqual(newCredentials.Username, newCopy.Username);
                Assert.AreEqual(newCredentials.GetDecryptedPassword(), newCopy.GetDecryptedPassword());
                Assert.AreEqual(newCredentials.Password, newCopy.Password);
            }
            finally
            {
                newCredentials.DeleteInDatabase();
            }
        }
Exemple #29
0
        public void SetupLogging()
        {
            var lm = CatalogueRepository.GetDefaultLogManager();

            lm.CreateNewLoggingTaskIfNotExists("aaa");
            _dli = lm.CreateDataLoadInfo("aaa", "HowFastIsDLETest", "Test", "", true);
        }
Exemple #30
0
        private void SetupLowPrivilegeUserRightsFor(DiscoveredDatabase db, TestLowPrivilegePermissions permissions, ITableInfo ti)
        {
            var dbType = db.Server.DatabaseType;

            //get access to the database using the current credentials
            var username = TestDatabaseSettings.GetLowPrivilegeUsername(dbType);
            var password = TestDatabaseSettings.GetLowPrivilegePassword(dbType);

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                Assert.Inconclusive();
            }

            //give the user access to the table
            var sql = GrantAccessSql(username, dbType, permissions);

            using (var con = db.Server.GetConnection())
                UsefulStuff.ExecuteBatchNonQuery(sql, con);

            if (ti != null)
            {
                //remove any existing credentials
                foreach (DataAccessCredentials cred in CatalogueRepository.GetAllObjects <DataAccessCredentials>())
                {
                    CatalogueRepository.TableInfoCredentialsManager.BreakAllLinksBetween(cred, ti);
                }

                //set the new ones
                DataAccessCredentialsFactory credentialsFactory = new DataAccessCredentialsFactory(CatalogueRepository);
                credentialsFactory.Create(ti, username, password, DataAccessContext.Any);
            }
        }
Exemple #31
0
        public List<Catalogue> GetList(CatalogueFilter filter)
        {
            if (filter == null) throw new ArgumentNullException("filter");

            CatalogueRepository repository = new CatalogueRepository();

            if (filter.UserRole == RoleConstants.ADMINISTRATOR)
                return repository.Select();
            else
                return repository.Select(filter);
        }
Exemple #32
0
        public Catalogue GetByID(int catalogueID)
        {
            if (catalogueID == 0) throw new ArgumentNullException("catalogueID");

            CatalogueRepository repository = new CatalogueRepository();
            return repository.Select(catalogueID);
        }
Exemple #33
0
        public Catalogue Save(Catalogue catalogue)
        {
            if (catalogue == null)
                throw new ArgumentNullException("catalogue");

            if (String.IsNullOrEmpty(catalogue.Name))
                throw new ArgumentNullException("Neplatný parametr Name");

            CatalogueRepository repository = new CatalogueRepository();

            if (catalogue.CatalogueID == 0)
            {
                catalogue.Created = DateTime.Now;
                catalogue.Modified = catalogue.Created;
                catalogue = repository.Create(catalogue);
            }
            else
            {
                catalogue.Modified = DateTime.Now;
                catalogue = repository.Update(catalogue);
            }

            return catalogue;
        }
Exemple #34
0
        public int Export(int catalogueID, string userName, string computer)
        {
            //kontrola vstupnich parametru
            if (catalogueID == 0)
                throw new ArgumentNullException("Neplatný parametr identifikátor katalogu.");

            int result = 0;
            CatalogueRepository repository = new CatalogueRepository();

            //kontrola existence katalogu
            Catalogue catalogue = repository.Select(catalogueID);
            if (catalogue == null)
                throw new ApplicationException(String.Format("Katalog (ID={0}) neexistuje.", catalogueID));

            StreamWriter sw = null;

            try
            {
                BookFilter filter = new BookFilter();
                filter.CatalogueID = catalogue.CatalogueID;
                filter.Status = StatusCode.Complete;
                List<Book> books = BookComponent.Instance.GetList(filter);

                filter.UseOCR = false;
                filter.Status = StatusCode.Scanned;
                books.AddRange(BookComponent.Instance.GetList(filter));

                if (books != null && books.Count > 0)
                {
                    string logFilePath = Path.Combine(catalogue.GetDirectoryFTP(), "Export.log");

                    if (File.Exists(logFilePath))
                        throw new ApplicationException(String.Format("Soubor s exportom '{0}' již existuje.", logFilePath));

                    foreach (var book in books)
                    {
                        try
                        {
                            if (BookComponent.Instance.Export(book.BookID, userName, computer))
                            {
                                string publication = book.Title;
                                if (!String.IsNullOrEmpty(book.Author))
                                    publication = String.Format("{0}: {1}", book.Author, publication);
                                if (!String.IsNullOrEmpty(book.Year))
                                    publication = String.Format("{0}, {1}", publication, book.Year);

                                string volume = null;
                                string jpgFileName = null;
                                string pdfFileName = null;
                                string txtFileName = null;

                                if (book.FrontCover != null)
                                {
                                    jpgFileName = book.FrontCover.FileName;
                                }

                                if (book.TableOfContents != null)
                                {
                                    volume = String.Format("Obsah {0}", book.Volume).Trim();
                                    pdfFileName = book.TableOfContents.OcrFileName;

                                    if (book.TableOfContents.UseOCR)
                                    {
                                        txtFileName = book.TableOfContents.TxtFileName;
                                    }
                                }

                                string exportBook = String.Join(" | ", new string[] { book.SysNo, publication, volume, jpgFileName, pdfFileName, txtFileName });

                                if (sw == null)
                                    sw = new StreamWriter(logFilePath, false);
                                sw.WriteLine(exportBook);
                                sw.Flush();

                                result++;
                            }
                        }
                        catch
                        {
                            //zapis chyby do textoveho suboru Errors.log
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(String.Format("Nepodařilo se exportovat katalog (ID={0}) na FTP: {1}", catalogueID, ex.Message));
            }
            finally
            {
                if (sw != null)
                {
                    sw.Flush();
                    sw.Close();
                }
            }

            return result;
        }
Exemple #35
0
        public List<Catalogue> GetByInstitutionID(int institutionID, string sortExpression)
        {
            CatalogueFilter filter = new CatalogueFilter();
            filter.InstitutionID = institutionID;

            CatalogueRepository repository = new CatalogueRepository();
            return GetList(filter).OrderBy(sortExpression).ToList();
        }
Exemple #36
0
        //[Obsolete]
        //public int Export2(int catalogueID, DateTime expoted)
        //{
        //    //kontrola vstupnich parametru
        //    if (catalogueID == 0)
        //        throw new ArgumentNullException("Neplatný parametr identifikátor katalogu.");
        //    int result = 0;
        //    CatalogueRepository repository = new CatalogueRepository();
        //    //kontrola existence katalogu
        //    Catalogue catalogue = repository.Select(catalogueID);
        //    if (catalogue == null)
        //        throw new ApplicationException(String.Format("Katalog (ID={0}) neexistuje.", catalogueID));
        //    try
        //    {
        //        BookFilter filter = new BookFilter();
        //        filter.CatalogueID = catalogue.CatalogueID;
        //        filter.Modified.From = expoted;
        //        filter.Modified.To = expoted;
        //        filter.Status = StatusCode.Exported;
        //        List<Book> books = BookComponent.Instance.GetList(filter);
        //        if (books != null && books.Count > 0)
        //        {
        //            foreach (var book in books)
        //            {
        //                try
        //                {
        //                    if (book.BookID != 1)
        //                    {
        //                        //string ftpPath = Path.Combine(App.FTP_DIR, catalogue.DatabaseName, book.Modified.ToString("yyyyMMdd"));
        //                        string ftpPath = Path.Combine(App.FTP_DIR, catalogue.DatabaseName, DateTime.Now.ToString("yyyyMMdd"));
        //                        if (!Directory.Exists(ftpPath)) Directory.CreateDirectory(ftpPath);
        //                        string logFilePath = Path.Combine(ftpPath, "Export.log");
        //                        StreamWriter sw = new StreamWriter(logFilePath, true);
        //                        if (BookComponent.Instance.Export2(book.BookID, ftpPath))
        //                        {
        //                            string publication = book.Title;
        //                            if (!String.IsNullOrEmpty(book.Author))
        //                                publication = String.Format("{0}: {1}", book.Author, publication);
        //                            if (!String.IsNullOrEmpty(book.Year))
        //                                publication = String.Format("{0}, {1}", publication, book.Year);
        //                            string volume = null;
        //                            string jpgFileName = null;
        //                            string pdfFileName = null;
        //                            string txtFileName = null;
        //                            if (book.FrontCover != null)
        //                            {
        //                                jpgFileName = book.FrontCover.FileName;
        //                            }
        //                            if (book.TableOfContents != null)
        //                            {
        //                                volume = String.Format("Obsah {0}", book.Volume).Trim();
        //                                pdfFileName = book.TableOfContents.OcrFileName;
        //                                if (book.TableOfContents.UseOCR)
        //                                {
        //                                    txtFileName = book.TableOfContents.TxtFileName;
        //                                }
        //                            }
        //                            string exportBook = String.Join(" | ", new string[] { book.SysNo, publication, volume, jpgFileName, pdfFileName, txtFileName });
        //                            sw.WriteLine(exportBook);
        //                            sw.Flush();
        //                            sw.Close();
        //                            sw = null;
        //                            result++;
        //                        }
        //                    }
        //                }
        //                catch
        //                {
        //                    //zapis chyby do textoveho suboru Errors.log
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new ApplicationException(String.Format("Nepodařilo se exportovat katalog (ID={0}) na FTP: {1}", catalogueID, ex.Message));
        //    }
        //    return result;
        //}
        public bool Delete(int catalogueID)
        {
            CatalogueRepository repository = new CatalogueRepository();
            Catalogue catalogue = repository.Select(catalogueID);

            return repository.Delete(catalogue);
        }
Exemple #37
0
        public List<Catalogue> GetAll()
        {
            List<Catalogue> result = default(List<Catalogue>);

            try
            {
                CatalogueRepository repository = new CatalogueRepository();
                result = repository.Select();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw ex;
            }

            return result;
        }