Esempio n. 1
0
        public static List <LinkElementRootListItem> LoadSelectionList()
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                List <LinkElementRootListItem> tmp = new List <LinkElementRootListItem>();

                //load System
                LinkElementRootListItem li = new LinkElementRootListItem(0, "System", LinkElementType.System);

                tmp.Add(li);

                //load Metadata Strutcure
                IEnumerable <MetadataStructure> metadataStructures = metadataStructureManager.Repo.Get();

                foreach (var metadataStructure in metadataStructures)
                {
                    li = new LinkElementRootListItem(
                        metadataStructure.Id,
                        metadataStructure.Name,
                        LinkElementType.MetadataStructure
                        );

                    tmp.Add(li);
                }

                return(tmp);
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 2
0
        public ActionResult DownloadSchema(long id)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);
                string            name = metadataStructure.Name;

                string path = OutputMetadataManager.GetSchemaDirectoryPathFromMetadataStructure(id, metadataStructureManager);

                ZipFile zip = new ZipFile();
                if (Directory.Exists(path))
                {
                    zip.AddDirectory(path);
                }

                MemoryStream stream = new MemoryStream();
                zip.Save(stream);
                stream.Position = 0;
                var result = new FileStreamResult(stream, "application/zip")
                {
                    FileDownloadName = name + ".zip"
                };

                return(result);
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 3
0
        private MetadataStructureManagerModel GetDefaultModel()
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                MetadataStructureManagerModel tmp = new MetadataStructureManagerModel();

                //load all metadatastructure
                IEnumerable <MetadataStructure> metadataStructures = metadataStructureManager.Repo.Get();

                foreach (var metadataStructure in metadataStructures)
                {
                    tmp.MetadataStructureModels.Add(convertToMetadataStructureModel(metadataStructure, metadataStructureManager));
                }

                if (tmp.MetadataStructureModels.Any())
                {
                    tmp.MetadataStructureModels = tmp.MetadataStructureModels.OrderBy(m => m.Id).ToList();
                }

                return(tmp);
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 4
0
        public ActionResult Delete(long id)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();


            try
            {
                MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);
                // delete local files
                if (XmlSchemaManager.Delete(metadataStructure))
                {
                    metadataStructureManager.Delete(metadataStructure);
                }

                if (metadataStructureManager.Repo.Get(id) == null)
                {
                    return(Json(true));
                }

                return(Json(false));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 5
