Exemplo n.º 1
0
        public ActionResult CreateTestDatasets(int n)
        {
            DatasetManager           datasetManager           = new DatasetManager();
            DataStructureManager     dataStructureManager     = new DataStructureManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            ResearchPlanManager      researchPlanManager      = new ResearchPlanManager();


            try
            {
                var structure         = dataStructureManager.UnStructuredDataStructureRepo.Get(1);
                var metadatastructure = metadataStructureManager.Repo.Get(1);
                var researchplan      = researchPlanManager.Repo.Get(1);
                var xmlDatasetHelper  = new XmlDatasetHelper();

                var xmlMetadatWriter = new XmlMetadataWriter(XmlNodeMode.xPath);
                var metadataXml      = xmlMetadatWriter.CreateMetadataXml(metadatastructure.Id);

                for (int i = 0; i < n; i++)
                {
                    var dataset = datasetManager.CreateEmptyDataset(structure, researchplan, metadatastructure);


                    if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, "test") || datasetManager.CheckOutDataset(dataset.Id, "test"))
                    {
                        DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id);

                        datasetManager.EditDatasetVersion(workingCopy, null, null, null);
                        datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None);


                        workingCopy.Metadata = Xml.Helpers.XmlWriter.ToXmlDocument(metadataXml);

                        string xpath = xmlDatasetHelper.GetInformationPath(metadatastructure.Id, NameAttributeValues.title);

                        workingCopy.Metadata.SelectSingleNode(xpath).InnerText = i.ToString();
                        workingCopy.Title = i.ToString();

                        datasetManager.EditDatasetVersion(workingCopy, null, null, null);
                        datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datasetManager.Dispose();
                dataStructureManager.Dispose();
                metadataStructureManager.Dispose();
                researchPlanManager.Dispose();
            }


            return(View("Index"));
        }
Exemplo n.º 2
0
        public ResearchPlan CreateResearchPlan()
        {
            ResearchPlanManager researchPlanManager = new ResearchPlanManager();

            try
            {
                return(researchPlanManager.Create("ResearchPlan_UT", "Researchplan for unit tests."));
            }
            finally
            {
                researchPlanManager.Dispose();
            }
        }
Exemplo n.º 3
0
        public void PurgeAllResearchPlans()
        {
            var manager = new ResearchPlanManager();

            try
            {
                var plans = manager.Repo.Query().ToList();
                manager.Delete(plans);
            }
            finally
            {
                manager.Dispose();
            }
        }
