Skip to content

Commit

Permalink
Merge branch 'main' of
Browse files Browse the repository at this point in the history
git@github.com:NASA-PDS/pds4-information-model.git into main

Found and fixed bug in LDDTool parsing of Terminological Entry
  • Loading branch information
jshughes committed Mar 23, 2023
1 parent efeb465 commit 2bd3a98
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 37 deletions.
Binary file added docs/release/1K00/1K00.zip
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2019, California Institute of Technology ("Caltech").
// U.S. Government sponsorship acknowledged.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * Neither the name of Caltech nor its operating division, the Jet Propulsion
// Laboratory, nor the names of its contributors may be used to endorse or
// promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

package gov.nasa.pds.model.plugin;

import java.util.ArrayList;

public class DMDebugUtils {

public DMDebugUtils() {

}

static public void dumpTermEntryMap(String id, DOMAttr domAttr) {

// Terminological Entries
if (domAttr.termEntryMap != null && domAttr.termEntryMap.size() > 0) {
System.out.println("\ndebug DMDebugUtils termEntryMap");
ArrayList <TermEntryDefn> termEntryDefnArr = new ArrayList <TermEntryDefn> (domAttr.termEntryMap.values());

for (TermEntryDefn termEntryDefn : termEntryDefnArr) {
dumpTermEntry(id, termEntryDefn);
}
}
return;
}

static public void dumpTermEntry(String id, TermEntryDefn termEntryDefn) {
System.out.println("\ndebug DMDebugUtils -" + id + "- termEntryDefn.name:" + termEntryDefn.name);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.lddName:" + termEntryDefn.lddName);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.lddVersion:" + termEntryDefn.lddVersion);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.definition:" + termEntryDefn.definition);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.language:" + termEntryDefn.language);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.semanticRelation:" + termEntryDefn.semanticRelation);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.mappingProperty:" + termEntryDefn.mappingProperty);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.sourceNamespaceId:" + termEntryDefn.sourceNamespaceId);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.fromInstanceId:" + termEntryDefn.fromInstanceId);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.toInstanceId:" + termEntryDefn.toInstanceId);
System.out.println("debug DMDebugUtils -" + id + "- termEntryDefn.isPreferred:" + termEntryDefn.isPreferred);
System.out.println("");
return;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ public void cloneAttr(DOMAttr lOrgAttr) {
this.isChoice = lOrgAttr.isChoice;
this.isAny = lOrgAttr.isAny;
this.isFromLDD = lOrgAttr.isFromLDD;
this.isExposed = lOrgAttr.isExposed;
this.isAssociatedExternalAttr = lOrgAttr.isAssociatedExternalAttr;
this.isExtendedAttribute = lOrgAttr.isExtendedAttribute;

this.hasRetiredValue = lOrgAttr.hasRetiredValue;

this.valArr = lOrgAttr.valArr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,11 @@ static public void DOMAttrWriter(DOMAttr attr, PrintWriter prDOMWriter) {
prDOMWriter.println(" attr.isChoice:" + attr.isChoice);
prDOMWriter.println(" attr.isAny:" + attr.isAny);
prDOMWriter.println(" attr.isFromLDD:" + attr.isFromLDD);
prDOMWriter.println(" attr.isExposed:" + attr.isExposed);
prDOMWriter.println(" attr.isExtendedAttribute:" + attr.isExtendedAttribute);
prDOMWriter.println(" attr.isAssociatedExternalAttr:" + attr.isAssociatedExternalAttr);

prDOMWriter.println(" attr.hasRetiredValue:" + attr.hasRetiredValue);

prDOMWriter.println(" attr.classWord:" + attr.classWord);
prDOMWriter.println(" attr.deDataIdentifier:" + attr.deDataIdentifier);

Expand All @@ -1504,6 +1507,27 @@ static public void DOMAttrWriter(DOMAttr attr, PrintWriter prDOMWriter) {
} else {
prDOMWriter.println(" attr.domPermValueArr.size():" + attr.domPermValueArr.size());
}

// Terminological Entries
if (attr.termEntryMap != null && attr.termEntryMap.size() > 0) {
prDOMWriter.println("\n termEntryMap");
// TreeMap<String, TermEntryDefn> termEntryMap
ArrayList <TermEntryDefn> termEntryDefnArr = new ArrayList <TermEntryDefn> (attr.termEntryMap.values());

for (TermEntryDefn termEntryDefn : termEntryDefnArr) {
prDOMWriter.println(" termEntryDefn.name:" + termEntryDefn.name);
prDOMWriter.println(" termEntryDefn.lddName:" + termEntryDefn.lddName);
prDOMWriter.println(" termEntryDefn.lddVersion:" + termEntryDefn.lddVersion);
prDOMWriter.println(" termEntryDefn.definition:" + termEntryDefn.definition);
prDOMWriter.println(" termEntryDefn.language:" + termEntryDefn.language);
prDOMWriter.println(" termEntryDefn.semanticRelation:" + termEntryDefn.semanticRelation);
prDOMWriter.println(" termEntryDefn.mappingProperty:" + termEntryDefn.mappingProperty);
prDOMWriter.println(" termEntryDefn.sourceNamespaceId:" + termEntryDefn.sourceNamespaceId);
prDOMWriter.println(" termEntryDefn.fromInstanceId:" + termEntryDefn.fromInstanceId);
prDOMWriter.println(" termEntryDefn.toInstanceId:" + termEntryDefn.toInstanceId);
prDOMWriter.println(" termEntryDefn.isPreferred:" + termEntryDefn.isPreferred);
}
}
}

static public void DOMPropWriter(DOMProp lProp, PrintWriter prDOMWrite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,11 @@ private void getAttributes (SchemaFileDefn lSchemaFileDefn, Element docEle) {
// get the list of all DD_Attribute_External nodes
private void getAttributesExtended (SchemaFileDefn lSchemaFileDefn, Element docEle) {
//get a nodelist of <DD_Attribute> elements and iterate
// NodeList nl = docEle.getElementsByTagName("DD_Attribute_External");
NodeList nl = docEle.getElementsByTagName("DD_Attribute_Extended");
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
//get the element
Element el = (Element)nl.item(i);
// System.out.println("debug getAttributesExtended -- FOUND -- getTextValue(el,\"name\"):" + getTextValue(el,"name"));

getAttribute_properties (lSchemaFileDefn, docEle, el, true);
}
}
Expand Down Expand Up @@ -432,14 +429,15 @@ private void getAttribute_properties (SchemaFileDefn lSchemaFileDefn, Element do
if ((lNillableFlag.compareTo("true") == 0) || (lNillableFlag.compareTo("1") == 0)) lDOMAttr.isNilable = true;
lDOMAttr.propType = "ATTRIBUTE";
lDOMAttr.isAttribute = true;
// System.out.println("debug getAttribute_properties -- FOUND -- getTextValue(el,\"name\"):" + getTextValue(el,"name"));

// get the value domain
getValueDomain (lDOMAttr, el);

// get the terminological entry
getTermEntry (lDOMAttr, el);

// DMDebugUtils.dumpTermEntryMap("0", lDOMAttr);

// check if attribute already exists
String lid = DMDocument.registrationAuthorityIdentifierValue + lLocalIdentifierCleaned;
DOMAttr lExternAttr = DOMInfoModel.masterDOMAttrIdMap.get(lid);
Expand Down Expand Up @@ -552,6 +550,7 @@ private void getTermEntry(Object lObject, Element docEle) {
Element el = (Element) nl.item(i);
termEntryNum++;
String termEntryId = termEntryIdPrefix + Integer.toString(termEntryNum);

lVal = getTextValue(el, "language");
if (lVal != null) {
TermEntryDefn lTermEntry = new TermEntryDefn();
Expand All @@ -560,13 +559,14 @@ private void getTermEntry(Object lObject, Element docEle) {
lTermEntry.toInstanceId = DOMInfoModel.cleanCharString(toInstanceId);
lTermEntry.semanticRelation = DOMInfoModel.cleanCharString(semanticRelation);
lTermEntry.language = lVal;
if (lObject.getClass().getName().compareTo("DOMAttr") == 0) {

if (lObject instanceof DOMAttr) {
DOMAttr lAttr = (DOMAttr) lObject;
lAttr.termEntryMap.put(termEntryId, lTermEntry);
} else if (lObject.getClass().getName().compareTo("DOMClass") == 0) {
lAttr.termEntryMap.put(termEntryId, lTermEntry);
} else if (lObject instanceof DOMClass) {
DOMClass lClass = (DOMClass) lObject;
lClass.termEntryMap.put(termEntryId, lTermEntry);
}
}

lVal = getTextValue(el, "name");
if (lVal != null) {
Expand Down Expand Up @@ -2701,13 +2701,13 @@ public void finishCloneOfLDDUserAttributes() {
}

public void validateLDDAttributes() {
for (Iterator<DOMAttr> i = attrArr.iterator(); i.hasNext();) {
DOMAttr lDOMAttr = i.next();
for (DOMAttr lDOMAttr : attrArr) {
validateAttribute(lDOMAttr);
}
}

private void validateAttribute(DOMAttr lDOMAttr) {
if (lDOMAttr.isExtendedAttribute) return;
int numMatches = 0, maxMatches = 7;
DOMDataType lDOMDataType = DOMInfoModel.masterDOMDataTypeTitleMap.get(lDOMAttr.valueType);
if (lDOMDataType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,16 +1290,13 @@ public void GetMasterCDMaps() {
}
}


// 027 - Set Master Attribute XML Base Data Type From the Data Type
public void SetMasterAttrXMLBaseDataTypeFromDataType() {
// for each PDS4 attribute set the xml_schema_base_type from the data type

for (Iterator<DOMAttr> i = DOMInfoModel.masterDOMAttrArr.iterator(); i.hasNext();) {
DOMAttr lAttr = i.next();
if (lAttr.isInactive) {
continue;
}
for (DOMAttr lAttr : DOMInfoModel.masterDOMAttrArr) {
if (lAttr.isInactive) continue;
if (lAttr.isExtendedAttribute) continue;
if (lAttr.isPDS4) {
DOMDataType lDataType = DOMInfoModel.masterDOMDataTypeTitleMap.get(lAttr.valueType);
if (lDataType != null) {
Expand All @@ -1318,13 +1315,10 @@ public void SetMasterAttrXMLBaseDataTypeFromDataType() {

// 029.1 - find attributes that have no overrides; compare to data type
public void sethasAttributeOverride1(ArrayList<DOMAttr> lMasterDOMAttrArr) {
for (Iterator<DOMAttr> i = lMasterDOMAttrArr.iterator(); i.hasNext();) {
DOMAttr lAttr = i.next();
if (lAttr.isInactive) {
continue;
}
for (DOMAttr lAttr : lMasterDOMAttrArr) {
if (lAttr.isInactive) continue;
if (lAttr.isExtendedAttribute) continue;
if (lAttr.isAttribute) {
// DOMDataType lValueType = DOMInfoModel.masterDOMDataTypeMap.get(lAttr.valueType);
DOMDataType lValueType = DOMInfoModel.masterDOMDataTypeTitleMap.get(lAttr.valueType);
if (lValueType == null) {
DMDocument.registerMessage("1>error "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public WriteDOMTermEntryJSON () {
}

// write terminological entries
public void WriteDOMTermEntries (SchemaFileDefn lSchemaFileDefn) throws java.io.IOException {
// String lFileName = lSchemaFileDefn.relativeFileSpecCCSDSCSV;
public void WriteDOMTermEntries (SchemaFileDefn lSchemaFileDefn) throws java.io.IOException {
String lFileName = lSchemaFileDefn.relativeFileSpecDOMModelJSON;
lFileName = lFileName.replace(".JSON", "_TM.JSON");

Expand All @@ -63,7 +62,8 @@ public void WriteDOMTermEntries (SchemaFileDefn lSchemaFileDefn) throws java.io.
JSONObject jsonObjectRoot = getJSONObject (TermEntryDefnGroupMap);

// write the JSON object
writeJson(jsonObjectRoot, "C:\\AA7Ontologies\\A01PDS4\\Document\\LDDTool\\export\\csv\\PDS4_PDS_CCSDS_1I00_termmap.JSON");
// writeJson(jsonObjectRoot, "C:\\AA7Ontologies\\A01PDS4\\Document\\LDDTool\\export\\csv\\PDS4_PDS_CCSDS_1I00_termmap.JSON");
writeJson(jsonObjectRoot, lFileName);
return;
}

Expand Down Expand Up @@ -95,21 +95,10 @@ private TreeMap <String, TermEntryDefnGroup> getTermMappings () {
lddName = lTermEntryDefn.lddName;
lddVersion = lTermEntryDefn.lddVersion;
String lKey = lDOMAttr.identifier + "_" + lTermEntryDefn.name + "_" + DOMInfoModel.getNextUId();

TermEntryDefnGroup termEntryDefnGroup = new TermEntryDefnGroup ();
termEntryDefnGroup.identifier = lKey;
termEntryDefnGroup.attrId = lDOMAttr.nameSpaceId + lDOMAttr.title;
termEntryDefnGroup.termEntryDefn = lTermEntryDefn;

/* System.out.println("\ndebug getTermMappings termEntryDefnGroup.identifier:" + termEntryDefnGroup.identifier);
System.out.println("debug getTermMappings termEntryDefnGroup.attrId:" + termEntryDefnGroup.attrId);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.fromInstanceId:" + termEntryDefnGroup.termEntryDefn.fromInstanceId);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.toInstanceId:" + termEntryDefnGroup.termEntryDefn.toInstanceId);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.name:" + termEntryDefnGroup.termEntryDefn.name);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.semanticRelation:" + termEntryDefnGroup.termEntryDefn.semanticRelation);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.lddName:" + termEntryDefnGroup.termEntryDefn.lddName);
System.out.println("debug getTermMappings termEntryDefnGroup.termEntryDefn.lddVersion:" + termEntryDefnGroup.termEntryDefn.lddVersion);
*/
termEntryDefnGroupMap.put(lKey, termEntryDefnGroup);
}
}
Expand Down

0 comments on commit 2bd3a98

Please sign in to comment.