0
        public List <ListViewItem> LoadMetadataStructureViewList()
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                IEnumerable <MetadataStructure> metadataStructureList = metadataStructureManager.Repo.Get();

                List <ListViewItem> temp = new List <ListViewItem>();

                foreach (MetadataStructure metadataStructure in metadataStructureList)
                {
                    if (xmlDatasetHelper.IsActive(metadataStructure.Id) &&
                        xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset"))
                    {
                        string title = metadataStructure.Name;

                        temp.Add(new ListViewItem(metadataStructure.Id, title, metadataStructure.Description));
                    }
                }

                return(temp.OrderBy(p => p.Title).ToList());
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 6
0
        public ActionResult Save(MetadataStructureModel metadataStructureModel)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                if (ModelState.IsValid)
                {
                    MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(metadataStructureModel.Id);
                    metadataStructure = updateMetadataStructure(metadataStructure, metadataStructureModel);
                    metadataStructureManager.Update(metadataStructure);


                    return(Json(true));
                }

                return(Json(false));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 7
0
        public List <ListItem> GetMetadataStructureList()
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            XmlDatasetHelper         xmlDatasetHelper         = new XmlDatasetHelper();

            try
            {
                IEnumerable <MetadataStructure> metadataStructureList = metadataStructureManager.Repo.Get();

                List <ListItem> temp = new List <ListItem>();

                foreach (MetadataStructure metadataStructure in metadataStructureList)
                {
                    if (xmlDatasetHelper.IsActive(metadataStructure.Id) &&
                        xmlDatasetHelper.HasEntityType(metadataStructure.Id, "BExIS.Emm.Entities.Event.Event"))
                    {
                        string title = metadataStructure.Name;

                        temp.Add(new ListItem(metadataStructure.Id, title));
                    }
                }

                return(temp.OrderBy(p => p.Name).ToList());
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 8
0
        public ActionResult SheetSelectMetaData(int index)
        {
            MetadataStructureManager msm = new MetadataStructureManager();

            try
            {
                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

                //set current stepinfo based on index
                if (TaskManager != null)
                {
                    TaskManager.SetCurrent(index);

                    // remove if existing
                    TaskManager.RemoveExecutedStep(TaskManager.Current());
                }

                SelectMetaDataModel model = new SelectMetaDataModel();

                //Load available metadata structures
                IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get();

                foreach (MetadataStructure metadataStructure in metadataStructureList)
                {
                    if (xmlDatasetHelper.IsActive(metadataStructure.Id) &&
                        xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset"))
                    {
                        model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name));
                    }
                }
                //Sort the metadata structures
                model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1));

                //If there's already a selected Metadata schema, load its id into the model
                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                {
                    model.SelectedMetaDataId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                }

                //if the title was changed at some point during the upload, load the title into the model
                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                {
                    model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                }
                //if it wasn't changed yet, the default title is the filename
                else
                {
                    model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);
                }

                model.StepInfo = TaskManager.Current();

                return(PartialView(model));
            }
            finally
            {
                msm.Dispose();
            }
        }
        public ActionResult Save(MetadataStructureModel metadataStructureModel)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            DatasetManager           datasetManager           = new DatasetManager();

            try
            {
                if (ModelState.IsValid)
                {
                    MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(metadataStructureModel.Id);

                    metadataStructure = updateMetadataStructure(metadataStructure, metadataStructureModel);
                    metadataStructureManager.Update(metadataStructure);

                    //update dsv title and description if there is a change
                    //ToDo check if there is a change in the xpaths
                    // update datasetversion

                    // get all datasetIds which using the metadata structure
                    var datasetIds = datasetManager.DatasetRepo.Query().Where(d => d.MetadataStructure.Id.Equals(metadataStructure.Id)).Select(d => d.Id);

                    if (datasetIds.Any())
                    {
                        //get all datasetversions of the dataset ids
                        var datasetVersionIds = datasetManager.DatasetVersionRepo.Query().Where(dsv => datasetIds.Contains(dsv.Dataset.Id)).Select(dsv => dsv.Id).ToList();

                        //load all titles & descriptions from versions
                        var allTitles       = xmlDatasetHelper.GetInformationFromVersions(datasetVersionIds, metadataStructure.Id, NameAttributeValues.title);
                        var allDescriptions = xmlDatasetHelper.GetInformationFromVersions(datasetVersionIds, metadataStructure.Id, NameAttributeValues.description);


                        // update each datasetversion
                        foreach (var datasetVersionId in datasetVersionIds)
                        {
                            // load dataset version
                            var datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId);

                            datasetVersion.Title       = allTitles.ContainsKey(datasetVersion.Id) ? allTitles[datasetVersion.Id] : string.Empty;
                            datasetVersion.Description = allDescriptions.ContainsKey(datasetVersion.Id) ? allDescriptions[datasetVersion.Id] : string.Empty;

                            datasetManager.UpdateDatasetVersion(datasetVersion);
                        }
                    }

                    return(Json(true));
                }

                return(Json(false));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            finally
            {
                metadataStructureManager.Dispose();
                datasetManager.Dispose();
            }
        }
Esempio n. 10
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"));
        }
