Inheritance: BusinessEntity
        /// <summary>
        /// Removes end2 from end1 without deleting either end1 or end 2.
        /// </summary>
        /// <param name="end1">The parent object</param>
        /// <param name="end2">The child object</param>
        /// <returns></returns>
        public bool RemoveChild(MDS.MetadataStructure end1, MDS.MetadataStructure end2)
        {
            Contract.Requires(end1 != null && end1.Id >= 0);
            Contract.Requires(end2 != null && end2.Id >= 0);

            bool result = false;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MDS.MetadataStructure> repo = uow.GetRepository <MDS.MetadataStructure>();

                end1 = repo.Reload(end1);
                repo.LoadIfNot(end1.Children);

                end2 = repo.Reload(end2);
                repo.LoadIfNot(end2.Parent);

                if (end1.Children.Contains(end2) || end2.Parent.Equals(end1))
                {
                    end1.Children.Remove(end2);
                    end2.Parent = null;
                    uow.Commit();
                    result = true;
                }
            }
            return(result);
        }
        public MDS.MetadataStructure Update(MDS.MetadataStructure entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result <MDS.MetadataStructure>() != null && Contract.Result <MDS.MetadataStructure>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MDS.MetadataStructure> repo = uow.GetRepository <MDS.MetadataStructure>();
                repo.Merge(entity);
                var merged = repo.Get(entity.Id);
                repo.Put(merged);

                uow.Commit();
            }
            return(entity);
        }
        private List <MetadataPackageUsage> GetPackages(Int64 structureId)
        {
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IReadOnlyRepository <MDS.MetadataStructure> repo = uow.GetReadOnlyRepository <MDS.MetadataStructure>();
                List <MetadataPackageUsage> list = new List <MetadataPackageUsage>();
                MDS.MetadataStructure       metadataStructure = repo.Get(structureId);

                if (metadataStructure.Parent != null)
                {
                    list.AddRange(GetPackages(metadataStructure.Parent.Id));
                }

                list.AddRange(metadataStructure.MetadataPackageUsages);

                return(list);
            }
        }
