-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PDS label file paths and manifest files as additional possible in…
…puts (#745) * make it so the arguemnt can be a lidvid, label, or manifest A lidvid must start with urn:nasa:pds: to be detected as such. A label must be a well formed PDS4 XML file. A manifest file is a one item per line where an item may be either a lidvid or a label. * update help * Improved help information Expand help information to be more descriptive for users. * Fix typo * Cleanup help display * Fix test failure --------- Co-authored-by: Al Niessner <[email protected]> Co-authored-by: Jordan Padams <[email protected]> Co-authored-by: Jordan Padams <[email protected]>
- Loading branch information
1 parent
8fef282
commit f49894e
Showing
3 changed files
with
107 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package gov.nasa.pds.validate.ri; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.xml.transform.sax.SAXSource; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.xml.sax.InputSource; | ||
import gov.nasa.pds.tools.util.LabelParser; | ||
import gov.nasa.pds.tools.util.XMLExtractor; | ||
import net.sf.saxon.om.TreeInfo; | ||
import net.sf.saxon.tree.tiny.TinyNodeImpl; | ||
|
||
class UserInput { | ||
final private Logger log = LogManager.getLogger(UserInput.class); | ||
public String labels_lidvid = ""; | ||
public static List<String> toLidvids (List<String> cliList){ | ||
return new UserInput().process (cliList); | ||
} | ||
private List<String> expandManifest (String cliArg) { | ||
File file = new File(cliArg); | ||
List<String> lidvids = new ArrayList<String>(); | ||
if (file.exists()) { | ||
try (Stream<String> lines = Files.lines(Paths.get(cliArg))) { | ||
lidvids.addAll (this.process(lines.collect(Collectors.toList()))); | ||
} catch (Exception e) { | ||
log.warn ("The argument '" + cliArg + "' does not look like a LIDVID, Label, or manifest file. Ignoring it."); | ||
} | ||
} | ||
return lidvids; | ||
} | ||
private boolean isLabel (String cliArg) { | ||
if (cliArg.endsWith(".xml") || cliArg.endsWith (".lblx")) { | ||
File file = new File(cliArg); | ||
if (file.exists()) { | ||
try { | ||
SAXSource saxSource = new SAXSource(new InputSource(new FileReader(file))); | ||
TreeInfo docInfo = LabelParser.parse(saxSource); // Parses a label. | ||
List<TinyNodeImpl> xmlModels = new ArrayList<>(); | ||
XMLExtractor extractor = new XMLExtractor(docInfo.getRootNode()); | ||
xmlModels = extractor.getNodesFromDoc("logical_identifier"); | ||
this.labels_lidvid = xmlModels.get(0).getStringValue(); | ||
return true; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
private List<String> process (List<String> cliList){ | ||
List<String> lidvids = new ArrayList<String>(); | ||
for (String cliArg : cliList) { | ||
if (cliArg.startsWith ("urn:")) { | ||
lidvids.add (cliArg); | ||
} else if (this.isLabel (cliArg)) { | ||
lidvids.add (this.labels_lidvid); | ||
} else { | ||
lidvids.addAll (this.expandManifest (cliArg)); | ||
} | ||
} | ||
return lidvids; | ||
} | ||
} |
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,2 @@ | ||
urn:nasa:pds:insight_rad::2.1 | ||
urn:nasa:pds:insight_rad::2.0 |