diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/OmexHandler.java b/vcell-cli/src/main/java/org/vcell/cli/run/OmexHandler.java index dc164bde3e..7b0857cc4d 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/OmexHandler.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/OmexHandler.java @@ -13,10 +13,7 @@ import java.net.URI; import java.nio.file.*; import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class OmexHandler { String tempPath; @@ -111,40 +108,35 @@ public static void rename(String zipFileName, String entryOldName, String entryN } } - public ArrayList getSedmlLocationsRelative(){ - ArrayList sedmlList = new ArrayList<>(); - + public List getSedmlLocationsRelative(){ Collection entries = this.archive.getEntries(); + int MASTER = 1; + int REGULAR = 2; int masterCount = 0; + Map> sedmlMap = new HashMap<>(); + sedmlMap.put(MASTER, new ArrayList<>()); + sedmlMap.put(REGULAR, new ArrayList<>()); + for (ArchiveEntry entry : entries) { - if (entry.isMainEntry()) { - if (isSedmlFormat(entry)) { - masterCount++; - } else { - throw new RuntimeException("No SED-ML's are intended to be executed (non SED-ML file is set to be master)"); - } - } + boolean isMaster = entry.isMainEntry(); + if (isMaster) masterCount++; + if (!this.isSedmlFormat(entry)) continue; + sedmlMap.get(isMaster ? MASTER : REGULAR).add(entry); } - if( masterCount > 1) { - throw new RuntimeException("More than two master SED-ML's found"); - } + // Test corner cases + if (sedmlMap.get(MASTER).isEmpty()){ + if (masterCount > 0) + throw new RuntimeException("No SED-MLs are intended to be executed (non SED-ML file is set to be master)"); + if (sedmlMap.get(REGULAR).isEmpty()) + throw new RuntimeException("There are no SED-MLs in the archive to execute"); - for (ArchiveEntry entry : entries) { - if(masterCount == 0 ) { - if (isSedmlFormat(entry)) { - sedmlList.add(entry.getFilePath()); - } - } else { - if (isSedmlFormat(entry) && entry.isMainEntry()) { - sedmlList.add(entry.getFilePath()); - } - } + return sedmlMap.get(REGULAR).stream().map(ArchiveEntry::getFilePath).toList(); } - return sedmlList; + return sedmlMap.get(MASTER).stream().map(ArchiveEntry::getFilePath).toList(); } private boolean isSedmlFormat(ArchiveEntry entry) { @@ -155,7 +147,7 @@ private boolean isSedmlFormat(ArchiveEntry entry) { public ArrayList getSedmlLocationsAbsolute(){ ArrayList sedmlListAbsolute = new ArrayList<>(); - ArrayList sedmlListRelative = this.getSedmlLocationsRelative(); + List sedmlListRelative = this.getSedmlLocationsRelative(); for (String sedmlFileRelative : sedmlListRelative) { sedmlListAbsolute.add(Paths.get(this.tempPath, sedmlFileRelative).normalize().toString()); @@ -166,7 +158,7 @@ public ArrayList getSedmlLocationsAbsolute(){ public String getOutputPathFromSedml(String absoluteSedmlPath) { String outputPath = ""; //String sedmlName = absoluteSedmlPath.substring(absoluteSedmlPath.lastIndexOf(File.separator) + 1); - ArrayList sedmlListRelative = this.getSedmlLocationsRelative(); + List sedmlListRelative = this.getSedmlLocationsRelative(); for (String sedmlFileRelative : sedmlListRelative) { boolean check = absoluteSedmlPath.contains(Paths.get(sedmlFileRelative).normalize().toString()); if (check) { diff --git a/vcell-core/src/main/java/org/jlibsedml/execution/ModelResolver.java b/vcell-core/src/main/java/org/jlibsedml/execution/ModelResolver.java index 8b61dd2621..35ac685e47 100644 --- a/vcell-core/src/main/java/org/jlibsedml/execution/ModelResolver.java +++ b/vcell-core/src/main/java/org/jlibsedml/execution/ModelResolver.java @@ -118,7 +118,11 @@ public String getModelString(Model m) { try { String modelRef = baseModelRef; do { - srcURI = sedml.getModelWithId(modelRef).getSourceURI(); + org.jlibsedml.Model mod = sedml.getModelWithId(modelRef); + URI testURI = new URI("test%20model.xml"); + String roundTrip = testURI.toASCIIString(); + roundTrip = testURI.toString(); + srcURI = mod.getSourceURI(); // If we need to recurse to the next level: modelRef = sedml.getModelWithId(modelRef.startsWith("#") ? modelRef.substring(1): modelRef).getSourcePathOrURIString();