Skip to content

Commit 9c73b39

Browse files
committed
Handle packed workflows with multiple choices through the JSON API
1 parent a3b9437 commit 9c73b39

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737

3838
import javax.servlet.http.HttpServletRequest;
3939
import javax.servlet.http.HttpServletResponse;
40-
import java.util.Collections;
41-
import java.util.Map;
40+
import java.util.*;
4241

4342
import static org.commonwl.view.cwl.CWLToolStatus.SUCCESS;
4443

@@ -121,6 +120,27 @@ public ResponseEntity<?> newWorkflowFromGitURLJson(@RequestParam(value="url") St
121120
if (queued == null) {
122121
try {
123122
queued = workflowService.createQueuedWorkflow(gitInfo);
123+
if (queued.getWorkflowList() != null) {
124+
if (queued.getWorkflowList().size() == 1) {
125+
// Parse the packed workflow within automatically if there is only one
126+
gitInfo.setPackedId(queued.getWorkflowList().get(0).getFileName());
127+
queued = workflowService.getQueuedWorkflow(gitInfo);
128+
if (queued == null) {
129+
queued = workflowService.createQueuedWorkflow(gitInfo);
130+
}
131+
} else {
132+
// Error with alternatives suggested
133+
List<String> workflowUris = new ArrayList<>();
134+
for (WorkflowOverview overview : queued.getWorkflowList()) {
135+
workflowUris.add(overview.getFileName());
136+
}
137+
Map<String, Object> responseMap = new HashMap<>();
138+
responseMap.put("message", "This workflow file is packed and contains multiple workflow " +
139+
"descriptions. Please choose one to add");
140+
responseMap.put("workflows", workflowUris);
141+
return new ResponseEntity<Map>(responseMap, HttpStatus.UNPROCESSABLE_ENTITY);
142+
}
143+
}
124144
} catch (CWLValidationException ex) {
125145
Map<String, String> message = Collections.singletonMap("message", "Error:" + ex.getMessage());
126146
return new ResponseEntity<Map>(message, HttpStatus.BAD_REQUEST);

0 commit comments

Comments
 (0)