@@ -147,13 +147,13 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
147
147
*/
148
148
@ GetMapping (value ={"/workflows/{domain}.com/{owner}/{repoName}/tree/{branch}/**" ,
149
149
"/workflows/{domain}.com/{owner}/{repoName}/blob/{branch}/**" })
150
- public ModelAndView getWorkflowByGithubDetails (@ Value ("${applicationURL}" ) String applicationURL ,
151
- @ PathVariable ("domain" ) String domain ,
152
- @ PathVariable ("owner" ) String owner ,
153
- @ PathVariable ("repoName" ) String repoName ,
154
- @ PathVariable ("branch" ) String branch ,
155
- HttpServletRequest request ,
156
- RedirectAttributes redirectAttrs ) {
150
+ public ModelAndView getWorkflowByGitSiteDetails (@ Value ("${applicationURL}" ) String applicationURL ,
151
+ @ PathVariable ("domain" ) String domain ,
152
+ @ PathVariable ("owner" ) String owner ,
153
+ @ PathVariable ("repoName" ) String repoName ,
154
+ @ PathVariable ("branch" ) String branch ,
155
+ HttpServletRequest request ,
156
+ RedirectAttributes redirectAttrs ) {
157
157
158
158
// The wildcard end of the URL is the path
159
159
String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
@@ -163,49 +163,38 @@ public ModelAndView getWorkflowByGithubDetails(@Value("${applicationURL}") Strin
163
163
GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
164
164
165
165
// Get workflow
166
- QueuedWorkflow queued = null ;
167
- Workflow workflowModel = workflowService .getWorkflow (gitDetails );
168
- if (workflowModel == null ) {
169
- // Check if already queued
170
- queued = workflowService .getQueuedWorkflow (gitDetails );
171
- if (queued == null ) {
172
- // Validation
173
- WorkflowForm workflowForm = new WorkflowForm (gitDetails .getUrl ());
174
- BeanPropertyBindingResult errors = new BeanPropertyBindingResult (workflowForm , "errors" );
175
- workflowFormValidator .validateAndParse (workflowForm , errors );
176
- if (!errors .hasErrors ()) {
177
- try {
178
- queued = workflowService .createQueuedWorkflow (gitDetails );
179
- } catch (GitAPIException ex ) {
180
- errors .rejectValue ("url" , "git.retrievalError" , ex .getMessage ());
181
- } catch (CWLValidationException ex ) {
182
- errors .rejectValue ("url" , "cwltool.validationError" , ex .getMessage ());
183
- } catch (IOException ex ) {
184
- errors .rejectValue ("url" , "githubURL.parsingError" , "The workflow could not be parsed from the given URL" );
185
- }
186
- }
187
- // Redirect to main page with errors if they occurred
188
- if (errors .hasErrors ()) {
189
- redirectAttrs .addFlashAttribute ("errors" , errors );
190
- return new ModelAndView ("redirect:/?url=" + gitDetails .getUrl ());
191
- }
192
- }
166
+ ModelAndView modelAndView = getWorkflow (gitDetails , redirectAttrs );
167
+ return modelAndView .addObject ("appURL" , applicationURL );
168
+
169
+ }
170
+
171
+ @ GetMapping (value ="/workflows/**/*.git/{branch}/**" )
172
+ public ModelAndView getWorkflowByGitDetails (@ Value ("${applicationURL}" ) String applicationURL ,
173
+ @ PathVariable ("branch" ) String branch ,
174
+ HttpServletRequest request ,
175
+ RedirectAttributes redirectAttrs ) {
176
+ String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
177
+
178
+ // The repository URL is the part after /workflows/ and up to and including .git
179
+ String repoUrl = path .substring (11 );
180
+ int extensionIndex = repoUrl .indexOf (".git" );
181
+ if (extensionIndex == -1 ) {
182
+ throw new WorkflowNotFoundException ();
193
183
}
184
+ repoUrl = "https://" + repoUrl .substring (0 , extensionIndex + 4 );
194
185
195
- // Display this model along with the view
196
- ModelAndView modelAndView ;
197
- if (queued != null ) {
198
- // Retry creation if there has been an error in cwltool parsing
199
- if (queued .getCwltoolStatus () == CWLToolStatus .ERROR ) {
200
- workflowService .retryCwltool (queued );
201
- }
202
- modelAndView = new ModelAndView ("loading" , "queued" , queued );
203
- } else {
204
- modelAndView = new ModelAndView ("workflow" , "workflow" , workflowModel );
186
+ // The path is after the branch
187
+ int slashAfterBranch = path .indexOf ("/" , path .indexOf (branch ));
188
+ if (slashAfterBranch == -1 || slashAfterBranch == path .length ()) {
189
+ throw new WorkflowNotFoundException ();
205
190
}
191
+ path = path .substring (slashAfterBranch + 1 );
206
192
207
- return modelAndView .addObject ("appURL" , applicationURL );
193
+ // Construct GitDetails object for this workflow
194
+ GitDetails gitDetails = new GitDetails (repoUrl , branch , path );
208
195
196
+ ModelAndView modelAndView = getWorkflow (gitDetails , redirectAttrs );
197
+ return modelAndView .addObject ("appURL" , applicationURL );
209
198
}
210
199
211
200
/**
@@ -381,4 +370,53 @@ public static GitDetails getGitDetails(String domain, String owner, String repoN
381
370
}
382
371
return new GitDetails (repoUrl , branch , path );
383
372
}
373
+
374
+ /**
375
+ * Get a workflow from Git Details
376
+ * @param gitDetails The details of the Git repository
377
+ * @param redirectAttrs Error attributes for redirect
378
+ * @return The model and view to be returned by the controller
379
+ */
380
+ private ModelAndView getWorkflow (GitDetails gitDetails , RedirectAttributes redirectAttrs ) {
381
+ // Get workflow
382
+ QueuedWorkflow queued = null ;
383
+ Workflow workflowModel = workflowService .getWorkflow (gitDetails );
384
+ if (workflowModel == null ) {
385
+ // Check if already queued
386
+ queued = workflowService .getQueuedWorkflow (gitDetails );
387
+ if (queued == null ) {
388
+ // Validation
389
+ WorkflowForm workflowForm = new WorkflowForm (gitDetails .getUrl ());
390
+ BeanPropertyBindingResult errors = new BeanPropertyBindingResult (workflowForm , "errors" );
391
+ workflowFormValidator .validateAndParse (workflowForm , errors );
392
+ if (!errors .hasErrors ()) {
393
+ try {
394
+ queued = workflowService .createQueuedWorkflow (gitDetails );
395
+ } catch (GitAPIException ex ) {
396
+ errors .rejectValue ("url" , "git.retrievalError" , ex .getMessage ());
397
+ } catch (CWLValidationException ex ) {
398
+ errors .rejectValue ("url" , "cwltool.validationError" , ex .getMessage ());
399
+ } catch (IOException ex ) {
400
+ errors .rejectValue ("url" , "githubURL.parsingError" , "The workflow could not be parsed from the given URL" );
401
+ }
402
+ }
403
+ // Redirect to main page with errors if they occurred
404
+ if (errors .hasErrors ()) {
405
+ redirectAttrs .addFlashAttribute ("errors" , errors );
406
+ return new ModelAndView ("redirect:/?url=" + gitDetails .getUrl ());
407
+ }
408
+ }
409
+ }
410
+
411
+ // Display this model along with the view
412
+ if (queued != null ) {
413
+ // Retry creation if there has been an error in cwltool parsing
414
+ if (queued .getCwltoolStatus () == CWLToolStatus .ERROR ) {
415
+ workflowService .retryCwltool (queued );
416
+ }
417
+ return new ModelAndView ("loading" , "queued" , queued );
418
+ } else {
419
+ return new ModelAndView ("workflow" , "workflow" , workflowModel );
420
+ }
421
+ }
384
422
}
0 commit comments