23
23
import org .commonwl .view .cwl .CWLToolStatus ;
24
24
import org .commonwl .view .cwl .CWLValidationException ;
25
25
import org .commonwl .view .git .GitDetails ;
26
- import org .commonwl .view .git .GitType ;
27
26
import org .commonwl .view .graphviz .GraphVizService ;
28
27
import org .eclipse .jgit .api .errors .GitAPIException ;
29
28
import org .slf4j .Logger ;
@@ -139,15 +138,17 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
139
138
}
140
139
141
140
/**
142
- * Display a page for a particular workflow from Github details
143
- * @param owner The owner of the Github repository
141
+ * Display a page for a particular workflow from Github or Github format URL
142
+ * @param domain The domain of the hosting site, Github or Gitlab
143
+ * @param owner The owner of the repository
144
144
* @param repoName The name of the repository
145
145
* @param branch The branch of repository
146
146
* @return The workflow view with the workflow as a model
147
147
*/
148
- @ GetMapping (value ={"/workflows/github .com/{owner}/{repoName}/tree/{branch}/**" ,
149
- "/workflows/github .com/{owner}/{repoName}/blob/{branch}/**" })
148
+ @ GetMapping (value ={"/workflows/{domain} .com/{owner}/{repoName}/tree/{branch}/**" ,
149
+ "/workflows/{domain} .com/{owner}/{repoName}/blob/{branch}/**" })
150
150
public ModelAndView getWorkflowByGithubDetails (@ Value ("${applicationURL}" ) String applicationURL ,
151
+ @ PathVariable ("domain" ) String domain ,
151
152
@ PathVariable ("owner" ) String owner ,
152
153
@ PathVariable ("repoName" ) String repoName ,
153
154
@ PathVariable ("branch" ) String branch ,
@@ -159,8 +160,7 @@ public ModelAndView getWorkflowByGithubDetails(@Value("${applicationURL}") Strin
159
160
path = extractPath (path , 7 );
160
161
161
162
// Construct a GitDetails object to search for in the database
162
- GitDetails gitDetails = new GitDetails ("https://github.com/" + owner + "/" +
163
- repoName + ".git" , branch , path , GitType .GITHUB );
163
+ GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
164
164
165
165
// Get workflow
166
166
QueuedWorkflow queued = null ;
@@ -210,23 +210,24 @@ public ModelAndView getWorkflowByGithubDetails(@Value("${applicationURL}") Strin
210
210
211
211
/**
212
212
* Download the Research Object Bundle for a particular workflow
213
- * @param owner The owner of the Github repository
213
+ * @param domain The domain of the hosting site, Github or Gitlab
214
+ * @param owner The owner of the repository
214
215
* @param repoName The name of the repository
215
216
* @param branch The branch of repository
216
217
*/
217
- @ GetMapping (value ={"/robundle/github .com/{owner}/{repoName}/tree/{branch}/**" ,
218
- "/robundle/github .com/{owner}/{repoName}/blob/{branch}/**" },
218
+ @ GetMapping (value ={"/robundle/{domain} .com/{owner}/{repoName}/tree/{branch}/**" ,
219
+ "/robundle/{domain} .com/{owner}/{repoName}/blob/{branch}/**" },
219
220
produces = "application/vnd.wf4ever.robundle+zip" )
220
221
@ ResponseBody
221
- public FileSystemResource downloadROBundle (@ PathVariable ("owner" ) String owner ,
222
- @ PathVariable ("repoName" ) String repoName ,
223
- @ PathVariable ("branch" ) String branch ,
224
- HttpServletRequest request ,
225
- HttpServletResponse response ) throws IOException {
222
+ public FileSystemResource downloadROBundle (@ PathVariable ("domain" ) String domain ,
223
+ @ PathVariable ("owner" ) String owner ,
224
+ @ PathVariable ("repoName" ) String repoName ,
225
+ @ PathVariable ("branch" ) String branch ,
226
+ HttpServletRequest request ,
227
+ HttpServletResponse response ) throws IOException {
226
228
String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
227
229
path = extractPath (path , 7 );
228
- GitDetails gitDetails = new GitDetails ("https://github.com/" + owner + "/" +
229
- repoName + ".git" , branch , path , GitType .GITHUB );
230
+ GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
230
231
File bundleDownload = workflowService .getROBundle (gitDetails );
231
232
response .setHeader ("Content-Disposition" , "attachment; filename=bundle.zip;" );
232
233
return new FileSystemResource (bundleDownload );
@@ -235,23 +236,24 @@ public FileSystemResource downloadROBundle(@PathVariable("owner") String owner,
235
236
236
237
/**
237
238
* Download a generated graph for a workflow as an svg
238
- * @param owner The owner of the Github repository
239
+ * @param domain The domain of the hosting site, Github or Gitlab
240
+ * @param owner The owner of the repository
239
241
* @param repoName The name of the repository
240
242
* @param branch The branch of repository
241
243
*/
242
- @ GetMapping (value ={"/graph/svg/github .com/{owner}/{repoName}/tree/{branch}/**" ,
243
- "/graph/svg/github .com/{owner}/{repoName}/blob/{branch}/**" },
244
+ @ GetMapping (value ={"/graph/svg/{domain} .com/{owner}/{repoName}/tree/{branch}/**" ,
245
+ "/graph/svg/{domain} .com/{owner}/{repoName}/blob/{branch}/**" },
244
246
produces = "image/svg+xml" )
245
247
@ ResponseBody
246
- public FileSystemResource getGraphAsSvg (@ PathVariable ("owner" ) String owner ,
248
+ public FileSystemResource getGraphAsSvg (@ PathVariable ("domain" ) String domain ,
249
+ @ PathVariable ("owner" ) String owner ,
247
250
@ PathVariable ("repoName" ) String repoName ,
248
251
@ PathVariable ("branch" ) String branch ,
249
252
HttpServletRequest request ,
250
253
HttpServletResponse response ) throws IOException {
251
254
String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
252
255
path = extractPath (path , 8 );
253
- GitDetails gitDetails = new GitDetails ("https://github.com/" + owner + "/" +
254
- repoName + ".git" , branch , path , GitType .GITHUB );
256
+ GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
255
257
Workflow workflow = workflowService .getWorkflow (gitDetails );
256
258
if (workflow == null ) {
257
259
throw new WorkflowNotFoundException ();
@@ -263,23 +265,24 @@ public FileSystemResource getGraphAsSvg(@PathVariable("owner") String owner,
263
265
264
266
/**
265
267
* Download a generated DOT graph for a workflow as a png
266
- * @param owner The owner of the Github repository
268
+ * @param domain The domain of the hosting site, Github or Gitlab
269
+ * @param owner The owner of the repository
267
270
* @param repoName The name of the repository
268
271
* @param branch The branch of repository
269
272
*/
270
- @ GetMapping (value ={"/graph/png/github .com/{owner}/{repoName}/tree/{branch}/**" ,
271
- "/graph/png/github .com/{owner}/{repoName}/blob/{branch}/**" },
273
+ @ GetMapping (value ={"/graph/png/{domain} .com/{owner}/{repoName}/tree/{branch}/**" ,
274
+ "/graph/png/{domain} .com/{owner}/{repoName}/blob/{branch}/**" },
272
275
produces = "image/png" )
273
276
@ ResponseBody
274
- public FileSystemResource getGraphAsPng (@ PathVariable ("owner" ) String owner ,
277
+ public FileSystemResource getGraphAsPng (@ PathVariable ("domain" ) String domain ,
278
+ @ PathVariable ("owner" ) String owner ,
275
279
@ PathVariable ("repoName" ) String repoName ,
276
280
@ PathVariable ("branch" ) String branch ,
277
281
HttpServletRequest request ,
278
282
HttpServletResponse response ) throws IOException {
279
283
String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
280
284
path = extractPath (path , 8 );
281
- GitDetails gitDetails = new GitDetails ("https://github.com/" + owner + "/" +
282
- repoName + ".git" , branch , path , GitType .GITHUB );
285
+ GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
283
286
Workflow workflow = workflowService .getWorkflow (gitDetails );
284
287
if (workflow == null ) {
285
288
throw new WorkflowNotFoundException ();
@@ -291,23 +294,24 @@ public FileSystemResource getGraphAsPng(@PathVariable("owner") String owner,
291
294
292
295
/**
293
296
* Download a generated DOT graph for a workflow as xdot
294
- * @param owner The owner of the Github repository
297
+ * @param domain The domain of the hosting site, Github or Gitlab
298
+ * @param owner The owner of the repository
295
299
* @param repoName The name of the repository
296
300
* @param branch The branch of repository
297
301
*/
298
- @ GetMapping (value ={"/graph/xdot/github .com/{owner}/{repoName}/tree/{branch}/**" ,
299
- "/graph/xdot/github .com/{owner}/{repoName}/blob/{branch}/**" },
302
+ @ GetMapping (value ={"/graph/xdot/{domain} .com/{owner}/{repoName}/tree/{branch}/**" ,
303
+ "/graph/xdot/{domain} .com/{owner}/{repoName}/blob/{branch}/**" },
300
304
produces = "text/vnd.graphviz" )
301
305
@ ResponseBody
302
- public FileSystemResource getGraphAsXdot (@ PathVariable ("owner" ) String owner ,
306
+ public FileSystemResource getGraphAsXdot (@ PathVariable ("domain" ) String domain ,
307
+ @ PathVariable ("owner" ) String owner ,
303
308
@ PathVariable ("repoName" ) String repoName ,
304
309
@ PathVariable ("branch" ) String branch ,
305
310
HttpServletRequest request ,
306
311
HttpServletResponse response ) throws IOException {
307
312
String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
308
313
path = extractPath (path , 8 );
309
- GitDetails gitDetails = new GitDetails ("https://github.com/" + owner + "/" +
310
- repoName + ".git" , branch , path , GitType .GITHUB );
314
+ GitDetails gitDetails = getGitDetails (domain , owner , repoName , branch , path );
311
315
Workflow workflow = workflowService .getWorkflow (gitDetails );
312
316
if (workflow == null ) {
313
317
throw new WorkflowNotFoundException ();
@@ -352,4 +356,29 @@ public static String extractPath(String path, int startSlashNum) {
352
356
return "/" ;
353
357
}
354
358
}
359
+
360
+ /**
361
+ * Constructs a GitDetails object for Github/Gitlab details
362
+ * @param domain The domain name (always .com)
363
+ * @param owner The owner of the repository
364
+ * @param repoName The name of the repository
365
+ * @param branch The branch of the repository
366
+ * @param path The path within the repository
367
+ * @return A constructed GitDetails object
368
+ */
369
+ public static GitDetails getGitDetails (String domain , String owner , String repoName ,
370
+ String branch , String path ) {
371
+ String repoUrl ;
372
+ switch (domain ) {
373
+ case "github" :
374
+ repoUrl = "https://github.com/" + owner + "/" + repoName + ".git" ;
375
+ break ;
376
+ case "gitlab" :
377
+ repoUrl = "https://gitlab.com/" + owner + "/" + repoName + ".git" ;
378
+ break ;
379
+ default :
380
+ throw new WorkflowNotFoundException ();
381
+ }
382
+ return new GitDetails (repoUrl , branch , path );
383
+ }
355
384
}
0 commit comments