Skip to content

Commit f8346ed

Browse files
authored
Merge pull request #973 from NASA-PDS/251003_948_Override_the_default_namespace_version
Added the -s option to LDDTool to override the LDD name space version number
2 parents 4dacba9 + 762102b commit f8346ed

File tree

5 files changed

+82
-33
lines changed

5 files changed

+82
-33
lines changed

model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMDocument.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public static boolean run(String[] args) throws Throwable {
349349
Namespace argparse4jNamespace = null;
350350
try {
351351
argparse4jNamespace = getArgumentParserNamespace(args);
352-
} catch (Throwable e) {
352+
} catch (Exception e) {
353353
return false;
354354
}
355355

@@ -721,9 +721,6 @@ static private void init() {
721721

722722
// process state for used flags, files, and directories
723723
dmProcessState = new DMProcessState();
724-
725-
// System.out.println("Debug main 240515");
726-
727724
PDSOptionalFlag = false;
728725
LDDToolFlag = false;
729726
// Secondary LDD Models
@@ -1138,7 +1135,7 @@ static void setRegistryAttrFlag() {
11381135
registryAttr.add("version_id");
11391136
}
11401137

1141-
static Namespace getArgumentParserNamespace(String args[]) throws Throwable {
1138+
static Namespace getArgumentParserNamespace(String[] args) throws ArgumentParserException {
11421139
parser = ArgumentParsers.newFor("LDDTool").build().defaultHelp(true).version(LDDToolVersionId)
11431140
.description("LDDTool process control:");
11441141

@@ -1176,7 +1173,11 @@ static Namespace getArgumentParserNamespace(String args[]) throws Throwable {
11761173

11771174
parser.addArgument("-N", "--namespace").dest("N").type(Boolean.class).nargs(1)
11781175
.action(Arguments.storeTrue()).help("Print the list of configured namespaces to the log");
1179-
1176+
1177+
parser.addArgument("-s", "--namespace-version").dest("s").type(Integer.class)
1178+
.help("Specify the namespace version number (positive integer). Required when using -s or --namespace-version.")
1179+
.action(Arguments.store());
1180+
11801181
parser.addArgument("-1", "--im_specification").dest("1").type(Boolean.class).nargs(1)
11811182
.action(Arguments.storeTrue())
11821183
.help("Write the Information Model Specification for an LDD");
@@ -1295,6 +1296,15 @@ static boolean processArgumentParserNamespacePhase2(Namespace ns) {
12951296
dmProcessState.setprintNamespaceFlag();
12961297
printNamespaceFlag = true;
12971298
}
1299+
1300+
Integer lOverrideNameSpaceVersionInt = ns.getInt("s");
1301+
if (lOverrideNameSpaceVersionInt != null) {
1302+
if (lOverrideNameSpaceVersionInt <= 0) {
1303+
lOverrideNameSpaceVersionInt = 1;
1304+
}
1305+
// Convert to string
1306+
dmProcessState.setOverrideNameSpaceVersionFlag(String.valueOf(lOverrideNameSpaceVersionInt));
1307+
}
12981308

12991309
Boolean dFlag = ns.getBoolean("d");
13001310
if (dFlag) {
@@ -1360,6 +1370,7 @@ static boolean processArgumentParserNamespacePhase2(Namespace ns) {
13601370
LDDSchemaFileSortArr.add(lLDDSchemaFileDefn);
13611371
masterLDDSchemaFileDefn = lLDDSchemaFileDefn; // the last Ingest_LDD named is the master.
13621372
}
1373+
masterLDDSchemaFileDefn.isMasterLDD = true; // the last Ingest_LDD named is the master.
13631374
return true;
13641375
}
13651376

model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMProcessState.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ public class DMProcessState {
4545
// written files map
4646
TreeMap<String, Integer> writtenFilesMap;
4747
TreeMap<Integer, String> writtenFilesSortMap;
48+
49+
// variables
50+
private String overrideNameSpaceVersion;
4851

4952
public DMProcessState() {
5053
// init the process flag map
5154
processFlagMap = new TreeMap<>();
5255
processFlagSortMap = new TreeMap<>();
5356
writtenFilesMap = new TreeMap<>();
5457
writtenFilesSortMap = new TreeMap<>();
58+
overrideNameSpaceVersion = "1"; // default
5559
}
5660

5761
// - getters -
@@ -176,6 +180,14 @@ public Boolean getprintNamespaceFlag() {
176180
return false;
177181
}
178182

183+
public String getOverrideNameSpaceVersionFlag() {
184+
Integer lProcessOrder = processFlagMap.get("Override Namespace Version");
185+
if (lProcessOrder != null) {
186+
return overrideNameSpaceVersion;
187+
}
188+
return null;
189+
}
190+
179191
public Boolean getLDDAttrElementFlag() {
180192
Integer lProcessOrder = processFlagMap.get("Attr Element Flag");
181193
if (lProcessOrder != null) {
@@ -326,7 +338,13 @@ public void setprintNamespaceFlag() {
326338
processFlagMap.put("Print Namespace Flag", 1100);
327339
return;
328340
}
329-
341+
342+
public void setOverrideNameSpaceVersionFlag(String overrideNameSpaceVersion) {
343+
processFlagMap.put("Override Namespace Version", 1105);
344+
this.overrideNameSpaceVersion = overrideNameSpaceVersion;
345+
return;
346+
}
347+
330348
public void setLDDAttrElementFlag() {
331349
processFlagMap.put("Attr Element Flag", 1110);
332350
return;
@@ -432,7 +450,6 @@ public void setRelativeFileSpecDOMModelJSON(SchemaFileDefn lSchemaFileDefn) {
432450
public void setRelativeFileSpecDDCSV(SchemaFileDefn lSchemaFileDefn) {
433451
writtenFilesMap.put(lSchemaFileDefn.relativeFileSpecDDCSV, 1110);
434452
// checkCreateDirectory not needed, file is in root directory
435-
return;
436453
}
437454

438455
public void setRelativeFileSpecCCSDSCSV(SchemaFileDefn lSchemaFileDefn) {

model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/LDDDOMParser.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ private void parseDocument(SchemaFileDefn lSchemaFileDefn) {
308308
}
309309

310310
lSchemaFileDefn.setVersionIds(); // set variations of versions and all filenames
311+
312+
// LDD version id might override the default IM version id
313+
// https://url.com/ldd/v2 vs https://url.com/ldd/v1
314+
if (lSchemaFileDefn.isMasterLDD) {
315+
String overrideNameSpaceVersion = DMDocument.dmProcessState.getOverrideNameSpaceVersionFlag();
316+
if (overrideNameSpaceVersion != null) {
317+
lSchemaFileDefn.setNameSpaceVersionId(overrideNameSpaceVersion);
318+
}
319+
}
311320

312321
String lStewardId = getTextValue(docEle, "steward_id");
313322
if (!(lStewardId == null || (lStewardId.indexOf("TBD") == 0))) {
@@ -379,25 +388,6 @@ private void resolveComponentsReferences(SchemaFileDefn lSchemaFileDefn) {
379388
validateEnumeratedFlags();
380389
Utility.registerMessage("0>info parseDocument.validateEnumeratedFlags() Done");
381390
}
382-
383-
private void printClassDebug(String lLable, String lIdentifier) {
384-
DOMClass lClass = classMap.get(lIdentifier);
385-
if (lClass == null) {
386-
System.out.println("\ndebug label:" + lLable
387-
+ " printClassDebug INVALID IDENTIFIER lIdentifier:" + lIdentifier);
388-
return;
389-
}
390-
System.out.println(
391-
"\ndebug label:" + lLable + " printClassDebug lClass.identifier:" + lClass.identifier);
392-
for (Iterator<DOMProp> j = lClass.ownedAttrArr.iterator(); j.hasNext();) {
393-
DOMProp lDOMProp = j.next();
394-
if (lDOMProp.domObject != null && lDOMProp.domObject instanceof DOMAttr) {
395-
DOMAttr lDOMAttr = (DOMAttr) lDOMProp.domObject;
396-
System.out.println("debug printClassDebug lDOMAttr.identifier:" + lDOMAttr.identifier);
397-
}
398-
}
399-
}
400-
401391

402392
// get the list of all DD_Attribute nodes
403393
private void getAttributes (SchemaFileDefn lSchemaFileDefn, Element docEle) {
@@ -2305,7 +2295,6 @@ private ArrayList<String> getXMLValueArr(String tagName, Element elem) {
23052295
&& (lNode.getNodeName().indexOf(tagName) == 0)) {
23062296
Element lElement = (Element) lNode;
23072297
String lVal = lElement.getFirstChild().getNodeValue();
2308-
// System.out.println("debug getXMLValueArr - local_identifier:" + lVal);
23092298
if (lVal != null && lVal.length() > 0) {
23102299
lValArr.add(lVal);
23112300
}
@@ -3014,7 +3003,6 @@ public String getClassWord(String deName) {
30143003

30153004
public String getDescriptorWord(boolean isValue, String deName) {
30163005
String lDENameUpper = deName.toUpperCase();
3017-
// System.out.println("debug getDescriptorWord lDENameUpper:" + lDENameUpper);
30183006
String lDescriptorWord = lDENameUpper;
30193007
String lTerm = lDENameUpper;
30203008
int lDENameUpperLen = lDENameUpper.length();

model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/SchemaFileDefn.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class SchemaFileDefn {
7878

7979
// isLDD indicates an LDD schema
8080
boolean isLDD;
81+
boolean isMasterLDD;
8182

8283
// isDiscipline indicates a discipline schema
8384
boolean isDiscipline;
@@ -149,6 +150,7 @@ public SchemaFileDefn(String id) {
149150
governanceLevel = "TBD_governanceLevel";
150151
isMaster = false;
151152
isLDD = false;
153+
isMasterLDD = false;
152154
isDiscipline = false;
153155
isMission = false;
154156
relativeFileSpecModelSpec_DOM = "TBD_relativeFileSpecModelSpec_DOM";
@@ -208,6 +210,11 @@ public String getSchemaVersionId() {
208210
public String getNameSpaceVersionId() {
209211
return ns_version_id;
210212
}
213+
214+
//set ns_version_id
215+
public void setNameSpaceVersionId(String nsVersionId) {
216+
this.ns_version_id = nsVersionId;
217+
}
211218

212219
//get identifier_version_id
213220
public String getIdentiferVersionId() {

test/smoke-tests.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ if [ ! -f model-lddtool/target/lddtool*.tar.gz ]; then
1111
fi
1212

1313
# Cleanup
14-
rm -fr ldd-repo/ lddtool-pkg/
14+
rm -fr ldd-repo/ ldd-repo-template/ lddtool-pkg/
1515

1616
# Unpack lddtool
1717
mkdir lddtool-pkg
1818
tar -xvzf model-lddtool/target/lddtool*.tar.gz -C lddtool-pkg/
1919

2020
echo "Test 1: ldd-template"
21-
git clone https://github.com/pds-data-dictionaries/ldd-template.git ldd-repo/
21+
git clone https://github.com/pds-data-dictionaries/ldd-template.git ldd-repo-template/
2222

2323
# Run lddtool
24-
lddtool-pkg/lddtool*/bin/lddtool -lpJ ldd-repo/src/*IngestLDD.xml
24+
lddtool-pkg/lddtool*/bin/lddtool -lpJ ldd-repo-template/src/*IngestLDD.xml
2525

2626
if [ $? -ne 0 ]; then
2727
echo "Test 1: FAILED"
@@ -30,7 +30,6 @@ fi
3030
echo "Test 1: SUCCESS"
3131

3232
echo "Test 2: ldd-cart"
33-
rm -fr ldd-repo
3433
git clone https://github.com/pds-data-dictionaries/ldd-cart.git ldd-repo/
3534

3635
cd ldd-repo/; git submodule update --init --force --remote; cd ..
@@ -66,4 +65,31 @@ if [ $count -ne 18 ]; then
6665
fi
6766
echo "Test 4: SUCCESS"
6867

68+
# File count check
69+
echo "Test 5: Test -s option. https://github.com/NASA-PDS/pds4-information-model/issues/948"
70+
lddtool-pkg/lddtool*/bin/lddtool -lpJ -s 1000 ldd-repo-template/src/*IngestLDD.xml
71+
if [ $? -ne 0 ]; then
72+
echo "Test 5: FAILED"
73+
exit $?
74+
fi
75+
76+
egrep '<sch:ns uri="http://pds.nasa.gov/pds4/example/v1000" prefix="example"/>' PDS4_EXAMPLE_*.sch > tmp.txt
77+
lines=$(wc -l tmp.txt | awk '{print $1}')
78+
79+
if [ $lines -ne 1 ]; then
80+
echo "Test 5: FAILED"
81+
exit $?
82+
fi
83+
84+
egrep 'http://pds.nasa.gov/pds4/example/v1000' PDS4_EXAMPLE_*.xsd > tmp.txt
85+
lines=$(wc -l tmp.txt | awk '{print $1}')
86+
87+
if [ $lines -ne 2 ]; then
88+
echo "Test 5: FAILED"
89+
exit $?
90+
fi
91+
92+
# Check if the output schema uses namespace with the applicable version
93+
echo "Test 5: SUCCESS"
94+
6995
exit $?

0 commit comments

Comments
 (0)