-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from IGNF/issue_281
validator-plugin-cnig: control at least one assiette/generateur file
- Loading branch information
Showing
8 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../src/main/java/fr/ign/validator/cnig/validation/document/AtLeastOneAssietteValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...rc/main/java/fr/ign/validator/cnig/validation/document/AtLeastOneGenerateurValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters