createXmlTemplate() public method

public createXmlTemplate ( long metadataStructureId ) : System.Xml.Linq.XDocument
metadataStructureId long
return System.Xml.Linq.XDocument
コード例 #1
0
ファイル: Migration.cs プロジェクト: BEXIS2/Core
        public void DataSetTransfer()
        {
            string filePath = AppConfiguration.GetModuleWorkspacePath("BMM");
            //string xsdPath = @"C:\Data\Temp\Administrator";
            string xsdPath = Path.Combine(AppConfiguration.DataPath, "Temp", "Administrator");
            string xsdUserName = "******";
            string researchPlanName = "Research plan";

            MappingReader mappingReader = new MappingReader();
            AttributeCreator attributeCreator = new AttributeCreator();
            MetadataCreator metadataCreator = new MetadataCreator();
            MigrationHelpers migrationHelpers = new MigrationHelpers();

            #region create datatypes, unit, dimensions for datastructure from mapping file
            // read data types from excel mapping file
            DataTable mappedDataTypes = mappingReader.readDataTypes(filePath);
            // create read data types in bpp
            attributeCreator.CreateDataTypes(ref mappedDataTypes);

            // read dimensions from excel mapping file
            DataTable mappedDimensions = mappingReader.readDimensions(filePath);
            // create dimensions in bpp
            attributeCreator.CreateDimensions(ref mappedDimensions);

            // read units from excel mapping file
            DataTable mappedUnits = mappingReader.readUnits(filePath, mappedDimensions);
            // create read units in bpp
            attributeCreator.CreateUnits(ref mappedUnits, mappedDataTypes);

            // read attributes from excel mapping file
            DataTable mappedAttributes = mappingReader.readAttributes(filePath, mappedUnits, mappedDataTypes);
            // Speicher freigeben
            mappedDataTypes.Clear();
            mappedDimensions.Clear();
            // create read attributes in bpp
            attributeCreator.CreateAttributes(ref mappedAttributes);

            // read variables from XLSX or TSV (tab seperated values) mapping file
            //DataTable mappedVariables = mappingReader.readVariables(filePath, mappedAttributes);
            DataTable mappedVariables = mappingReader.readVariablesTSV(filePath, mappedAttributes, mappedUnits);
            // Speicher freigeben
            mappedAttributes.Clear();
            mappedUnits.Clear();

            #endregion

            #region create metadatastructure and prepare a xmltemplate based on the structure

            // if not existing: import METADATA structure, using file "schema.xsd" similar to bexis1 schema
            long metadataStructureId = metadataCreator.importMetadataStructure(xsdPath, xsdUserName);
            // create BppmetadataXmlTemplate to get XmlAttributes
            XmlDocument metadataXmlTemplate = BExIS.Xml.Helpers.XmlMetadataWriter.ToXmlDocument(metadataCreator.createXmlTemplate(metadataStructureId));

            #endregion

            #region create Dataset(Metadata,Datastructure)
            // the dataStructure, metadata and dataset of these bexis1 datasets will be transfered
            DataStructureCreator dataStructureCreator = new DataStructureCreator();
            DatasetCreator datasetCreator = new DatasetCreator();
            List<string> datasetIds = migrationHelpers.getDatasets(filePath);
            foreach (string dataSetID in datasetIds)
            {
                dataStructureCreator = new DataStructureCreator();
                datasetCreator = new DatasetCreator();
                XmlDocument metadataXml = new XmlDocument();
                List<string> variableNames = new List<string>();
                string fileType = "";

                // get metadata from Bexis1 DB and restructure it for Bpp using xml-mapping file
                metadataXml = metadataCreator.createMetadata(dataSetID, filePath, DataBase, ref variableNames, ref fileType);

                //long dataStructureId = -1;
                BExIS.Dlm.Entities.DataStructure.DataStructure dataStructure = null;
                if (fileType == "structuredData" || fileType == "lookupTable")
                {
                    // create dataStructure on bpp
                    dataStructure = dataStructureCreator.CreateDataStructure(dataSetID, mappedVariables, variableNames);
                }
                else if (fileType.Length > 0)
                {
                    // create unstructured dataStructure on bpp
                    dataStructure = dataStructureCreator.CreateDataStructure(fileType);
                }

                long datasetId = -1;
                if (dataStructure.Id > 0)
                {
                    datasetId = datasetCreator.DatasetExistsByOldDatasetId(dataSetID, dataStructure.Id);
                }

                if (datasetId <= 0) // dataset not exists => create dataset
                {
                    // integrate BppXmlAttributes by using metadataXmlTemplate
                    metadataXml = metadataCreator.fillInXmlAttributes(metadataXml, metadataXmlTemplate);

                    // create dataset with Bexis1_metadata
                    datasetId = datasetCreator.createDataset(dataSetID, metadataXml, metadataStructureId, dataStructure, researchPlanName);
                }

                string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt");
                string[] DatasetMappingtexts = File.ReadAllLines(DatasetMappingPath);
                string DatasetMappingtext = DatasetMappingtexts.FirstOrDefault(item => item.Split('\t')[0] == dataSetID);
                //to prevent of repeating data
                if (DatasetMappingtext != null)
                    File.WriteAllLines(DatasetMappingPath, DatasetMappingtexts.Where(item => item != DatasetMappingtext));
                File.AppendAllText(DatasetMappingPath, dataSetID + "\t" + datasetId + "\r\n");

            }
            #endregion
        }
コード例 #2
0
ファイル: Migration.cs プロジェクト: BEXIS2/Core
        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 "";
        }