ssmith-nova
9 months agoNew Contributor III
Trying to extract a Maintenance Unit into one XML file using a BR
As the subject line says I am trying to extract a Maintenance unit using a business rule. We are on 8.1.0. Below is the code I am using. I have tried to use MetadataExtract.ExtractXML and XmlExtractContoller.ExtractXML, but I don't get what I am looking for. It ends up dumping everything into the XML file. The name of the Maintenance Unit in this case is Integrations.
Can anyone see what I am doing wrong, or is there another Method I should be using?
' Extract options
Dim xmlOptions As New XmlExtractOptions
' extract all items
xmlOptions.ExtractAllItems = False
' extract specified items
Dim extractDict As New Dictionary(Of XmlExtractItemPk, Boolean)
' Groups are required to be added if extracting Cube Views
extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.DashboardMaintUnit,"Integrations"), True)
'extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.BusinessRule,"XS_ExportAppTypes"), True)
Dim xm As XmlExtractItemPk = New XmlExtractItemPk(XmlExtractItemType.DashboardMaintUnit,"Integrations")
'Execute the Metadata Extract
Using dbConnFW As DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp As DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
' extract application type XML to target location
'File.WriteAllText(filePath,MetadataExtract.ExtractXML(dbConnFW,dbConnApp,xmlOptions,extractDict))
File.WriteAllText(filePath,XmlExtractController.ExtractXML(dbConnFW,dbConnApp,Nothing,xmlOptions,extractDict,XmlLoadExtractType.ApplicationWorkspaces))
Thanks,
Scott
Its a bit kludgy, but it should get you what you're after:
(Change the assignment of maintUnitToExtract to the name of your maintenance unit)Dim isExtractAllItemsTrue = True Dim isExtractUniqueIdsTrue = True Dim xmlOptions As New XmlExtractOptions(isExtractAllItemFalse, isExtractUniqueIdsTrue) Dim xmlString As String = String.Empty Dim maintUnitToExtract As String = "GolfStream Charts" ' extract specified items doesn't seem to work, but we need it Dim extractDict As New Dictionary(Of XmlExtractItemPk, Boolean) From { {New XmlExtractItemPk(XmlExtractItemType.DashboardMaintUnit, maintUnitToExtract), True} } 'Execute the Metadata Extract Using dbConnFW As DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si) Using dbConnApp As DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si) xmlString = XmlExtractController.ExtractXML(dbConnFW, dbConnApp, Nothing, xmlOptions, extractDict, XmlLoadExtractType.ApplicationWorkspaces) End Using End Using Dim xmlDoc As XDocument = XDocument.Parse(xmlString) Dim extractedMaintUnitElement As XElement = xmlDoc.Descendants("maintenanceUnit").Where(Function(mu) mu.Attribute("name").Value = maintUnitToExtract).FirstOrDefault() If extractedMaintUnitElement IsNot Nothing Then Dim workspaceElement = extractedMaintUnitElement.Ancestors("workspace").FirstOrDefault() Dim newWorkspaceElement As New XElement("workspace", workspaceElement.Attributes()) newWorkspaceElement.Add(New XElement("maintenanceUnits", extractedMaintUnitElement)) Dim newXmlDoc As New XDocument( New XElement("OneStreamXF", xmlDoc.Root.Attributes(), New XElement("applicationWorkspacesRoot", New XElement("workspaces", newWorkspaceElement) ) ) ) newXmlDoc.Save(filePath) End If
this is probably doable with their library methods, but I don't have time to figure it out today. I can look again tomorrow.