Exemplo n.º 4
0
        public void CreateDatasetVersionTest()
        {
            long numberOfTuples = 1000;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                var dsHelper = new DatasetHelper();
                StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                //dm.SyncView(ds.Id, ViewCreationBehavior.Create);
                //dm.SyncView(ds.Id, ViewCreationBehavior.Refresh);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);

                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Exemplo n.º 5
0
        private static void createResearchPlan()
        {
            //ResearchPlan
            ResearchPlanManager rpm = null;

            try
            {
                rpm = new ResearchPlanManager();
                ResearchPlan researchPlan = rpm.Repo.Get(r => r.Title.Equals("Research plan")).FirstOrDefault();
                if (researchPlan == null)
                {
                    rpm.Create("Research plan", "");
                }
            }
            finally
            {
                rpm.Dispose();
            }
        }
Exemplo n.º 6
0
        public void DeleteDatasetTest()
        {
            var dm  = new DatasetManager();
            var rsm = new ResearchPlanManager();
            var mdm = new MetadataStructureManager();

            try
            {
                var dsHelper = new DatasetHelper();
                StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dm.DeleteDataset(dataset.Id, "Javad", false);

                dataset.Should().NotBeNull();
                dataset.Id.Should().BeGreaterThan(0, "Dataset is not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.Deleted, "Dataset must be in Deleted status.");

                dm.PurgeDataset(dataset.Id);
                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Exemplo n.º 7
0
        public void ProjectExpressionTest()
        {
            var dsHelper = new DatasetHelper();
            StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();

            dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

            string var1Name = "var" + dataStructure.Variables.First().Id;
            string var3Name = "var" + dataStructure.Variables.Skip(2).First().Id;

            //create prjection expression
            ProjectionExpression projectionExpression = new ProjectionExpression();

            projectionExpression.Items.Add(new ProjectionItemExpression()
            {
                FieldName = var1Name
            });
            projectionExpression.Items.Add(new ProjectionItemExpression()
            {
                FieldName = var3Name
            });

            // create a dataset and test the filter, sorting, and projectgion
            long numberOfTuples = 10;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                // pass this filter to get a subset of dataset X
                var dst = dm.GetLatestDatasetVersionTuples(dataset.Id, null, null, projectionExpression, 1, 3);
                dst.Should().NotBeNull();
                dst.Rows.Count.Should().BeLessOrEqualTo(3);
                dst.Columns.Count.Should().BeLessOrEqualTo(3, "Projection failed, wrong number of columns");

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);
                dsHelper.PurgeAllDataStructures();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Exemplo n.º 8
0
        public void CreateAndExpressionForQueryingTest()
        {
            var dsHelper = new DatasetHelper();
            StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();

            dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

            string var1Name = "var" + dataStructure.Variables.First().Id;
            string var2Name = "var" + dataStructure.Variables.Skip(1).First().Id;

            FilterExpression fex = BinaryFilterExpression
                                   .And(
                new FilterNumberItemExpression()
            {
                Field = new Field()
                {
                    DataType = Utils.NH.Querying.DataType.Ineteger, Name = var1Name
                }
                ,
                Operator = NumberOperator.Operation.GreaterThan
                ,
                Value = 12
            }
                ,
                new FilterStringItemExpression()
            {
                Field = new Field()
                {
                    DataType = Utils.NH.Querying.DataType.String, Name = var2Name
                }
                ,
                Operator = StringOperator.Operation.EndsWith
                ,
                Value = "Test"
            }
                );

            fex.ToSQL().Should().Be($"(({var1Name}) > (12)) AND (({var2Name}) ILIKE ('%Test'))");

            // this is to show how to apply a NOT operator on any other expression.
            // It can be applied on Numeric, String, Date, and any other type of expression
            FilterExpression notFex = UnaryFilterExpression.Not(fex);

            notFex.ToSQL().Should().Be($"NOT ((({var1Name}) > (12)) AND (({var2Name}) ILIKE ('%Test')))");
            notFex.ToSQL().Should().Be($"NOT ({fex.ToSQL()})");

            OrderByExpression orderByExpr = new OrderByExpression(
                new List <OrderItemExpression>()
            {
                new OrderItemExpression(var1Name),
                new OrderItemExpression(var2Name, SortDirection.Descending)
            });

            orderByExpr.ToSQL().Should().Be($"{var1Name} ASC, {var2Name} DESC");

            // create a dataset and test the filter, sorting, and projectgion
            long numberOfTuples = 100;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                // pass this filter to get a subset of dataset X
                var dst = dm.GetLatestDatasetVersionTuples(dataset.Id, fex, null, null, 1, 10);
                dst.Should().NotBeNull();
                dst.Rows.Count.Should().BeLessOrEqualTo(10);

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);

                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Exemplo n.º 9
0
        public void GenerateSeedData()
        {
            ResearchPlanManager      researchPlanManager      = new ResearchPlanManager();
            DataStructureManager     dataStructureManager     = new DataStructureManager();
            UnitManager              unitManager              = new UnitManager();
            EntityManager            entityManager            = new EntityManager();
            FeatureManager           featureManager           = new FeatureManager();
            OperationManager         operationManager         = new OperationManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                #region create none researchPlan

                if (!researchPlanManager.Repo.Get().Any(r => r.Title.Equals("none")))
                {
                    researchPlanManager.Create("none", "If no research plan is used.");
                }

                #endregion create none researchPlan

                #region create none structure

                if (!dataStructureManager.AllTypesDataStructureRepo.Get().Any(d => d.Name.Equals("none")))
                {
                    dataStructureManager.CreateUnStructuredDataStructure("none", "If no data strutcure is used.");
                }

                #endregion create none structure

                #region create none unit

                Dimension dimension = null;

                if (!unitManager.DimensionRepo.Get().Any(d => d.Name.ToLower().Equals("none")))
                {
                    dimension = unitManager.Create("none", "none", "If no unit is used."); // the null dimension should be replaced bz a proper valid one. Javad 11.06
                }
                else
                {
                    dimension = unitManager.DimensionRepo.Get().Where(d => d.Name.ToLower().Equals("none")).FirstOrDefault();
                }

                if (!unitManager.Repo.Get().Any(u => u.Name.ToLower().Equals("none")))
                {
                    unitManager.Create("none", "none", "If no unit is used.", dimension, MeasurementSystem.Unknown);
                }

                #endregion create none unit

                #region create entities

                // Entities
                Entity entity = entityManager.Entities.Where(e => e.Name.ToUpperInvariant() == "Dataset".ToUpperInvariant()).FirstOrDefault();

                if (entity == null)
                {
                    entity                 = new Entity();
                    entity.Name            = "Dataset";
                    entity.EntityType      = typeof(Dataset);
                    entity.EntityStoreType = typeof(Xml.Helpers.DatasetStore);
                    entity.UseMetadata     = true;
                    entity.Securable       = true;

                    //add to Extra

                    XmlDocument      xmlDoc           = new XmlDocument();
                    XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
                    xmlDatasetHelper.AddReferenceToXml(xmlDoc, AttributeNames.name.ToString(), "ddm", AttributeType.parameter.ToString(), "extra/modules/module");

                    entity.Extra = xmlDoc;

                    entityManager.Create(entity);
                }
                else
                {
                    XmlDocument xmlDoc = new XmlDocument();

                    if (entity.Extra != null)
                    {
                        xmlDoc.AppendChild(entity.Extra);
                    }

                    //update to Extra
                    XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();
                    xmlDatasetHelper.AddReferenceToXml(xmlDoc, AttributeNames.name.ToString(), "ddm", AttributeType.parameter.ToString(), "extra/modules/module");

                    entity.Extra = xmlDoc;

                    entityManager.Update(entity);
                }

                #endregion create entities

                #region SECURITY

                //workflows = größere sachen, vielen operation
                //operations = einzelne actions

                //1.controller-> 1.Operation

                Feature DataCollectionFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Data Collection"));
                if (DataCollectionFeature == null)
                {
                    DataCollectionFeature = featureManager.Create("Data Collection", "Data Collection");
                }

                Feature DatasetCreationFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Data Creation"));
                if (DatasetCreationFeature == null)
                {
                    DatasetCreationFeature = featureManager.Create("Data Creation", "Data Creation", DataCollectionFeature);
                }

                Feature DatasetUploadFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Dataset Upload"));
                if (DatasetUploadFeature == null)
                {
                    DatasetUploadFeature = featureManager.Create("Dataset Upload", "Dataset Upload", DataCollectionFeature);
                }

                Feature ImportDataFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Import Data"));
                if (ImportDataFeature == null)
                {
                    ImportDataFeature = featureManager.Create("Import Data", "Easy way to load data into bexis", DataCollectionFeature);
                }

                Feature MetadataManagementFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Metadata Management"));
                if (MetadataManagementFeature == null)
                {
                    MetadataManagementFeature = featureManager.Create("Metadata Management", "Metadata Management", DataCollectionFeature);
                }

                #region Help Workflow

                operationManager.Create("DCM", "Help", "*");

                #endregion Help Workflow

                #region Create Dataset Workflow

                operationManager.Create("DCM", "CreateDataset", "*", DatasetCreationFeature);
                operationManager.Create("DCM", "Form", "*");
                operationManager.Create("Api", "DatasetIn", "*", DatasetCreationFeature);
                operationManager.Create("Api", "Dataset", "*", DatasetCreationFeature);
                operationManager.Create("Api", "MetadataIn", "*", DatasetCreationFeature);
                operationManager.Create("Api", "Metadata", "*", DatasetCreationFeature);

                #endregion Create Dataset Workflow

                #region Update Dataset Workflow

                operationManager.Create("DCM", "Submit", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitChooseUpdateMethod", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitGetFileInformation", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSelectAFile", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSpecifyDataset", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSummary", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitValidation", "*", DatasetUploadFeature);

                //Load files to server
                operationManager.Create("DCM", "Push", "*", DatasetUploadFeature);

                operationManager.Create("Api", "DataIn", "*", DatasetUploadFeature);
                operationManager.Create("Api", "Data", "*", DatasetUploadFeature);
                operationManager.Create("Api", "AttachmentIn", "*", DatasetUploadFeature);
                operationManager.Create("Api", "Attachment", "*", DatasetUploadFeature);

                #endregion Update Dataset Workflow

                #region Easy Upload

                operationManager.Create("DCM", "EasyUpload", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadSelectAFile", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadSelectAreas", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadSheetDataStructure", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadSheetSelectMetaData", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadSummary", "*", ImportDataFeature);
                operationManager.Create("DCM", "EasyUploadVerification", "*", ImportDataFeature);

                #endregion Easy Upload

                #region Metadata Managment Workflow

                operationManager.Create("DCM", "ImportMetadataStructure", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureReadSource", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSelectAFile", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSetParameters", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSummary", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ManageMetadataStructure", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "SubmitSpecifyDataset", "*", MetadataManagementFeature);

                #endregion Metadata Managment Workflow

                #region public available

                //because of reuse in ddm this controller must be public
                // but the funktions should be secured
                operationManager.Create("DCM", "Form", "*");
                operationManager.Create("DCM", "EntityReference", "*");
                //Attachments
                operationManager.Create("DCM", "Attachments", "*");

                #endregion public available

                #endregion SECURITY

                #region Add Metadata


                if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Basic ABCD")))
                {
                    string titleXPath =
                        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Title/TitleType";
                    string descriptionXpath =
                        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Details/DetailsType";

                    ImportSchema("Basic ABCD", "ABCD_2.06.XSD", "DataSet", entity.Name, entity.EntityType.FullName,
                                 titleXPath, descriptionXpath);
                }

                //if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Full ABCD")))
                //{
                //    string titleXPath =
                //        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Title/TitleType";
                //    string descriptionXpath =
                //        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Details/DetailsType";

                //    ImportSchema("Full ABCD", "ABCD_2.06.XSD", "DataSet", entity.Name, entity.EntityType.FullName,
                //        titleXPath, descriptionXpath);

                //}

                if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("GBIF")))
                {
                    string titleXPath       = "Metadata/Basic/BasicType/title/titleType";
                    string descriptionXpath = "Metadata/abstract/abstractType/para/paraType";

                    ImportSchema("GBIF", "eml.xsd", "Dataset", entity.Name, entity.EntityType.FullName, titleXPath,
                                 descriptionXpath);
                }
                //if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Basic Eml")))
                //    ImportSchema("Basic Eml", "eml-dataset.xsd", entity.Name, entity.Name, entity.EntityType.FullName);

                #endregion Add Metadata
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                researchPlanManager.Dispose();
                dataStructureManager.Dispose();
                unitManager.Dispose();
                entityManager.Dispose();
                featureManager.Dispose();
                operationManager.Dispose();
                metadataStructureManager.Dispose();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Submit a Dataset based on the imformations
        /// in the CreateTaskManager
        /// </summary>
        public long SubmitDataset(bool valid)
        {
            #region create dataset
            DatasetManager       dm  = new DatasetManager();
            DataStructureManager dsm = new DataStructureManager();
            ResearchPlanManager  rpm = new ResearchPlanManager();
            XmlDatasetHelper     xmlDatasetHelper = new XmlDatasetHelper();
            string title      = "";
            long   datasetId  = 0;
            bool   newDataset = true;

            try
            {
                TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

                if (TaskManager.Bus.ContainsKey(CreateTaskmanager.DATASTRUCTURE_ID) &&
                    TaskManager.Bus.ContainsKey(CreateTaskmanager.RESEARCHPLAN_ID) &&
                    TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID))
                {
                    // for e new dataset
                    if (!TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID))
                    {
                        long datastructureId     = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.DATASTRUCTURE_ID]);
                        long researchPlanId      = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.RESEARCHPLAN_ID]);
                        long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);

                        DataStructure dataStructure = dsm.StructuredDataStructureRepo.Get(datastructureId);
                        //if datastructure is not a structured one
                        if (dataStructure == null)
                        {
                            dataStructure = dsm.UnStructuredDataStructureRepo.Get(datastructureId);
                        }

                        ResearchPlan rp = rpm.Repo.Get(researchPlanId);

                        MetadataStructureManager msm = new MetadataStructureManager();
                        MetadataStructure        metadataStructure = msm.Repo.Get(metadataStructureId);

                        var ds = dm.CreateEmptyDataset(dataStructure, rp, metadataStructure);
                        datasetId = ds.Id;

                        // add security
                        if (GetUsernameOrDefault() != "DEFAULT")
                        {
                            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
                            entityPermissionManager.Create <User>(GetUsernameOrDefault(), "Dataset", typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast <RightType>().ToList());
                        }
                    }
                    else
                    {
                        datasetId  = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]);
                        newDataset = false;
                    }

                    TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"];

                    if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                    {
                        DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(datasetId);

                        if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML))
                        {
                            XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML];
                            workingCopy.Metadata = Xml.Helpers.XmlWriter.ToXmlDocument(xMetadata);
                        }

                        //set status

                        if (workingCopy.StateInfo == null)
                        {
                            workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo();
                        }

                        if (valid)
                        {
                            workingCopy.StateInfo.State = DatasetStateInfo.Valid.ToString();
                        }
                        else
                        {
                            workingCopy.StateInfo.State = DatasetStateInfo.NotValid.ToString();
                        }

                        title = xmlDatasetHelper.GetInformationFromVersion(workingCopy.Id, NameAttributeValues.title);
                        if (string.IsNullOrEmpty(title))
                        {
                            title = "No Title available.";
                        }

                        TaskManager.AddToBus(CreateTaskmanager.ENTITY_TITLE, title);//workingCopy.Metadata.SelectNodes("Metadata/Description/Description/Title/Title")[0].InnerText);
                        TaskManager.AddToBus(CreateTaskmanager.ENTITY_ID, datasetId);

                        dm.EditDatasetVersion(workingCopy, null, null, null);
                        dm.CheckInDataset(datasetId, "Metadata was submited.", GetUsernameOrDefault(), ViewCreationBehavior.None);

                        //add to index
                        // ToDo check which SearchProvider it is, default luceneprovider

                        // BUG: invalid call to ddm method
                        // TODO: mODULARITY ->Call DDM Reindex

                        /*
                         * <Export tag="internalApi" id="SearchIndex"
                         * title="Reindex Search" description="Reindex Search" icon=""
                         * controller="SearchIndex" action="Get"
                         * extends="" />
                         */
                        // WORKAROUND: do not reindex
                        //ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider;
                        //provider?.UpdateSingleDatasetIndex(datasetId, IndexingAction.CREATE);

                        if (this.IsAccessibale("DDM", "SearchIndex", "ReIndexSingle"))
                        {
                            var x = this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                            {
                                { "id", datasetId }
                            });
                        }

                        LoggerFactory.LogData(datasetId.ToString(), typeof(Dataset).Name, Vaiona.Entities.Logging.CrudState.Created);


                        if (newDataset)
                        {
                            var es = new EmailService();
                            es.Send(MessageHelper.GetCreateDatasetHeader(),
                                    MessageHelper.GetCreateDatasetMessage(datasetId, title, GetUsernameOrDefault()),
                                    ConfigurationManager.AppSettings["SystemEmail"]
                                    );
                        }
                        else
                        {
                            var es = new EmailService();
                            es.Send(MessageHelper.GetUpdateDatasetHeader(),
                                    MessageHelper.GetUpdateDatasetMessage(datasetId, title, GetUsernameOrDefault()),
                                    ConfigurationManager.AppSettings["SystemEmail"]
                                    );
                        }
                    }


                    return(datasetId);
                }
            }
            catch (Exception ex)
            {
                var es = new EmailService();
                es.Send(MessageHelper.GetUpdateDatasetHeader(),
                        ex.Message,
                        ConfigurationManager.AppSettings["SystemEmail"]
                        );
            }
            finally
            {
                dm.Dispose();
                rpm.Dispose();
                dsm.Dispose();
            }


            #endregion create dataset

            return(-1);
        }