Esempio n. 11
0
        public static string CreateConvertedMetadata(long datasetId, TransmissionType type)
        {
            XmlDocument              newXml;
            DatasetManager           datasetManager = new DatasetManager();
            MetadataStructureManager metadataMetadataStructureManager = new MetadataStructureManager();

            try
            {
                DatasetVersion    datasetVersion    = datasetManager.GetDatasetLatestVersion(datasetId);
                MetadataStructure metadataStructure = metadataMetadataStructureManager.Repo.Get(datasetVersion.Dataset.MetadataStructure.Id);
                XmlDatasetHelper  xmlDatasetHelper  = new XmlDatasetHelper();

                int    versionNr   = datasetManager.GetDatasetVersionNr(datasetVersion);
                string mappingName = metadataStructure.Name;

                string mappingFileName = xmlDatasetHelper.GetTransmissionInformation(datasetVersion.Id, type, mappingName);
                //if mapping file not exist
                if (string.IsNullOrEmpty(mappingFileName))
                {
                    return("");
                }
                string pathMappingFile = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), mappingFileName);

                XmlMapperManager xmlMapperManager = new XmlMapperManager(TransactionDirection.InternToExtern);
                xmlMapperManager.Load(pathMappingFile, "exporttest");

                newXml = xmlMapperManager.Export(datasetVersion.Metadata, datasetVersion.Id, mappingName, true);

                string title = datasetVersion.Title;

                // store in content descriptor
                string filename = "metadata";
                if (String.IsNullOrEmpty(mappingName) || mappingName.ToLower() == "generic")
                {
                    storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, filename, ".xml");
                }
                else
                {
                    filename = "metadata_" + mappingName;
                    storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, filename,
                                                              ".xml");
                }

                return(OutputDatasetManager.GetDynamicDatasetStorePath(datasetId, versionNr, filename, ".xml"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datasetManager.Dispose();
                metadataMetadataStructureManager.Dispose();
            }
        }
Esempio n. 12
0
        public string Convert(long datasetVersionId)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            DatasetManager           datasetManager           = new DatasetManager();


            SubmissionManager  submissionManager  = new SubmissionManager();
            PublicationManager publicationManager = new PublicationManager();


            try
            {
                DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId);

                _broker   = publicationManager.GetBroker(_broker.Id);
                _dataRepo = publicationManager.GetRepository(_dataRepo.Id);


                long   datasetId = datasetVersion.Dataset.Id;
                string name      = datasetManager.GetDatasetVersion(datasetVersionId).Dataset.MetadataStructure.Name;

                XmlDocument metadata = OutputMetadataManager.GetConvertedMetadata(datasetId,
                                                                                  TransmissionType.mappingFileExport, name, false);

                // create links to the api calls of the primary data?



                //add all to a zip


                //save document  and return filepath for download


                string path     = submissionManager.GetDirectoryPath(datasetId, _broker.Name);
                string filename = submissionManager.GetFileNameForDataRepo(datasetId, datasetVersionId, _dataRepo.Name, "xml");

                string filepath = Path.Combine(path, filename);

                FileHelper.CreateDicrectoriesIfNotExist(path);

                metadata.Save(filepath);


                return(filepath);
            }
            finally
            {
                datasetManager.Dispose();
                metadataStructureManager.Dispose();
                publicationManager.Dispose();
            }
        }
Esempio n. 13
0
        private static List <LinkElementModel> getChildrenFromMetadataPackageUsage(LinkElementModel model)
        {
            MetadataStructureManager msm = new MetadataStructureManager();

            try
            {
                MetadataPackageUsage metadataPackageUsage = msm.PackageUsageRepo.Get(model.ElementId);

                return(getChildrenFromMetadataPackage(metadataPackageUsage.MetadataPackage.Id, model.Position));
            }
            finally
            {
                msm.Dispose();
            }
        }
