コード例 #1
0
def buildIntermediateXML(objectMapFromARIS):
    try:
        ## Build XML
        intermediateXML = Document()
        rootElement = Element('data')
        intermediateXML.setRootElement(rootElement)
        cisElement = Element('cis')
        linksElement = Element('links')
        rootElement.addContent(cisElement)
        rootElement.addContent(linksElement)

        if objectMapFromARIS:
            ## Add CIs
            for objectFromARIS in objectMapFromARIS.values():
                ciElement = Element('ci')
                if buildIntermediateCiXML(ciElement, objectFromARIS):
                    cisElement.addContent(ciElement)
                ## Add relationships
                relationshipsFromObject = objectFromARIS.links
                if relationshipsFromObject:
                    for relationshipFromObject in relationshipsFromObject:
                        linkElement = Element('link')
                        linkElement.setAttribute('type',
                                                 relationshipFromObject.type)
                        linkEndCount = 1
                        for linkEndCi in [
                                objectMapFromARIS[relationshipFromObject.end1],
                                objectMapFromARIS[relationshipFromObject.end2]
                        ]:
                            endCiElement = Element('end' + str(linkEndCount) +
                                                   'ci')
                            linkEndCount = linkEndCount + 1
                            if buildIntermediateCiXML(endCiElement, linkEndCi):
                                linkElement.addContent(endCiElement)
                            else:
                                debugPrint(
                                    3, '[' + SCRIPT_NAME +
                                    ':buildIntermediateXML] Error building link end for link with GUID <%s>! Skipping...'
                                    % relationshipFromObject.id)
                        linksElement.addContent(linkElement)
        return intermediateXML
    except:
        excInfo = logger.prepareJythonStackTrace('')
        debugPrint('[' + SCRIPT_NAME +
                   ':buildIntermediateXML] Exception: <%s>' % excInfo)
        pass
コード例 #2
0
ファイル: Pull_from_ARIS.py プロジェクト: ddonnelly19/dd-git
def buildIntermediateXML(objectMapFromARIS):
	try:
		## Build XML
		intermediateXML = Document()
		rootElement = Element('data')
		intermediateXML.setRootElement(rootElement)
		cisElement = Element('cis')
		linksElement = Element('links')
		rootElement.addContent(cisElement)
		rootElement.addContent(linksElement)

		if objectMapFromARIS:
			## Add CIs
			for objectFromARIS in objectMapFromARIS.values():
				ciElement = Element('ci')
				if buildIntermediateCiXML(ciElement, objectFromARIS):
					cisElement.addContent(ciElement)
				## Add relationships
				relationshipsFromObject = objectFromARIS.links
				if relationshipsFromObject:
					for relationshipFromObject in relationshipsFromObject:
						linkElement = Element('link')
						linkElement.setAttribute('type', relationshipFromObject.type)
						linkEndCount = 1
						for linkEndCi in [objectMapFromARIS[relationshipFromObject.end1], objectMapFromARIS[relationshipFromObject.end2]]:
							endCiElement = Element('end' + str(linkEndCount) + 'ci')
							linkEndCount = linkEndCount + 1
							if buildIntermediateCiXML(endCiElement, linkEndCi):
								linkElement.addContent(endCiElement)
							else:
								debugPrint(3, '[' + SCRIPT_NAME + ':buildIntermediateXML] Error building link end for link with GUID <%s>! Skipping...' % relationshipFromObject.id)
						linksElement.addContent(linkElement)
		return intermediateXML
	except:
		excInfo = logger.prepareJythonStackTrace('')
		debugPrint('[' + SCRIPT_NAME + ':buildIntermediateXML] Exception: <%s>' % excInfo)
		pass
