Skip to content

Commit

Permalink
Merge pull request #282 from IGNF/issue_281
Browse files Browse the repository at this point in the history
validator-plugin-cnig: control at least one assiette/generateur file
  • Loading branch information
cboucheIGN authored Sep 8, 2022
2 parents 4ee68e6 + 408ffc3 commit 0db70c5
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 12 deletions.
12 changes: 12 additions & 0 deletions validator-core/src/main/resources/error-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,18 @@
"message": "Le code de territoire '{EMPRISE}' est invalide dans le nom de dossier.",
"documentation": "Les départements doivent être codés sur 3 caractères."
},
{
"name": "CNIG_GENERATEUR_SUP_NOT_FOUND",
"level": "ERROR",
"message": "Aucun générateur trouvée.",
"documentation": "Selon la catégorie de SUP des géométries sont autorisées, au moins une doit être présente."
},
{
"name": "CNIG_ASSIETTE_SUP_NOT_FOUND",
"level": "ERROR",
"message": "Aucune assiette trouvée.",
"documentation": "Selon la catégorie de SUP des géométries sont autorisées, au moins une doit être présente."
},
{
"name": "DGPR_DOCUMENT_PREFIX_ERROR",
"level": "WARNING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import fr.ign.validator.cnig.process.SupRelationsPostProcess;
import fr.ign.validator.cnig.validation.attribute.GeometryComplexityValidator;
import fr.ign.validator.cnig.validation.attribute.InseeValidator;
import fr.ign.validator.cnig.validation.document.AtLeastOneAssietteValidator;
import fr.ign.validator.cnig.validation.document.AtLeastOneGenerateurValidator;
import fr.ign.validator.cnig.validation.document.AtLeastOneWritingMaterialValidator;
import fr.ign.validator.cnig.validation.document.DocumentNameValidator;
import fr.ign.validator.cnig.validation.metadata.CnigMetadataDateOfLastRevisionValidator;
Expand Down Expand Up @@ -43,39 +45,51 @@ public void setup(Context context) {
context.setNormalizeEnabled(true);

/*
* Join SUP files to add a column "fichiers" and "nomsuplitt" (must run before
* CreateShapefilesPostProcess)
* PreProcess - Customize idurba
*/
context.addListener(new CustomizeIdurbaPreProcess());

/*
* PostProcess - Join SUP files to add a column "fichiers" and "nomsuplitt"
* (must run before CreateShapefilesPostProcess)
*/
context.addListener(new SupRelationsPostProcess());
/*
* Converts DATA/*.csv to DATA/*.shp (must follow ReferenceActeSupPostProcess)
* PostProcess- Converts DATA/*.csv to DATA/*.shp (must follow
* ReferenceActeSupPostProcess)
*/
context.addListener(new CreateShapefilesPostProcess());
/*
* Compute document.tag.typeref (must run before document-info.json generation)
* PostProcess - Compute document.tag.typeref (must run before
* document-info.json generation)
*/
context.addListenerBefore(
new DocUrbaPostProcess(),
DocumentInfoExtractorPostProcess.class
);

/*
* Extends DOC_URBA_COM validation
* PostProcess - DOC_URBA_COM validation for PLUi
*/
context.addListener(new DocUrbaComPostProcess());

/*
* Extends PERIMETRE_SCOT validation
* PostProcess - Extends PERIMETRE_SCOT validation
*/
context.addListener(new PerimetreScotPostProcess());

/*
* Extends document validation
*/
context.addListener(new DocumentNameValidator());
context.addListener(new AtLeastOneWritingMaterialValidator());
context.addListener(new AtLeastOneGenerateurValidator());
context.addListener(new AtLeastOneAssietteValidator());

/*
* Extends attribute validation
*/
context.addListener(new InseeValidator());
context.addListener(new AtLeastOneWritingMaterialValidator());
context.addListener(new DocumentNameValidator());
context.addListener(new CustomizeIdurbaPreProcess());
context.addListener(new GeometryComplexityValidator());

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class CnigErrorCodes {
public static final ErrorCode CNIG_SUP_IDGEN_NOT_FOUND = ErrorCode.valueOf(
"CNIG_SUP_IDGEN_NOT_FOUND"
);
/**
* SUP - reported when no generateur / assiette file found
*/
public static final ErrorCode CNIG_GENERATEUR_SUP_NOT_FOUND = ErrorCode.valueOf("CNIG_GENERATEUR_SUP_NOT_FOUND");
public static final ErrorCode CNIG_ASSIETTE_SUP_NOT_FOUND = ErrorCode.valueOf("CNIG_ASSIETTE_SUP_NOT_FOUND");

public static final ErrorCode CNIG_METADATA_SPECIFICATION_NOT_FOUND = ErrorCode.valueOf(
"CNIG_METADATA_SPECIFICATION_NOT_FOUND"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class DocumentModelName {

private static final String REGEXP_YYYY = "[0-9]{4}";

public static final String TYPE_SUP = "SUP";
public static final String TYPE_SCOT = "SCOT";
public static final String TYPE_PLU = "PLU";

/**
* Test if document model is a CNIG standard
*
Expand All @@ -38,6 +42,19 @@ public static String getDocumentType(String documentModelName) {
return parts[1];
}

/**
* Check that document name belong to SUP type
*
* @param documentModelName
* @return
*/
public static boolean isDocumentModelSup(String documentModelName) {
if (getDocumentType(documentModelName) != null) {
return getDocumentType(documentModelName).toUpperCase().equals(TYPE_SUP);
}
return false;
}

/**
* Get version
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.ign.validator.cnig.validation.document;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import fr.ign.validator.Context;
import fr.ign.validator.ValidatorListener;
import fr.ign.validator.cnig.error.CnigErrorCodes;
import fr.ign.validator.cnig.model.DocumentModelName;
import fr.ign.validator.data.Document;
import fr.ign.validator.data.DocumentFile;
import fr.ign.validator.model.TableModel;
import fr.ign.validator.validation.Validator;

public class AtLeastOneAssietteValidator implements Validator<Document>, ValidatorListener {

public static final Logger log = LogManager.getRootLogger();
public static final Marker MARKER = MarkerManager.getMarker("AtLeastOneAssietteValidator");

@Override
public void validate(Context context, Document document) {
if (!DocumentModelName.isDocumentModelSup(document.getDocumentModel().getName())) {
log.info(MARKER, "Skip control if document model is not a SUP.");
return;
}
log.info(MARKER, "Ensure that document contains at least one assiete file...");
int count = 0;
for (DocumentFile documentFile : document.getDocumentFiles()) {
if (!(documentFile.getFileModel() instanceof TableModel)) {
continue;
}
if (documentFile.getFileModel().getName().contains("ASSIETTE")) {
count++;
}
}
log.info(MARKER, "Found {} ASSIETTE file(s).", count);
if (count == 0) {
context.report(CnigErrorCodes.CNIG_ASSIETTE_SUP_NOT_FOUND);
}
}

@Override
public void beforeMatching(Context context, Document document) throws Exception {

}

@Override
public void beforeValidate(Context context, Document document) throws Exception {
document.getDocumentModel().addValidator(this);
}

@Override
public void afterValidate(Context context, Document document) throws Exception {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.ign.validator.cnig.validation.document;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import fr.ign.validator.Context;
import fr.ign.validator.ValidatorListener;
import fr.ign.validator.cnig.error.CnigErrorCodes;
import fr.ign.validator.cnig.model.DocumentModelName;
import fr.ign.validator.data.Document;
import fr.ign.validator.data.DocumentFile;
import fr.ign.validator.model.TableModel;
import fr.ign.validator.validation.Validator;

public class AtLeastOneGenerateurValidator implements Validator<Document>, ValidatorListener {

public static final Logger log = LogManager.getRootLogger();
public static final Marker MARKER = MarkerManager.getMarker("AtLeastOneGenerateurValidator");

@Override
public void validate(Context context, Document document) {
if (!DocumentModelName.isDocumentModelSup(document.getDocumentModel().getName())) {
log.info(MARKER, "Skip control if document model is not a SUP.");
return;
}
log.info(MARKER, "Ensure that document contains at least one generateur file...");
int count = 0;
for (DocumentFile documentFile : document.getDocumentFiles()) {
if (!(documentFile.getFileModel() instanceof TableModel)) {
continue;
}
if (documentFile.getFileModel().getName().contains("GENERATEUR")) {
count++;
}
}
log.info(MARKER, "Found {} GENERATEUR file(s).", count);
if (count == 0) {
context.report(CnigErrorCodes.CNIG_GENERATEUR_SUP_NOT_FOUND);
}
}

@Override
public void beforeMatching(Context context, Document document) throws Exception {

}

@Override
public void beforeValidate(Context context, Document document) throws Exception {
document.getDocumentModel().addValidator(this);
}

@Override
public void afterValidate(Context context, Document document) throws Exception {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ public void testIsCnigStandard() {
public void testGetDocumentType() {
assertNull(DocumentModelName.getDocumentType("cnig"));

assertEquals("SCOT", DocumentModelName.getDocumentType("cnig_SCOT_2013"));
assertEquals("PLU", DocumentModelName.getDocumentType("cnig_PLU_2013"));
assertEquals("SUP", DocumentModelName.getDocumentType("cnig_SUP_AC2_2013"));
assertEquals(DocumentModelName.TYPE_SCOT, DocumentModelName.getDocumentType("cnig_SCOT_2013"));
assertEquals(DocumentModelName.TYPE_PLU, DocumentModelName.getDocumentType("cnig_PLU_2013"));
assertEquals(DocumentModelName.TYPE_SUP, DocumentModelName.getDocumentType("cnig_SUP_AC2_2013"));
}

@Test
public void testIsDocumentSup() {
assertFalse(DocumentModelName.isDocumentModelSup("cnig"));

assertFalse(DocumentModelName.isDocumentModelSup("cnig_SCOT_2013"));
assertFalse(DocumentModelName.isDocumentModelSup("cnig_PLU_2013"));
assertTrue(DocumentModelName.isDocumentModelSup("cnig_SUP_AC2_2013"));
assertTrue(DocumentModelName.isDocumentModelSup("cnig_sup_ac2_2013"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import fr.ign.validator.cnig.CnigRegressHelper;
import fr.ign.validator.cnig.ReportAssert;
import fr.ign.validator.cnig.error.CnigErrorCodes;
import fr.ign.validator.cnig.model.DocumentModelName;
import fr.ign.validator.cnig.model.DocumentName;
import fr.ign.validator.cnig.model.DocumentType;
import fr.ign.validator.data.Document;
import fr.ign.validator.error.CoreErrorCodes;
import fr.ign.validator.error.ErrorLevel;
Expand Down Expand Up @@ -659,6 +662,9 @@ public void test213000896_INT1_83044_20160130() throws Exception {
*/
Assert.assertEquals(StandardCharsets.UTF_8, context.getEncoding());
Assert.assertEquals("213000896_INT1_83044_20160130", document.getDocumentName());
DocumentName documentName = new DocumentName(document.getDocumentName());
Assert.assertEquals(DocumentType.SUP, documentName.getDocumentType());
Assert.assertTrue(DocumentModelName.isDocumentModelSup(document.getDocumentModel().getName()));

/*
* check document-info.json
Expand All @@ -682,6 +688,9 @@ public void test213000896_INT1_83044_20160130() throws Exception {
}
}

ReportAssert.assertCount(0, CnigErrorCodes.CNIG_GENERATEUR_SUP_NOT_FOUND, report);
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_ASSIETTE_SUP_NOT_FOUND, report);

}

/**
Expand Down Expand Up @@ -717,6 +726,8 @@ 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(20, ErrorLevel.ERROR, report);
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_GENERATEUR_SUP_NOT_FOUND, report);
ReportAssert.assertCount(0, CnigErrorCodes.CNIG_ASSIETTE_SUP_NOT_FOUND, report);

{
ValidatorError error = report.getErrorsByCode(CoreErrorCodes.TABLE_FOREIGN_KEY_NOT_FOUND).get(0);
Expand Down

0 comments on commit 0db70c5

Please sign in to comment.