Esempio n. 14
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();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// </summary>
        /// <param name="id"></param>
        /// <param name="titlePath"></param>
        /// <param name="descriptionPath"></param>
        /// <param name="mappingFilePath"></param>
        /// <param name="direction"></param>
        private void StoreParametersToMetadataStruture(long id, string titlePath, string descriptionPath, string entity, string mappingFilePathImport, string mappingFilePathExport)
        {
            MetadataStructureManager mdsManager    = new MetadataStructureManager();
            EntityManager            entityManager = new EntityManager();

            try
            {
                MetadataStructure metadataStructure = this.GetUnitOfWork().GetReadOnlyRepository <MetadataStructure>().Get(id);

                XmlDocument xmlDoc = new XmlDocument();

                if (metadataStructure.Extra != null)
                {
                    xmlDoc = (XmlDocument)metadataStructure.Extra;
                }

                // add title Node
                xmlDoc = AddReferenceToMetadatStructure("title", titlePath, AttributeType.xpath.ToString(), "extra/nodeReferences/nodeRef", xmlDoc);
                // add Description
                xmlDoc = AddReferenceToMetadatStructure("description", descriptionPath, AttributeType.xpath.ToString(), "extra/nodeReferences/nodeRef", xmlDoc);


                if (entityManager.EntityRepository.Get().Any(e => { return(e.Name != null && e.Name.Equals(entity)); }))
                {
                    Entity e = entityManager.EntityRepository.Get().FirstOrDefault(x => x.Name != null && x.Name.Equals(entity));
                    if (e != null)
                    {
                        xmlDoc = AddReferenceToMetadatStructure(e.Name, e.EntityType.FullName, AttributeType.entity.ToString(), "extra/entity", xmlDoc);
                    }
                }

                // add mappingFilePath
                xmlDoc = AddReferenceToMetadatStructure(metadataStructure.Name, mappingFilePathImport, "mappingFileImport", "extra/convertReferences/convertRef", xmlDoc);
                xmlDoc = AddReferenceToMetadatStructure(metadataStructure.Name, mappingFilePathExport, "mappingFileExport", "extra/convertReferences/convertRef", xmlDoc);

                //set active
                xmlDoc = AddReferenceToMetadatStructure(NameAttributeValues.active.ToString(), true.ToString(), AttributeType.parameter.ToString(), "extra/parameters/parameter", xmlDoc);

                metadataStructure.Extra = xmlDoc;
                mdsManager.Update(metadataStructure);
            }
            finally
            {
                mdsManager.Dispose();
                entityManager.Dispose();
            }
        }
Esempio n. 16
0
        public static LinkElementRootModel LoadFromMetadataStructure(long id, LinkElementPostion rootModelType, MappingManager mappingManager)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);

                LinkElementRootModel model = new LinkElementRootModel(LinkElementType.MetadataStructure, id, metadataStructure.Name, rootModelType);

                if (metadataStructure != null)
                {
                    LinkElement metadataStructureLinkElement = mappingManager.GetLinkElement(metadataStructure.Id,
                                                                                             LinkElementType.MetadataStructure);

                    long metadataStructureLinkElementId = 0;
                    if (metadataStructureLinkElement != null)
                    {
                        metadataStructureLinkElementId = metadataStructureLinkElement.Id;
                    }


                    LinkElementModel LEModel = new LinkElementModel(
                        metadataStructureLinkElementId,
                        metadataStructure.Id,
                        LinkElementType.MetadataStructure,
                        metadataStructure.Name, "Metadata",
                        rootModelType,
                        LinkElementComplexity.Complex,
                        metadataStructure.Description);


                    foreach (var pUsage in metadataStructure.MetadataPackageUsages)
                    {
                        addUsageAsLinkElement(pUsage, "Metadata", model, LEModel);
                    }

                    model    = CreateLinkElementContainerModels(model);
                    model.Id = id;
                }
                return(model);
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 17
0
        public ActionResult Edit(long id)
        {
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(id);

                MetadataStructureModel model = convertToMetadataStructureModel(metadataStructure, metadataStructureManager);

                return(PartialView("_editMetadataStructureView", model));
            }
            finally
            {
                metadataStructureManager.Dispose();
            }
        }
