public static Delete ( |
||
metadataStructure | ||
Résultat | bool |
// 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; }
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); }
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 ""; }