-
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.
enable table validation for tables in MultiTableModel (refs #231)
- Loading branch information
Showing
14 changed files
with
204 additions
and
86 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
101 changes: 101 additions & 0 deletions
101
validator-core/src/main/java/fr/ign/validator/data/Table.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,101 @@ | ||
package fr.ign.validator.data; | ||
|
||
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.data.file.MultiTableFile; | ||
import fr.ign.validator.data.file.TableFile; | ||
import fr.ign.validator.error.CoreErrorCodes; | ||
import fr.ign.validator.mapping.FeatureTypeMapper; | ||
import fr.ign.validator.model.FeatureType; | ||
import fr.ign.validator.tools.TableReader; | ||
import fr.ign.validator.validation.Validatable; | ||
|
||
/** | ||
* A Table from a {@link TableFile} or a {@link MultiTableFile} | ||
* | ||
* @author MBorne | ||
*/ | ||
public class Table implements Validatable { | ||
public static final Logger log = LogManager.getRootLogger(); | ||
public static final Marker MARKER = MarkerManager.getMarker("DocumentFile"); | ||
|
||
/** | ||
* Expected model for the table. | ||
*/ | ||
private FeatureType featureType; | ||
|
||
/** | ||
* Source file to read table data. | ||
*/ | ||
private TableReader reader; | ||
|
||
/** | ||
* Path relative to the root of the document, suffixed with an hash for | ||
* MultiTableFile, in order to report errors. | ||
*/ | ||
private String relativePath; | ||
|
||
public Table(FeatureType featureType, TableReader reader, String relativePath) { | ||
this.featureType = featureType; | ||
this.reader = reader; | ||
this.relativePath = relativePath; | ||
} | ||
|
||
@Override | ||
public void validate(Context context) { | ||
context.beginData(this); | ||
doValidate(context); | ||
context.endData(this); | ||
} | ||
|
||
public void doValidate(Context context) { | ||
log.info(MARKER, "Validate '{}' according to {}...", relativePath, featureType); | ||
if (!reader.isCharsetValid()) { | ||
log.error(MARKER, "Invalid charset '{}' for '{}'", context.getEncoding(), relativePath); | ||
context.report( | ||
context.createError(CoreErrorCodes.TABLE_UNEXPECTED_ENCODING) | ||
.setMessageParam("ENCODING", context.getEncoding().toString()) | ||
); | ||
} | ||
|
||
/* | ||
* header validation | ||
*/ | ||
String[] columns = reader.getHeader(); | ||
FeatureTypeMapper mapping = new FeatureTypeMapper(columns, featureType); | ||
Header header = new Header(relativePath, mapping); | ||
header.validate(context); | ||
|
||
/* | ||
* feature validation | ||
*/ | ||
int count = 0; | ||
while (reader.hasNext()) { | ||
count++; | ||
|
||
Row row = new Row(count, reader.next(), mapping); | ||
row.validate(context); | ||
if (count % 10000 == 0) { | ||
log.debug(MARKER, "'{}' : {} rows processed...", relativePath, count); | ||
} | ||
} | ||
|
||
/* | ||
* check for empty file | ||
*/ | ||
if (count == 0) { | ||
context.report( | ||
context.createError(CoreErrorCodes.FILE_EMPTY) | ||
.setMessageParam("FILEPATH", relativePath) | ||
); | ||
} | ||
|
||
log.info(MARKER, "'{}' : {} row(s) processed", relativePath, count); | ||
|
||
} | ||
|
||
} |
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
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
Oops, something went wrong.