public ActionResult GenerateMS()
        {
            //open schema
                XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();

                string root = "";
                string schemaName = "";
                long metadataStructureid = 0;

                TaskManager = (ImportMetadataStructureTaskManager) Session["TaskManager"];

                if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.ROOT_NODE))
                    root = TaskManager.Bus[ImportMetadataStructureTaskManager.ROOT_NODE].ToString();

                if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.SCHEMA_NAME))
                    schemaName = TaskManager.Bus[ImportMetadataStructureTaskManager.SCHEMA_NAME].ToString();

                string path = TaskManager.Bus[ImportMetadataStructureTaskManager.FILEPATH].ToString();
                //path = @"https://code.ecoinformatics.org/code/eml/tags/RELEASE_EML_2_1_1/eml.xsd";

                ReadSourceModel model = new ReadSourceModel(TaskManager.Current());
                model.SchemaName = schemaName;
                model.RootNode = root;

                try
                {
                    //file.WriteLine("check schema exist");
                    if (SchemaNameExist(schemaName))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other,
                            "A Metadata structure with this name already exist. Please choose a other name."));
                    }
                    else
                    if (String.IsNullOrEmpty(schemaName))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "A Metadata structure must have a name."));
                    }
                    else
                        xmlSchemaManager.Load(path, GetUserNameOrDefault());

                    if (!String.IsNullOrEmpty(model.RootNode) && !xmlSchemaManager.Elements.Any(e => e.Name.Equals(model.RootNode)))
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Root node not exist"));
                    }

                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    model.ErrorList.Add(new Error(ErrorType.Other, "Can not create metadatastructure."));
                    throw ex;
                }

                if (model.ErrorList.Count == 0)
                {
                    try
                    {
                        metadataStructureid = xmlSchemaManager.GenerateMetadataStructure(root, schemaName);
                    }
                    catch (Exception ex)
                    {
                        xmlSchemaManager.Delete(schemaName);
                        ModelState.AddModelError("", ex.Message);
                        model.ErrorList.Add(new Error(ErrorType.Other, "Can not create metadatastructure."));
                    }
                }

                TaskManager.AddToBus(ImportMetadataStructureTaskManager.MAPPING_FILE_NAME_IMPORT,
                    xmlSchemaManager.mappingFileNameImport);
                TaskManager.AddToBus(ImportMetadataStructureTaskManager.MAPPING_FILE_NAME_EXPORT,
                    xmlSchemaManager.mappingFileNameExport);

                model.StepInfo.notExecuted = false;

                if (model.ErrorList.Count == 0)
                {
                    model.IsGenerated = true;

                    if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.IS_GENERATE))
                        TaskManager.Bus[ImportMetadataStructureTaskManager.IS_GENERATE] = true;
                    else
                        TaskManager.Bus.Add(ImportMetadataStructureTaskManager.IS_GENERATE, true);

                    if (TaskManager.Bus.ContainsKey(ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID))
                        TaskManager.Bus[ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID] = metadataStructureid;
                    else
                        TaskManager.Bus.Add(ImportMetadataStructureTaskManager.METADATASTRUCTURE_ID, metadataStructureid);
                }

            return PartialView("ReadSource",model);
        }
Example #2
0
        public string TransferPublications()
        {
            string xsdPath = Path.Combine(AppConfiguration.DataPath, "Temp", "Administrator");
            PublicationManager pms = new PublicationManager();
            MetadataCreator metadataCreator = new MetadataCreator();
            //Import MetaDataStructure
            string schemaFile = xsdPath + @"\publication.xsd";
            //open schema
            XmlSchemaManager xmlSchemaManager = new XmlSchemaManager();
            string userName = "******";
            xmlSchemaManager.Load(schemaFile, userName);
            long metadataStructureId = 0;
            try
            {
                metadataStructureId = metadataCreator.importMetadataStructure(schemaFile, userName, schemaFile, "Publication", "Metadata/publicationDetails/publicationDetails/title/title", "Metadata/publicationDetails/publicationDetails/information/information");// xmlSchemaManager.GenerateMetadataStructure("publication", "publication");
            }
            catch (Exception ex)
            {
                xmlSchemaManager.Delete("publication");
                return "Couldn't create publication metadatastructure!";
            }
            //Create an empty publication
            MetadataStructureManager msm = new MetadataStructureManager();
            MetadataStructure metadataStructure = msm.Repo.Get(metadataStructureId);
            XmlDocument metadataXmlTemplate = BExIS.Xml.Helpers.XmlMetadataWriter.ToXmlDocument(metadataCreator.createXmlTemplate(metadataStructureId));
            var publicationsMetaData = metadataCreator.getPublicationsMetadataXml(DataBase);
            var xmlMapperManager = new XmlMapperManager();
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");
            string path_mappingFile = filePath + @"\bexis_publication_metadata_mapping.xml";
            foreach (var publicationMetaData in publicationsMetaData)
            {
                var pc = pms.CreateEmptyPublication(metadataStructure);
                var publicationId = pc.Id;
                if (pms.IsPublicationCheckedOutFor(publicationId, userName) || pms.CheckOutPublication(publicationId, userName))
                {

                    PublicationVersion workingCopy = pms.GetPublicationWorkingCopy(publicationId);
                    // XML mapper + mapping file
                    xmlMapperManager.Load(path_mappingFile, "Publication");
                    XmlDocument metadataBpp = xmlMapperManager.Generate(publicationMetaData.MetaDataXml, 99);
                    metadataBpp = metadataCreator.fillInXmlAttributes(metadataBpp, metadataXmlTemplate);
                    workingCopy.Metadata = metadataBpp;

                    foreach (var pbContent in publicationMetaData.PublicationContentDescriptors)
                    {
                        string storePath = Path.Combine(AppConfiguration.DataPath, "Publications", publicationId.ToString());
                        storePath = Path.Combine(storePath, publicationId.ToString() + "_" + workingCopy.VersionNo.ToString() + "_" + pbContent.Name);
                        File.Move(pbContent.URI, storePath);
                        pbContent.URI = storePath;
                        pbContent.PublicationVersion = workingCopy;
                        workingCopy.PublicationContentDescriptors.Add(pbContent);
                    }
                    pms.CheckInPublication(publicationId, "Metadata was submited.", userName);
                }
            }
            return "";
        }