Exemple #4
0
        private static XmlDocument AddReferenceToMetadatStructure(MetadataStructure metadataStructure, string nodeName, string nodePath, string destinationPath, XmlDocument xmlDoc)
        {
            XmlDocument doc = xmlDoc;
            XmlNode extra;

            if (doc.DocumentElement == null)
            {
                if (metadataStructure.Extra != null)
                {

                    extra = ((XmlDocument)metadataStructure.Extra).DocumentElement;
                }
                else
                {
                    extra = doc.CreateElement("extra", "");
                }

                doc.AppendChild(extra);
            }

            XmlNode x = createMissingNodes(destinationPath, doc.DocumentElement, doc);

            if (x.Attributes.Count > 0)
            {
                foreach (XmlAttribute attr in x.Attributes)
                {
                    if (attr.Name == "name") attr.Value = nodeName;
                    if (attr.Name == "value") attr.Value = nodePath;
                }
            }
            else
            {
                XmlAttribute name = doc.CreateAttribute("name");
                name.Value = nodeName;
                XmlAttribute value = doc.CreateAttribute("value");
                value.Value = nodePath;

                x.Attributes.Append(name);
                x.Attributes.Append(value);

            }

            return doc;
        }
        public MetadataPackageUsage AddMetadataPackageUsage(MDS.MetadataStructure structure, MetadataPackage package, string label, string description, int minCardinality, int maxCardinality, XmlDocument extra = null)
        {
            Contract.Requires(package != null && package.Id >= 0);
            Contract.Requires(structure != null && structure.Id >= 0);

            Contract.Ensures(Contract.Result <MetadataPackageUsage>() != null && Contract.Result <MetadataPackageUsage>().Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MetadataPackageUsage>  repo  = uow.GetRepository <MetadataPackageUsage>();
                IRepository <MDS.MetadataStructure> repo2 = uow.GetRepository <MDS.MetadataStructure>();
                repo2.Reload(structure);
                repo2.LoadIfNot(structure.MetadataPackageUsages);
                int count = 0;
                try
                {
                    count = (from v in structure.MetadataPackageUsages
                             where v.MetadataPackage.Id.Equals(package.Id)
                             select v
                             )
                            .Count();
                }
                catch { }

                MetadataPackageUsage usage = new MetadataPackageUsage()
                {
                    MetadataPackage   = package,
                    MetadataStructure = structure,
                    // if no label is provided, use the package name and a sequence number calculated by the number of occurrences of that package in the current structure
                    Label          = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? package.Name : string.Format("{0} ({1})", package.Name, count)),
                    Description    = description,
                    MinCardinality = minCardinality,
                    MaxCardinality = maxCardinality,
                    Extra          = extra
                };
                structure.MetadataPackageUsages.Add(usage);
                package.UsedIn.Add(usage);

                repo.Put(usage);
                uow.Commit();
                return(usage);
            }
        }
        public bool Delete(MDS.MetadataStructure entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);
            IReadOnlyRepository <Dataset> datasetRepo = this.GetUnitOfWork().GetReadOnlyRepository <Dataset>();

            if (datasetRepo.Query(p => p.MetadataStructure.Id == entity.Id).Count() > 0)
            {
                throw new Exception(string.Format("Metadata structure {0} is used by datasets. Deletion Failed", entity.Id));
            }
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MDS.MetadataStructure> repo = uow.GetRepository <MDS.MetadataStructure>();
                entity = repo.Reload(entity);
                repo.Delete(entity);

                uow.Commit();
            }
            return(true);
        }
        public MDS.MetadataStructure Create(string name, string description, string xsdFileName, string xslFileName, MDS.MetadataStructure parent)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Ensures(Contract.Result <MDS.MetadataStructure>() != null && Contract.Result <MDS.MetadataStructure>().Id >= 0);

            MDS.MetadataStructure u = new MDS.MetadataStructure()
            {
                Name        = name,
                Description = description,
                XsdFileName = xsdFileName,
                XslFileName = xslFileName,
                Parent      = parent, // if parent is null, current node will be a root
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MDS.MetadataStructure> repo = uow.GetRepository <MDS.MetadataStructure>();
                repo.Put(u);
                uow.Commit();
            }
            return(u);
        }
        /// <summary>
        /// Adds end2 object to the list of children of end1 object, if not already there
        /// </summary>
        /// <param name="end1">The parent object</param>
        /// <param name="end2">The child object</param>
        /// <returns></returns>
        public bool AddChild(MDS.MetadataStructure end1, MDS.MetadataStructure end2)
        {
            Contract.Requires(end1 != null && end1.Id >= 0);
            Contract.Requires(end2 != null && end2.Id >= 0);

            bool result = false;

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MDS.MetadataStructure> repo = uow.GetRepository <MDS.MetadataStructure>();

                end1 = repo.Reload(end1);
                repo.LoadIfNot(end1.Children);
                if (!end1.Children.Contains(end2))
                {
                    //needs loop prevention control, so that end2 is in the set of {end1 and its parents}
                    end1.Children.Add(end2);
                    end2.Parent = end1;
                    uow.Commit();
                    result = true;
                }
            }
            return(result);
        }
 public List <MetadataPackageUsage> GetEffectivePackages(MDS.MetadataStructure structure)
 {
     return(GetEffectivePackages(structure.Id));
 }
Exemple #10
0
 public void Add(MetadataStructure metadataStructure)
 {
     this.MetadataStructuresDic.Add(metadataStructure.Id,
                                  metadataStructure.Name);
 }
Exemple #11
0
        private bool IsExportAvailable(MetadataStructure metadataStructure)
        {
            bool hasMappingFile = false;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(metadataStructure.Extra.OuterXml);

            if (XmlUtility.GetXElementByNodeName("convertRef", XmlUtility.ToXDocument(doc)).Count() > 0)
            {
                hasMappingFile = true;
            }

            return hasMappingFile;
        }
Exemple #12
0
        private List<DatasetVersionModel> getDatasetVersionsDic(MetadataStructure metadataStructure, List<long> datasetVersionIds)
        {
            List<DatasetVersionModel> datasetVersions = new List<DatasetVersionModel>();
            DatasetManager datasetManager = new DatasetManager();

            // gets all the dataset versions that their Id is in the datasetVersionIds and they are using a specific metadata structure as indicated by metadataStructure parameter
            var q = datasetManager.DatasetVersionRepo.Get(p => datasetVersionIds.Contains(p.Id) &&
                                                          p.Dataset.MetadataStructure.Id.Equals(metadataStructure.Id)).Distinct();

            foreach (DatasetVersion datasetVersion in q)
            {
                if (datasetManager.IsDatasetCheckedIn(datasetVersion.Dataset.Id))
                {
                    datasetVersions.Add(
                        new DatasetVersionModel
                        {
                            DatasetVersionId = datasetVersion.Id,
                            DatasetId = datasetVersion.Dataset.Id,
                            Title = XmlDatasetHelper.GetInformation(datasetVersion, NameAttributeValues.title),
                            MetadataDownloadPath = ""
                        });
                }
            }
            return datasetVersions;
        }
