Esempio n. 1
0
    def fillOshDict(self, processor, attrDefs):
        """
        Sets OSHs attributes and stores them in the inner dictionaries.
        SheetProcessor, {str: AttrTypeDef} -> None
        """
        sheetName = processor.getSheetName()
        for rowNum in xrange(1, processor.getLastRowNum()+1):
            osh = ObjectStateHolder(sheetName)
            reference = self.getOshKey(sheetName, rowNum)
            compositeKey = None

            for colNum in xrange(processor.getLastColNum(0)):
                attrName = processor.getCellValueAt(0, colNum)
                if not attrName:
                    logger.debug('Column doesn\'t have the header representing an attribute name')
                    continue
                if attrName.startswith(self.__COMMENT_START) or attrName == 'root_container':
                    continue
                try:
                    attrValue = processor.getCellValueAt(rowNum, colNum)
                    if attrValue and ((type(attrValue) == type(' ')) or (type(attrValue) == type(u' '))):
                        attrValue = attrValue.strip()
                    if attrValue or self.set_empty_value:
                        self.classModelUtils.setCiAttribute(osh, attrName, attrValue, attrDefs[attrName].attrType)
                        #TODO: this part is left for backward compatibility
                        #this code allows to refer CIs by composition of key attributes
                        #but without class name and should be deprecated
                        #@see:  resolveOsh method
                        if attrDefs[attrName].isId:
                            if compositeKey:
                                if type(attrValue) in [type(u''), type('')]:
                                    compositeKey += self.__KEY_DELIMITER + attrValue
                                else:
                                    compositeKey += self.__KEY_DELIMITER + str(attrValue)
                            else:
                                compositeKey = attrValue
                except Exception, e:
                    logger.debugException(reference)
                    logger.reportWarning(e.args[0])

            if osh.getAttributeAll().size() == 0:
                continue

            #prepare references to object in view like 'key1|key2|key3' -> OSH
            if compositeKey:
                if self.oshByCompositeKeys.has_key(compositeKey):
                    logger.reportWarning('Object references are overlapped. Not all relations can be assigned')
                    logger.warn("%s %i: Object reference '%s' is overlapped. It won't be accessible. " % (sheetName, rowNum, compositeKey))
                    self.oshByCompositeKeysCount[compositeKey] = self.oshByCompositeKeysCount[compositeKey] + 1
                    self.oshByCompositeKeys[compositeKey] = osh
                else:
                    self.oshByCompositeKeys[compositeKey] = osh
                    self.oshByCompositeKeysCount[compositeKey] = 1

            #prepare object reference in form 'sheetName rowNumber' to uniquely identify OSH
            if self.keysToOsh.has_key(reference):
                raise Exception, 'This can only happen if references map was modified outside'
            else:
                self.keysToOsh[reference] = osh
Esempio n. 2
0
    def fillOshDict(self, processor, attrDefs):
        """
        Sets OSHs attributes and stores them in the inner dictionaries.
        SheetProcessor, {str: AttrTypeDef} -> None
        """
        sheetName = processor.getSheetName()
        for rowNum in xrange(1, processor.getLastRowNum() + 1):
            osh = ObjectStateHolder(sheetName)
            reference = self.getOshKey(sheetName, rowNum)
            compositeKey = None

            for colNum in xrange(processor.getLastColNum(0)):
                attrName = processor.getCellValueAt(0, colNum)
                if not attrName:
                    logger.debug(
                        'Column doesn\'t have the header representing an attribute name'
                    )
                    continue
                if attrName.startswith(
                        self.__COMMENT_START) or attrName == 'root_container':
                    continue
                try:
                    attrValue = processor.getCellValueAt(rowNum, colNum)
                    if attrValue and ((type(attrValue) == type(' ')) or
                                      (type(attrValue) == type(u' '))):
                        attrValue = attrValue.strip()
                    if attrValue or self.set_empty_value:
                        self.classModelUtils.setCiAttribute(
                            osh, attrName, attrValue,
                            attrDefs[attrName].attrType)
                        #TODO: this part is left for backward compatibility
                        #this code allows to refer CIs by composition of key attributes
                        #but without class name and should be deprecated
                        #@see:  resolveOsh method
                        if attrDefs[attrName].isId:
                            if compositeKey:
                                if type(attrValue) in [type(u''), type('')]:
                                    compositeKey += self.__KEY_DELIMITER + attrValue
                                else:
                                    compositeKey += self.__KEY_DELIMITER + str(
                                        attrValue)
                            else:
                                compositeKey = attrValue
                except Exception, e:
                    logger.debugException(reference)
                    logger.reportWarning(e.args[0])

            if osh.getAttributeAll().size() == 0:
                continue

            #prepare references to object in view like 'key1|key2|key3' -> OSH
            if compositeKey:
                if self.oshByCompositeKeys.has_key(compositeKey):
                    logger.reportWarning(
                        'Object references are overlapped. Not all relations can be assigned'
                    )
                    logger.warn(
                        "%s %i: Object reference '%s' is overlapped. It won't be accessible. "
                        % (sheetName, rowNum, compositeKey))
                    self.oshByCompositeKeysCount[
                        compositeKey] = self.oshByCompositeKeysCount[
                            compositeKey] + 1
                    self.oshByCompositeKeys[compositeKey] = osh
                else:
                    self.oshByCompositeKeys[compositeKey] = osh
                    self.oshByCompositeKeysCount[compositeKey] = 1

            #prepare object reference in form 'sheetName rowNumber' to uniquely identify OSH
            if self.keysToOsh.has_key(reference):
                raise Exception, 'This can only happen if references map was modified outside'
            else:
                self.keysToOsh[reference] = osh