@Test public void ontologyWhenDateAsKeywordConversionThenOK() throws Exception { JsonNode data = JsonHandler.createObjectNode() .put("keyword", "2000-01-01"); ObjectNode updatedData = ontologyValidator.verifyAndReplaceFields(data); assertThat(updatedData).isEqualTo(data); }
public ObjectNode verifyAndReplaceFields(JsonNode jsonNode) throws MetadataValidationException { ObjectNode transformedJsonNode = jsonNode.deepCopy(); List<OntologyModel> ontologyModels = ontologyLoader.loadOntologies(); Map<String, OntologyModel> ontologyModelMap = ontologyModels.stream().collect(Collectors.toMap(OntologyModel::getIdentifier, oM -> oM)); List<String> errors = new ArrayList<>(); Iterator<Map.Entry<String, JsonNode>> iterator = transformedJsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); verifyLine(transformedJsonNode, ontologyModelMap, errors, entry); } if (!errors.isEmpty()) { String error = "Archive unit contains fields declared in ontology with a wrong format : " + CollectionUtils.join(errors, ","); throw new MetadataValidationException(MetadataValidationErrorCode.ONTOLOGY_VALIDATION_FAILURE, error); } return transformedJsonNode; }
OntologyValidator { public ObjectNode verifyAndReplaceFields(JsonNode jsonNode) throws MetadataValidationException { ObjectNode transformedJsonNode = jsonNode.deepCopy(); List<OntologyModel> ontologyModels = ontologyLoader.loadOntologies(); Map<String, OntologyModel> ontologyModelMap = ontologyModels.stream().collect(Collectors.toMap(OntologyModel::getIdentifier, oM -> oM)); List<String> errors = new ArrayList<>(); Iterator<Map.Entry<String, JsonNode>> iterator = transformedJsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); verifyLine(transformedJsonNode, ontologyModelMap, errors, entry); } if (!errors.isEmpty()) { String error = "Archive unit contains fields declared in ontology with a wrong format : " + CollectionUtils.join(errors, ","); throw new MetadataValidationException(MetadataValidationErrorCode.ONTOLOGY_VALIDATION_FAILURE, error); } return transformedJsonNode; } }
OntologyValidator { public ObjectNode verifyAndReplaceFields(JsonNode jsonNode) throws MetadataValidationException { ObjectNode transformedJsonNode = jsonNode.deepCopy(); List<OntologyModel> ontologyModels = ontologyLoader.loadOntologies(); Map<String, OntologyModel> ontologyModelMap = ontologyModels.stream().collect(Collectors.toMap(OntologyModel::getIdentifier, oM -> oM)); List<String> errors = new ArrayList<>(); Iterator<Map.Entry<String, JsonNode>> iterator = transformedJsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); verifyLine(transformedJsonNode, ontologyModelMap, errors, entry); } if (!errors.isEmpty()) { String error = "Archive unit contains fields declared in ontology with a wrong format : " + CollectionUtils.join(errors, ","); throw new MetadataValidationException(MetadataValidationErrorCode.ONTOLOGY_VALIDATION_FAILURE, error); } return transformedJsonNode; } OntologyValidator(OntologyLoader ontologyLoader); }
OntologyValidator { public ObjectNode verifyAndReplaceFields(JsonNode jsonNode) throws MetadataValidationException { ObjectNode transformedJsonNode = jsonNode.deepCopy(); List<OntologyModel> ontologyModels = ontologyLoader.loadOntologies(); Map<String, OntologyModel> ontologyModelMap = ontologyModels.stream().collect(Collectors.toMap(OntologyModel::getIdentifier, oM -> oM)); List<String> errors = new ArrayList<>(); Iterator<Map.Entry<String, JsonNode>> iterator = transformedJsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); verifyLine(transformedJsonNode, ontologyModelMap, errors, entry); } if (!errors.isEmpty()) { String error = "Archive unit contains fields declared in ontology with a wrong format : " + CollectionUtils.join(errors, ","); throw new MetadataValidationException(MetadataValidationErrorCode.ONTOLOGY_VALIDATION_FAILURE, error); } return transformedJsonNode; } OntologyValidator(OntologyLoader ontologyLoader); ObjectNode verifyAndReplaceFields(JsonNode jsonNode); }
OntologyValidator { public ObjectNode verifyAndReplaceFields(JsonNode jsonNode) throws MetadataValidationException { ObjectNode transformedJsonNode = jsonNode.deepCopy(); List<OntologyModel> ontologyModels = ontologyLoader.loadOntologies(); Map<String, OntologyModel> ontologyModelMap = ontologyModels.stream().collect(Collectors.toMap(OntologyModel::getIdentifier, oM -> oM)); List<String> errors = new ArrayList<>(); Iterator<Map.Entry<String, JsonNode>> iterator = transformedJsonNode.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); verifyLine(transformedJsonNode, ontologyModelMap, errors, entry); } if (!errors.isEmpty()) { String error = "Archive unit contains fields declared in ontology with a wrong format : " + CollectionUtils.join(errors, ","); throw new MetadataValidationException(MetadataValidationErrorCode.ONTOLOGY_VALIDATION_FAILURE, error); } return transformedJsonNode; } OntologyValidator(OntologyLoader ontologyLoader); ObjectNode verifyAndReplaceFields(JsonNode jsonNode);  }