コード例 #3
0
def addCIs(rootElement, allObjectChildren):
    iter = allObjectChildren.iterator()
    mamIdToAttributesMap = HashMap()
    while iter.hasNext():
        ciElement = Element('ci')
        attributeMap = HashMap()
        objectElement = iter.next()
        familyClassName = objectElement.getAttributeValue('name')
        mamId = objectElement.getAttributeValue('mamId')
        # split dest class into family and class names
        splitIdx = string.rfind(familyClassName, '.')
        familyName = familyClassName[0:splitIdx]
        className = familyClassName[splitIdx+1:len(familyClassName)]
        #print familyName, " - ", className
        if familyName != None and className != None:
            classElement = Element('class')
            classElement.setText(className)
            ciElement.addContent(classElement)
            attributeMap.put('class', className)
            familyElement = Element('family')
            familyElement.setText(familyName)
            ciElement.addContent(familyElement)
            attributeMap.put('family', familyName)
            # get the fields
            fieldChildren  = objectElement.getChildren('field')
            if fieldChildren is not None:
                iter2 = fieldChildren.iterator()
                while iter2.hasNext():
                    fieldElement = iter2.next()
                    fieldName = fieldElement.getAttributeValue('name')
                    fieldValue = fieldElement.getText()
                    if fieldValue == None or fieldValue == '':
                        fieldValue = 'EMPTY'
                    #print fieldName, ' - ', fieldValue
                    setFieldElement = Element(fieldName)
                    setFieldElement.setText(fieldValue)
                    ciElement.addContent(setFieldElement)
                    attributeMap.put(fieldName, fieldValue)
        mamIdToAttributesMap.put(mamId, attributeMap)
        rootElement.addContent(ciElement)
    
    return (mamIdToAttributesMap, rootElement)
コード例 #4
0
def addCIs(rootElement, allObjectChildren):
    iter = allObjectChildren.iterator()
    mamIdToAttributesMap = HashMap()
    while iter.hasNext():
        ciElement = Element('ci')
        attributeMap = HashMap()
        objectElement = iter.next()
        familyClassName = objectElement.getAttributeValue('name')
        mamId = objectElement.getAttributeValue('mamId')
        # split dest class into family and class names
        splitIdx = string.rfind(familyClassName, '.')
        familyName = familyClassName[0:splitIdx]
        className = familyClassName[splitIdx + 1:len(familyClassName)]
        #print familyName, " - ", className
        if familyName != None and className != None:
            classElement = Element('class')
            classElement.setText(className)
            ciElement.addContent(classElement)
            attributeMap.put('class', className)
            familyElement = Element('family')
            familyElement.setText(familyName)
            ciElement.addContent(familyElement)
            attributeMap.put('family', familyName)
            # get the fields
            fieldChildren = objectElement.getChildren('field')
            if fieldChildren is not None:
                iter2 = fieldChildren.iterator()
                while iter2.hasNext():
                    fieldElement = iter2.next()
                    fieldName = fieldElement.getAttributeValue('name')
                    fieldValue = fieldElement.getText()
                    if fieldValue == None or fieldValue == '':
                        fieldValue = 'EMPTY'
                    #print fieldName, ' - ', fieldValue
                    setFieldElement = Element(fieldName)
                    setFieldElement.setText(fieldValue)
                    ciElement.addContent(setFieldElement)
                    attributeMap.put(fieldName, fieldValue)
        mamIdToAttributesMap.put(mamId, attributeMap)
        rootElement.addContent(ciElement)

    return (mamIdToAttributesMap, rootElement)
