Skip to content

Commit

Permalink
Merge pull request #914 from NASA-PDS/issue_905
Browse files Browse the repository at this point in the history
Update duplicate file check to only check for Product Observational
  • Loading branch information
jordanpadams committed May 31, 2024
2 parents c8a5d55 + 80b0d23 commit 6cbd1cd
Show file tree
Hide file tree
Showing 14 changed files with 3,788 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import gov.nasa.pds.tools.util.LabelUtil;

public class CrossLabelFileAreaReferenceChecker {
final private static HashMap<String,Boolean> isObservational = new HashMap<String,Boolean>();
final private static HashMap<String,List<String>> knownRefs = new HashMap<String,List<String>>();
private static String resolve (String name, ValidationTarget target) throws URISyntaxException {
if (!name.startsWith ("/")) {
Expand All @@ -33,20 +34,24 @@ private static String resolve (String name, ValidationTarget target) throws URIS
* @throws SAXException
* @throws URISyntaxException
*/
public static boolean add (String name, ValidationTarget target) throws IOException, ParserConfigurationException, SAXException, URISyntaxException {
public static boolean add (String name, ValidationTarget target, boolean isObs)
throws IOException, ParserConfigurationException, SAXException, URISyntaxException {
boolean success = false;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document xml = dbf.newDocumentBuilder().parse(target.getUrl().openStream());
DOMSource domSource = new DOMSource(xml);
DOMSource domSource = new DOMSource(xml);
String full_name = resolve(name, target);
isObservational.put(full_name,
isObs || (isObservational.containsKey(full_name) ? isObservational.get(full_name) : false));
for (String lid : LabelUtil.getLogicalIdentifiers (domSource, target.getUrl())) {
if (lid.contains("::")) {
lid = lid.substring (0, lid.indexOf("::"));
}
if (!knownRefs.keySet().contains (resolve(name, target))) {
knownRefs.put(resolve(name, target), (List<String>)Arrays.asList(lid, target.getUrl().getPath()));
if (!knownRefs.keySet().contains (full_name)) {
knownRefs.put(full_name, (List<String>)Arrays.asList(lid, target.getUrl().getPath()));
success = true;
} else {
success = false;
success = !isObservational.get(full_name);
}
}
return success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -73,7 +75,8 @@ public class FileReferenceValidationRule extends AbstractValidationRule {
*/
private final String FILE_AREA_OBJECTS_XPATH =
"//*[starts-with(name(), 'File_Area')] | //Document_File";

private final HashSet<String> OBS_DATA_TAGS = new HashSet<String>(Arrays.asList(
"Product_Observational", "Observation_Area", "File_Area_Observational", "File_Area_Observational_Supplemental"));
private Map<URL, String> checksumManifest;
private PDFUtil pdfUtil = null; // Define pdfUtil so we can reuse it for every call to
// validateFileReferences()
Expand Down Expand Up @@ -323,8 +326,14 @@ private boolean validate(NodeInfo xml) {
} // for (TinyNodeImpl child : children)

if (!name.isBlank()) {
boolean isObservational = OBS_DATA_TAGS.contains(fileAreaObject.getLocalPart());
NodeInfo ancestor = fileAreaObject;
String fullName = directory.isBlank() ? name : String.join(File.pathSeparator, directory, name);
if (!CrossLabelFileAreaReferenceChecker.add (fullName, target)) {
while (!isObservational && !fileAreaObject.getRoot().isSameNodeInfo(ancestor)) {
ancestor = ancestor.getParent();
isObservational |= OBS_DATA_TAGS.contains(ancestor.getLocalPart());
}
if (!CrossLabelFileAreaReferenceChecker.add (fullName, target, isObservational)) {
this.getListener().addProblem(
new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.DUPLICATED_FILE_AREA_REFERENCE,
Expand Down
5 changes: 4 additions & 1 deletion src/test/resources/features/developer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Scenario Outline: Execute validate command for tests below.
Examples:
| testName | testDir | messageCount | messageText | problemEnum | resourceDir | reportDir | commandArgs | refOutputValue |

# Validate#905
|"NASA-PDS/validate#905 Success no duplicates in non-observational;" | "github905" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github905.json -s json --skip-context-validation -t {resourceDir}/github905/dsn_0159-science.2008-02-29.xml {resourceDir}/github905/dsn_0159-science.2009-05-18.xml" | "report_github905.json" |

# Validate#873
|"NASA-PDS/validate#873 Success files same name different paths" | "github873" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github873.json -s json --skip-context-validation -R pds4.bundle -t {resourceDir}/github873" | "report_github873.json" |

Expand Down Expand Up @@ -296,7 +299,7 @@ Scenario Outline: Execute validate command for tests below.
# https://github.com/NASA-PDS/validate/issues/188 As a user, I want to validate a bundle that uses multiple versions of the Information Model / Discipline LDDs
|"NASA-PDS/validate#188 VALID" | "github188" | 0 | "0 errors message expected" | "totalErrors" | "src/test/resources" | "target/test" | "--skip-content-validation -r {reportDir}/report_github188_label_valid_both.json -s json -t {resourceDir}/github188/bundle_cassini-huygens-coradar.xml {resourceDir}/github188/BILQH07S314_D065_T008S02_V02_without_Missing_Area_tag.xml" | "report_github188_label_valid_both.json" |

|"NASA-PDS/validate#217 Success with Errors: Tables Types" | "github217" | 65 | "65 error message expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github217.json -s json -t {resourceDir}/github217" | "report_github217.json" |
|"NASA-PDS/validate#217 Success with Errors: Tables Types" | "github217" | 63 | "63 error message expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github217.json -s json -t {resourceDir}/github217" | "report_github217.json" |

# https://github.com/NASA-PDS/validate/issues/210 As a user, I want validate to raise a WARNING when differing versions of IM are used within a bundle
|"NASA-PDS/validate#210 WITH_WARNING" | "github210" | 1 | "1 warning message expected" | "totalWarnings" | "src/test/resources" | "target/test" | "--skip-content-validation -r {reportDir}/report_github210_label_valid_both_with_warning.json -s json -t {resourceDir}/github210/bundle_cassini-huygens-coradar.xml {resourceDir}/github210/BILQH07S314_D065_T008S02_V02_without_Missing_Area_tag.xml" | "report_github210_label_valid_both_with_warning.json" |
Expand Down
Loading

0 comments on commit 6cbd1cd

Please sign in to comment.