Forum Discussion

ssmith-nova's avatar
ssmith-nova
New Contributor III
9 months ago

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.

     

     



  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    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.

     

     



    • ssmith-nova's avatar
      ssmith-nova
      New Contributor III

      Think you for this.  I am going to mark this as the solution and open another post on "is there a way to import the XML into an app?"  My goal is to export the XML, modify it, and then import it back in.

      Thanks again.  

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    Hi NicolasArgente , 

    I think the easiest way to do this would be to programmatically extract the ApplicationDashboards.xml, and load that into an xmldocument object.  Then use the DOM to remove all nodes under (xpath, roughly) workspaces/workspace/maintenanceunits/maintenanceunit/dashboards except the dashboard you want to keep and remove all nodes under components except the component you want to keep.  You'll also want to clear nodes from parameters and datasources, etc.  Don't remove the sections, just all the nodes in the sections. That way you don't have to rebuild the XML structure, you're just pruning it.

    Once all the pruning is done, write the xml back to a file or string, whatever suits.

    All in all its pretty basic XML, DOM, xpath, coding.  With this requirement I wouldn't even bother to serialize the xml into objects.