Skip to content

Commit 1f30577

Browse files
committed
Return text/uri-list if ?part= is missing
This is part of #176
1 parent 5fc1c6c commit 1f30577

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,46 @@ public void retryCwltool(QueuedWorkflow queuedWorkflow) {
396396
* @return A workflow model with the above two parameters
397397
*/
398398
public Workflow findByCommitAndPath(String commitID, String path) throws WorkflowNotFoundException {
399+
return findByCommitAndPath(commitID, path, Optional.empty());
400+
}
401+
402+
/**
403+
* Find a workflow by commit ID and path
404+
*
405+
* @param commitID
406+
* The commit ID of the workflow
407+
* @param path
408+
* The path to the workflow within the repository
409+
* @param part
410+
* The #part within the workflow, or Optional.empty() for no part, or
411+
* <code>null</code> for any part
412+
* @return A workflow model with the above two parameters
413+
*/
414+
public Workflow findByCommitAndPath(String commitID, String path, Optional<String> part)
415+
throws WorkflowNotFoundException, MultipleWorkflowsException {
399416
List<Workflow> matches = workflowRepository.findByCommitAndPath(commitID, path);
400-
if (matches == null || matches.size() == 0) {
417+
if (matches == null || matches.isEmpty()) {
401418
throw new WorkflowNotFoundException();
402-
} else if (matches.size() == 1) {
419+
} else if (part == null) {
420+
// any part will do - so we'll pick the first one
403421
return matches.get(0);
404422
} else {
405423
// Multiple matches means either added by both branch and ID
406424
// Or packed workflow
407425
for (Workflow workflow : matches) {
408-
if (workflow.getRetrievedFrom().getPackedId() != null) {
409-
// This is a packed file
410-
// TODO: return 300 multiple choices response for this in controller
411-
throw new WorkflowNotFoundException();
426+
if (Objects.equals(part.orElse(null), workflow.getRetrievedFrom().getPackedId())) {
427+
// either both are null; or both are non-null and equal
428+
return workflow;
412429
}
413430
}
414-
// Not a packed workflow, just different references to the same ID
415-
return matches.get(0);
431+
if (part.isPresent()) {
432+
// Sorry, don't know about your part!
433+
throw new WorkflowNotFoundException();
434+
} else {
435+
// No part requested, let's show some alternate permalinks,
436+
// in addition to the raw redirect
437+
throw new MultipleWorkflowsException(matches);
438+
}
416439
}
417440
}
418441

0 commit comments

Comments
 (0)