Skip to content

Commit

Permalink
Merge pull request #890 from NASA-PDS/issue_860
Browse files Browse the repository at this point in the history
Add WARNING messages for context product metadata mismatch with labels and new flag `--disable-context-mismatch-warnings` to disable the messages
  • Loading branch information
jordanpadams committed May 8, 2024
2 parents 285a975 + 520f8c1 commit aa25295
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/main/java/gov/nasa/pds/tools/label/LocationValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ public void setRule(String ruleName) {
public void setEveryN(int value) {
ruleContext.setEveryN(value);
}
public void setContextMismatchAsWarn(boolean value) {
ruleContext.setContextMismatchAsWarn(value);
}
public void setCompleteDescriptions(boolean b) {
ruleContext.setCompleteDescriptions(b);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gov/nasa/pds/tools/validate/ProblemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ public enum ProblemType {

CONTEXT_REFERENCE_FOUND("info.label.context_ref_found"),

CONTEXT_REFERENCE_FOUND_MISMATCH("info.label.context_ref_mismatch"),
CONTEXT_REFERENCE_FOUND_MISMATCH_INFO("info.label.context_ref_mismatch"),
CONTEXT_REFERENCE_FOUND_MISMATCH_WARN("warning.label.context_ref_mismatch"),

LOCAL_ID_FOUND("info.label.local_identifier_found"),

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/gov/nasa/pds/tools/validate/rule/RuleContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class RuleContext extends ContextBase {
* The key used to indicate how many lines or records to skip during content validation.
*/
public static final String EVERY_N_KEY = "validate.every-n";

public static final String CONTEXT_MISMATCH_AS_WARN_KEY = "validate.context-mismatch-as-warn";
/**
* The key used to indicate enable/disable of every bit account for in file area
*/
Expand Down Expand Up @@ -408,11 +408,17 @@ public void setCheckData(boolean flag) {
}

public int getEveryN() {
return getContextValue(EVERY_N_KEY, Integer.class) == null ? 1 : getContextValue(EVERY_N_KEY, Integer.class);
return getContextValue(EVERY_N_KEY, Integer.class) == null ? 1 : getContextValue(EVERY_N_KEY, Integer.class);
}
public boolean getContextMismatchAsWarn() {
return getContextValue(CONTEXT_MISMATCH_AS_WARN_KEY, Boolean.class) == null ? false : getContextValue(CONTEXT_MISMATCH_AS_WARN_KEY, Boolean.class);
}
public void setEveryN(int value) {
putContextValue(EVERY_N_KEY, value);
}
public void setContextMismatchAsWarn (boolean value) {
putContextValue(CONTEXT_MISMATCH_AS_WARN_KEY, value);
}
public boolean getCompleteDescriptions() {
return getContextValue(COMPLETE_DESCRIPTIONS, Boolean.class) == null ? false : getContextValue(COMPLETE_DESCRIPTIONS, boolean.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public void checkContextReferences() throws XPathExpressionException {
for (String name : names) {
if (!rgpNames.stream().anyMatch(name::equalsIgnoreCase)) {
getListener().addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.INFO,
ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH,
new ProblemDefinition(this.getContext().getContextMismatchAsWarn() ? ExceptionType.WARNING : ExceptionType.INFO,
this.getContext().getContextMismatchAsWarn() ? ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_WARN : ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_INFO,
"Context reference name mismatch. Value: '" + name + "'"
+ " Expected one of: '" + rgp.getNames() + "'"),
target, locator.getLineNumber(), -1));
Expand All @@ -292,8 +292,8 @@ public void checkContextReferences() throws XPathExpressionException {
!topNode.getLocalName().equals("Observing_System_Component")) {
// TODO: For now, we are punting on Observing_System_Component
getListener().addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.INFO,
ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH,
new ProblemDefinition(this.getContext().getContextMismatchAsWarn() ? ExceptionType.WARNING : ExceptionType.INFO,
this.getContext().getContextMismatchAsWarn() ? ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_WARN : ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_INFO,
"Context reference type mismatch. Value: '" + type + "'"
+ " Expected one of: '" + rgp.getTypes() + "'"),
target, locator.getLineNumber(), -1));
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/gov/nasa/pds/validate/ValidateLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ public class ValidateLauncher {

private int everyN;

private boolean contextMismatchAsWarn = true;

private String pdfErrorDir;

private int spotCheckData;
Expand Down Expand Up @@ -276,6 +278,7 @@ public ValidateLauncher() throws TransformerConfigurationException {
maxErrors = MAX_ERRORS;
completeDescriptions = false;
everyN = 1;
contextMismatchAsWarn = true;
spotCheckData = -1;
allowUnlabeledFiles = false;
registeredAndNonRegistedProducts = new HashMap<>();
Expand Down Expand Up @@ -426,6 +429,8 @@ public void query(CommandLine line) throws Exception {
setContextReferenceCheck(false);
} else if (Flag.CHECK_INBETWEEN_FIELDS.getLongName().equals(o.getLongOpt())) {
setCheckInbetweenFields(true);
} else if (Flag.DISABLE_CONTEXT_MISMATCH_WARNINGS.getLongName().equals(o.getLongOpt())) {
setContextMismatchAsWarn(false);
} else if (Flag.ENABLE_STACK_PRINTING.getLongName().equals(o.getLongOpt())) {
FlagsUtil.setStackPrintingFlag(true);
// Also call setSeverity to 0.
Expand Down Expand Up @@ -768,6 +773,10 @@ public void query(File configuration) throws ConfigurationException {
if (config.containsKey(ConfigKey.EVERY_N)) {
setEveryN(config.getInt(ConfigKey.EVERY_N));
}
if (config.containsKey(ConfigKey.DISABLE_CONTEXT_MISMATCH_WARNINGS)) {
contextMismatchAsWarn = false;
setContextMismatchAsWarn(false);
}
if (config.containsKey(ConfigKey.COMPLETE_DESCRIPTIONS)) {
setCompleteDescriptions(true);
}
Expand Down Expand Up @@ -1066,6 +1075,10 @@ public void setEveryN(int value) {
this.everyN = value;
}

public void setContextMismatchAsWarn(boolean value) {
this.contextMismatchAsWarn = value;
}

public void setCompleteDescriptions(boolean b) {
this.completeDescriptions = b;
}
Expand Down Expand Up @@ -1383,6 +1396,7 @@ public boolean doValidation(Map<URL, String> checksumManifest) throws Exception
validator.setCheckData(contentValidationFlag);
validator.setSpotCheckData(spotCheckData);
validator.setEveryN(everyN);
validator.setContextMismatchAsWarn(contextMismatchAsWarn);
validator.setCompleteDescriptions(this.completeDescriptions);
validator.setPDFErrorDir(pdfErrorDir);
validator.setAllowUnlabeledFiles(allowUnlabeledFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public class ConfigKey {
*/
public static final String EVERY_N = "validate.everyN";

/**
* Property to if context ref mismatches should be INFO or WARNING.
*/
public static final String DISABLE_CONTEXT_MISMATCH_WARNINGS = "validate.disableContextMismatchWarnings";

/**
* Property to enable/disable (true/false) full bit checking of tables and arrays
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public enum Flag {
"Specify file extension for the labels files. Default: xml. NOTE: Support for intermingled bundles where collections have differing label file extensions is not yet supported."),

EVERY_N(null, "everyN", "value", int.class, "Process every N files with the default being every file."),
DISABLE_CONTEXT_MISMATCH_WARNINGS(null, "disable-context-mismatch-warnings", "When present, context mismatches will reported as info otherwise as warnings"),
/**
* DEPRECATED: Flag to force the tool to perform validation against the schema and schematron
* specified in a given label.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class FlagOptions {
options.addOption(new ToolsOption(Flag.CHECKSUM_MANIFEST));
options.addOption(new ToolsOption(Flag.COMPLETE_DESCRIPTIONS));
options.addOption(new ToolsOption(Flag.CONFIG));
options.addOption(new ToolsOption(Flag.DISABLE_CONTEXT_MISMATCH_WARNINGS));
options.addOption(new ToolsOption(Flag.MAX_ERRORS));
options.addOption(new ToolsOption(Flag.EXTENSION));
options.addOption(new ToolsOption(Flag.EVERY_N));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void testGithub15() {

count = this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_NOT_FOUND.getKey());
count +=
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH.getKey());
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_INFO.getKey());
assertEquals(count, 3,
"Three errors expected for invalid context reference (Lid, name, value) test.");

Expand Down Expand Up @@ -255,7 +255,7 @@ void testGithub47() {
int count =
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_NOT_FOUND.getKey());
count +=
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH.getKey());
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_INFO.getKey());
assertEquals(count, 0, "No errors expected. Context validation disabled.");

// test without option: "--no-context-valid"
Expand All @@ -274,7 +274,7 @@ void testGithub47() {

count = this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_NOT_FOUND.getKey());
count +=
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH.getKey());
this.getMessageCount(reportJson, ProblemType.CONTEXT_REFERENCE_FOUND_MISMATCH_INFO.getKey());
assertEquals(count, 3, "Three errors expected. Context validation enabled.");

} catch (ExitException e) {
Expand Down
20 changes: 10 additions & 10 deletions src/test/resources/features/developer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Scenario Outline: Execute validate command for tests below.
|"NASA-PDS/validate#631 Success context case matching" | "github631" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github631.json -s json -v 1 -t {resourceDir}/github631/hyb2_tir_20180629_075501_l1.xml" | "report_github631.json" |

# Validate#628
|"NASA-PDS/validate#628 Warning Version Mismatch" | "github628" | 1 | "1 warnings expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github628.json -s json --skip-content-validation -t {resourceDir}/github628/mp2_flat_20061109.xml" | "report_github628.json" |
|"NASA-PDS/validate#628 Warning Version Mismatch" | "github628" | 1 | "1 warnings expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github628.json -s json --skip-content-validation --disable-context-mismatch-warnings -t {resourceDir}/github628/mp2_flat_20061109.xml" | "report_github628.json" |

# Validate#617
|"NASA-PDS/validate#617 Warning File Extension Mismatch" | "github617" | 1 | "1 warnings expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github617.json -s json --skip-content-validation -t {resourceDir}/github617/uvis_euv_2005_159_solar_time_series_ingress.xml" | "report_github617.json" |
Expand Down Expand Up @@ -213,8 +213,8 @@ Scenario Outline: Execute validate command for tests below.

# https://github.com/NASA-PDS/validate/issues/15 Verify that all name/type attribute values correspond to names denoted context products

|"NASA-PDS/validate#15 1" | "github15" | 0 | "0 valid context references should be found" | "CONTEXT_REFERENCE_NOT_FOUND" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github15_pass.json -s json -R pds4.label -t {resourceDir}/github15/test_check-pass_context_products.xml" | "report_github15_pass.json" |
|"NASA-PDS/validate#15 2" | "github15" | 4 | "4 errors expected for invalid context reference (Lid, name, value) test." | "CONTEXT_REFERENCE_NOT_FOUND,CONTEXT_REFERENCE_FOUND_MISMATCH" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github15_no-pass.json -s json {resourceDir}/github15/test_check-no-pass_context_products.xml" | "report_github15_no-pass.json" |
|"NASA-PDS/validate#15 1" | "github15" | 0 | "0 valid context references should be found" | "CONTEXT_REFERENCE_NOT_FOUND" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github15_pass.json -s json --disable-context-mismatch-warnings -R pds4.label -t {resourceDir}/github15/test_check-pass_context_products.xml" | "report_github15_pass.json" |
|"NASA-PDS/validate#15 2" | "github15" | 4 | "4 errors expected for invalid context reference (Lid, name, value) test." | "CONTEXT_REFERENCE_NOT_FOUND,CONTEXT_REFERENCE_FOUND_MISMATCH_INFO" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github15_no-pass.json -s json --disable-context-mismatch-warnings {resourceDir}/github15/test_check-no-pass_context_products.xml" | "report_github15_no-pass.json" |

# The below tests are for real.

Expand All @@ -225,8 +225,8 @@ Scenario Outline: Execute validate command for tests below.
|"NASA-PDS/validate#137 1" | "github137" | 2 | "FIELD_VALUE_DATA_TYPE_MISMATCH info/error messages not expected." | "FIELD_VALUE_DATA_TYPE_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github137_2.json -s json -t {resourceDir}/github137/delimited_table_bad.xml" | "report_github137_2.json" |

## Note that the reference code re-use the JSON report file for both tests but we won't
|"NASA-PDS/validate#47 1" | "github47" | 0 | "No errors expected. Context validation disabled" | "CONTEXT_REFERENCE_NOT_FOUND" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github47_disable-valid.json -s json -R pds4.label --skip-content-validation --skip-context-validation {resourceDir}/github47/test_context_products.xml" | "report_github47_disable-valid.json" |
|"NASA-PDS/validate#47 2" | "github47" | 4 | "4 errors expected. Context validation enabled." | "CONTEXT_REFERENCE_NOT_FOUND,CONTEXT_REFERENCE_FOUND_MISMATCH" | "src/test/resources" | "target/test" | "-v1 --skip-content-validation -r {reportDir}/report_github47_enable-valid.json -s json -R pds4.label {resourceDir}/github47/test_context_products.xml" | "report_github47_enable-valid.json" |
|"NASA-PDS/validate#47 1" | "github47" | 0 | "No errors expected. Context validation disabled" | "CONTEXT_REFERENCE_NOT_FOUND" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github47_disable-valid.json -s json --disable-context-mismatch-warnings -R pds4.label --skip-content-validation --skip-context-validation {resourceDir}/github47/test_context_products.xml" | "report_github47_disable-valid.json" |
|"NASA-PDS/validate#47 2" | "github47" | 4 | "4 errors expected. Context validation enabled." | "CONTEXT_REFERENCE_NOT_FOUND,CONTEXT_REFERENCE_FOUND_MISMATCH_INFO" | "src/test/resources" | "target/test" | "-v1 --skip-content-validation -r {reportDir}/report_github47_enable-valid.json -s json --disable-context-mismatch-warnings -R pds4.label {resourceDir}/github47/test_context_products.xml" | "report_github47_enable-valid.json" |

|"NASA-PDS/validate#62 1" | "github62" | 4 | "4 info.label.context_ref_found info messages expected.\n" | "CONTEXT_REFERENCE_FOUND" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github62_1.json -s json --no-data-check -t {resourceDir}/github62/ele_mom_tblChar.xml" | "report_github62_1.json" |
|"NASA-PDS/validate#62 2" | "github62" | 8 | "8 info/error messages expected.\n" | "CONTEXT_REFERENCE_FOUND,CONTEXT_REFERENCE_NOT_FOUND" | "src/test/resources" | "target/test" | "-v1 -r {reportDir}/report_github62_2.json -s json --no-data-check -t {resourceDir}/github62/spacecraft.orex_1.1.xml" | "report_github62_2.json" |
Expand Down Expand Up @@ -264,12 +264,12 @@ Scenario Outline: Execute validate command for tests below.

# The 3 tests below are from "github209"
# There should be no WARN message for VALID test.
|"NASA-PDS/validate#209 VALID" | "github209" | 0 | "0 WARN message(s) expected. See validation report:" | "totalWarnings" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_1.json -s json -t {resourceDir}/github209/VALID_odf07155_msgr_11.xml" | "report_github209_1.json" |
|"NASA-PDS/validate#209 VALID" | "github209" | 0 | "0 WARN message(s) expected. See validation report:" | "totalWarnings" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_1.json -s json --disable-context-mismatch-warnings -t {resourceDir}/github209/VALID_odf07155_msgr_11.xml" | "report_github209_1.json" |
# For some reason, when ran, the actual number is 4 instead of 1.
# [{"severity":"ERROR","type":"error.table.field_value_overlap","table":12,"record":1,"field":5,"message":"The bit field overlaps the next field. Current stop_bit_location: 23. Next start_bit_location: 20"}]}]}],"summary":{"totalErrors":4,
|"NASA-PDS/validate#209 FAIL1" | "github209" | 1 | "1 message(s) expected. See validation report:" | "FIELD_VALUE_OVERLAP" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_2.json -s json -t {resourceDir}/github209/FAIL1_overlapping_bit_fields.xml" | "report_github209_2.json" |
|"NASA-PDS/validate#209 FAIL1" | "github209" | 1 | "1 message(s) expected. See validation report:" | "FIELD_VALUE_OVERLAP" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_2.json -s json --disable-context-mismatch-warnings -t {resourceDir}/github209/FAIL1_overlapping_bit_fields.xml" | "report_github209_2.json" |
# ,{"severity":"ERROR","type":"error.table.bad_field_read","table":12,"record":1,"field":6,"message":"Error while getting field value: Stop bit past end of packed field (32 > 31)"}]}]}],"summary":{"totalErrors":5,
|"NASA-PDS/validate#209 FAIL2" | "github209" | 2 | "2 message(s) expected. See validation report:" | "FIELD_VALUE_OVERLAP,BAD_FIELD_READ" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_3.json -s json -t {resourceDir}/github209/FAIL2_bad_stop_bit.xml" | "report_github209_3.json" |
|"NASA-PDS/validate#209 FAIL2" | "github209" | 2 | "2 message(s) expected. See validation report:" | "FIELD_VALUE_OVERLAP,BAD_FIELD_READ" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github209_3.json -s json --disable-context-mismatch-warnings -t {resourceDir}/github209/FAIL2_bad_stop_bit.xml" | "report_github209_3.json" |
#
#
# The correct location of file catalog.xml is in {reportDir} and not {resourceDir}
Expand Down Expand Up @@ -454,12 +454,12 @@ Scenario Outline: Execute validate command for tests below.
# https://github.com/NASA-PDS/validate/issues/419 validate 2.2.0-SNAPSHOT warns about a pretty benign bundle + readme.txt


|"NASA-PDS/validate#419 VALID" | "github419" | 0 | "0 warning messages expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-R pds4.label -r {reportDir}/report_github419_label_valid.json -s json -t {resourceDir}/github419/bundle_astromat_chem.xml" | "report_github419_label_valid.json" |
|"NASA-PDS/validate#419 VALID" | "github419" | 0 | "0 warning messages expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-R pds4.label -r {reportDir}/report_github419_label_valid.json -s json --disable-context-mismatch-warnings -t {resourceDir}/github419/bundle_astromat_chem.xml" | "report_github419_label_valid.json" |


# https://github.com/NASA-PDS/validate/issues/429 validate warns "document standard id ... is not correct" on good labels

|"NASA-PDS/validate#429 VALID" | "github429" | 0 | "0 warning messages expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-R pds4.label -r {reportDir}/report_github429_label_valid.json -s json -t {resourceDir}/github429/EPPS_EDR_SIS.xml" | "report_github429_label_valid.json" |
|"NASA-PDS/validate#429 VALID" | "github429" | 0 | "0 warning messages expected" | "totalWarnings" | "src/test/resources" | "target/test" | "-R pds4.label -r {reportDir}/report_github429_label_valid.json -s json --disable-context-mismatch-warnings -t {resourceDir}/github429/EPPS_EDR_SIS.xml" | "report_github429_label_valid.json" |

# Validate#427
|"NASA-PDS/validate#427 Success with spaces in directory" | "github427" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github427.json -s json --skip-context-validation -t {resourceDir}/github427/dir%20with%20spaces/rs_20160518_014000_udsc64_l3_e_v10.xml" | "report_github427.json" |
Expand Down

0 comments on commit aa25295

Please sign in to comment.