Skip to content

Commit 30dc589

Browse files
committed
Add select workflow page for packed files with multiple workflows
Standard parsing if only one
1 parent f38d547 commit 30dc589

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ public List<WorkflowOverview> getWorkflowOverviewsFromPacked(File packedFile) th
158158
/**
159159
* Gets the Workflow object from internal parsing
160160
* @param workflowFile The workflow file to be parsed
161+
* @param packedWorkflowId The ID of the workflow object if the file is packed
161162
* @return The constructed workflow object
162163
*/
163-
public Workflow parseWorkflowNative(File workflowFile) throws IOException {
164+
public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId) throws IOException {
164165

165166
// Check file size limit before parsing
166167
long fileSizeBytes = workflowFile.length();
@@ -169,14 +170,12 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
169170
// Parse file as yaml
170171
JsonNode cwlFile = yamlStringToJson(readFileToString(workflowFile));
171172

172-
// If the CWL file is packed there can be multiple workflows in a file
173-
Map<String, JsonNode> packedFiles = new HashMap<>();
174-
if (cwlFile.has(DOC_GRAPH)) {
175-
// Packed CWL, find the first subelement which is a workflow and take it
173+
if (packedWorkflowId != null) {
176174
for (JsonNode jsonNode : cwlFile.get(DOC_GRAPH)) {
177-
packedFiles.put(jsonNode.get(ID).asText(), jsonNode);
178-
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW) {
175+
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW &&
176+
jsonNode.get(ID).asText().equals(packedWorkflowId)) {
179177
cwlFile = jsonNode;
178+
break;
180179
}
181180
}
182181
}
@@ -190,10 +189,7 @@ public Workflow parseWorkflowNative(File workflowFile) throws IOException {
190189
// Construct the rest of the workflow model
191190
Workflow workflowModel = new Workflow(label, extractDoc(cwlFile), getInputs(cwlFile),
192191
getOutputs(cwlFile), getSteps(cwlFile), null);
193-
194-
if (packedFiles.size() > 0) {
195-
workflowModel.setPackedWorkflowID(cwlFile.get(ID).asText());
196-
}
192+
workflowModel.setPackedWorkflowID(packedWorkflowId);
197193

198194
workflowModel.setCwltoolVersion(cwlTool.getVersion());
199195

@@ -510,7 +506,7 @@ public WorkflowOverview getWorkflowOverview(File file) throws IOException {
510506
}
511507

512508
// Return the constructed overview
513-
return new WorkflowOverview(file.getName(), label, extractDoc(cwlFile));
509+
return new WorkflowOverview("/" + file.getName(), label, extractDoc(cwlFile));
514510
} else {
515511
// Return null if not a workflow file
516512
return null;

src/main/java/org/commonwl/view/workflow/QueuedWorkflow.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import org.commonwl.view.cwl.CWLToolStatus;
66
import org.springframework.data.annotation.Id;
77

8+
import java.util.List;
9+
810
/**
911
* A workflow pending completion of cwltool
1012
*/
11-
@JsonIgnoreProperties(value = {"id", "tempRepresentation"})
13+
@JsonIgnoreProperties(value = {"id", "tempRepresentation", "workflowList"})
1214
@JsonInclude(JsonInclude.Include.NON_EMPTY)
1315
public class QueuedWorkflow {
1416

@@ -19,6 +21,10 @@ public class QueuedWorkflow {
1921
// Very barebones workflow to build loading thumbnail and overview
2022
private Workflow tempRepresentation;
2123

24+
// List of packed workflows for packed workflows
25+
// TODO: Refactor so this is not necessary
26+
private List<WorkflowOverview> workflowList;
27+
2228
// Cwltool details
2329
private CWLToolStatus cwltoolStatus = CWLToolStatus.RUNNING;
2430
private String cwltoolVersion = "";
@@ -60,4 +66,11 @@ public void setMessage(String message) {
6066
this.message = message;
6167
}
6268

69+
public List<WorkflowOverview> getWorkflowList() {
70+
return workflowList;
71+
}
72+
73+
public void setWorkflowList(List<WorkflowOverview> workflowList) {
74+
this.workflowList = workflowList;
75+
}
6376
}

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ public ModelAndView createWorkflow(@Valid WorkflowForm workflowForm, BindingResu
122122
if (workflow == null) {
123123
try {
124124
if (gitInfo.getPath().endsWith(".cwl")) {
125-
workflow = workflowService.createQueuedWorkflow(gitInfo).getTempRepresentation();
125+
QueuedWorkflow result = workflowService.createQueuedWorkflow(gitInfo);
126+
if (result.getWorkflowList() == null) {
127+
workflow = result.getTempRepresentation();
128+
} else {
129+
return new ModelAndView("redirect:" + gitInfo.getInternalUrl());
130+
}
126131
} else {
127132
return new ModelAndView("redirect:" + gitInfo.getInternalUrl());
128133
}
@@ -460,6 +465,11 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
460465
try {
461466
if (gitDetails.getPath().endsWith(".cwl")) {
462467
queued = workflowService.createQueuedWorkflow(gitDetails);
468+
if (queued.getWorkflowList() != null) {
469+
// Packed workflow listing
470+
return new ModelAndView("selectworkflow", "workflowOverviews", queued.getWorkflowList())
471+
.addObject("gitDetails", gitDetails);
472+
}
463473
} else {
464474
List<WorkflowOverview> workflowOverviews = workflowService.getWorkflowsFromDirectory(gitDetails);
465475
if (workflowOverviews.size() > 1) {

src/main/java/org/commonwl/view/workflow/WorkflowService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,24 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
307307
}
308308

309309
File workflowFile = new File(pathToWorkflowFile.toString());
310-
Workflow basicModel = cwlService.parseWorkflowNative(workflowFile);
310+
311+
// Handling of packed workflows
312+
String packedWorkflowId = null;
313+
if (cwlService.isPacked(workflowFile)) {
314+
List<WorkflowOverview> overviews = cwlService.getWorkflowOverviewsFromPacked(workflowFile);
315+
if (overviews.size() == 0) {
316+
throw new IOException("No workflow was found within the packed CWL file");
317+
} else if (overviews.size() == 1) {
318+
packedWorkflowId = overviews.get(0).getFileName();
319+
} else {
320+
// Dummy queued workflow object to return the list
321+
QueuedWorkflow overviewList = new QueuedWorkflow();
322+
overviewList.setWorkflowList(overviews);
323+
return overviewList;
324+
}
325+
}
326+
327+
Workflow basicModel = cwlService.parseWorkflowNative(workflowFile, packedWorkflowId);
311328

312329
// Set origin details
313330
basicModel.setRetrievedOn(new Date());

src/main/resources/templates/selectworkflow.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ <h1 th:text="'Choose Workflow from ' + ${gitDetails.path}">Choose Workflow</h1>
3838
<p>Multiple CWL files were found, please select the workflow you would like to view below</p>
3939
</div>
4040
<div class="list-group">
41-
<a href="#" class="list-group-item" th:each="workflowOverview : ${workflowOverviews}" th:href="@{${gitDetails.getInternalUrl()} + '/' + ${workflowOverview.fileName}}">
42-
<h4 class="list-group-item-heading" th:text="${workflowOverview.fileName}">ExampleWorkflow.cwl</h4>
41+
<a href="#" class="list-group-item" th:each="workflowOverview : ${workflowOverviews}" th:href="@{${gitDetails.getInternalUrl()} + ${workflowOverview.fileName.replace('#', '%23')}}">
42+
<h4 class="list-group-item-heading" th:text="${workflowOverview.fileName.replaceFirst('^/', '')}">ExampleWorkflow.cwl</h4>
4343
<p class="list-group-item-text">
4444
<span th:if="${workflowOverview.label != null}" th:text="${workflowOverview.label}">Label</span>
4545
<i th:if="${workflowOverview.doc != null}" th:text="' - ' + ${workflowOverview.doc}">Doc</i>

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public ResultSet answer(InvocationOnMock invocation) throws Throwable {
9494
public void parseLobSTRDraft3WorkflowNative() throws Exception {
9595
CWLService cwlService = new CWLService(rdfService, Mockito.mock(CWLTool.class), 5242880);
9696
Workflow lobSTRDraft3 = cwlService.parseWorkflowNative(
97-
new File("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl"));
97+
new File("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl"), null);
9898
testLobSTRWorkflow(lobSTRDraft3, true);
9999
}
100100

@@ -105,7 +105,7 @@ public void parseLobSTRDraft3WorkflowNative() throws Exception {
105105
public void parseLobSTRv1WorkflowNative() throws Exception {
106106
CWLService cwlService = new CWLService(rdfService, new CWLTool(), 5242880);
107107
Workflow lobSTRv1 = cwlService.parseWorkflowNative(
108-
new File("src/test/resources/cwl/lobstr-v1/lobSTR-workflow.cwl"));
108+
new File("src/test/resources/cwl/lobstr-v1/lobSTR-workflow.cwl"), null);
109109
testLobSTRWorkflow(lobSTRv1, true);
110110
}
111111

@@ -157,7 +157,7 @@ public void workflowOverSingleFileSizeLimitThrowsIOException() throws Exception
157157

158158
CWLService cwlService = new CWLService(rdfService, Mockito.mock(CWLTool.class), 0);
159159
cwlService.parseWorkflowNative(
160-
new File("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl"));
160+
new File("src/test/resources/cwl/lobstr-draft3/lobSTR-workflow.cwl"), null);
161161

162162
}
163163

src/test/java/org/commonwl/view/workflow/WorkflowServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void getWorkflowCacheHasExpired() throws Exception {
125125
when(mockWorkflowRepo.findByRetrievedFrom(anyObject())).thenReturn(oldWorkflow);
126126

127127
CWLService mockCWLService = Mockito.mock(CWLService.class);
128-
when(mockCWLService.parseWorkflowNative(anyObject())).thenReturn(updatedWorkflow);
128+
when(mockCWLService.parseWorkflowNative(anyObject(), anyObject())).thenReturn(updatedWorkflow);
129129

130130
Repository mockRepo = Mockito.mock(Repository.class);
131131
when(mockRepo.getWorkTree()).thenReturn(new File("src/test/resources/cwl/make_to_cwl/dna.cwl"));

0 commit comments

Comments
 (0)