Exemple #13
0
        /// <summary>
        /// Delete all depending xsdFiles under the workspace
        /// && all generated mapping files
        /// </summary>
        /// <param name="metadataStructure"></param>
        /// <returns></returns>
        public static bool Delete(MetadataStructure metadataStructure)
        {
            string directoryPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "Metadata",
                metadataStructure.Name);

            string mappingFileDirectory = AppConfiguration.GetModuleWorkspacePath("DIM");

            // delete all mapping files
            // delete export mappings
            List<string> mappingFilPaths =
                XmlDatasetHelper.GetAllTransmissionInformationFromMetadataStructure(metadataStructure.Id,
                    TransmissionType.mappingFileExport, AttributeNames.value).ToList();

            if (mappingFilPaths.Count > 0)
            {
                foreach (var file in mappingFilPaths)
                {
                    FileHelper.Delete(Path.Combine(mappingFileDirectory,file));
                }
            }

            // delete import mappings
            mappingFilPaths =
                XmlDatasetHelper.GetAllTransmissionInformationFromMetadataStructure(metadataStructure.Id,
                    TransmissionType.mappingFileImport, AttributeNames.value).ToList();

            if (mappingFilPaths.Count > 0)
            {
                foreach (var file in mappingFilPaths)
                {
                    FileHelper.Delete(Path.Combine(mappingFileDirectory, file));
                }
            }

            // deleting all xsds
            if (Directory.Exists(directoryPath))
                Directory.Delete(directoryPath,true);

            if (!Directory.Exists(directoryPath)) return true;

            return false;
        }
