Skip to content
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
16 changes: 16 additions & 0 deletions validator-core/src/main/java/fr/ign/validator/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import fr.ign.validator.data.Attribute;
import fr.ign.validator.data.Document;
import fr.ign.validator.data.DocumentFile;
import fr.ign.validator.data.Header;
import fr.ign.validator.data.Row;
import fr.ign.validator.data.Table;
import fr.ign.validator.data.file.MetadataFile;
Expand Down Expand Up @@ -160,6 +161,11 @@ public class Context {
*/
private boolean enableConditions = false;

/**
* Header class to use.
*/
private Class<?> headerClass = Header.class;

public Context() {
registerDefaultListeners();
}
Expand Down Expand Up @@ -817,4 +823,14 @@ public void setEnableConditions(boolean enableConditions) {
this.enableConditions = enableConditions;
}

public void setHeaderClass(Class<?> class1) {
if (Header.class.isAssignableFrom(class1)) {
this.headerClass = class1;
}
}

public Class<?> getHeaderClass() {
return this.headerClass;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,6 @@ private void addDocumentFile(FileModel fileModel, File path) {
private void addMisplacedDocumentFiles(Context context) {

for (MisplacedFile misplacedFile : this.misplacedFileManager.getMisplacedFiles()) {
if (misplacedFile.getStatus() == MisplacedFile.Status.FILE_MODEL_OVERLOAD) {
context.report(
context.createError(CoreErrorCodes.FILE_MODEL_OVERLOAD)
.setMessageParam("FILEMODEL", misplacedFile.getFileModel().getName())
);
}
addDocumentFile(misplacedFile.getFileModel(), misplacedFile.getFile());
}
}
Expand Down
24 changes: 19 additions & 5 deletions validator-core/src/main/java/fr/ign/validator/data/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public Header(String relativePath, FeatureTypeMapper mapping) {
this.mapping = mapping;
}

public String getRelativePath() {
return this.relativePath;
}

@Override
public void validate(Context context) {
context.beginData(this);
Expand Down Expand Up @@ -70,11 +74,7 @@ public void validate(Context context) {
.setMessageParam("FILEPATH", relativePath)
);
} else if (!missingAttribute.getConstraints().isRequired()) {
context.report(
context.createError(CoreErrorCodes.TABLE_MISSING_NULLABLE_ATTRIBUTE)
.setMessageParam("ATTRIBUTE_NAME", missingAttribute.getName())
.setMessageParam("FILEPATH", relativePath)
);
this.reportTableMissingNullableAttribute(missingAttribute, context);
} else {
context.report(
context.createError(CoreErrorCodes.TABLE_MISSING_ATTRIBUTE)
Expand All @@ -88,4 +88,18 @@ public void validate(Context context) {
context.endData(this);
}

/**
* Create report when missing attribute is required
*
* @param missingAttribute
* @param context
*/
public void reportTableMissingNullableAttribute(AttributeType<?> missingAttribute, Context context) {
context.report(
context.createError(CoreErrorCodes.TABLE_MISSING_NULLABLE_ATTRIBUTE)
.setMessageParam("ATTRIBUTE_NAME", missingAttribute.getName())
.setMessageParam("FILEPATH", relativePath)
);
}

}
18 changes: 16 additions & 2 deletions validator-core/src/main/java/fr/ign/validator/data/Table.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.ign.validator.data;

import java.lang.reflect.Constructor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
Expand Down Expand Up @@ -71,8 +73,20 @@ public void doValidate(Context context) {
*/
String[] columns = reader.getHeader();
FeatureTypeMapper mapping = new FeatureTypeMapper(columns, featureType);
Header header = new Header(relativePath, mapping);
header.validate(context);

try {
Class<?> headerClass = context.getHeaderClass();
log.info(MARKER, "headerClass: {}", headerClass.getName());
Constructor<?> headerConstructor = headerClass.getConstructor(String.class, FeatureTypeMapper.class);
Header header = (Header) headerConstructor.newInstance(relativePath, mapping);
log.info(MARKER, "header: {}", header.getClass().getName());
header.validate(context);
} catch (Exception e) {
log.error(MARKER, "FATAL ERROR. message: {} ; trace: {}", e.getMessage(), e.getStackTrace());
context.report(
context.createError(CoreErrorCodes.VALIDATOR_EXCEPTION)
);
}

/*
* feature validation
Expand Down
6 changes: 6 additions & 0 deletions validator-core/src/main/resources/error-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@
"message": "Seuls les fichiers avec les extensions suivantes sont autorisés : xml, pdf, csv, MapInfo (map, mid), ArcGIS (shp, dbf), geojson, gml",
"documentation": ""
},
{
"name": "CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE",
"level": "ERROR",
"message": "Le fichier optionnel '{FILEMODEL_NAME}' est absent du document.",
"documentation": "Cette erreur se produit lorsqu'un fichier marqué comme mandatory=WARNING est absent dans le cadre d'une validation CNIG."
},
{
"name": "CNIG_IDURBA_INVALID",
"level": "ERROR",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.ign.validator.cnig;

import fr.ign.validator.Context;
import fr.ign.validator.cnig.data.CnigHeader;
import fr.ign.validator.cnig.process.CreateShapefilesPostProcess;
import fr.ign.validator.cnig.process.CustomizeIdurbaPreProcess;
import fr.ign.validator.cnig.process.DocUrbaComPostProcess;
Expand Down Expand Up @@ -48,6 +49,11 @@ public void setup(Context context) {
// --normalize is required with CNIG plugin
context.setNormalizeEnabled(true);

/**
* Use CnigHeader class instead of Header
*/
context.setHeaderClass(CnigHeader.class);

/*
* PreProcess - Customize idurba
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.ign.validator.cnig.data;

import fr.ign.validator.Context;
import fr.ign.validator.cnig.error.CnigErrorCodes;
import fr.ign.validator.data.Header;
import fr.ign.validator.mapping.FeatureTypeMapper;
import fr.ign.validator.model.AttributeType;

public class CnigHeader extends Header {

/**
* @param columns
* @param mapping
*/
public CnigHeader(String relativePath, FeatureTypeMapper mapping) {
super(relativePath, mapping);
}

@Override
public void reportTableMissingNullableAttribute(AttributeType<?> missingAttribute, Context context) {
context.report(
context.createError(CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE)
.setMessageParam("ATTRIBUTE_NAME", missingAttribute.getName())
.setMessageParam("FILEPATH", this.getRelativePath())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public class CnigErrorCodes {
public static final ErrorCode CNIG_PIECE_ECRITE_ONLY_PDF = ErrorCode.valueOf("CNIG_PIECE_ECRITE_ONLY_PDF");
public static final ErrorCode CNIG_FILE_EXTENSION_INVALID = ErrorCode.valueOf("CNIG_FILE_EXTENSION_INVALID");

/**
* Overrides CORE_TABLE_MISSING_NULLABLE_ATTRIBUTE
*/
public static final ErrorCode CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE = ErrorCode.valueOf(
"CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE"
);

/**
* DU - Reported when ZONE_URBA.IDURBA doesn't match any format
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public void test50545_CC_20130902() throws Exception {
*/
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_METADATA_SPECIFICATION_NOT_FOUND, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_METADATA_REFERENCESYSTEMIDENTIFIER_URI_NOT_FOUND, report);
ReportAssert.assertCount(2, ErrorLevel.ERROR, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(1 + 1 + 1, ErrorLevel.ERROR, report);

/*
* check warnings
Expand All @@ -222,9 +223,10 @@ public void test50545_CC_20130902() throws Exception {
/*
* check some infos
*/
ReportAssert.assertCount(1, CoreErrorCodes.TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(0, CoreErrorCodes.TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
{
ValidatorError error = report.getErrorsByCode(CoreErrorCodes.TABLE_MISSING_NULLABLE_ATTRIBUTE).get(0);
ValidatorError error = report.getErrorsByCode(CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE).get(0);
assertEquals("DATECOG", error.getAttribute());
}

Expand Down Expand Up @@ -325,7 +327,8 @@ public void test19182_CC_20150517() throws Exception {
ReportAssert.assertCount(2, CoreErrorCodes.ATTRIBUTE_GEOMETRY_INVALID, report);
ReportAssert.assertCount(19, CoreErrorCodes.ATTRIBUTE_UNEXPECTED_VALUE, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_GEOMETRY_COMPLEXITY_ERROR, report);
ReportAssert.assertCount(1 + 2 + 2 + 19 + 1, ErrorLevel.ERROR, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(1 + 2 + 2 + 19 + 1 + 1, ErrorLevel.ERROR, report);

/*
* check warnings
Expand Down Expand Up @@ -760,7 +763,10 @@ public void test30014_PLU_20171013() throws Exception {
ReportAssert.assertCount(0, CoreErrorCodes.DATABASE_CONSTRAINT_MISMATCH, report);
ReportAssert.assertCount(1, CoreErrorCodes.TABLE_FOREIGN_KEY_NOT_FOUND, report);
ReportAssert.assertCount(2, CnigErrorCodes.CNIG_PIECE_ECRITE_ONLY_PDF, report);
ReportAssert.assertCount(23, ErrorLevel.ERROR, report);
ReportAssert.assertCount(6, CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(1, CoreErrorCodes.ATTRIBUTE_UNEXPECTED_VALUE, report);
ReportAssert.assertCount(1, CoreErrorCodes.ATTRIBUTE_FILE_NOT_FOUND, report);
ReportAssert.assertCount(18 + 0 + 1 + 2 + 6 + 1 + 1, ErrorLevel.ERROR, report);
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_GENERATEUR_SUP_NOT_FOUND, report);
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_ASSIETTE_SUP_NOT_FOUND, report);

Expand Down Expand Up @@ -825,7 +831,7 @@ public void test30014_PLU_20171013_flatOption() throws Exception {
* check errors
*/
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_PIECE_ECRITE_ONLY_PDF, report);
ReportAssert.assertCount(21, ErrorLevel.ERROR, report);
ReportAssert.assertCount(27, ErrorLevel.ERROR, report);

/*
* check warnings
Expand Down Expand Up @@ -875,7 +881,8 @@ public void test200011781_PLUi_20180101() throws Exception {
*/
ReportAssert.assertCount(4, CoreErrorCodes.ATTRIBUTE_GEOMETRY_INVALID, report);
ReportAssert.assertCount(1, CoreErrorCodes.ATTRIBUTE_INVALID_REGEXP, report);
ReportAssert.assertCount(5, ErrorLevel.ERROR, report);
ReportAssert.assertCount(1, CnigErrorCodes.CNIG_TABLE_MISSING_NULLABLE_ATTRIBUTE, report);
ReportAssert.assertCount(4 + 1 + 1, ErrorLevel.ERROR, report);

/*
* check warnings
Expand Down