def validate_entity(self, entity: Entity): # identify which attribute cases the error attribute = 'fake_attribute' error_msg = 'Example error message' entity.add_error(attribute, error_msg) # or if multiple errors occur for the same attribute error_msgs = ['error 1', 'error 2'] entity.add_errors(attribute, error_msgs) raise NotImplementedError('Example validate entity used')
def __add_errors_to_entity(entity: Entity, schema_errors: dict): for schema_error in schema_errors: attribute_name = str(schema_error['dataPath']).strip('.') stripped_errors = [] for error in schema_error['errors']: error.replace('"', '\'') if error == 'should NOT be valid': error = JsonValidator.__improve_not_be_valid_error_message( entity.identifier.entity_type, attribute_name) if error != 'should match some schema in anyOf': stripped_errors.append(error) entity.add_errors(attribute_name, stripped_errors)
def validate_entity(self, entity: Entity): sample = entity.attributes sample_errors = {} if 'tax_id' in sample and 'scientific_name' in sample: tax_response = self.ena_taxonomy.validate_taxonomy( tax_id=sample['tax_id'], scientific_name=sample['scientific_name'] ) sample_errors = self.get_taxonomy_errors(tax_response) else: if 'tax_id' in sample: tax_response = self.ena_taxonomy.validate_tax_id(sample['tax_id']) sample_errors = self.get_errors(tax_response, 'tax_id') elif 'scientific_name' in sample: tax_response = self.ena_taxonomy.validate_scientific_name(sample['scientific_name']) sample_errors = self.get_errors(tax_response, 'scientific_name') for attribute, errors in sample_errors.items(): entity.add_errors(attribute, errors)