コード例 #5
0
def addRelations(rootElement, allRelationChildren, mamIdToAttributesMap):
    removeAtts = ['family', 'class']
    iter = allRelationChildren.iterator()
    while iter.hasNext():
        relElement = Element('relation')
        linkElement = iter.next()
        linkType = linkElement.getAttribute('targetRelationshipClass').getValue()
        targetParent = linkElement.getAttribute('targetParent').getValue()
        splitIdx_targetParent = string.rfind(targetParent, '.')
        targetParentFamilyName = targetParent[0:splitIdx_targetParent]
        targetParentClassName = targetParent[splitIdx_targetParent+1:len(targetParent)]

        targetChild = linkElement.getAttribute('targetChild').getValue()
        splitIdx_targetChild = string.rfind(targetChild, '.')
        targetChildFamilyName = targetChild[0:splitIdx_targetChild]
        targetChildClassName = targetChild[splitIdx_targetChild+1:len(targetChild)]

        id1base = ''
        id2base = ''
        if linkType != None and targetParent != None and targetChild != None:
            fieldChildren  = linkElement.getChildren('field')
            if fieldChildren is not None:
                iter2 = fieldChildren.iterator()
                while iter2.hasNext():
                    fieldElement = iter2.next()
                    fieldName = fieldElement.getAttributeValue('name')
                    if fieldName == 'DiscoveryID1':
                        id1base = fieldElement.getText()
                    if fieldName == 'DiscoveryID2':
                        id2base = fieldElement.getText()
                
                # set type
                typeElement = Element('type')
                typeElement.setText(linkType)
                relElement.addContent(typeElement)
                
                # set provider
                providerElement = Element('provider')
                
                if mamIdToAttributesMap.containsKey(id1base):
                    otherProviderAttributes = mamIdToAttributesMap.get(id1base)
                    iter3 = otherProviderAttributes.entrySet().iterator()
                    while iter3.hasNext():
                        entry = iter3.next()
                        name = entry.getKey()
                        if name in removeAtts:
                            continue
                        value = entry.getValue()
                        otherElement = Element(name)
                        otherElement.setText(value)
                        providerElement.addContent(otherElement)
                
                relElement.addContent(providerElement)
                
                # set dependent
                dependentElement = Element('dependent')
                
                if mamIdToAttributesMap.containsKey(id2base):
                    otherdependentAttributes = mamIdToAttributesMap.get(id2base)
                    iter3 = otherdependentAttributes.entrySet().iterator()
                    while iter3.hasNext():
                        entry = iter3.next()
                        name = entry.getKey()
                        if name in removeAtts:
                            continue
                        value = entry.getValue()
                        otherElement = Element(name)
                        otherElement.setText(value)
                        dependentElement.addContent(otherElement)

                relElement.addContent(dependentElement)
        rootElement.addContent(relElement)
        
    return rootElement    
コード例 #6
0
def addRelations(rootElement, allRelationChildren, mamIdToAttributesMap):
    removeAtts = ['family', 'class']
    iter = allRelationChildren.iterator()
    while iter.hasNext():
        relElement = Element('relation')
        linkElement = iter.next()
        linkType = linkElement.getAttribute(
            'targetRelationshipClass').getValue()
        targetParent = linkElement.getAttribute('targetParent').getValue()
        splitIdx_targetParent = string.rfind(targetParent, '.')
        targetParentFamilyName = targetParent[0:splitIdx_targetParent]
        targetParentClassName = targetParent[splitIdx_targetParent +
                                             1:len(targetParent)]

        targetChild = linkElement.getAttribute('targetChild').getValue()
        splitIdx_targetChild = string.rfind(targetChild, '.')
        targetChildFamilyName = targetChild[0:splitIdx_targetChild]
        targetChildClassName = targetChild[splitIdx_targetChild +
                                           1:len(targetChild)]

        id1base = ''
        id2base = ''
        if linkType != None and targetParent != None and targetChild != None:
            fieldChildren = linkElement.getChildren('field')
            if fieldChildren is not None:
                iter2 = fieldChildren.iterator()
                while iter2.hasNext():
                    fieldElement = iter2.next()
                    fieldName = fieldElement.getAttributeValue('name')
                    if fieldName == 'DiscoveryID1':
                        id1base = fieldElement.getText()
                    if fieldName == 'DiscoveryID2':
                        id2base = fieldElement.getText()

                # set type
                typeElement = Element('type')
                typeElement.setText(linkType)
                relElement.addContent(typeElement)

                # set provider
                providerElement = Element('provider')

                if mamIdToAttributesMap.containsKey(id1base):
                    otherProviderAttributes = mamIdToAttributesMap.get(id1base)
                    iter3 = otherProviderAttributes.entrySet().iterator()
                    while iter3.hasNext():
                        entry = iter3.next()
                        name = entry.getKey()
                        if name in removeAtts:
                            continue
                        value = entry.getValue()
                        otherElement = Element(name)
                        otherElement.setText(value)
                        providerElement.addContent(otherElement)

                relElement.addContent(providerElement)

                # set dependent
                dependentElement = Element('dependent')

                if mamIdToAttributesMap.containsKey(id2base):
                    otherdependentAttributes = mamIdToAttributesMap.get(
                        id2base)
                    iter3 = otherdependentAttributes.entrySet().iterator()
                    while iter3.hasNext():
                        entry = iter3.next()
                        name = entry.getKey()
                        if name in removeAtts:
                            continue
                        value = entry.getValue()
                        otherElement = Element(name)
                        otherElement.setText(value)
                        dependentElement.addContent(otherElement)

                relElement.addContent(dependentElement)
        rootElement.addContent(relElement)

    return rootElement