@@ -396,23 +396,46 @@ public void retryCwltool(QueuedWorkflow queuedWorkflow) {
396
396
* @return A workflow model with the above two parameters
397
397
*/
398
398
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 {
399
416
List <Workflow > matches = workflowRepository .findByCommitAndPath (commitID , path );
400
- if (matches == null || matches .size () == 0 ) {
417
+ if (matches == null || matches .isEmpty () ) {
401
418
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
403
421
return matches .get (0 );
404
422
} else {
405
423
// Multiple matches means either added by both branch and ID
406
424
// Or packed workflow
407
425
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 ;
412
429
}
413
430
}
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
+ }
416
439
}
417
440
}
418
441
0 commit comments