diff --git a/src/main/java/nl/esciencecenter/controller/dto/WorkflowsZip.java b/src/main/java/nl/esciencecenter/controller/dto/WorkflowsZip.java index 97e7988..2ad9107 100644 --- a/src/main/java/nl/esciencecenter/controller/dto/WorkflowsZip.java +++ b/src/main/java/nl/esciencecenter/controller/dto/WorkflowsZip.java @@ -1,5 +1,6 @@ package nl.esciencecenter.controller.dto; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -82,15 +83,24 @@ public List getSnakemakePaths() { } /** - * Get the paths to the CWL, Snakemake and the SVG files. + * Get the paths to the existing CWL, Snakemake and the SVG files. * - * @return List of paths to the CWL, Snakemake and the SVG files. + * @return List of paths to the existing CWL, Snakemake and the SVG files. */ public List getAllPaths() { List paths = new ArrayList<>(); for (String fileName : workflows) { - paths.add(RestApeUtils.calculatePath(runID, "CWL", fileName)); - paths.add(RestApeUtils.calculatePath(runID, "Snakemake", fileName.replace(".cwl", ".smk"))); + + Path cwlPath = RestApeUtils.calculatePath(runID, "CWL", fileName); + if(Files.exists(cwlPath)) { + paths.add(cwlPath); + } + + Path smkPath = RestApeUtils.calculatePath(runID, "Snakemake", fileName.replace(".cwl", ".smk")); + if(Files.exists(smkPath)) { + paths.add(smkPath); + } + paths.add(RestApeUtils.calculatePath(runID, "Figures", fileName.replace(".cwl", ".svg"))); } return paths; diff --git a/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java b/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java index 240ae9d..8c89c70 100644 --- a/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java +++ b/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java @@ -8,6 +8,9 @@ import lombok.NoArgsConstructor; import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow; +import java.nio.file.Files; +import java.nio.file.Path; + /** * The {@link APEWorkflowMetadata} class represents metadata for a workflow solution from the APE solver. * This class encapsulates the details and metadata of a workflow solution, @@ -50,11 +53,26 @@ public APEWorkflowMetadata(SolutionWorkflow sol, String runID, boolean benchmark this.description = sol.getDescription(); this.workflowLength = sol.getSolutionLength(); this.runId = runID; - this.cwlName = sol.getFileName() + ".cwl"; - this.snakemakeName = sol.getFileName() + ".smk"; - this.figureName = sol.getFileName(); + + String fileName = sol.getFileName(); + + Path cwlPath = RestApeUtils.calculatePath(runID, "CWL", fileName + ".cwl"); + if(Files.notExists(cwlPath)) { + this.cwlName = ""; + } else { + this.cwlName = fileName + ".cwl"; + } + + Path smkPath = RestApeUtils.calculatePath(runID, "Snakemake", fileName + ".smk"); + if(Files.notExists(smkPath)) { + this.snakemakeName = ""; + } else { + this.snakemakeName = fileName + ".smk"; + } + + this.figureName = fileName; if (benchmark) { - this.benchmarkFile = sol.getFileName() + ".json"; + this.benchmarkFile = fileName + ".json"; } } diff --git a/src/main/java/nl/esciencecenter/restape/ApeAPI.java b/src/main/java/nl/esciencecenter/restape/ApeAPI.java index 14ac833..2e0a90f 100644 --- a/src/main/java/nl/esciencecenter/restape/ApeAPI.java +++ b/src/main/java/nl/esciencecenter/restape/ApeAPI.java @@ -246,11 +246,27 @@ public static List runSynthesis(JSONObject configJson, bool // Define the synthesis run ID String runID = RestApeUtils.generateRunID(configJson.toString()); - SolutionsList candidateSolutions = executeSynthesis(configJson, runID); + String solutionPath = RestApeUtils.createDirectory(runID); + + APE apeFramework = new APE(configJson); + + APERunConfig runConfig = new APERunConfig(configJson, apeFramework.getDomainSetup()); + + runConfig.setSolutionPath(solutionPath); + int maxSol = runConfig.getMaxNoSolutions(); + runConfig.setNoCWL(maxSol); + runConfig.setNoSnakemake(maxSol); + runConfig.setNoGraphs(maxSol); + runConfig.setDebugMode(true); + + boolean createPartialScripts = runConfig.getCreatePartialScripts(); + + // run the synthesis and retrieve the solutions + SolutionsList candidateSolutions = apeFramework.runSynthesis(runConfig); // Write solutions (as CWL and Snakemake files and figures) to the file system. - APE.writeCWLWorkflows(candidateSolutions, true); - APE.writeSnakemakeWorkflows(candidateSolutions, true); + APE.writeCWLWorkflows(candidateSolutions, createPartialScripts); + APE.writeSnakemakeWorkflows(candidateSolutions, createPartialScripts); APE.writeTavernaDesignGraphs(candidateSolutions, Format.SVG); APE.writeTavernaDesignGraphs(candidateSolutions, Format.PNG);