diff --git a/model-dmdocument/pom.xml b/model-dmdocument/pom.xml index cef72c19..d4fe01bb 100644 --- a/model-dmdocument/pom.xml +++ b/model-dmdocument/pom.xml @@ -156,6 +156,16 @@ + + org.slf4j + slf4j-simple + 2.0.13 + + + org.slf4j + slf4j-api + 2.0.13 + org.apache.maven maven-plugin-api diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ClassPropertiesBase.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ClassPropertiesBase.java index 5c19ccd0..a4777fd5 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ClassPropertiesBase.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ClassPropertiesBase.java @@ -58,6 +58,7 @@ class ClassPropertiesBase extends Object{ static boolean isFuseki = false; public ClassPropertiesBase () { + isFuseki = false; iri = "TBD_iri"; identifier = "TBD_identifier"; versionId = "TBD_versionId"; diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMDocument.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMDocument.java index 55e1ee82..1ee217c1 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMDocument.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DMDocument.java @@ -36,17 +36,18 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TimeZone; import java.util.TreeMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.helper.HelpScreenException; import net.sourceforge.argparse4j.impl.Arguments; @@ -59,6 +60,8 @@ * */ public class DMDocument extends Object { + + protected static final Logger log = LoggerFactory.getLogger(DMDocument.class); // environment variables static String parentDir; @@ -311,329 +314,17 @@ public class DMDocument extends Object { // command line argument parser static ArgumentParser parser; - /********************************************************************************************************** - * main - ***********************************************************************************************************/ - - public static void main(String args[]) throws Throwable { - - // process state for used flags, files, and directories - dmProcessState = new DMProcessState(); - - // System.out.println("Debug main 240515"); - - PDSOptionalFlag = false; - LDDToolFlag = false; - // Secondary LDD Models - LDDDOMModelArr = new ArrayList<>(); - LDDSchemaFileSortArr = new ArrayList<>(); - LDDToolAnnotateDefinitionFlag = false; - - // The current version is included to allow for -V currentIMVersion - alternateIMVersionArr = new ArrayList<>(); - alternateIMVersionArr.add("1N00"); // current - alternateIMVersionArr.add("1M00"); - alternateIMVersionArr.add("1L00"); - alternateIMVersionArr.add("1K00"); - alternateIMVersionArr.add("1J00"); - alternateIMVersionArr.add("1I00"); - alternateIMVersionArr.add("1H00"); - alternateIMVersionArr.add("1G00"); - alternateIMVersionArr.add("1F00"); - alternateIMVersionArr.add("1E00"); - alternateIMVersionArr.add("1D00"); - alternateIMVersionArr.add("1C00"); - alternateIMVersionArr.add("1B10"); - alternateIMVersionArr.add("1B00"); - - // message handling - DOMMsgDefn.init(); - - // message level counts - Integer msgCount0info = 0; - Integer msgCount0warning = 0; - Integer msgCount0error = 0; - Integer msgCount1info = 0; - Integer msgCount1warning = 0; - Integer msgCount1error = 0; - Integer msgCount2info = 0; - Integer msgCount2warning = 0; - Integer msgCount2error = 0; - Integer msgCount3error = 0; - Integer msgCount4error = 0; - messageLevelCountMap.put("0>info", msgCount0info); - messageLevelCountMap.put("0>warning", msgCount0warning); - messageLevelCountMap.put("0>error", msgCount0error); - messageLevelCountMap.put("1>info", msgCount1info); - messageLevelCountMap.put("1>warning", msgCount1warning); - messageLevelCountMap.put("1>error", msgCount1error); - messageLevelCountMap.put("2>info", msgCount2info); - messageLevelCountMap.put("2>warning", msgCount2warning); - messageLevelCountMap.put("2>error", msgCount2error); - messageLevelCountMap.put("3>error", msgCount3error); - messageLevelCountMap.put("4>error", msgCount4error); - - // get dates - rTodaysDate = new Date(); - sTodaysDate = rTodaysDate.toString(); - masterTodaysDate = sTodaysDate; - masterTodaysDateUTC = getUTCDate(); - masterTodaysDateyymmdd = masterTodaysDateUTC.substring(2, 4) - + masterTodaysDateUTC.substring(5, 7) + masterTodaysDateUTC.substring(8, 10); - masterTodaysDateTimeUTC = getUTCDateTime(); - masterTodaysDateTimeUTCwT = replaceString(masterTodaysDateTimeUTC, " ", "T"); - masterTodaysDateTimeUTCFromInstant = getUTCDateTimeFromInstant(); - - rdfPrefix = "http://pds.nasa.gov/infomodel/pds#"; - creationDateValue = masterTodaysDateUTC; - beginDatePDS4Value = "2009-06-09"; - - endDateValue = "2019-12-31"; - futureDateValue = "2019-12-31"; - versionIdentifierValue = "TBD_versionIdentifierValue"; - administrationRecordValue = "TBD_administrationRecordValue"; // set in GetModels - stewardValue = "Steward_PDS"; - submitterValue = "Submitter_PDS"; - - // registeredByValue = "RA_0001_NASA_PDS_1"; - registeredByValue = "TBD_registeredByValue"; - registrationAuthorityIdentifierValue = "TBD_registrationAuthorityIdentifierValue"; - - // Master User Class Name - masterUserClassNamespaceIdNC = "all"; - masterUserClassName = "USER"; - - // master unique sequence number - masterUId = 100000000; - - // master class order - masterClassOrder = 1000; - - // master group number - masterGroupNum = 10; - - // reserved Class names - reservedClassNames = new ArrayList<>(); - reservedClassNames.add("Internal_Reference"); - reservedClassNames.add("Local_Internal_Reference"); - reservedClassNames.add("Reference_Pixel_Regression_Test"); - - // reserved Attribute names - reservedAttrNames = new ArrayList<>(); - reservedAttrNames.add("logical_identifier"); - reservedAttrNames.add("local_identifier"); - reservedAttrNames.add("pixel_latitude_Regression_Test"); - - omitClass = new ArrayList<>(); - omitClass.add("Data_Object"); - omitClass.add("Digital_Object"); - omitClass.add("Physical_Object"); - omitClass.add("Conceptual_Object"); - - // set registryAttr - setRegistryAttrFlag(); - - // set exposed elements - setexposedElementFlag(); - - // get the command line arguments using argparse4j - Namespace argparse4jNamespace = getArgumentParserNamespace(args); - - // process first set of arguments - // this must be done before config file processing - // the use of the option "V" (alternate IM version) will change the input file directory (config - // included) - processArgumentParserNamespacePhase1(argparse4jNamespace); - - String sysDataHome = System.getProperty("data.home"); - if (sysDataHome != null) { - sysDataHome = sysDataHome.replace('\\', '/'); - parentDir = sysDataHome + "/"; - dataDirPath = parentDir; - // if this is an LDDTool run then an alternate path is allowed (option "V") - // IMTool runs ignore the -V option - if (LDDToolFlag && alternateIMVersionFlag) { - if (alternateIMVersion.compareTo(buildIMVersionFolderId) != 0) { - dataDirPath = parentDir + alternateIMVersion + "/"; - } - } - } else { - registerMessage("0>info - Property data.home is null"); - String sysUserDir = System.getProperty("user.dir"); - if (sysUserDir == null) { - registerMessage("3>error Environment variable sysUserDir is null"); - printErrorMessages(); - System.exit(1); - } - sysUserDir = sysUserDir.replace('\\', '/'); - parentDir = sysUserDir; - String dirExt = "/model-ontology/src/ontology/Data/"; -// if (debugFlag) dirExt = "/bin/../Data/"; - dataDirPath = parentDir + dirExt; - if (debugFlag) { - parentDir = System.getProperty("user.home") + "/git/pds4-information-model/model-ontology/src/ontology"; - dataDirPath = System.getProperty("user.home") + "/git/pds4-information-model/model-ontology/src/ontology/Data/"; - } - // if this is an LDDTool run then an alternate path is allowed (option "V") - // IMTool runs ignore the -V option - if (LDDToolFlag && alternateIMVersionFlag) { - if (alternateIMVersion.compareTo(buildIMVersionFolderId) != 0) { - dataDirPath = parentDir + "/Data/" + alternateIMVersion + "/"; - } - } - } - registerMessage("0>info - Parent Directory:" + parentDir); - registerMessage("0>info - IM Directory Path:" + dataDirPath); - registerMessage("0>info - IM Versions Available:" + alternateIMVersionArr); - - // read the configuration file and initialize key attributes; SchemaFileDefn map is initialized - // below (setupNameSpaceInfoAll) - // "props" are used again below in setupNameSpaceInfoAll) - String configInputFile = dataDirPath + "config.properties"; - String configInputStr; - File configFile = new File(configInputFile); - try { - FileReader reader = new FileReader(configFile); - // Properties props = new Properties(); - props.load(reader); - configInputStr = props.getProperty("infoModelVersionId"); - if (configInputStr != null) { - infoModelVersionId = configInputStr; - } - configInputStr = props.getProperty("schemaLabelVersionId"); - if (configInputStr != null) { - schemaLabelVersionId = configInputStr; - } - configInputStr = props.getProperty("pds4BuildId"); - if (configInputStr != null) { - pds4BuildId = configInputStr; - } - configInputStr = props.getProperty("imSpecDocTitle"); - if (configInputStr != null) { - imSpecDocTitle = configInputStr; - } - configInputStr = props.getProperty("imSpecDocAuthor"); - if (configInputStr != null) { - imSpecDocAuthor = configInputStr; - } - configInputStr = props.getProperty("imSpecDocSubTitle"); - if (configInputStr != null) { - imSpecDocSubTitle = configInputStr; - } - configInputStr = props.getProperty("ddDocTitle"); - if (configInputStr != null) { - ddDocTitle = configInputStr; - } - configInputStr = props.getProperty("debugFlag"); - if (configInputStr != null && configInputStr.compareTo("true") == 0) { - debugFlag = true; - } - // configInputStr= props.getProperty("lSchemaFileDefn.pds.regAuthId"); - configInputStr = props.getProperty("mastRegAuthId"); - if (configInputStr != null) { - registrationAuthorityIdentifierValue = configInputStr; - registeredByValue = "RA_" + registrationAuthorityIdentifierValue; - } - configInputStr = props.getProperty("ddDocTeam"); - if (configInputStr != null) { - ddDocTeam = configInputStr; - } - configInputStr = props.getProperty("pds4ModelFlag"); - if (configInputStr != null && configInputStr.compareTo("true") == 0) { - pds4ModelFlag = true; - } - configInputStr = props.getProperty("mastModelId"); - if (configInputStr != null) { - mastModelId = configInputStr; - } - - configInputStr = props.getProperty("toolVersionId"); - if (configInputStr != null) { - DMDocVersionId = LDDToolVersionId = configInputStr; - } - configInputStr = props.getProperty("buildDate"); - if (configInputStr != null) { - buildDate = configInputStr; - } - - reader.close(); - } catch (FileNotFoundException ex) { - // file does not exist - registerMessage("3>error Configuration file does not exist. [config.properties]"); - } catch (IOException ex) { - // I/O error - registerMessage("3>error Configuration file IO Exception. [config.properties]"); - } - - // process second set of arguments - processArgumentParserNamespacePhase2(argparse4jNamespace); - - // check the files - checkRequiredFiles(); - - if (LDDToolFlag) { - for (Iterator i = LDDSchemaFileSortArr.iterator(); i.hasNext();) { - SchemaFileDefn lSchemaFileDefn = i.next(); - cleanupLDDInputFileName(lSchemaFileDefn); - } - } - - // set up the System Build version - XMLSchemaLabelBuildNum = pds4BuildId; - - // intialize the masterAllSchemaFileSortMap - all namespaces in config.properties file - // set up the Master Schema Information for both normal and LDD processing (dirpath, namespaces, - // etc) - setupNameSpaceInfoAll(props); - - // output the context info - if (!LDDToolFlag) { - registerMessage("1>info DMDoc Version: " + DMDocVersionId); - registerMessage("1>info IM Version Id: " + DMDocument.masterPDSSchemaFileDefn.versionId); - registerMessage("1>info IM Namespace Id: " + DMDocument.masterPDSSchemaFileDefn.identifier); - registerMessage( - "1>info IM Label Version Id: " + DMDocument.masterPDSSchemaFileDefn.labelVersionId); - } else { - registerMessage("1>info LDDTOOL Version: " + LDDToolVersionId); - registerMessage("1>info IM Version Id: " + DMDocument.masterPDSSchemaFileDefn.versionId); - registerMessage("1>info IM Namespace Id: " + DMDocument.masterPDSSchemaFileDefn.identifier); - registerMessage( - "1>info IM Label Version Id: " + DMDocument.masterPDSSchemaFileDefn.labelVersionId); - } - - registerMessage("1>info Date: " + sTodaysDate); - registerMessage("1>info PARENT_DIR: " + parentDir); - - // get the 11179 Attribute Dictionary - .pins file - ProtPinsDOM11179DD lProtPinsDOM11179DD = new ProtPinsDOM11179DD(); - lProtPinsDOM11179DD.getProtPins11179DD(DMDocument.registrationAuthorityIdentifierValue, - DMDocument.dataDirPath + "dd11179.pins"); - - // get the models - GetDOMModelDoc lGetDOMModelDoc = new GetDOMModelDoc(); - lGetDOMModelDoc.getModels(docFileName + ".pins"); - - // get the DOM Model - GetDOMModel lGetDOMModel = new GetDOMModel(); - lGetDOMModel.getDOMModel(docFileName + ".pins"); - if (debugFlag) { - DOMInfoModel.domWriter(DOMInfoModel.masterDOMClassArr, "DOMModelListPerm.txt"); - } + /** + * main method + * + * @param args + * @throws Throwable + */ + public static void main(String[] args) throws Throwable { + + + run(args); - // export the models - if (DMDocument.LDDToolFlag) { - ExportModels lExportModels = new ExportModels(); - lExportModels.writeLDDArtifacts(); - } else if (DMDocument.mapToolFlag) { - WriteMappingFile writeMappingFile = new WriteMappingFile(); - writeMappingFile.writeMappingFile(registrationAuthorityIdentifierValue, propertyMapFileName); - } else { - ExportModels lExportModels = new ExportModels(); - lExportModels.writeAllArtifacts(); - } - registerMessage("0>info Next UID: " + DOMInfoModel.getNextUId()); - printErrorMessages(); - if (lMessageErrorCount > 0 || lMessageFatalErrorCount > 0) { System.out.println(""); System.out.println(">> INFO Exit(1)"); @@ -641,7 +332,221 @@ public static void main(String args[]) throws Throwable { } System.out.println(""); System.out.println(">> INFO Exit(0)"); - // System.exit(0); + System.exit(0); + } + + /** + * DMDocument Plugin Runner + * @throws Throwable + * @throws IOException + */ + public static void run(String[] args) throws Throwable { + init(); + + // get the command line arguments using argparse4j + Namespace argparse4jNamespace = getArgumentParserNamespace(args); + + // process first set of arguments + // this must be done before config file processing + // the use of the option "V" (alternate IM version) will change the input file directory (config + // included) + processArgumentParserNamespacePhase1(argparse4jNamespace); + + String sysDataHome = System.getProperty("data.home"); + if (sysDataHome != null) { + sysDataHome = sysDataHome.replace('\\', '/'); + parentDir = sysDataHome + "/"; + dataDirPath = parentDir; + // if this is an LDDTool run then an alternate path is allowed (option "V") + // IMTool runs ignore the -V option + if (LDDToolFlag && alternateIMVersionFlag) { + if (alternateIMVersion.compareTo(buildIMVersionFolderId) != 0) { + dataDirPath = parentDir + alternateIMVersion + "/"; + } + } + } else { + registerMessage("0>info - Property data.home is null"); + String sysUserDir = System.getProperty("user.dir"); + if (sysUserDir == null) { + registerMessage("3>error Environment variable sysUserDir is null"); + printErrorMessages(); + System.exit(1); + } + sysUserDir = sysUserDir.replace('\\', '/'); + parentDir = sysUserDir; + String dirExt = "/model-ontology/src/ontology/Data/"; +// if (debugFlag) dirExt = "/bin/../Data/"; + dataDirPath = parentDir + dirExt; + if (debugFlag) { + parentDir = System.getProperty("user.home") + "/git/pds4-information-model/model-ontology/src/ontology"; + dataDirPath = System.getProperty("user.home") + "/git/pds4-information-model/model-ontology/src/ontology/Data/"; + } + // if this is an LDDTool run then an alternate path is allowed (option "V") + // IMTool runs ignore the -V option + if (LDDToolFlag && alternateIMVersionFlag) { + if (alternateIMVersion.compareTo(buildIMVersionFolderId) != 0) { + dataDirPath = parentDir + "/Data/" + alternateIMVersion + "/"; + } + } + } + registerMessage("0>info - Parent Directory:" + parentDir); + registerMessage("0>info - IM Directory Path:" + dataDirPath); + registerMessage("0>info - IM Versions Available:" + alternateIMVersionArr); + + // read the configuration file and initialize key attributes; SchemaFileDefn map is initialized + // below (setupNameSpaceInfoAll) + // "props" are used again below in setupNameSpaceInfoAll) + String configInputFile = dataDirPath + "config.properties"; + String configInputStr; + File configFile = new File(configInputFile); + FileReader reader = null; + try { + reader = new FileReader(configFile); + // Properties props = new Properties(); + props.load(reader); + configInputStr = props.getProperty("infoModelVersionId"); + if (configInputStr != null) { + infoModelVersionId = configInputStr; + } + configInputStr = props.getProperty("schemaLabelVersionId"); + if (configInputStr != null) { + schemaLabelVersionId = configInputStr; + } + configInputStr = props.getProperty("pds4BuildId"); + if (configInputStr != null) { + pds4BuildId = configInputStr; + } + configInputStr = props.getProperty("imSpecDocTitle"); + if (configInputStr != null) { + imSpecDocTitle = configInputStr; + } + configInputStr = props.getProperty("imSpecDocAuthor"); + if (configInputStr != null) { + imSpecDocAuthor = configInputStr; + } + configInputStr = props.getProperty("imSpecDocSubTitle"); + if (configInputStr != null) { + imSpecDocSubTitle = configInputStr; + } + configInputStr = props.getProperty("ddDocTitle"); + if (configInputStr != null) { + ddDocTitle = configInputStr; + } + configInputStr = props.getProperty("debugFlag"); + if (configInputStr != null && configInputStr.compareTo("true") == 0) { + debugFlag = true; + } + // configInputStr= props.getProperty("lSchemaFileDefn.pds.regAuthId"); + configInputStr = props.getProperty("mastRegAuthId"); + if (configInputStr != null) { + registrationAuthorityIdentifierValue = configInputStr; + registeredByValue = "RA_" + registrationAuthorityIdentifierValue; + } + configInputStr = props.getProperty("ddDocTeam"); + if (configInputStr != null) { + ddDocTeam = configInputStr; + } + configInputStr = props.getProperty("pds4ModelFlag"); + if (configInputStr != null && configInputStr.compareTo("true") == 0) { + pds4ModelFlag = true; + } + configInputStr = props.getProperty("mastModelId"); + if (configInputStr != null) { + mastModelId = configInputStr; + } + + configInputStr = props.getProperty("toolVersionId"); + if (configInputStr != null) { + DMDocVersionId = LDDToolVersionId = configInputStr; + } + configInputStr = props.getProperty("buildDate"); + if (configInputStr != null) { + buildDate = configInputStr; + } + } catch (FileNotFoundException ex) { + // file does not exist + registerMessage("3>error Configuration file does not exist. [config.properties]"); + } catch (IOException ex) { + // I/O error + registerMessage("3>error Configuration file IO Exception. [config.properties]"); + } finally { + try { + reader.close(); + } catch (IOException|NullPointerException e) { + // Do nothing + } + } + + // process second set of arguments + processArgumentParserNamespacePhase2(argparse4jNamespace); + + // check the files + checkRequiredFiles(); + + if (LDDToolFlag) { + for (Iterator i = LDDSchemaFileSortArr.iterator(); i.hasNext();) { + SchemaFileDefn lSchemaFileDefn = i.next(); + cleanupLDDInputFileName(lSchemaFileDefn); + } + } + + // set up the System Build version + XMLSchemaLabelBuildNum = pds4BuildId; + + // intialize the masterAllSchemaFileSortMap - all namespaces in config.properties file + // set up the Master Schema Information for both normal and LDD processing (dirpath, namespaces, + // etc) + setupNameSpaceInfoAll(props); + + // output the context info + if (!LDDToolFlag) { + registerMessage("1>info DMDoc Version: " + DMDocVersionId); + registerMessage("1>info IM Version Id: " + DMDocument.masterPDSSchemaFileDefn.versionId); + registerMessage("1>info IM Namespace Id: " + DMDocument.masterPDSSchemaFileDefn.identifier); + registerMessage( + "1>info IM Label Version Id: " + DMDocument.masterPDSSchemaFileDefn.labelVersionId); + } else { + registerMessage("1>info LDDTOOL Version: " + LDDToolVersionId); + registerMessage("1>info IM Version Id: " + DMDocument.masterPDSSchemaFileDefn.versionId); + registerMessage("1>info IM Namespace Id: " + DMDocument.masterPDSSchemaFileDefn.identifier); + registerMessage( + "1>info IM Label Version Id: " + DMDocument.masterPDSSchemaFileDefn.labelVersionId); + } + + registerMessage("1>info Date: " + sTodaysDate); + registerMessage("1>info PARENT_DIR: " + parentDir); + + // get the 11179 Attribute Dictionary - .pins file + ProtPinsDOM11179DD lProtPinsDOM11179DD = new ProtPinsDOM11179DD(); + lProtPinsDOM11179DD.getProtPins11179DD(DMDocument.registrationAuthorityIdentifierValue, + DMDocument.dataDirPath + "dd11179.pins"); + + // get the models + GetDOMModelDoc lGetDOMModelDoc = new GetDOMModelDoc(); + lGetDOMModelDoc.getModels(docFileName + ".pins"); + + // get the DOM Model + GetDOMModel lGetDOMModel = new GetDOMModel(); + lGetDOMModel.getDOMModel(docFileName + ".pins"); + if (debugFlag) { + DOMInfoModel.domWriter(DOMInfoModel.masterDOMClassArr, "DOMModelListPerm.txt"); + } + + // export the models + if (DMDocument.LDDToolFlag) { + ExportModels lExportModels = new ExportModels(); + lExportModels.writeLDDArtifacts(); + } else if (DMDocument.mapToolFlag) { + WriteMappingFile writeMappingFile = new WriteMappingFile(); + writeMappingFile.writeMappingFile(registrationAuthorityIdentifierValue, propertyMapFileName); + } else { + ExportModels lExportModels = new ExportModels(); + lExportModels.writeAllArtifacts(); + } + registerMessage("0>info Next UID: " + DOMInfoModel.getNextUId()); + printErrorMessages(); + + reset(); } /********************************************************************************************************** @@ -737,6 +642,205 @@ static public void checkRequiredFiles() { System.exit(1); } } + + static private void init() { + // configuration file variables + infoModelVersionId = "0.0.0.0"; + schemaLabelVersionId = "0.0"; + pds4BuildId = "0a"; + + imSpecDocTitle = "TBD_imSpecDocTitle"; + imSpecDocAuthor = "TBD_imSpecDocAuthor"; + imSpecDocSubTitle = "TBD_imSpecDocSubTitle"; + ddDocTitle = "TBD_ddDocTitle"; + ddDocTeam = "TBD_ddDocTeam"; + + dataDirPath = "TBD_dataDirPath"; + outputDirPath = "./"; + + DMDocVersionId = "0.0.0"; + + LDDToolVersionId = "0.0.0"; + buildDate = ""; + buildIMVersionId = "1.23.0.0"; + buildIMVersionFolderId = "1N00"; + classVersionIdDefault = "1.0.0.0"; + PDS4MergeFlag = false; // create protege output; not currently used + LDDAttrElementFlag = false; // if true, write XML elements for attributes + LDDNuanceFlag = false; + overWriteClass = true; // use dd11179.pins class disp, isDeprecated, and versionId + // to overwrite Master DOMClasses, DOMAttrs, and + // DOMPermvalues + // alternate IM Version + // if no option "V" is provided on the command line, then the default is the current IM version. + alternateIMVersionFlag = false; + alternateIMVersion = buildIMVersionFolderId; // default + + // import export file flags + exportJSONFileFlag = false; // LDDTool, set by -J option + exportJSONFileAllFlag = false; // LDDTool, set by -6 option *** Not Currently Used - Deprecate? *** + exportSpecFileFlag = false; + exportDDFileFlag = false; + exportTermMapFileFlag = false; + exportOWLRDFTTLFileFlag = false; + exportOWLRDFFileFlag = false; + exportCustomFileFlag = false; + + importJSONAttrFlag = false; // non PDS processing - not currently used + pds4ModelFlag = false; // set in config.properties files (read by WriteDOMDocBook + // to exclude PDS3 from generated DD) + printNamespaceFlag = false; // print the configured namespaces to the log + disciplineMissionFlag = false; // set by -d; Omit the term "mission" from the + // namespace of a Mission dictionary + writeDOMCount = 0; // *** Deprecate *** LDDParser DOM Error write count; if + // exportDOMFlag=true then DOM code is executed and so error/warning + // messages are duplicated in log and txt file. + LDDToolMissionFlag = false; + LDDToolSingletonClassTitle = "USER"; + LDDToolSingletonDOMClass = null; + + mapToolFlag = false; + masterAllSchemaFileSortMap = new TreeMap<>(); + LDDSchemaFileSortMap = new TreeMap<>(); + LDDImportNameSpaceIdNCArr = new ArrayList<>(); + nameSpaceIdExtrnFlagArr = new ArrayList<>(); + masterNameSpaceIdNCLC = "TBD_masterNameSpaceIdNCLC"; + Literal_DEPRECATED = " *Deprecated*"; + deprecatedAddedDOM = false; + msgOrder = 100000; + mainMsgArr = new ArrayList<>(); + masterDOMMsgDefn = new DOMMsgDefn(); + messageLevelCountMap = new TreeMap<>(); + lMessageWarningCount = 0; + lMessageErrorCount = 0; + lMessageFatalErrorCount = 0; + props = new Properties(); + propertyMapFileName = new ArrayList<>(); + + // process state for used flags, files, and directories + dmProcessState = new DMProcessState(); + + // System.out.println("Debug main 240515"); + + PDSOptionalFlag = false; + LDDToolFlag = false; + // Secondary LDD Models + LDDDOMModelArr = new ArrayList<>(); + LDDSchemaFileSortArr = new ArrayList<>(); + LDDToolAnnotateDefinitionFlag = false; + + // The current version is included to allow for -V currentIMVersion + alternateIMVersionArr = new ArrayList<>(); + alternateIMVersionArr.add("1N00"); // current + alternateIMVersionArr.add("1M00"); + alternateIMVersionArr.add("1L00"); + alternateIMVersionArr.add("1K00"); + alternateIMVersionArr.add("1J00"); + alternateIMVersionArr.add("1I00"); + alternateIMVersionArr.add("1H00"); + alternateIMVersionArr.add("1G00"); + alternateIMVersionArr.add("1F00"); + alternateIMVersionArr.add("1E00"); + alternateIMVersionArr.add("1D00"); + alternateIMVersionArr.add("1C00"); + alternateIMVersionArr.add("1B10"); + alternateIMVersionArr.add("1B00"); + + // message handling + DOMMsgDefn.init(); + + // message level counts + Integer msgCount0info = 0; + Integer msgCount0warning = 0; + Integer msgCount0error = 0; + Integer msgCount1info = 0; + Integer msgCount1warning = 0; + Integer msgCount1error = 0; + Integer msgCount2info = 0; + Integer msgCount2warning = 0; + Integer msgCount2error = 0; + Integer msgCount3error = 0; + Integer msgCount4error = 0; + messageLevelCountMap.put("0>info", msgCount0info); + messageLevelCountMap.put("0>warning", msgCount0warning); + messageLevelCountMap.put("0>error", msgCount0error); + messageLevelCountMap.put("1>info", msgCount1info); + messageLevelCountMap.put("1>warning", msgCount1warning); + messageLevelCountMap.put("1>error", msgCount1error); + messageLevelCountMap.put("2>info", msgCount2info); + messageLevelCountMap.put("2>warning", msgCount2warning); + messageLevelCountMap.put("2>error", msgCount2error); + messageLevelCountMap.put("3>error", msgCount3error); + messageLevelCountMap.put("4>error", msgCount4error); + + // get dates + rTodaysDate = new Date(); + sTodaysDate = rTodaysDate.toString(); + masterTodaysDate = sTodaysDate; + masterTodaysDateUTC = getUTCDate(); + masterTodaysDateyymmdd = masterTodaysDateUTC.substring(2, 4) + + masterTodaysDateUTC.substring(5, 7) + masterTodaysDateUTC.substring(8, 10); + masterTodaysDateTimeUTC = getUTCDateTime(); + masterTodaysDateTimeUTCwT = replaceString(masterTodaysDateTimeUTC, " ", "T"); + masterTodaysDateTimeUTCFromInstant = getUTCDateTimeFromInstant(); + + rdfPrefix = "http://pds.nasa.gov/infomodel/pds#"; + creationDateValue = masterTodaysDateUTC; + beginDatePDS4Value = "2009-06-09"; + + endDateValue = "2019-12-31"; + futureDateValue = "2019-12-31"; + versionIdentifierValue = "TBD_versionIdentifierValue"; + administrationRecordValue = "TBD_administrationRecordValue"; // set in GetModels + stewardValue = "Steward_PDS"; + submitterValue = "Submitter_PDS"; + + // registeredByValue = "RA_0001_NASA_PDS_1"; + registeredByValue = "TBD_registeredByValue"; + registrationAuthorityIdentifierValue = "TBD_registrationAuthorityIdentifierValue"; + + // Master User Class Name + masterUserClassNamespaceIdNC = "all"; + masterUserClassName = "USER"; + + // master unique sequence number + masterUId = 100000000; + + // master class order + masterClassOrder = 1000; + + // master group number + masterGroupNum = 10; + + // reserved Class names + reservedClassNames = new ArrayList<>(); + reservedClassNames.add("Internal_Reference"); + reservedClassNames.add("Local_Internal_Reference"); + reservedClassNames.add("Reference_Pixel_Regression_Test"); + + // reserved Attribute names + reservedAttrNames = new ArrayList<>(); + reservedAttrNames.add("logical_identifier"); + reservedAttrNames.add("local_identifier"); + reservedAttrNames.add("pixel_latitude_Regression_Test"); + + omitClass = new ArrayList<>(); + omitClass.add("Data_Object"); + omitClass.add("Digital_Object"); + omitClass.add("Physical_Object"); + omitClass.add("Conceptual_Object"); + + // set registryAttr + setRegistryAttrFlag(); + + // set exposed elements + setexposedElementFlag(); + } + + static private void reset() { + DOMInfoModel.reset(); + init(); + } static void setupNameSpaceInfoAll(Properties prop) { SchemaFileDefn lSchemaFileDefn; diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMInfoModel.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMInfoModel.java index 83a4edfe..e036183d 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMInfoModel.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMInfoModel.java @@ -32,6 +32,7 @@ import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; // import org.apache.commons.lang.WordUtils; @@ -515,6 +516,63 @@ public void initInfoModel() { texSectionFormats.add("\\subsection"); texSectionFormats.add("\\subsubsection"); } + + static public void reset() { + master11179AdminArr = null; + master11179AdminMap = null; + master11179AdminMapId = null; + fundamentalStructures = null; + masterMetaAttribute = null; + masterDOMClassArr = new ArrayList<>(); + masterDOMClassMap = new TreeMap<>(); + masterDOMClassIdMap = new TreeMap<>(); + masterDOMClassTitleMap = new TreeMap<>(); + masterDOMUserClass = null; + masterDOMAttrArr = new ArrayList<>(); + masterDOMAttrMap = new TreeMap<>(); + masterDOMAttrIdMap = new TreeMap<>(); + userDOMClassAttrIdMap = new TreeMap<>(); + userSingletonDOMClassAttrIdMap = new TreeMap<>(); + masterDOMPropArr = new ArrayList<>(); + masterDOMPropMap = new TreeMap<>(); + masterDOMPropIdMap = new TreeMap<>(); + masterDOMRuleArr = new ArrayList<>(); + masterDOMRuleMap = new TreeMap<>(); + masterDOMRuleIdMap = new TreeMap<>(); + masterDOMRuleNewArr = null; + masterDOMRuleNewMap = null; + masterDOMDataTypeArr = new ArrayList<>(); + masterDOMDataTypeMap = new TreeMap<>(); + masterDOMDataTypeTitleMap = new TreeMap<>(); + masterDOMUnitArr = new ArrayList<>(); + masterDOMUnitMap = new TreeMap<>(); + masterDOMUnitTitleMap = new TreeMap<>(); + master11179DataDict = null; + masterDOMUseCaseArr = new ArrayList<>(); + masterDOMUseCaseMap = new TreeMap<>(); + masterDOMUseCaseIdMap = new TreeMap<>(); + masterPropertyMapsMap = new TreeMap<>(); + masterPropertyMapsArr = new ArrayList<>(); + cdDOMAttrMap = new TreeMap<>(); + decDOMAttrMap = new TreeMap<>(); + LDDToolSingletonDOMClass = null; + attrIsInactiveArr = null; + sfDisciplineFacetDefnMap = new TreeMap<>(); + classConcept = null; + dataConcept = null; + dataTypePDS4ProtegeMap = null; + rawValueTypeMap = null; + metricConceptMap = null; + dataTypeToConceptMap = null; + cdID2CDTitleMap = null; + cdTitle2CDIDMap = null; + decID2DECTitleMap = null; + decTitle2DECIDMap = null; + masterValueMeaningMap = null; + parsedClassMap = null; + parsedProtAttrArr = null; + parsedProtAttrMap = null; + } /********************************************************************************************************** * getters and setters @@ -1332,8 +1390,9 @@ static public ArrayList getPropArrByTitleStewardClassSteward() { /** * print all classes */ - static void domWriter(ArrayList classArr, String lFileName) throws java.io.IOException { - prDOMWriter = + static void domWriter(ArrayList classArr, String lFileName) throws IOException { + try { + prDOMWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(lFileName)), "UTF-8")); prDOMWriter.println("\ndebug - domWriter - classArr.size():" + classArr.size()); for (Iterator i = classArr.iterator(); i.hasNext();) { @@ -1344,7 +1403,11 @@ static void domWriter(ArrayList classArr, String lFileName) throws jav // write DOMRules prDOMWriter.println("\ndebug - domWriter - masterDOMRuleArr.size():" + masterDOMRuleArr.size()); printRulesAllDebug(masterDOMRuleArr, prDOMWriter); - prDOMWriter.close(); + } catch (IOException e) { + throw e; + } finally { + prDOMWriter.close(); + } } static void domClassWriter(DOMClass objClass, PrintWriter prDOMWriter, String lFileName) { diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMMsgDefn.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMMsgDefn.java index a7c1e3ea..5cbdee0a 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMMsgDefn.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/DOMMsgDefn.java @@ -52,6 +52,9 @@ public class DOMMsgDefn extends Object { public DOMMsgDefn() { // messageLevelArr is initialized (init()) when masterDOMMsgDefn is created in DMDocument + messageLevelArr = new ArrayList<>(); + messageLevelTitleMap = new TreeMap<>(); + messagePrefixMap = new TreeMap<>(); } public DOMMsgDefn(String lMessage) { diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ExportModels.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ExportModels.java index f32875dd..c1a8188c 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ExportModels.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ExportModels.java @@ -34,14 +34,18 @@ import java.util.Iterator; import java.util.TreeMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Driver for getting document * */ public class ExportModels extends Object { + + private static final Logger LOG = LoggerFactory.getLogger(ExportModels.class); public ExportModels() { - } /********************************************************************************************************** @@ -49,7 +53,6 @@ public ExportModels() { ***********************************************************************************************************/ public void writeAllArtifacts() throws java.io.IOException { - // check if the export/ directory exists; if not create it DMDocument.checkCreateDirectory(DMDocument.outputDirPath + "export/"); @@ -184,8 +187,7 @@ public void writeAllArtifacts() throws java.io.IOException { return; } - public void writeLDDArtifacts() throws java.io.IOException { - + public void writeLDDArtifacts() throws java.io.IOException { // check if the export directory exists; if not create it DMDocument.checkCreateDirectory(DMDocument.outputDirPath + "export/"); @@ -225,7 +227,7 @@ public void writeLDDArtifacts() throws java.io.IOException { XML4LabelSchemaDOM xml4LabelSchemaDOM = new XML4LabelSchemaDOM(); xml4LabelSchemaDOM.writeXMLSchemaFiles(DMDocument.masterLDDSchemaFileDefn, lLDDDOMClassArr); DMDocument - .registerMessage("0>info " + "writeAllArtifacts - XML Schema - lSchemaFileDefn.identifier:" + .registerMessage("0>info " + "writeLDDArtifacts - XML Schema - lSchemaFileDefn.identifier:" + DMDocument.masterLDDSchemaFileDefn.identifier + " - Done"); // write schematron file @@ -233,7 +235,7 @@ public void writeLDDArtifacts() throws java.io.IOException { WriteDOMSchematron writeDOMSchematron = new WriteDOMSchematron(); writeDOMSchematron.writeSchematronFile(DMDocument.masterLDDSchemaFileDefn, lLDDDOMClassMap); DMDocument - .registerMessage("0>info " + "writeAllArtifacts - Schematron - lSchemaFileDefn.identifier:" + .registerMessage("0>info " + "writeLDDArtifacts - Schematron - lSchemaFileDefn.identifier:" + DMDocument.masterLDDSchemaFileDefn.identifier + " - Done"); // write label file for XML Schema and Schematron @@ -257,7 +259,7 @@ public void writeLDDArtifacts() throws java.io.IOException { DMDocument.dmProcessState.setRelativeFileSpecDOMModelJSON(DMDocument.masterPDSSchemaFileDefn); WriteDOMDDJSONFileLib writeDOMDDJSONFileLib = new WriteDOMDDJSONFileLib(); writeDOMDDJSONFileLib.writeJSONFile(DMDocument.masterPDSSchemaFileDefn); - DMDocument.registerMessage("0>info " + "writeAllArtifacts - JSON Done"); + DMDocument.registerMessage("0>info " + "writeLDDArtifacts - JSON Done"); } // write the Info Spec file diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/LDDDOMParser.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/LDDDOMParser.java index 05cb14a0..cada56e1 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/LDDDOMParser.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/LDDDOMParser.java @@ -118,6 +118,31 @@ public class LDDDOMParser extends Object { public LDDDOMParser() { + classMap = new TreeMap<>(); + classMapLocal = new TreeMap<>(); + classArr = new ArrayList<>(); + + attrArr = new ArrayList<>(); + attrMap = new TreeMap<>(); + attrMapLocal = new TreeMap<>(); + + attrArrResolved = new ArrayList<>(); + + LDDDOMPropArr = new ArrayList<>(); + + ruleArr = new ArrayList<>(); + ruleMap = new TreeMap<>(); + ruleReferenceArr = new ArrayList<>(); + + propertyMapsArr = new ArrayList<>(); + propertyMapsMap = new TreeMap<>(); + + lddErrorMsg = new ArrayList<>(); + lLDDValArrExtUpdDefnClassMap = new TreeMap<>(); + + lComment = "TBD_lComment"; + lRegAuthId = DMDocument.registrationAuthorityIdentifierValue; + // initialize the concept arrays initializeConceptArrs(); } diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ProtPinsDOM11179DD.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ProtPinsDOM11179DD.java index fa38392f..835fdda2 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ProtPinsDOM11179DD.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/ProtPinsDOM11179DD.java @@ -197,5 +197,9 @@ public void dumpMaster11179DataDict() { } } } + + public void flush() { + this.protPinsInst = null; + } } diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/RegConfig.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/RegConfig.java index 1d498a1f..b914c781 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/RegConfig.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/RegConfig.java @@ -40,8 +40,8 @@ class RegConfig extends Object { - static String reference_string = "_reference"; - static int reference_string_length = reference_string.length(); + private static final String REFERENCE_STRING = "_reference"; + private static final int REFERENCE_STRING_LENGTH = REFERENCE_STRING.length(); ArrayList associationsArr = new ArrayList<>(); ArrayList allSearchAttrArr = new ArrayList<>(); @@ -125,11 +125,11 @@ public void writeRegRIMClass(DOMClass lClass, String delimiter, PrintWriter prRI for (DOMAttr lAttr : lAttrArr) { String lTitle = lAttr.title; // System.out.println("debug writeRegRIM slot lAttr.title:" + lAttr.title); - int lIndex = lTitle.indexOf(reference_string); + int lIndex = lTitle.indexOf(REFERENCE_STRING); if (lIndex > -1) { prRIM1.println(" rel_label:" + lTitle); int lLength = lTitle.length(); - String lObjectType = lTitle.substring(0, (lLength - reference_string_length)); + String lObjectType = lTitle.substring(0, (lLength - REFERENCE_STRING_LENGTH)); } } } diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/UMLModelClassifications.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/UMLModelClassifications.java index 461c43e3..1039c85a 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/UMLModelClassifications.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/UMLModelClassifications.java @@ -37,15 +37,18 @@ class UMLModelClassifications extends Object { // classification map and array - categories {method, binding, ...} with an order, title, // description, and a set of IM classes. - static TreeMap classClassificationMap = new TreeMap<>(); + static TreeMap classClassificationMap; static ArrayList classClassificationArr; static ArrayList activeClasses; - static TreeMap definedClassToClassificationMap = new TreeMap<>(); + static TreeMap definedClassToClassificationMap; public UMLModelClassifications() { + classClassificationMap = new TreeMap<>(); + definedClassToClassificationMap = new TreeMap<>(); + // Initialize the maps initMapDeclaration(); initMapProcess(); diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteDOMCSVFile.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteDOMCSVFile.java index fbc99640..caa7bfbe 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteDOMCSVFile.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteDOMCSVFile.java @@ -35,11 +35,9 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Iterator; -import java.util.TreeMap; class WriteDOMCSVFiles extends Object { - static final String DELM_BEGIN = "\"", DELM_MID = "\",\"", DELM_END = "\""; - TreeMap termEntryMap; + private static final String DELM_BEGIN = "\"", DELM_MID = "\",\"", DELM_END = "\""; public WriteDOMCSVFiles() { return; diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteMappingFile.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteMappingFile.java index 6dca8099..be69bb88 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteMappingFile.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/WriteMappingFile.java @@ -64,12 +64,12 @@ class WriteMappingFile extends Object { static final String INSIGHT_NUANCE_COLUMN = "INSIGHT_NUANCE"; static final String MSL_NUANCE_COLUMN = "MSL_NUANCE"; - static String[] column_keywords = + static final String[] COLUMN_KEYWORDS = {PARENT_COLUMN, CLASS_COLUMN, ATTR_COLUMN, XPATH_FULL_COLUMN, XPATH_SHORT_COLUMN, PDS3_KEYWORD_COLUMN, PDS3_GROUP_COLUMN, ODL_KEYWORD_COLUMN, ODL_GROUP_COLUMN, VICAR_KEYWORD_COLUMN, VICAR_GROUP_COLUMN, INSIGHT_NUANCE_COLUMN, MSL_NUANCE_COLUMN}; - int[] columns = new int[column_keywords.length]; + final int[] columns = new int[COLUMN_KEYWORDS.length]; // write the mapping file public void writeMappingFile(String registrationAuthority, ArrayList inputFileName) @@ -406,8 +406,8 @@ public void processColumnFormat(StringTokenizer tokenizer) { int total_column = 0; while (tokenizer.hasMoreTokens()) { String tok = tokenizer.nextToken(); - for (int i = 0; i < column_keywords.length; i++) { - if (tok.equalsIgnoreCase(column_keywords[i])) { + for (int i = 0; i < COLUMN_KEYWORDS.length; i++) { + if (tok.equalsIgnoreCase(COLUMN_KEYWORDS[i])) { columns[total_column] = i; total_column++; } diff --git a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/XML4LabelSchemaDOM.java b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/XML4LabelSchemaDOM.java index 7633f46b..065f125f 100644 --- a/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/XML4LabelSchemaDOM.java +++ b/model-dmdocument/src/main/java/gov/nasa/pds/model/plugin/XML4LabelSchemaDOM.java @@ -38,11 +38,18 @@ import java.util.Iterator; import java.util.TreeMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import jdk.internal.org.jline.utils.Log; + // This code writes the information model to XML schema, attempting to replicate the class // hierarchy. // It is written to a single schema file (single namespace). class XML4LabelSchemaDOM extends Object { + private static final Logger LOG = LoggerFactory.getLogger(XML4LabelSchemaDOM.class); + PrintWriter prXML; ArrayList allAttrTypeIdArr = new ArrayList<>(); TreeMap allAttrTypeMap = new TreeMap<>(); @@ -1068,6 +1075,7 @@ public void writeXMLExtendedRestrictedNonEnumerated(SchemaFileDefn lSchemaFileDe // write the XML Schema data types public void writeXMLDataTypes(SchemaFileDefn lSchemaFileDefn, PrintWriter prXML) throws java.io.IOException { + // Sort the data types TreeMap sortDataTypeMap = new TreeMap<>(); for (Iterator i = DOMInfoModel.masterDOMClassArr.iterator(); i.hasNext();) { diff --git a/model-lddtool/pom.xml b/model-lddtool/pom.xml index f3fe6246..bec1f537 100644 --- a/model-lddtool/pom.xml +++ b/model-lddtool/pom.xml @@ -150,6 +150,16 @@ + + org.slf4j + slf4j-simple + 2.0.13 + + + org.slf4j + slf4j-api + 2.0.13 + gov.nasa.pds.model model-dmdocument @@ -178,6 +188,12 @@ 7.15.0 test + + io.cucumber + cucumber-junit + 7.15.0 + test + diff --git a/model-lddtool/src/test/java/cucumber/CucumberTest.java b/model-lddtool/src/test/java/cucumber/CucumberTest.java index 4f2d0abc..3ac237ee 100644 --- a/model-lddtool/src/test/java/cucumber/CucumberTest.java +++ b/model-lddtool/src/test/java/cucumber/CucumberTest.java @@ -1,8 +1,15 @@ package cucumber; -import io.cucumber.junit.platform.engine.Cucumber; +import org.junit.runner.RunWith; -@Cucumber +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty", "html:target/cucumber.html"}, + features = "src/test/resources/features/", glue = "cucumber") public class CucumberTest { + public CucumberTest() {} + } diff --git a/model-lddtool/src/test/java/cucumber/LddToolRunner.java b/model-lddtool/src/test/java/cucumber/LddToolRunner.java index 39b3b647..cb26339b 100644 --- a/model-lddtool/src/test/java/cucumber/LddToolRunner.java +++ b/model-lddtool/src/test/java/cucumber/LddToolRunner.java @@ -4,6 +4,9 @@ import java.io.PrintStream; import java.security.Permission; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import gov.nasa.pds.model.plugin.DMDocument; /** @@ -12,13 +15,13 @@ * It also captures the output of System.out and System.err for testing purposes */ public class LddToolRunner { - // ByteArrayOutputStreams to capture output and error streams - static final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - static final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private static final Logger LOG = LoggerFactory.getLogger(LddToolRunner.class); + + // ByteArrayOutputStreams to capture output stream + private static final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); // Original System.out and System.err streams to restore them after execution - static final PrintStream originalOut = System.out; - static final PrintStream originalErr = System.err; + private static final PrintStream originalOut = System.out; /** * This method runs the Lddtool and captures its output @@ -27,23 +30,12 @@ public class LddToolRunner { * @throws Throwable if an error occurs while running lddtool */ public static String runLddTool(String[] args) throws Throwable { - setupStreams(); // Redirect System.out and System.err to capture them String output = null; // output of lddtool try { - SecurityManager originalSecurityManager = System.getSecurityManager(); - // Set a custom SecurityManager that throws an exception instead of exiting - System.setSecurityManager(new NoExitSecurityManager()); - try { - // Call lddtool's main method with arguments and capture its output - DMDocument.main(args); - output = outContent.toString(); - } catch (ExitException e) { - // Handle the exception thrown by our NoExitSecurityManager when System.exit() is called - System.err.println("DMDocument attempted to exit with status: " + e.status); - } finally { - // Restore the original security manager - System.setSecurityManager(originalSecurityManager); - } + LOG.info("Run LDDTool"); + setupStreams(); // Redirect System.out and System.err to capture them + DMDocument.run(args); + output = outContent.toString(); } catch (Exception e) { // Throw an exception if an error occurs while setting the SecurityManager throw new Exception("An error occurred while setting the SecurityManager in runLddTool", e); @@ -59,15 +51,14 @@ public static String runLddTool(String[] args) throws Throwable { */ public static void clearStreams() { outContent.reset(); - errContent.reset(); } /** * Sets up custom PrintStreams to capture System.out and System.err output */ static void setupStreams() { - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); + PrintStream stream = new PrintStream(outContent); + System.setOut(stream); } /** @@ -75,63 +66,5 @@ static void setupStreams() { */ private static void restoreStreams() { System.setOut(originalOut); - System.setErr(originalErr); - } - - - /** - * A custom SecurityManager that prevents System.exit() from terminating the JVM - */ - private static class NoExitSecurityManager extends SecurityManager { - /** - * This method is called by the JVM when an application tries to exit - * @param perm the permission to check - */ - @Override - public void checkPermission(Permission perm) { - // Allow most actions by default - // This is where to restrict permissions if necessary. For now, it permits everything. - } - - /** - * This method is called by the JVM when an application tries to exit - * @param perm the permission to check - * @param context the context in which the permission is checked - */ - @Override - public void checkPermission(Permission perm, Object context) { - // Allow most actions by default - // Similar to checkPermission(Permission perm), this version is used in context-restricted scenarios. - } - - /** - * This method is called by the JVM when an application tries to exit - * @param status the exit status requested by the application - */ - @Override - public void checkExit(int status) { - super.checkExit(status); // call original checkExit method - // throw a custom exception instead of exiting - // prevents the application from terminating the JVM - throw new ExitException(status); - } - } - - - /** - * A custom SecurityException to handle the prevention of System.exit() - * It captures the exit status requested by the application - */ - private static class ExitException extends SecurityException { - public final int status; // exit status requested by the application - - /** - * Constructor for ExitException - * @param status the exit status requested by the application - */ - public ExitException(int status) { - super("Prevented System.exit"); - this.status = status; - } } } diff --git a/model-lddtool/src/test/java/cucumber/StepDefs.java b/model-lddtool/src/test/java/cucumber/StepDefs.java index fdf1668c..bfea3b25 100644 --- a/model-lddtool/src/test/java/cucumber/StepDefs.java +++ b/model-lddtool/src/test/java/cucumber/StepDefs.java @@ -21,10 +21,15 @@ import java.util.List; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This class connects the feature files with the Cucumber test code */ public class StepDefs { + private static final Logger LOG = LoggerFactory.getLogger(StepDefs.class); + // The values of these variables should come from a row in the table in the // feature file. private String inputDirectory; @@ -201,6 +206,7 @@ public void setUp() { this.inputDirectory = null; this.outputDirectory = null; this.commandArgs = null; + System.setProperty(org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG"); } /** diff --git a/model-lddtool/src/test/resources/features/integration.feature b/model-lddtool/src/test/resources/features/integration.feature index 3fb4e8b6..c75720cd 100644 --- a/model-lddtool/src/test/resources/features/integration.feature +++ b/model-lddtool/src/test/resources/features/integration.feature @@ -10,11 +10,11 @@ Feature: Running integration tests for lddtool Examples: | testName | inputDirectory | outputDirectory | commandArgs | assertType | output | actualOutputFile | - #| "NASA-PDS/pds4-information-model#733 LDDTool is throwing ERROR SetMasterAttrXMLBaseDataTypeFromDataType - Data Type is missing" | "src/test/resources/github733" | "target/generated-files/github733" | "-lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "not contain" | "ERROR SetMasterAttrXMLBaseDataTypeFromDataType" | "lddtool-output.txt" | - #| "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738" | "-lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "contain" | "http://www.kari.re.kr/kpds/mission/kplo/v1" | ".xsd" | - #| "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738" | "-lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "not contain" | "http://www.kari.re.kr/kpdsmission/kplo/v1 " | ".xsd" | - #| "NASA-PDS/pds4-information-model#716 [namespace-registry]update namespace URL for KPDS" | "src/test/resources/github716" | "target/generated-files/github716" | "-lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "contain" | "http://www.kari.re.kr/kpds/mission/kplo/v1" | ".sch" | - #| "NASA-PDS/pds4-information-model#744 LDDTool producing invalid XSD for Voyager LDD" | "src/test/resources/github744" | "target/generated-files/github744" | "-lpJ {inputDirectory}/PDS4_VGR_IngestLDD.xml" | "not contain" | "The element type \"xs:documentation\" must be terminated by the matching end-tag \"\"" | ".xsd" | + | "NASA-PDS/pds4-information-model#733 LDDTool is throwing ERROR SetMasterAttrXMLBaseDataTypeFromDataType - Data Type is missing" | "src/test/resources/github733" | "target/generated-files/github733" | "-V 1N00 -lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "not contain" | "ERROR SetMasterAttrXMLBaseDataTypeFromDataType" | "lddtool-output.txt" | + | "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738_1" | "-V 1N00 -lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "contain" | "http://www.kari.re.kr/kpds/mission/kplo/v1" | ".xsd" | + | "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738_2" | "-V 1N00 -lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "not contain" | "http://www.kari.re.kr/kpdsmission/kplo/v1 " | ".xsd" | + | "NASA-PDS/pds4-information-model#716 [namespace-registry]update namespace URL for KPDS" | "src/test/resources/github716" | "target/generated-files/github716" | "-V 1N00 -lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "contain" | "http://www.kari.re.kr/kpds/mission/kplo/v1" | ".sch" | + | "NASA-PDS/pds4-information-model#744 LDDTool producing invalid XSD for Voyager LDD" | "src/test/resources/github744" | "target/generated-files/github744" | "-lpJ {inputDirectory}/PDS4_VGR_IngestLDD.xml" | "not contain" | "The element type \"xs:documentation\" must be terminated by the matching end-tag \"\"" | ".xsd" | Scenario Outline: Comparing lddtool output files to expected files @@ -24,4 +24,4 @@ Feature: Running integration tests for lddtool Examples: | testName | inputDirectory | outputDirectory | commandArgs | expectedOutputFile | actualOutputFile | excludeStrings | - | "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738" | "-lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "PDS4_KPLO_1N00_1000.xsd" | ".xsd" | "PDS4 XML/Schema,Generated from the PDS4" | + | "NASA-PDS/pds4-information-model#738 LDDTool is not creating valid URL for KPLO" | "src/test/resources/github738" | "target/generated-files/github738_3" | "-V 1N00 -lpJ {inputDirectory}/PDS4_KPLO_IngestLDD.xml" | "PDS4_KPLO_1N00_1000.xsd" | ".xsd" | "PDS4 XML/Schema,Generated from the PDS4" |