Example #3
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;
        }
Example #4
0
        /// <summary>
        /// Load from mapping file
        /// create a XmlMapper
        /// </summary>
        /// <returns></returns>
        public XmlMapper Load(string mappingFilePath, string username)
        {
            xmlMapper = new XmlMapper();

            mappingFile = new XmlDocument();
            mappingFile.Load(mappingFilePath);

            XmlNode root = mappingFile.DocumentElement;
            #region get id and name of standard

            XmlNode mapping = mappingFile.GetElementsByTagName(XmlMapperTags.mapping.ToString())[0];

            if (mapping.Attributes.Count > 0)
            {
                foreach (XmlAttribute attr in mapping.Attributes)
                {
                    if (attr.Name.Equals(XmlMapperAttributes.id.ToString()))
                        xmlMapper.Id = Convert.ToInt32(attr.Value);

                    if (attr.Name.Equals(XmlMapperAttributes.name.ToString()))
                        xmlMapper.Name = attr.Value;
                }
            }

            #endregion

            #region create Header as xmlMappingHeader

            XmlMappingHeader xmlMappingHeader = new XmlMappingHeader();

            XmlNode header = mappingFile.GetElementsByTagName(XmlMapperTags.header.ToString())[0];

            foreach(XmlNode xmlNode in header.ChildNodes)
            {
                if(xmlNode.NodeType.Equals(System.Xml.XmlNodeType.Element))
                {
                    #region create destination

                    if(xmlNode.Name.Equals(XmlMapperTags.destination.ToString()))
                    {
                        xmlMappingHeader.Destination = Destination.Convert(xmlNode);
                    }

                    #endregion

                    #region read & add packages
                    if (xmlNode.Name.Equals(XmlMapperTags.packages.ToString()))
                    {
                        foreach(XmlNode childNode in xmlNode.ChildNodes)
                        {
                            if (childNode.Name.Equals(XmlMapperTags.package.ToString()))
                            {
                                xmlMappingHeader.AddToPackages(childNode);
                            }

                        }
                    }

                    #endregion

                    #region read & add Attributes
                        if (xmlNode.Name.Equals(XmlMapperTags.attributes.ToString()))
                        {
                            foreach (XmlNode childNode in xmlNode.ChildNodes)
                            {
                                if (childNode.Name.Equals(XmlMapperTags.attribute.ToString()))
                                {
                                    xmlMappingHeader.AddToAttributes(childNode);
                                }

                            }
                        }
                    #endregion

                    #region read & add schemas

                    if (xmlNode.Name.Equals(XmlMapperTags.schema.ToString()))
                    {
                        xmlMappingHeader.AddToSchemas(xmlNode);
                    }

                    #endregion
                }
            }

            xmlMapper.Header = xmlMappingHeader;

            #endregion

            #region create Routes

            XmlNodeList routes = mappingFile.GetElementsByTagName(XmlMapperTags.routes.ToString())[0].ChildNodes;
            foreach (XmlNode childNode in routes)
            {
                xmlMapper.Routes.Add(XmlMappingRoute.Convert(childNode));
            }

            #endregion

            #region xmlschema

            xmlSchemaManager = new XmlSchemaManager();

            if (xmlMapper.Header.Schemas.Count > 0)
            {
                xmlSchemaManager = new XmlSchemaManager();
                string schemaPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), xmlMapper.Header.Schemas.First().Value);
                xmlSchemaManager.Load(schemaPath, username);
            }

            #endregion

            return xmlMapper;
        }