Exemple #14
0
        // import metadata structure
        public long importMetadataStructure(string filePath, string userName, string schemaFile = "", string schemaName = "", string titlePath = "", string descriptionPath = "")
        {
            if (string.IsNullOrEmpty(schemaFile))
                schemaFile = filePath + @"\schema_toImport.xsd";

            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();
            MetadataStructure metadataStructure = new MetadataStructure();
            if (string.IsNullOrEmpty(schemaName))
                schemaName = "BExIS";
            string root = "";
            if (string.IsNullOrEmpty(titlePath))
                titlePath = "Metadata/general/general/title/title";
            if (string.IsNullOrEmpty(descriptionPath))
                descriptionPath = "Metadata/methodology/methodology/introduction/introduction";

            MetadataStructure existMetadataStructures = metadataStructureManager.Repo.Get(m => m.Name.Equals(schemaName)).FirstOrDefault();

            if (existMetadataStructures == null)
            {
                // load schema xsd
                long metadataStructureid = 0;
                xmlSchemaManager.Load(schemaFile, userName);
                try
                {
                    metadataStructureid = xmlSchemaManager.GenerateMetadataStructure(root, schemaName);
                }
                catch
                {
                    xmlSchemaManager.Delete(schemaName);
                }
                metadataStructure = metadataStructureManager.Repo.Get(metadataStructureid);
                try
                {
                    // set parameters:
                    XmlDocument xmlDoc = new XmlDocument();
                    if (metadataStructure.Extra != null)
                    {
                        xmlDoc = (XmlDocument)metadataStructure.Extra;
                    }

                    // add title Node
                    xmlDoc = AddReferenceToMetadatStructure(metadataStructure, "title", titlePath, "extra/nodeReferences/nodeRef", xmlDoc);
                    // add Description
                    xmlDoc = AddReferenceToMetadatStructure(metadataStructure, "description", descriptionPath, "extra/nodeReferences/nodeRef", xmlDoc);

                    metadataStructure.Extra = xmlDoc;
                    metadataStructureManager.Update(metadataStructure);
                }
                catch
                {
                    //
                }
            }
            else
            {
                metadataStructure = existMetadataStructures;
            }

            return metadataStructure.Id;
        }
        private MetadataStructure updateMetadataStructure(MetadataStructure metadataStructure,
            MetadataStructureModel metadataStructureModel)
        {
            if (metadataStructure.Id.Equals(metadataStructureModel.Id))
            {
                metadataStructure.Name = metadataStructureModel.Name;

                if (metadataStructure.Extra != null)
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    if (metadataStructure.Extra as XmlDocument != null)
                        xmlDocument = metadataStructure.Extra as XmlDocument;
                    else
                    {
                        xmlDocument.AppendChild(metadataStructure.Extra);
                    }

                    metadataStructureModel.MetadataNodes = GetAllXPath(metadataStructure.Id);

                    //set title & description
                    string titleXPath =
                        metadataStructureModel.MetadataNodes
                            .Where(e => e.DisplayName.Equals(metadataStructureModel.TitleNode))
                            .FirstOrDefault()
                            .XPath;

                    XmlNode tmp = XmlUtility.GetXmlNodeByAttribute(xmlDocument.DocumentElement,
                        nodeNames.nodeRef.ToString(), AttributeNames.name.ToString(),
                        NameAttributeValues.title.ToString());

                    tmp.Attributes[AttributeNames.value.ToString()].Value = titleXPath;

                    string descriptionXPath =
                        metadataStructureModel.MetadataNodes
                            .Where(e => e.DisplayName.Equals(metadataStructureModel.DescriptionNode))
                            .FirstOrDefault()
                            .XPath;

                    tmp = XmlUtility.GetXmlNodeByAttribute(xmlDocument.DocumentElement, nodeNames.nodeRef.ToString(),
                        AttributeNames.name.ToString(), NameAttributeValues.description.ToString());
                    tmp.Attributes[AttributeNames.value.ToString()].Value = descriptionXPath;

                    //set entity
                    tmp = XmlUtility.GetXmlNodeByName(xmlDocument.DocumentElement, nodeNames.entity.ToString());
                    if (tmp != null)
                        tmp.Attributes[AttributeNames.value.ToString()].Value = metadataStructureModel.Entity.ClassPath;
                    else
                    {
                        xmlDocument = XmlDatasetHelper.AddReferenceToXml(xmlDocument, nodeNames.entity.ToString(),
                            metadataStructureModel.Entity.ClassPath, AttributeType.entity.ToString(), "extra/entity");
                    }

                    //set active
                    tmp = XmlUtility.GetXmlNodeByAttribute(xmlDocument.DocumentElement, nodeNames.parameter.ToString(),
                        AttributeNames.name.ToString(), NameAttributeValues.active.ToString());
                    if (tmp != null)
                        tmp.Attributes[AttributeNames.value.ToString()].Value = metadataStructureModel.Active.ToString();
                    else
                    {
                        xmlDocument = XmlDatasetHelper.AddReferenceToXml(xmlDocument,
                            NameAttributeValues.active.ToString(),
                            metadataStructureModel.Active.ToString(), AttributeType.parameter.ToString(),
                            "extra/parameters/parameter");

                    }

                    metadataStructure.Extra = xmlDocument;
                }

            }
            return metadataStructure;
        }
        private MetadataStructureModel convertToMetadataStructureModel(MetadataStructure metadataStructure)
        {
            MetadataStructureModel metadataStructureModel = new MetadataStructureModel();
            metadataStructureModel.Id = metadataStructure.Id;
            metadataStructureModel.Name = metadataStructure.Name;

            try
            {
                metadataStructureModel.MetadataNodes = GetAllXPath(metadataStructure.Id);

                //get all informaions from xml
                metadataStructureModel.EntityClasses = GetEntityModelList();
                string EntityClassPath = XmlDatasetHelper.GetEntityTypeFromMetadatStructure(metadataStructure.Id);
                var entityModel =
                    metadataStructureModel.EntityClasses.Where(e => e.ClassPath.Equals(EntityClassPath))
                        .FirstOrDefault();
                if (entityModel != null) metadataStructureModel.Entity = entityModel;

                string xpath = XmlDatasetHelper.GetInformationPath(metadataStructure, NameAttributeValues.title);

                var searchMetadataNode =
                    metadataStructureModel.MetadataNodes.Where(e => e.XPath.Equals(xpath)).FirstOrDefault();
                if (searchMetadataNode != null)
                    metadataStructureModel.TitleNode =
                        searchMetadataNode.DisplayName;

                xpath = XmlDatasetHelper.GetInformationPath(metadataStructure,
                    NameAttributeValues.description);

                //check if xsd exist
                string schemapath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "Metadata",
                    metadataStructure.Name);

                if (Directory.Exists(schemapath) && Directory.GetFiles(schemapath).Length > 0)
                    metadataStructureModel.HasSchema = true;

                var firstOrDefault =
                    metadataStructureModel.MetadataNodes.Where(e => e.XPath.Equals(xpath)).FirstOrDefault();
                if (firstOrDefault != null)
                    metadataStructureModel.DescriptionNode =
                        firstOrDefault.DisplayName;

                metadataStructureModel.MetadataNodes = GetAllXPath(metadataStructureModel.Id);

                metadataStructureModel.Active = XmlDatasetHelper.IsActive(metadataStructure.Id);
            }
            catch(Exception exception)
            {
                metadataStructureModel = new MetadataStructureModel();
                metadataStructureModel.Id = metadataStructure.Id;
                metadataStructureModel.Name = metadataStructure.Name;
            }

            return metadataStructureModel;
        }