Skip to content

Commit

Permalink
Merge pull request #869 from NASA-PDS/250114_LDDTool_AllLDD_DD
Browse files Browse the repository at this point in the history
LDDTool does not property generate the All LDD Data Dictionary
  • Loading branch information
jordanpadams authored Jan 28, 2025
2 parents 6fd89c6 + b087a42 commit fe8dd1c
Show file tree
Hide file tree
Showing 8 changed files with 112,412 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public abstract class DOMInfoModel extends Object {
static ArrayList<String> masterMetaAttribute;

// ==========================================================

// LDDParser classes
private TreeMap<String, DOMClass> initDOMClassMap = new TreeMap<>();
private TreeMap<String, DOMAttr> initDOMAttrMap = new TreeMap<>();
private ArrayList<DOMProp> initDOMPropArr = new ArrayList<>();
private TreeMap<String, DOMRule> initDOMRuleMap = new TreeMap<>();

// global classes
static ArrayList<DOMClass> masterDOMClassArr = new ArrayList<>();
Expand Down Expand Up @@ -577,7 +583,53 @@ static public void reset() {
/**********************************************************************************************************
* getters and setters
***********************************************************************************************************/

// getters and setters for the raw LDDParser classes, attributes, properties, and rules
public TreeMap<String, DOMClass> getInitDOMClassMap() {
return initDOMClassMap;
}

public ArrayList <DOMClass> getInitDOMClassArr() {
return new ArrayList <> (getInitDOMClassMap().values());
}

public TreeMap<String, DOMAttr> getInitDOMAttrMap() {
return initDOMAttrMap;
}

public ArrayList <DOMAttr> getInitDOMAttrArr() {
return new ArrayList <> (getInitDOMAttrMap().values());
}

public ArrayList <DOMProp> getInitDOMPropArr() {
return initDOMPropArr;
}

public TreeMap<String, DOMRule> getInitDOMRuleMap() {
return initDOMRuleMap;
}

public ArrayList <DOMRule> getInitDOMRuleArr() {
return new ArrayList <> (getInitDOMRuleMap().values());
}

public void setInitDOMClassMap(String id, DOMClass lDOMClass) {
initDOMClassMap.put(id, lDOMClass);
}

public void setInitDOMAttrMap(String id, DOMAttr lDOMAttr) {
initDOMAttrMap.put(id, lDOMAttr);
}

public void setInitDOMPropArr(DOMProp lDOMProp) {
initDOMPropArr.add(lDOMProp);
}

public void setInitDOMRuleMap(String id, DOMRule lDOMRule) {
initDOMRuleMap.put(id, lDOMRule);
}

// getters and setters to be refactored
static public ArrayList<DOMClass> getMasterDOMClassArr() {
return masterDOMClassArr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void getDOMModel(String docFileName) throws Throwable {
// phase one - parse the Ingest_LDD
for (Iterator<SchemaFileDefn> i = DMDocument.LDDSchemaFileSortArr.iterator(); i.hasNext();) {
SchemaFileDefn lSchemaFileDefn = i.next();
LDDDOMParser lLDDDOMParser = new LDDDOMParser();
LDDDOMParser lLDDDOMParser = new LDDDOMParser(DMDocument.masterDOMInfoModel.getInitDOMClassMap(), DMDocument.masterDOMInfoModel.getInitDOMAttrMap(), DMDocument.masterDOMInfoModel.getInitDOMPropArr(), DMDocument.masterDOMInfoModel.getInitDOMRuleMap());
DMDocument.LDDDOMModelArr.add(lLDDDOMParser);
DMDocument.primaryLDDDOMModel = lLDDDOMParser; // last in array is the primary.
lLDDDOMParser.gSchemaFileDefn = lSchemaFileDefn; // the schema definition file for this
Expand Down Expand Up @@ -592,6 +592,21 @@ public String getSlotMapValue(ArrayList<String> valarr) {
}
return null;
}

public void dumpMaster (String title) {
// 555 debug
ArrayList<DOMClass> dispClassArr = new ArrayList<>(DOMInfoModel.masterDOMClassMap.values());
ArrayList<String> dispClassRDFIdArr = new ArrayList<>();
ArrayList<String> dispClassIdArr = new ArrayList<>();
for (DOMClass lClass : dispClassArr) {
if (lClass.isFromLDD) {
dispClassRDFIdArr.add(lClass.rdfIdentifier);
dispClassIdArr.add(lClass.identifier);
}
}
System.out.println("\ndebug DMDocument - " + title + " - dispClassRDFIdArr:" + dispClassRDFIdArr);
System.out.println("debug DMDocument - " + title + " - dispClassIdArr:" + dispClassIdArr);
}

public void printInst(HashMap<String, InstDefn> instMap) throws Throwable {
Set<String> set1 = instMap.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ public class LDDDOMParser extends Object {
SchemaFileDefn gSchemaFileDefn;

// initialize the class structures
static TreeMap<String, DOMClass> classMap = new TreeMap<>();
static TreeMap<String, DOMClass> classMapLocal = new TreeMap<>();
static ArrayList<DOMClass> classArr = new ArrayList<>();
private TreeMap<String, DOMClass> classMap;
private TreeMap<String, DOMClass> classMapLocal = new TreeMap<>();
private ArrayList<DOMClass> classArr;

// initialize the attribute structures
static ArrayList<DOMAttr> attrArr = new ArrayList<>();
static TreeMap<String, DOMAttr> attrMap = new TreeMap<>();
static TreeMap<String, DOMAttr> attrMapLocal = new TreeMap<>();
private ArrayList<DOMAttr> attrArr;
private TreeMap<String, DOMAttr> attrMap;
private TreeMap<String, DOMAttr> attrMapLocal = new TreeMap<>();

// initialize the resolved properties (after LDD Attr or Class has been mapped to a class)
static ArrayList<DOMProp> attrArrResolved = new ArrayList<>();

// initialize the Property structures
static ArrayList<DOMProp> LDDDOMPropArr = new ArrayList<>();
private ArrayList<DOMProp> LDDDOMPropArr = new ArrayList<>();

// initialize the Rule structures
static ArrayList<DOMRule> ruleArr = new ArrayList<>();
static TreeMap<String, DOMRule> ruleMap = new TreeMap<>();
private ArrayList<DOMRule> ruleArr = new ArrayList<>();
private TreeMap<String, DOMRule> ruleMap = new TreeMap<>();

// initialize the Reference
static ArrayList<RuleReferenceTypeDefn> ruleReferenceArr = new ArrayList<>();
Expand Down Expand Up @@ -118,24 +118,33 @@ public class LDDDOMParser extends Object {
String lCardMax;
int lCardMaxI;

public LDDDOMParser() {
public LDDDOMParser(TreeMap<String, DOMClass> classMap, TreeMap<String, DOMAttr> attrMap, ArrayList<DOMProp> LDDDOMPropArr, TreeMap<String, DOMRule> ruleMap) {

classMap = new TreeMap<>();
classMapLocal = new TreeMap<>();
classArr = new ArrayList<>();
// get model class Map and concat new classes
this.classMap = classMap;
this.classArr = new ArrayList<>(classMap.values());
for (DOMClass lDOMClass : classArr) {
this.classMapLocal.put(lDOMClass.localIdentifier, lDOMClass);
}

attrArr = new ArrayList<>();
attrMap = new TreeMap<>();
attrMapLocal = new TreeMap<>();
// get model attribute Map and concat new attributes
this.attrMap = attrMap;
this.attrArr = new ArrayList<>(attrMap.values());
for (DOMAttr lDOMAttr : attrArr) {
this.attrMapLocal.put(lDOMAttr.lddLocalIdentifier, lDOMAttr);
}

attrArrResolved = new ArrayList<>();

LDDDOMPropArr = new ArrayList<>();
// get model property Map and concat new properties
this.LDDDOMPropArr = LDDDOMPropArr;

ruleArr = new ArrayList<>();
ruleMap = new TreeMap<>();
// get model rule Map and concat new rules
this.ruleMap = ruleMap;
this.ruleArr = new ArrayList<>(ruleMap.values());
ruleReferenceArr = new ArrayList<>();

// init Property Map array and tree map
propertyMapsArr = new ArrayList<>();
propertyMapsMap = new TreeMap<>();

Expand Down
157 changes: 91 additions & 66 deletions model-lddtool/src/test/java/cucumber/StepDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static String findFileByExtension(String directoryPath, String fileExten

// Check if the directory exists and is a valid directory
if (!directory.exists() || !directory.isDirectory()) {
throw new IllegalArgumentException("The provided path is not a valid directory: " + directoryPath);
throw new FileNotFoundException("The provided path is not a valid directory: " + directoryPath);
}

// Filter the files based on the extension
Expand All @@ -175,7 +175,7 @@ private static String findFileByExtension(String directoryPath, String fileExten

// Check if the file is found
if (matchingFiles == null || matchingFiles.length == 0) {
throw new FileNotFoundException("No file found with extension: " + fileExtension);
throw new FileNotFoundException("No file found with extension: " + fileExtension);
}

// Check if multiple files are found
Expand Down Expand Up @@ -225,8 +225,8 @@ public void setUp() {
public void test_directories_and_command_arguments(String inDir, String outDir, String commandArgs) {
inputDirectory = inDir;
outputDirectory = outDir;
LOG.debug("inputDirectory: " + inputDirectory);
LOG.debug("outputDirectory: " + outputDirectory);
LOG.debug("inputDirectory: {}", inputDirectory);
LOG.debug("outputDirectory: {}", outputDirectory);
this.commandArgs = commandArgs;
}

Expand All @@ -235,94 +235,119 @@ public void test_directories_and_command_arguments(String inDir, String outDir,
*/
@When("lddtool is run")
public void run_lddtool() {
exec_lddtool(this.commandArgs, this.outputDirectory);
exec_lddtool(this.commandArgs, outputDirectory);
}

/**
* This method is called after each test case to compare the actual output with the expected output
* This method is called after each test case to compare the actual output with the expected
* output
*
* @param assertType the type of assertion to perform
* @param output the expected output
* @param actualOutputFile the source of the actual output
*/
@Then("the produced output from lddtool command should {string} {string} in {string} file")
public void output_should_match_expected_response(String assertType, String output, String actualOutputFile) {
String actualResponse = null;

// If the actual output file starts with a dot, find the file with the specified extension in the output directory
if (actualOutputFile.startsWith(".")) {
try {
actualOutputFile = findFileByExtension(this.outputDirectory, actualOutputFile);
} catch (Exception ex) {
throw new RuntimeException("Failed to find file", ex);
}
}
public void output_should_match_expected_response(String assertType, String output,
String actualOutputFile) {
String actualResponse = null;

// Read the content of the actual output file
actualOutputFile = this.outputDirectory + "/" + actualOutputFile;
// If the actual output file starts with a dot, find the file with the specified extension in
// the output directory
if (actualOutputFile.startsWith(".")) {
try {
actualResponse = readFileContent(actualOutputFile);
} catch (IOException ex) {
throw new RuntimeException("Failed to read file", ex);
actualOutputFile = findFileByExtension(outputDirectory, actualOutputFile);
} catch (Exception ex) {
throw new RuntimeException("Failed to find file", ex);
}

// Perform the assertion based on the assertType
switch (assertType) {
case "contain":
assertTrue(actualResponse.contains(output),
"Output: " + output + "\nActual response:\n" + actualResponse);
break;
case "not contain":
assertFalse(actualResponse.contains(output),
"Output: " + output + "\nActual response:\n" + actualResponse);
break;
default:
throw new RuntimeException("Invalid assert type: " + assertType);
}

actualResponse = null;
actualOutputFile = null;
output = null;
}

// Read the content of the actual output file
actualOutputFile = Paths.get(outputDirectory, actualOutputFile).toString();
try {
actualResponse = readFileContent(actualOutputFile);
} catch (IOException ex) {
throw new RuntimeException("Failed to read file", ex);
}

// Perform the assertion based on the assertType
switch (assertType) {
case "contain":
assertTrue(actualResponse.contains(output),
"Output: " + output + "\nActual response:\n" + actualResponse);
break;
case "not contain":
assertFalse(actualResponse.contains(output),
"Output: " + output + "\nActual response:\n" + actualResponse);
break;
default:
throw new RuntimeException("Invalid assert type: " + assertType);
}

actualResponse = null;
actualOutputFile = null;
output = null;
}

/**
* This method is called after each test case to compare the actual-generated file with the expected file
* This method is called after each test case to compare the actual-generated file with the
* expected file
*
* @param actualOutputFile the source of the actual output
* @param expectedOutputFile the source of the expected output
* @param excludeStrings the lines to exclude from the comparison
*/
@Then("the contents of file {string} should match {string} except for lines containing comma-separated strings in {string}")
public void output_should_match_expected_file(String actualOutputFile, String expectedOutputFile, String excludeStrings) {
List<String> actualLines;
List<String> expectedLines;
List<String> excludeList = Arrays.asList(excludeStrings.split(",")); // convert the excludeStrings to a list of strings

// If the actual output file starts with a dot, find the file with the specified extension in the output directory
if (actualOutputFile.startsWith(".")) {
try {
actualOutputFile = findFileByExtension(this.outputDirectory, actualOutputFile);
} catch (Exception ex) {
throw new RuntimeException("Failed to find file", ex);
}
}

// Read the content of the actual and expected output files by line
public void output_should_match_expected_file(String actualOutputFile,
String expectedOutputFile, String excludeStrings) throws IOException {
List<String> actualLines = null;
List<String> expectedLines = null;
List<String> excludeList = null;

if (!excludeStrings.equals("")) {
excludeList = Arrays.asList(excludeStrings.split(",")); // convert the excludeStrings to a
// list of strings
}

// Check if the comparison is for the core IM, and if so, append /export to the actual path
String pattern = "(PDS4_PDS_[A-Z0-9]+\\.(xsd|sch|JSON)|dd.*\\.pins)";
if (expectedOutputFile.matches(pattern)) {
outputDirectory = Paths.get(outputDirectory, "export").toString();
}

// If the actual output file starts with a dot, find the file with the specified extension in
// the output directory
if (actualOutputFile.startsWith(".")) {
try {
actualLines = Files.readAllLines(Paths.get(outputDirectory, actualOutputFile));
expectedLines = Files.readAllLines(Paths.get(inputDirectory, expectedOutputFile));
} catch (IOException ex) {
throw new RuntimeException("Failed to read file", ex);
actualOutputFile = findFileByExtension(outputDirectory, actualOutputFile);
} catch (Exception ex) {
throw new RuntimeException("Failed to find file", ex);
}

}

// Read the content of the actual and expected output files by line
try {
actualLines =
Files.readAllLines(Paths.get(outputDirectory, actualOutputFile).toAbsolutePath());
expectedLines =
Files.readAllLines(Paths.get(inputDirectory, expectedOutputFile).toAbsolutePath());
} catch (IOException ex) {
throw new RuntimeException("Failed to read file", ex);
}

if (excludeList != null) {
// Filter the lines based on the excludeStrings
actualLines = filterLines(actualLines, excludeList);
System.out.println(actualLines.size());
expectedLines = filterLines(expectedLines, excludeList);
}

// Perform the assertion
assertEquals(expectedLines, actualLines);

// Perform the assertion
assertEquals(expectedLines, actualLines);

actualLines = null;
expectedLines = null;
excludeList = null;
actualLines = null;
expectedLines = null;
excludeList = null;
}

public static void exec_lddtool(String commandArgs, String outputDir) {
Expand Down
Loading

0 comments on commit fe8dd1c

Please sign in to comment.