Exemple #1
0
def buildIntermediateCiXML(theCiElement, objectFromARIS):
    try:
        theCiElement.setAttribute('type', objectFromARIS.type)
        objectAttributeMap = objectFromARIS.attMap
        ## Add CI attributes
        if objectAttributeMap:
            for objectAttributeName in objectAttributeMap.keys():
                if objectAttributeName and objectAttributeMap[
                        objectAttributeName]:
                    fieldElement = Element('field')
                    fieldElement.setAttribute('name', objectAttributeName)
                    fieldElement.setText(
                        objectAttributeMap[objectAttributeName])
                    theCiElement.addContent(fieldElement)
                else:
                    debugPrint(
                        3, '[' + SCRIPT_NAME +
                        ':buildIntermediateCiXML] Skipping attribute <%s> with invalid value'
                        % objectAttributeName)
        return 1
    except:
        excInfo = logger.prepareJythonStackTrace('')
        debugPrint('[' + SCRIPT_NAME +
                   ':buildIntermediateCiXML] Exception: <%s>' % excInfo)
        return -1
Exemple #2
0
def buildIntermediateCiXML(theCiElement, objectFromARIS):
	try:
		theCiElement.setAttribute('type', objectFromARIS.type)
		objectAttributeMap = objectFromARIS.attMap
		## Add CI attributes
		if objectAttributeMap:
			for objectAttributeName in objectAttributeMap.keys():
				if objectAttributeName and objectAttributeMap[objectAttributeName]:
					fieldElement = Element('field')
					fieldElement.setAttribute('name', objectAttributeName)
					fieldElement.setText(objectAttributeMap[objectAttributeName])
					theCiElement.addContent(fieldElement)
				else:
					debugPrint(3, '[' + SCRIPT_NAME + ':buildIntermediateCiXML] Skipping attribute <%s> with invalid value' % objectAttributeName)
		return 1
	except:
		excInfo = logger.prepareJythonStackTrace('')
		debugPrint('[' + SCRIPT_NAME + ':buildIntermediateCiXML] Exception: <%s>' % excInfo)
		return -1
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)
Exemple #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)
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    
Exemple #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