From d52570531e329c34418814cbfe237fa068d4b4b0 Mon Sep 17 00:00:00 2001 From: MBorne Date: Mon, 2 Aug 2021 16:28:34 +0200 Subject: [PATCH 1/4] validator-core - XSD_SCHEMA_ERROR - move line number from 'message' to 'id' --- .../ign/validator/validation/file/XsdSchemaValidator.java | 3 ++- validator-core/src/main/resources/error-code.json | 4 ++-- .../validation/file/XsdSchemaValidatorRegressTest.java | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/validator-core/src/main/java/fr/ign/validator/validation/file/XsdSchemaValidator.java b/validator-core/src/main/java/fr/ign/validator/validation/file/XsdSchemaValidator.java index 09ba6b03..582cf0f4 100644 --- a/validator-core/src/main/java/fr/ign/validator/validation/file/XsdSchemaValidator.java +++ b/validator-core/src/main/java/fr/ign/validator/validation/file/XsdSchemaValidator.java @@ -82,9 +82,10 @@ public void warning(SAXParseException e) { } private void report(SAXParseException e) { + // TODO retrieve more information from the exception context.report( context.createError(CoreErrorCodes.XSD_SCHEMA_ERROR) - .setMessageParam("LINE_NUMBER", "#" + e.getLineNumber()) + .setId(String.valueOf(e.getLineNumber())) // line number .setMessageParam("MESSAGE", e.getMessage()) ); } diff --git a/validator-core/src/main/resources/error-code.json b/validator-core/src/main/resources/error-code.json index f090120c..7a97d498 100644 --- a/validator-core/src/main/resources/error-code.json +++ b/validator-core/src/main/resources/error-code.json @@ -72,8 +72,8 @@ { "name": "XSD_SCHEMA_ERROR", "level": "ERROR", - "message": "{LINE_NUMBER} : {MESSAGE}", - "documentation": "Cette erreur se produit lors du nom respect d'un schéma XSD" + "message": "{MESSAGE}", + "documentation": "Cette erreur se produit lors du nom respect d'un schéma XSD associé à un fichier XML/GML" }, { "name": "TABLE_MISSING_ATTRIBUTE", diff --git a/validator-core/src/test/java/fr/ign/validator/validation/file/XsdSchemaValidatorRegressTest.java b/validator-core/src/test/java/fr/ign/validator/validation/file/XsdSchemaValidatorRegressTest.java index 35c11e30..4c1051e3 100644 --- a/validator-core/src/test/java/fr/ign/validator/validation/file/XsdSchemaValidatorRegressTest.java +++ b/validator-core/src/test/java/fr/ign/validator/validation/file/XsdSchemaValidatorRegressTest.java @@ -14,6 +14,7 @@ import fr.ign.validator.Context; import fr.ign.validator.error.CoreErrorCodes; import fr.ign.validator.error.ErrorLevel; +import fr.ign.validator.error.ErrorScope; import fr.ign.validator.error.ValidatorError; import fr.ign.validator.model.Projection; import fr.ign.validator.report.InMemoryReportBuilder; @@ -37,7 +38,7 @@ public void setUp() { context = new Context(); report = new InMemoryReportBuilder(); context.setReportBuilder(report); - context.setProjection(Projection.CODE_CRS84); // TODO + context.setProjection(Projection.CODE_CRS84); /* to access XML schema */ Networking.configureHttpClient(); @@ -95,10 +96,13 @@ public void testValidateGmlInfoPctInvalid() throws MalformedURLException { { ValidatorError error = report.getErrorsByCode(CoreErrorCodes.XSD_SCHEMA_ERROR).get(0); assertEquals(ErrorLevel.ERROR, error.getLevel()); + assertEquals(ErrorScope.DIRECTORY, error.getScope()); + // check line number + assertEquals("26", error.getId()); // see https://wiki.xmldation.com/Support/Validator/cvc-complex-type-2-4-d assertTrue( "unexpected message : " + error.getMessage(), - error.getMessage().startsWith("#26 : cvc-complex-type.2.4.d") + error.getMessage().startsWith("cvc-complex-type.2.4.d") ); } } From 5578154d3733a27ccf7e1bb83c0ede7e8746fc5a Mon Sep 17 00:00:00 2001 From: MBorne Date: Mon, 2 Aug 2021 16:57:33 +0200 Subject: [PATCH 2/4] validator-core - MULTITABLE_UNEXPECTED - simplify error message (refs #231) --- .../main/java/fr/ign/validator/data/file/MultiTableFile.java | 2 +- validator-core/src/main/resources/error-code.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/validator-core/src/main/java/fr/ign/validator/data/file/MultiTableFile.java b/validator-core/src/main/java/fr/ign/validator/data/file/MultiTableFile.java index 4c75d3ab..8ce5999f 100644 --- a/validator-core/src/main/java/fr/ign/validator/data/file/MultiTableFile.java +++ b/validator-core/src/main/java/fr/ign/validator/data/file/MultiTableFile.java @@ -65,7 +65,7 @@ protected void validateContent(Context context) { ); context.report( context.createError(CoreErrorCodes.MULTITABLE_UNEXPECTED) - .setMessageParam("FILEPATH", relativePath) + .setMessageParam("TABLENAME", tableName) ); continue; } diff --git a/validator-core/src/main/resources/error-code.json b/validator-core/src/main/resources/error-code.json index 7a97d498..b596692b 100644 --- a/validator-core/src/main/resources/error-code.json +++ b/validator-core/src/main/resources/error-code.json @@ -108,8 +108,8 @@ { "name": "MULTITABLE_UNEXPECTED", "level": "WARNING", - "message": "La table '{FILEPATH}' n'est pas prévue dans le modèle de validation.", - "documentation": "" + "message": "La table '{TABLENAME}' n'est pas prévue dans le modèle de validation.", + "documentation": "Une table est présente dans un fichier multi-table sans être définie dans le modèle. Elle est ignorée pour la validation, la normalisation et le calcul de statistique." }, { "name": "ATTRIBUTE_UNEXPECTED_NULL", From 61fb61769a9f9eea15265bf1603278fe5dd93de8 Mon Sep 17 00:00:00 2001 From: MBorne Date: Mon, 2 Aug 2021 17:02:36 +0200 Subject: [PATCH 3/4] validator-core - error.scope - fix HEADER for tables in MultiTable (refs #231) --- validator-core/src/main/java/fr/ign/validator/Context.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator-core/src/main/java/fr/ign/validator/Context.java b/validator-core/src/main/java/fr/ign/validator/Context.java index 10ac03a4..d1e9fb4f 100644 --- a/validator-core/src/main/java/fr/ign/validator/Context.java +++ b/validator-core/src/main/java/fr/ign/validator/Context.java @@ -17,8 +17,8 @@ import fr.ign.validator.data.Document; import fr.ign.validator.data.DocumentFile; import fr.ign.validator.data.Row; +import fr.ign.validator.data.Table; import fr.ign.validator.data.file.MetadataFile; -import fr.ign.validator.data.file.SingleTableFile; import fr.ign.validator.error.ErrorCode; import fr.ign.validator.error.ErrorFactory; import fr.ign.validator.error.ErrorScope; @@ -448,7 +448,7 @@ public T getDataByType(Class clazz) { public ErrorScope getScope() { if (getDataByType(Attribute.class) != null) { return ErrorScope.FEATURE; - } else if (getDataByType(SingleTableFile.class) != null) { + } else if (getDataByType(Table.class) != null) { return ErrorScope.HEADER; } else if (getDataByType(MetadataFile.class) != null) { return ErrorScope.METADATA; From 73eb080a8d15e4a9e64e3795b466acb32f27d7aa Mon Sep 17 00:00:00 2001 From: MBorne Date: Mon, 2 Aug 2021 17:40:35 +0200 Subject: [PATCH 4/4] validator-core - error.file - use an hash for tables in a MultiTable GML file (JeuxTestv2.gml#SeuilPCRS) --- validator-core/src/main/java/fr/ign/validator/Context.java | 6 ++++++ .../src/main/java/fr/ign/validator/data/Table.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/validator-core/src/main/java/fr/ign/validator/Context.java b/validator-core/src/main/java/fr/ign/validator/Context.java index d1e9fb4f..3e223ffb 100644 --- a/validator-core/src/main/java/fr/ign/validator/Context.java +++ b/validator-core/src/main/java/fr/ign/validator/Context.java @@ -464,6 +464,12 @@ public ErrorScope getScope() { * @return */ public String getFileName() { + // allows to group table in MultiTable using an # + Table table = getDataByType(Table.class); + if (table != null) { + return table.getRelativePath(); + } + DocumentFile documentFile = getDataByType(DocumentFile.class); if (documentFile != null) { return relativize(documentFile.getPath()); diff --git a/validator-core/src/main/java/fr/ign/validator/data/Table.java b/validator-core/src/main/java/fr/ign/validator/data/Table.java index d4ed3c38..8b81152f 100644 --- a/validator-core/src/main/java/fr/ign/validator/data/Table.java +++ b/validator-core/src/main/java/fr/ign/validator/data/Table.java @@ -45,6 +45,10 @@ public Table(FeatureType featureType, TableReader reader, String relativePath) { this.relativePath = relativePath; } + public String getRelativePath() { + return relativePath; + } + @Override public void validate(Context context) { context.beginData(this);