Esempio n. 18
0
        public string GetEntityName(long datasetid)
        {
            DatasetManager           datasetManager           = new DatasetManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                Dataset dataset = datasetManager.GetDataset(datasetid);

                // get MetadataStructure
                if (dataset != null)
                {
                    return(GetEntityNameFromMetadatStructure(dataset.MetadataStructure.Id));
                }
                return(string.Empty);
            }
            finally
            {
                datasetManager.Dispose();
                metadataStructureManager.Dispose();
            }
        }
        public int CountEntities()
        {
            using (var uow = this.GetUnitOfWork())
            {
                DatasetManager           dm = new DatasetManager();
                MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
                XmlDatasetHelper         xmlDatasetHelper         = new XmlDatasetHelper();
                var entities = new List <EntityStoreItem>();
                int count    = 0;

                try
                {
                    List <long> metadataStructureIds = metadataStructureManager.Repo.Query().Select(m => m.Id).ToList();

                    List <long> metadataSturctureIdsForDatasets = new List <long>();
                    metadataStructureIds.ForEach(m => xmlDatasetHelper.HasEntity(m, _entityName));

                    foreach (var msid in metadataStructureIds)
                    {
                        var datasetIds = new List <long>();
                        // get all datasets based on metadata data structure id

                        datasetIds = dm.DatasetRepo.Query(d => d.MetadataStructure.Id.Equals(msid)).Select(d => d.Id).ToList();
                        count     += datasetIds.Count;
                    }

                    return(count);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dm.Dispose();
                    metadataStructureManager.Dispose();
                }
            }
        }
