Skip to content

Commit addb177

Browse files
author
Mark Robinson
committed
Add controller method for URLs similar to github instead of IDs
Proposed in #29
1 parent 6d97305 commit addb177

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/main/java/org/commonwl/viewer/web/WorkflowController.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.viewer.web;
2121

22+
import org.apache.commons.lang.StringUtils;
2223
import org.commonwl.viewer.domain.GithubDetails;
2324
import org.commonwl.viewer.domain.Workflow;
2425
import org.commonwl.viewer.domain.WorkflowForm;
@@ -32,8 +33,10 @@
3233
import org.springframework.stereotype.Controller;
3334
import org.springframework.validation.BindingResult;
3435
import org.springframework.web.bind.annotation.*;
36+
import org.springframework.web.servlet.HandlerMapping;
3537
import org.springframework.web.servlet.ModelAndView;
3638

39+
import javax.servlet.http.HttpServletRequest;
3740
import javax.servlet.http.HttpServletResponse;
3841
import javax.validation.Valid;
3942
import java.io.File;
@@ -118,7 +121,7 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
118121
* @return The workflow view with the workflow as a model
119122
*/
120123
@RequestMapping(value="/workflows/{workflowID}")
121-
public ModelAndView getWorkflow(@PathVariable String workflowID){
124+
public ModelAndView getWorkflowByID(@PathVariable String workflowID){
122125

123126
// Get workflow from database
124127
Workflow workflowModel = workflowRepository.findOne(workflowID);
@@ -133,6 +136,40 @@ public ModelAndView getWorkflow(@PathVariable String workflowID){
133136

134137
}
135138

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+
136173
/**
137174
* Download the Research Object Bundle for a particular workflow
138175
* @param workflowID The ID of the workflow to download

0 commit comments

Comments
 (0)