Skip to content

Commit 87909db

Browse files
committed
Ordered enum of supported formats, used by WorkflowController
.. to make permalinks at bottom of page
1 parent 4e8bbd7 commit 87909db

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

src/main/java/org/commonwl/view/WebConfig.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,48 @@
1919

2020
package org.commonwl.view;
2121

22+
import static org.springframework.http.MediaType.parseMediaType;
23+
2224
import org.springframework.context.annotation.Configuration;
2325
import org.springframework.http.MediaType;
2426
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
2527
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
2628

27-
import static org.springframework.http.MediaType.parseMediaType;
28-
2929
@Configuration
3030
public class WebConfig extends WebMvcConfigurerAdapter {
3131

32+
/**
33+
* Ordered list of formats as presented on Workflow page - must match the
34+
* .mediaType() strings below.
35+
*
36+
*/
37+
public static enum formats {
38+
html, json, turtle, jsonld, rdfxml, svg, png, dot, zip, ro, yaml, raw
39+
}
40+
3241
/**
3342
* Allows the use of the format query parameter to be used
3443
* instead of the Accept HTTP header
3544
*/
3645
@Override
3746
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
3847
configurer.favorParameter(true)
39-
.mediaType("html", MediaType.TEXT_HTML)
48+
// Browser
49+
.mediaType("html", MediaType.TEXT_HTML)
50+
// API
4051
.mediaType("json", MediaType.APPLICATION_JSON)
52+
// RDF
4153
.mediaType("turtle", parseMediaType("text/turtle"))
4254
.mediaType("jsonld", parseMediaType("application/ld+json"))
4355
.mediaType("rdfxml", parseMediaType("application/rdf+xml"))
56+
// Images
4457
.mediaType("svg", parseMediaType("image/svg+xml"))
4558
.mediaType("png", MediaType.IMAGE_PNG)
59+
.mediaType("dot", parseMediaType("text/vnd+graphviz"))
60+
// Archives
61+
.mediaType("zip", parseMediaType("application/zip"))
4662
.mediaType("ro", parseMediaType("application/vnd.wf4ever.robundle+zip"))
47-
.mediaType("zip", parseMediaType("application/zip"))
48-
.mediaType("dot", parseMediaType("text/vnd+graphviz"))
63+
// raw redirects
4964
.mediaType("yaml", parseMediaType("text/x-yaml"))
5065
.mediaType("raw", MediaType.APPLICATION_OCTET_STREAM);
5166
}

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@
1919

2020
package org.commonwl.view.workflow;
2121

22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.util.List;
25+
26+
import javax.servlet.http.HttpServletRequest;
27+
import javax.servlet.http.HttpServletResponse;
28+
import javax.validation.Valid;
29+
2230
import org.apache.commons.lang.StringUtils;
31+
import org.commonwl.view.WebConfig;
2332
import org.commonwl.view.cwl.CWLToolStatus;
2433
import org.commonwl.view.git.GitDetails;
2534
import org.commonwl.view.graphviz.GraphVizService;
@@ -36,18 +45,15 @@
3645
import org.springframework.ui.Model;
3746
import org.springframework.validation.BeanPropertyBindingResult;
3847
import org.springframework.validation.BindingResult;
39-
import org.springframework.web.bind.annotation.*;
48+
import org.springframework.web.bind.annotation.GetMapping;
49+
import org.springframework.web.bind.annotation.PathVariable;
50+
import org.springframework.web.bind.annotation.PostMapping;
51+
import org.springframework.web.bind.annotation.RequestParam;
52+
import org.springframework.web.bind.annotation.ResponseBody;
4053
import org.springframework.web.servlet.HandlerMapping;
4154
import org.springframework.web.servlet.ModelAndView;
4255
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
4356

44-
import javax.servlet.http.HttpServletRequest;
45-
import javax.servlet.http.HttpServletResponse;
46-
import javax.validation.Valid;
47-
import java.io.File;
48-
import java.io.IOException;
49-
import java.util.List;
50-
5157
@Controller
5258
public class WorkflowController {
5359

@@ -58,15 +64,19 @@ public class WorkflowController {
5864
private final GraphVizService graphVizService;
5965

6066
/**
61-
* Autowired constructor to initialise objects used by the controller
62-
* @param workflowFormValidator Validator to validate the workflow form
63-
* @param workflowService Builds new Workflow objects
64-
* @param graphVizService Generates and stores imagess
67+
* Autowired constructor to initialise objects used by the controller.
68+
*
69+
* @param workflowFormValidator
70+
* Validator to validate the workflow form
71+
* @param workflowService
72+
* Builds new Workflow objects
73+
* @param graphVizService
74+
* Generates and stores images
6575
*/
6676
@Autowired
6777
public WorkflowController(WorkflowFormValidator workflowFormValidator,
6878
WorkflowService workflowService,
69-
GraphVizService graphVizService) {
79+
GraphVizService graphVizService) {
7080
this.workflowFormValidator = workflowFormValidator;
7181
this.workflowService = workflowService;
7282
this.graphVizService = graphVizService;
@@ -532,7 +542,8 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
532542
}
533543
return new ModelAndView("loading", "queued", queued);
534544
} else {
535-
return new ModelAndView("workflow", "workflow", workflowModel);
545+
return new ModelAndView("workflow", "workflow", workflowModel).addObject("formats",
546+
WebConfig.formats.values());
536547
}
537548
}
538549
}

0 commit comments

Comments
 (0)