19
19
20
20
package org .commonwl .viewer .web ;
21
21
22
+ import org .apache .commons .lang .StringUtils ;
22
23
import org .commonwl .viewer .domain .GithubDetails ;
23
24
import org .commonwl .viewer .domain .Workflow ;
24
25
import org .commonwl .viewer .domain .WorkflowForm ;
32
33
import org .springframework .stereotype .Controller ;
33
34
import org .springframework .validation .BindingResult ;
34
35
import org .springframework .web .bind .annotation .*;
36
+ import org .springframework .web .servlet .HandlerMapping ;
35
37
import org .springframework .web .servlet .ModelAndView ;
36
38
39
+ import javax .servlet .http .HttpServletRequest ;
37
40
import javax .servlet .http .HttpServletResponse ;
38
41
import javax .validation .Valid ;
39
42
import java .io .File ;
@@ -118,7 +121,7 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
118
121
* @return The workflow view with the workflow as a model
119
122
*/
120
123
@ RequestMapping (value ="/workflows/{workflowID}" )
121
- public ModelAndView getWorkflow (@ PathVariable String workflowID ){
124
+ public ModelAndView getWorkflowByID (@ PathVariable String workflowID ){
122
125
123
126
// Get workflow from database
124
127
Workflow workflowModel = workflowRepository .findOne (workflowID );
@@ -133,6 +136,40 @@ public ModelAndView getWorkflow(@PathVariable String workflowID){
133
136
134
137
}
135
138
139
+ /**
140
+ * Display a page for a particular workflow from Github details
141
+ * @param owner The owner of the Github repository
142
+ * @param repoName The name of the repository
143
+ * @param branch The branch of repository
144
+ * @return The workflow view with the workflow as a model
145
+ */
146
+ @ RequestMapping (value ="/workflows/github.com/{owner}/{repoName}/tree/{branch}/**" )
147
+ public ModelAndView getWorkflowByGithubDetails (@ PathVariable ("owner" ) String owner ,
148
+ @ PathVariable ("repoName" ) String repoName ,
149
+ @ PathVariable ("branch" ) String branch ,
150
+ HttpServletRequest request ) {
151
+
152
+ // The wildcard end of the URL is the path
153
+ String path = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
154
+ int pathStartIndex = StringUtils .ordinalIndexOf (path , "/" , 7 ) + 1 ;
155
+ path = path .substring (pathStartIndex );
156
+
157
+ // Construct a GithubDetails object to search for in the database
158
+ GithubDetails githubDetails = new GithubDetails (owner , repoName , branch , path );
159
+
160
+ // Get workflow from database
161
+ Workflow workflowModel = workflowRepository .findByRetrievedFrom (githubDetails );
162
+
163
+ // 404 error if workflow does not exist
164
+ if (workflowModel == null ) {
165
+ throw new WorkflowNotFoundException ();
166
+ }
167
+
168
+ // Display this model along with the view
169
+ return new ModelAndView ("workflow" , "workflow" , workflowModel );
170
+
171
+ }
172
+
136
173
/**
137
174
* Download the Research Object Bundle for a particular workflow
138
175
* @param workflowID The ID of the workflow to download
0 commit comments