Esempio n. 20
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();
            }
        }
        public ActionResult Summary(int index)
        {
            MetadataStructureManager msm = new MetadataStructureManager();

            try
            {
                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

                //set current stepinfo based on index
                if (TaskManager != null)
                {
                    TaskManager.SetCurrent(index);
                    // remove if existing
                    TaskManager.RemoveExecutedStep(TaskManager.Current());
                }

                EasyUploadSummaryModel model = new EasyUploadSummaryModel();
                model.StepInfo = TaskManager.Current();

                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILENAME))
                {
                    model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        if (!String.IsNullOrWhiteSpace(tmp))
                        {
                            model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                    }
                }

                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                {
                    long id = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                    model.MetadataSchemaTitle = msm.Repo.Get(m => m.Id == id).FirstOrDefault().Name;
                    msm.Dispose();
                }

                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT))
                {
                    model.FileFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString();
                }

                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA))
                {
                    string selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                    int[]  areaHeaderValues            = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                    if (model.FileFormat.ToLower() == "topdown")
                    {
                        model.NumberOfHeaders = (areaHeaderValues[3]) - (areaHeaderValues[1]) + 1;
                    }

                    if (model.FileFormat.ToLower() == "leftright")
                    {
                        model.NumberOfHeaders = (areaHeaderValues[2]) - (areaHeaderValues[0]) + 1;
                    }
                }

                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA))
                {
                    List <string> selectedDataAreaJsonArray = (List <String>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                    List <int[]>  areaDataValuesList        = new List <int[]>();
                    model.NumberOfData = 0;
                    foreach (string jsonArray in selectedDataAreaJsonArray)
                    {
                        areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(jsonArray));
                    }
                    foreach (int[] areaDataValues in areaDataValuesList)
                    {
                        if (model.FileFormat.ToLower() == "leftright")
                        {
                            model.NumberOfData += (areaDataValues[3]) - (areaDataValues[1]) + 1;
                        }

                        if (model.FileFormat.ToLower() == "topdown")
                        {
                            model.NumberOfData += (areaDataValues[2]) - (areaDataValues[0]) + 1;
                        }
                    }
                }

                return(PartialView("EasyUploadSummary", model));
            }
            finally
            {
                msm.Dispose();
            }
        }
        public ActionResult Summary(object[] data)
        {
            MetadataStructureManager msm = new MetadataStructureManager();

            try
            {
                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];
                EasyUploadSummaryModel model = new EasyUploadSummaryModel();

                model.StepInfo  = TaskManager.Current();
                model.ErrorList = FinishUpload(TaskManager);

                if (model.ErrorList.Count > 0)
                {
                    #region Populate model with data from the TaskManager

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILENAME))
                    {
                        model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                    {
                        long id = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                        model.MetadataSchemaTitle = msm.Repo.Get(m => m.Id == id).FirstOrDefault().Name;
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT))
                    {
                        model.FileFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString();
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA))
                    {
                        string selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                        int[]  areaHeaderValues            = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                        if (model.FileFormat.ToLower() == "topdown")
                        {
                            model.NumberOfHeaders = (areaHeaderValues[3]) - (areaHeaderValues[1]) + 1;
                        }

                        if (model.FileFormat.ToLower() == "leftright")
                        {
                            model.NumberOfHeaders = (areaHeaderValues[2]) - (areaHeaderValues[0]) + 1;
                        }
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA))
                    {
                        List <string> selectedDataAreaJsonArray = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                        List <int[]>  areaDataValuesList        = new List <int[]>();
                        foreach (string area in selectedDataAreaJsonArray)
                        {
                            areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area));
                        }

                        foreach (int[] areaDataValues in areaDataValuesList)
                        {
                            if (model.FileFormat.ToLower() == "leftright")
                            {
                                model.NumberOfData = (areaDataValues[3]) - (areaDataValues[1]) + 1;
                            }

                            if (model.FileFormat.ToLower() == "topdown")
                            {
                                model.NumberOfData = (areaDataValues[2]) - (areaDataValues[0]) + 1;
                            }
                        }
                    }

                    #endregion Populate model with data from the TaskManager

                    return(PartialView("EasyUploadSummary", model));
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                msm.Dispose();
            }
        }
        public List <EntityStoreItem> GetEntities(int skip, int take)
        {
            bool withPaging = (take > 0);


            using (var uow = this.GetUnitOfWork())
            {
                DatasetManager           dm = new DatasetManager();
                MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
                XmlDatasetHelper         xmlDatasetHelper         = new XmlDatasetHelper();
                var entities = new List <EntityStoreItem>();

                try
                {
                    List <long> metadataStructureIds = metadataStructureManager.Repo.Query().Select(m => m.Id).ToList();

                    List <long> metadataSturctureIdsForDatasets = new List <long>();
                    metadataSturctureIdsForDatasets = metadataStructureIds.Where(m => xmlDatasetHelper.HasEntity(m, _entityName)).ToList();

                    foreach (var msid in metadataSturctureIdsForDatasets)
                    {
                        var datasetIds = new List <long>();
                        // get all datasets based on metadata data structure id
                        if (withPaging)
                        {
                            datasetIds = dm.DatasetRepo
                                         .Query(d => d.MetadataStructure.Id.Equals(msid))
                                         .Skip(skip)
                                         .Take(take)
                                         .Select(d => d.Id).ToList();
                        }
                        else
                        {
                            datasetIds = dm.DatasetRepo.Query(d => d.MetadataStructure.Id.Equals(msid)).Select(d => d.Id).ToList();
                        }


                        if (!datasetIds.Any())
                        {
                            continue;
                        }

                        // create tuples based on dataset id list, and get latest version of each dataset

                        List <DatasetVersion> datasetVersions = dm.GetDatasetLatestVersions(datasetIds, false);
                        foreach (var dsv in datasetVersions)
                        {
                            var e = new EntityStoreItem()
                            {
                                Id      = dsv.Dataset.Id,
                                Title   = dsv.Title,
                                Version = dm.GetDatasetVersionCount(dsv.Dataset.Id)
                            };

                            entities.Add(e);
                        }
                    }

                    return(entities.ToList());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dm.Dispose();
                    metadataStructureManager.Dispose();
                }
            }
        }
