(self, data)
Check the values in a line of data.
Check the values in a line of data.
Check the values in a line of data .
def checkLine(self, data):
        """Check the values in a line of data."""
        super(StudyResourceValidator, self).checkLine(data)
        resource_id = ''
        resource_url = ''
        for col_index, col_name in enumerate(self.cols):
            # treat cells beyond the end of the line as blanks,
            # super().checkLine() has already logged an error
            value = ''
            if col_index < len(data):
                value = data[col_index].strip()
            # make sure RESOURCE_ID is defined correctly
            if col_name == 'RESOURCE_ID':
                if value not in RESOURCE_DEFINITION_DICTIONARY or 'STUDY' not in RESOURCE_DEFINITION_DICTIONARY[value]:
                    self.logger.error(
                        'RESOURCE_ID for study resource is not defined correctly in resource definition file',
                        extra={'line_number': self.line_number,
                               'column_number': col_index + 1,
                               'cause': value})
                if value in RESOURCE_DEFINITION_DICTIONARY and len(RESOURCE_DEFINITION_DICTIONARY[value]) > 1:
                    self.logger.warning(
                        'RESOURCE_ID for study resource has been used by more than one RESOURCE_TYPE',
                        extra={'line_number': self.line_number,
                               'column_number': col_index + 1,
                               'cause': RESOURCE_DEFINITION_DICTIONARY[value]})
            resource_id = value
            if col_name == 'URL':
                resource_url = value
        # check duplicate
        if (resource_id, resource_url) in self.defined_resources:
            self.logger.error(
                'Duplicated resources found',
                extra={'line_number': self.line_number,
                        'duplicated_line_number': self.defined_resources[(resource_id, resource_url)]})
        else:
            self.defined_resources[(resource_id, resource_url)] = self.line_number
def checkLine ( self , data ) : super ( StudyResourceValidator , self ) . checkLine ( data ) resource_id = '' resource_url = '' for col_index , col_name in enumerate ( self . cols ) : # treat cells beyond the end of the line as blanks, # super().checkLine() has already logged an error value = '' if col_index < len ( data ) : value = data [ col_index ] . strip ( ) # make sure RESOURCE_ID is defined correctly if col_name == 'RESOURCE_ID' : if value not in RESOURCE_DEFINITION_DICTIONARY or 'STUDY' not in RESOURCE_DEFINITION_DICTIONARY [ value ] : self . logger . error ( 'RESOURCE_ID for study resource is not defined correctly in resource definition file' , extra = { 'line_number' : self . line_number , 'column_number' : col_index + 1 , 'cause' : value } ) if value in RESOURCE_DEFINITION_DICTIONARY and len ( RESOURCE_DEFINITION_DICTIONARY [ value ] ) > 1 : self . logger . warning ( 'RESOURCE_ID for study resource has been used by more than one RESOURCE_TYPE' , extra = { 'line_number' : self . line_number , 'column_number' : col_index + 1 , 'cause' : RESOURCE_DEFINITION_DICTIONARY [ value ] } ) resource_id = value if col_name == 'URL' : resource_url = value # check duplicate if ( resource_id , resource_url ) in self . defined_resources : self . logger . error ( 'Duplicated resources found' , extra = { 'line_number' : self . line_number , 'duplicated_line_number' : self . defined_resources [ ( resource_id , resource_url ) ] } ) else : self . defined_resources [ ( resource_id , resource_url ) ] = self . line_number