Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 231 - improve reports for XSD and MultiTable validation #245

Merged
merged 4 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions validator-core/src/main/java/fr/ign/validator/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -448,7 +448,7 @@ public <T extends Validatable> T getDataByType(Class<T> 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;
Expand All @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions validator-core/src/main/java/fr/ign/validator/data/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void validateContent(Context context) {
);
context.report(
context.createError(CoreErrorCodes.MULTITABLE_UNEXPECTED)
.setMessageParam("FILEPATH", relativePath)
.setMessageParam("TABLENAME", tableName)
);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
Expand Down
8 changes: 4 additions & 4 deletions validator-core/src/main/resources/error-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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")
);
}
}
Expand Down