Esempio n. 24
0
        public ActionResult SaveMetaDataSelection(object[] data)
        {
            MetadataStructureManager msm = new MetadataStructureManager();

            try
            {
                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];
                SelectMetaDataModel model = new SelectMetaDataModel();

                long metadataId = -1;

                if (TaskManager != null)
                {
                    //Load available metadata structures and store them in the model
                    IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get();

                    foreach (MetadataStructure metadataStructure in metadataStructureList)
                    {
                        if (xmlDatasetHelper.IsActive(metadataStructure.Id) &&
                            xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset"))
                        {
                            model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name));
                        }
                    }
                    //Sort the metadata structures
                    model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1));

                    TaskManager.Current().SetValid(false);

                    //Grabs the id of the selected metadata from the Http-Request
                    foreach (string key in Request.Form.AllKeys)
                    {
                        if ("metadataId" == key)
                        {
                            metadataId = Convert.ToInt64(Request.Form[key]);
                        }
                    }

                    //If a valid id was submitted, save its id as the currently selected model id
                    model.SelectedMetaDataId = metadataId;

                    TaskManager.AddToBus(EasyUploadTaskManager.SCHEMA, model.SelectedMetaDataId);
                    TaskManager.Current().SetValid(true);


                    //Store all other information in the model
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                    }
                    else
                    {
                        model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);
                    }
                }

                return(PartialView("SheetSelectMetaData", model));
            }
            finally
            {
                msm.Dispose();
            }
        }
Esempio n. 25
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();
            }
        }
Esempio n. 26
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();
            }
        }
Esempio n. 27
0
        public ActionResult SheetSelectMetaData(object[] data)
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];
            SelectMetaDataModel model = new SelectMetaDataModel();

            model.StepInfo = TaskManager.Current();

            if (TaskManager != null)
            {
                TaskManager.Current().SetValid(false);

                //SetValid only if a metadata-structure was selected
                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                {
                    if (Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]) >= 0)
                    {
                        TaskManager.Current().SetValid(true);
                    }
                    else
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "No valid Metadata schema is selected."));
                    }
                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Other, "No Metadata schema is selected."));
                }

                //If the user typed in a title, the title must not be empty
                if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                {
                    string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                    if (String.IsNullOrWhiteSpace(tmp))
                    {
                        TaskManager.Current().SetValid(false);
                        model.ErrorList.Add(new Error(ErrorType.Other, "The title must not be empty."));
                    }
                }

                if (TaskManager.Current().valid == true) //Jump to next step of the upload
                {
                    TaskManager.AddExecutedStep(TaskManager.Current());
                    TaskManager.GoToNext();
                    Session["TaskManager"] = TaskManager;
                    ActionInfo actionInfo = TaskManager.Current().GetActionInfo;
                    return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary {
                        { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() }
                    }));
                }
                else //Model isn't valid, display an error and stay on the same site
                {
                    TaskManager.Current().SetStatus(StepStatus.error);
                    MetadataStructureManager msm = new MetadataStructureManager();
                    try
                    {
                        IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get();

                        foreach (MetadataStructure metadataStructure in metadataStructureList)
                        {
                            if (xmlDatasetHelper.IsActive(metadataStructure.Id) &&
                                xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset"))
                            {
                                model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name));
                            }
                        }
                        //Sort the metadata structures
                        model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1));

                        //reload model
                        model.StepInfo = TaskManager.Current();

                        //if the title was changed at some point during the upload, load the title into the model
                        if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                        {
                            model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                        //if it wasn't changed yet, the default title is the filename
                        else
                        {
                            model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);
                        }
                    }
                    finally
                    {
                        msm.Dispose();
                    }
                }
            }

            return(PartialView(model));
        }
Esempio n. 28
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();
            }
        }