Exemplo n.º 11
0
        public void GenerateSeedData()
        {
            ResearchPlanManager  researchPlanManager  = new ResearchPlanManager();
            DataStructureManager dataStructureManager = new DataStructureManager();
            UnitManager          unitManager          = new UnitManager();
            EntityManager        entityManager        = new EntityManager();
            FeatureManager       featureManager       = new FeatureManager();
            OperationManager     operationManager     = new OperationManager();

            try
            {
                #region create none researchPlan

                if (!researchPlanManager.Repo.Get().Any(r => r.Title.Equals("none")))
                {
                    researchPlanManager.Create("none", "If no research plan is used.");
                }



                #endregion

                #region create none structure


                if (!dataStructureManager.AllTypesDataStructureRepo.Get().Any(d => d.Name.Equals("none")))
                {
                    dataStructureManager.CreateUnStructuredDataStructure("none", "If no data strutcure is used.");
                }



                #endregion

                #region create none unit

                Dimension dimension = null;

                if (!unitManager.DimensionRepo.Get().Any(d => d.Name.ToLower().Equals("none")))
                {
                    dimension = unitManager.Create("none", "none", "If no unit is used."); // the null dimension should be replaced bz a proper valid one. Javad 11.06
                }
                else
                {
                    dimension = unitManager.DimensionRepo.Get().Where(d => d.Name.ToLower().Equals("none")).FirstOrDefault();
                }

                if (!unitManager.Repo.Get().Any(u => u.Name.ToLower().Equals("none")))
                {
                    unitManager.Create("none", "none", "If no unit is used.", dimension, MeasurementSystem.Unknown);
                }

                #endregion

                #region create entities

                // Entities
                Entity entity = entityManager.Entities.Where(e => e.Name.ToUpperInvariant() == "Dataset".ToUpperInvariant()).FirstOrDefault();

                if (entity == null)
                {
                    entity                 = new Entity();
                    entity.Name            = "Dataset";
                    entity.EntityType      = typeof(Dataset);
                    entity.EntityStoreType = typeof(Xml.Helpers.DatasetStore);
                    entity.UseMetadata     = true;
                    entity.Securable       = true;

                    entityManager.Create(entity);
                }



                #endregion

                #region SECURITY
                //workflows = größere sachen, vielen operation
                //operations = einzelne actions

                //1.controller-> 1.Operation



                Feature DataCollectionFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Data Collection"));
                if (DataCollectionFeature == null)
                {
                    DataCollectionFeature = featureManager.Create("Data Collection", "Data Collection");
                }

                Feature DatasetCreationFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Data Creation"));
                if (DatasetCreationFeature == null)
                {
                    DatasetCreationFeature = featureManager.Create("Data Creation", "Data Creation", DataCollectionFeature);
                }

                Feature DatasetUploadFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Dataset Upload"));
                if (DatasetUploadFeature == null)
                {
                    DatasetUploadFeature = featureManager.Create("Dataset Upload", "Dataset Upload", DataCollectionFeature);
                }

                Feature MetadataManagementFeature = featureManager.FeatureRepository.Get().FirstOrDefault(f => f.Name.Equals("Metadata Management"));
                if (MetadataManagementFeature == null)
                {
                    MetadataManagementFeature = featureManager.Create("Metadata Management", "Metadata Management", DataCollectionFeature);
                }


                #region Help Workflow

                operationManager.Create("DCM", "Help", "*");

                #endregion

                #region Create Dataset Workflow

                operationManager.Create("DCM", "CreateDataset", "*", DatasetCreationFeature);
                operationManager.Create("DCM", "Form", "*");

                #endregion

                #region Update Dataset Workflow

                operationManager.Create("DCM", "Push", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "Submit", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitDefinePrimaryKey", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitGetFileInformation", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSelectAFile", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSpecifyDataset", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitSummary", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "SubmitValidation", "*", DatasetUploadFeature);

                #endregion

                #region Easy Upload

                operationManager.Create("DCM", "EasyUpload", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadSelectAFile", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadSelectAreas", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadSheetDataStructure", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadSheetSelectMetaData", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadSummary", "*", DatasetUploadFeature);
                operationManager.Create("DCM", "EasyUploadVerification", "*", DatasetUploadFeature);

                #endregion

                #region Metadata Managment Workflow

                operationManager.Create("DCM", "ImportMetadataStructure", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureReadSource", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSelectAFile", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSetParameters", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ImportMetadataStructureSummary", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "ManageMetadataStructure", "*", MetadataManagementFeature);
                operationManager.Create("DCM", "SubmitSpecifyDataset", "*", MetadataManagementFeature);

                #endregion

                #region public available

                operationManager.Create("DCM", "Form", "*");

                #endregion

                #endregion

                #region Add Metadata
                MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

                if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Basic ABCD")))
                {
                    string titleXPath =
                        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Title/TitleType";
                    string descriptionXpath =
                        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Details/DetailsType";


                    ImportSchema("Basic ABCD", "ABCD_2.06.XSD", "DataSet", entity.Name, entity.EntityType.FullName,
                                 titleXPath, descriptionXpath);
                }

                //if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Full ABCD")))
                //{
                //    string titleXPath =
                //        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Title/TitleType";
                //    string descriptionXpath =
                //        "Metadata/Metadata/MetadataType/Description/DescriptionType/Representation/MetadataDescriptionRepr/Details/DetailsType";


                //    ImportSchema("Full ABCD", "ABCD_2.06.XSD", "DataSet", entity.Name, entity.EntityType.FullName,
                //        titleXPath, descriptionXpath);

                //}

                if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("GBIF")))
                {
                    string titleXPath       = "Metadata/Basic/BasicType/title/titleType";
                    string descriptionXpath = "Metadata/abstract/abstractType/para/paraType";

                    ImportSchema("GBIF", "eml.xsd", "Dataset", entity.Name, entity.EntityType.FullName, titleXPath,
                                 descriptionXpath);
                }
                //if (!metadataStructureManager.Repo.Get().Any(m => m.Name.Equals("Basic Eml")))
                //    ImportSchema("Basic Eml", "eml-dataset.xsd", entity.Name, entity.Name, entity.EntityType.FullName);
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                researchPlanManager.Dispose();
                dataStructureManager.Dispose();
                unitManager.Dispose();
                entityManager.Dispose();
                featureManager.Dispose();
                operationManager.Dispose();
            }
        }