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

Update functionality to throw ERROR for validation_format mismatch, and WARNING for field_format mismatch. #888

Merged
merged 10 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions src/main/java/gov/nasa/pds/tools/validate/ProblemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public enum ProblemType {
FIELD_VALUE_OUT_OF_MIN_MAX_RANGE("error.table.field_value_out_of_min_max_range"),
FIELD_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE("warning.table.field_value_out_of_special_constant_min_max_range"),

FIELD_VALUE_TOO_LONG("error.table.field_value_too_long"),
FIELD_VALID_TOO_LONG("error.table.field_value_too_long"),

FIELD_VALUE_DATA_TYPE_MISMATCH("error.table.field_value_data_type_mismatch"),

Expand All @@ -154,13 +154,13 @@ public enum ProblemType {

FIELD_VALUE_NOT_A_NUMBER("error.table.field_value_not_a_number"),

FIELD_VALUE_NOT_RIGHT_JUSTIFIED("error.table.field_value_not_right_justified"),
FIELD_VALID_NOT_RIGHT_JUSTIFIED("error.table.field_value_not_right_justified"),

FIELD_VALUE_NOT_LEFT_JUSTIFIED("error.table.field_value_not_left_justified"),
FIELD_VALID_NOT_LEFT_JUSTIFIED("error.table.field_value_not_left_justified"),

FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH("error.table.field_value_format_specifier_mismatch"),
FIELD_VALID_FORMAT_SPECIFIER_MISMATCH("error.table.field_value_format_specifier_mismatch"),

FIELD_VALUE_FORMAT_PRECISION_MISMATCH("error.table.field_value_format_precision_mismatch"),
FIELD_VALID_FORMAT_PRECISION_MISMATCH("error.table.field_value_format_precision_mismatch"),

LOCAL_IDENTIFIER_NOT_FOUND("error.label.local_identifier_not_found"),

Expand All @@ -170,6 +170,15 @@ public enum ProblemType {

// Warning message types

FIELD_VALUE_TOO_LONG("warning.table.field_value_too_long"),
FIELD_VALUE_NOT_RIGHT_JUSTIFIED("warning.table.field_value_not_right_justified"),

FIELD_VALUE_NOT_LEFT_JUSTIFIED("warning.table.field_value_not_left_justified"),

FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH("warning.table.field_value_format_specifier_mismatch"),

FIELD_VALUE_FORMAT_PRECISION_MISMATCH("warning.table.field_value_format_precision_mismatch"),

DATA_OBJECTS_OUT_OF_ORDER("warning.data_objects.out_of_order"),

SCHEMA_WARNING("warning.label.schema"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void validate(TableRecord record, FieldDescription[] fields, boolean chec
String message = "The length of the value '" + value.trim()
+ "' exceeds the defined max field length (expected max " + fields[i].getMaxLength()
+ ", got " + value.trim().length() + ")";
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_TOO_LONG, message,
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALID_TOO_LONG, message,
record.getLocation(), (i + 1));
}
}
Expand Down Expand Up @@ -361,14 +361,17 @@ public void validate(TableRecord record, FieldDescription[] fields, boolean chec
// Due to CCB-214, the tool should validate against the
// validation_format field for Character Tables.
if (record instanceof FixedTableRecord && (!fields[i].getValidationFormat().isEmpty() || !fields[i].getFieldFormat().isEmpty())) {
boolean asError = true;
String format = fields[i].getValidationFormat();
if (format.isEmpty())
if (format.isEmpty()) {
asError = false;
format = fields[i].getFieldFormat();
}

checkFormat(value, format, i + 1, record.getLocation());
checkFormat(value, format, i + 1, record.getLocation(), asError);
}
if (record instanceof DelimitedTableRecord && !fields[i].getFieldFormat().isEmpty()) {
checkFormat(value, fields[i].getFieldFormat(), i + 1, record.getLocation());
checkFormat(value, fields[i].getFieldFormat(), i + 1, record.getLocation(), false);
}
}
// Check that the field value is within the defined min/max values
Expand Down Expand Up @@ -768,8 +771,7 @@ private void checkType(String value, FieldType type) throws InvalidTableExceptio
* @param fieldIndex Where the field value is located.
* @param recordLocation The record location where the field is located.
*/
private void checkFormat(String value, String format, int fieldIndex,
RecordLocation recordLocation) {
private void checkFormat(String value, String format, int fieldIndex, RecordLocation recordLocation, boolean asError) {
Matcher matcher = formatPattern.matcher(format);
int precision = -1;
boolean isValid = true;
Expand All @@ -784,13 +786,15 @@ private void checkFormat(String value, String format, int fieldIndex,
if ("+".equals(justified)) {
// check if there is trailing whitespace
if (trailingWhiteSpacePattern.matcher(value).matches()) {
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_NOT_RIGHT_JUSTIFIED,
addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING,
asError ? ProblemType.FIELD_VALID_NOT_RIGHT_JUSTIFIED : ProblemType.FIELD_VALUE_NOT_RIGHT_JUSTIFIED,
"The value '" + value + "' is not right-justified.", recordLocation, fieldIndex);
isValid = false;
}
} else if ("-".equals(justified)) {
if (leadingWhiteSpacePattern.matcher(value).matches()) {
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_NOT_LEFT_JUSTIFIED,
addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING,
asError ? ProblemType.FIELD_VALID_NOT_LEFT_JUSTIFIED : ProblemType.FIELD_VALUE_NOT_LEFT_JUSTIFIED,
"The value '" + value + "' is not left-justified.", recordLocation, fieldIndex);
isValid = false;
}
Expand Down Expand Up @@ -823,13 +827,15 @@ private void checkFormat(String value, String format, int fieldIndex,
}
}
} catch (NumberFormatException e) {
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH,
addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING,
asError ? ProblemType.FIELD_VALID_FORMAT_SPECIFIER_MISMATCH : ProblemType.FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH,
"The value '" + value.trim() + "' does not match the "
+ "defined field format specifier '" + specifier + "': " + e.getMessage(),
recordLocation, fieldIndex);
}
if (value.trim().length() > width) {
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_TOO_LONG,
addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING,
asError ? ProblemType.FIELD_VALID_TOO_LONG : ProblemType.FIELD_VALUE_TOO_LONG,
"The length of the value '" + value.trim() + "' exceeds the max "
+ "width set in the defined field format " + "(max " + width + ", got "
+ value.trim().length() + ").",
Expand All @@ -849,7 +855,8 @@ private void checkFormat(String value, String format, int fieldIndex,
}
if (actual_precision > precision) {
isValid = false;
addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_FORMAT_PRECISION_MISMATCH,
addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING,
asError ? ProblemType.FIELD_VALID_FORMAT_PRECISION_MISMATCH : ProblemType.FIELD_VALUE_FORMAT_PRECISION_MISMATCH,
"The number of digits to the right of the decimal point " + "in the value '"
+ value.trim() + "' must be <= the precision set in the defined field format '"
+ format+ "' (Expected: <=" + precision + ", Actual: " + actual_precision + ").",
Expand Down