Skip to content

Commit 6ddfcee

Browse files
committed
Support packed workflows in permalinks
Fixes #176 by adding a new ?part= to the permalinks (It does not change the current %23 escaping in the UI, but that could also be considered. The UI parts are fixed to enable the permalinks also for packed workflows)
1 parent 764e063 commit 6ddfcee

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ private Optional<String> findRaw(String commitId, HttpServletRequest request) {
129129
@GetMapping(value = "/git/{commitid}/**",
130130
produces = "text/turtle")
131131
public byte[] getRdfAsTurtle(@PathVariable("commitid") String commitId,
132+
@RequestParam(name = "part") Optional<String> part,
132133
HttpServletRequest request,
133134
HttpServletResponse response) {
134-
Workflow workflow = getWorkflow(commitId, request);
135-
String rdfUrl = workflow.getPermalink();
135+
Workflow workflow = getWorkflow(commitId, request, part);
136+
String rdfUrl = workflow.getIdentifier();
136137
if (rdfService.graphExists(rdfUrl)) {
137138
response.setHeader("Content-Disposition", "inline; filename=\"workflow.ttl\"");
138139
return rdfService.getModel(rdfUrl, "TURTLE");
@@ -149,10 +150,11 @@ public byte[] getRdfAsTurtle(@PathVariable("commitid") String commitId,
149150
@GetMapping(value = "/git/{commitid}/**",
150151
produces = "application/ld+json")
151152
public byte[] getRdfAsJsonLd(@PathVariable("commitid") String commitId,
153+
@RequestParam(name = "part") Optional<String> part,
152154
HttpServletRequest request,
153155
HttpServletResponse response) {
154-
Workflow workflow = getWorkflow(commitId, request);
155-
String rdfUrl = workflow.getPermalink();
156+
Workflow workflow = getWorkflow(commitId, request, part);
157+
String rdfUrl = workflow.getIdentifier();
156158
if (rdfService.graphExists(rdfUrl)) {
157159
response.setHeader("Content-Disposition", "inline; filename=\"workflow.jsonld\"");
158160
return rdfService.getModel(rdfUrl, "JSON-LD");
@@ -169,10 +171,11 @@ public byte[] getRdfAsJsonLd(@PathVariable("commitid") String commitId,
169171
@GetMapping(value = "/git/{commitid}/**",
170172
produces = "application/rdf+xml")
171173
public byte[] getRdfAsRdfXml(@PathVariable("commitid") String commitId,
174+
@RequestParam(name = "part") Optional<String> part,
172175
HttpServletRequest request,
173176
HttpServletResponse response) {
174-
Workflow workflow = getWorkflow(commitId, request);
175-
String rdfUrl = workflow.getPermalink();
177+
Workflow workflow = getWorkflow(commitId, request, part);
178+
String rdfUrl = workflow.getIdentifier();
176179
if (rdfService.graphExists(rdfUrl)) {
177180
response.setHeader("Content-Disposition", "inline; filename=\"workflow.rdf\"");
178181
return rdfService.getModel(rdfUrl, "RDFXML");
@@ -189,9 +192,10 @@ public byte[] getRdfAsRdfXml(@PathVariable("commitid") String commitId,
189192
@GetMapping(value = "/git/{commitid}/**",
190193
produces = "image/svg+xml")
191194
public FileSystemResource getGraphAsSvg(@PathVariable("commitid") String commitId,
195+
@RequestParam(name = "part") Optional<String> part,
192196
HttpServletRequest request,
193197
HttpServletResponse response) {
194-
Workflow workflow = getWorkflow(commitId, request);
198+
Workflow workflow = getWorkflow(commitId, request, part);
195199
response.setHeader("Content-Disposition", "inline; filename=\"graph.svg\"");
196200
return workflowService.getWorkflowGraph("svg", workflow.getRetrievedFrom());
197201
}
@@ -204,9 +208,10 @@ public FileSystemResource getGraphAsSvg(@PathVariable("commitid") String commitI
204208
@GetMapping(value = "/git/{commitid}/**",
205209
produces = "image/png")
206210
public FileSystemResource getGraphAsPng(@PathVariable("commitid") String commitId,
211+
@RequestParam(name = "part") Optional<String> part,
207212
HttpServletRequest request,
208213
HttpServletResponse response) {
209-
Workflow workflow = getWorkflow(commitId, request);
214+
Workflow workflow = getWorkflow(commitId, request, part);
210215
response.setHeader("Content-Disposition", "inline; filename=\"graph.png\"");
211216
return workflowService.getWorkflowGraph("png", workflow.getRetrievedFrom());
212217
}
@@ -219,9 +224,10 @@ public FileSystemResource getGraphAsPng(@PathVariable("commitid") String commitI
219224
@GetMapping(value = "/git/{commitid}/**",
220225
produces = "text/vnd+graphviz")
221226
public FileSystemResource getGraphAsXDot(@PathVariable("commitid") String commitId,
227+
@RequestParam(name = "part") Optional<String> part,
222228
HttpServletRequest request,
223229
HttpServletResponse response) {
224-
Workflow workflow = getWorkflow(commitId, request);
230+
Workflow workflow = getWorkflow(commitId, request, part);
225231
response.setHeader("Content-Disposition", "inline; filename=\"graph.dot\"");
226232
return workflowService.getWorkflowGraph("xdot", workflow.getRetrievedFrom());
227233
}
@@ -235,24 +241,33 @@ public FileSystemResource getGraphAsXDot(@PathVariable("commitid") String commit
235241
@GetMapping(value = "/git/{commitid}/**",
236242
produces = {"application/vnd.wf4ever.robundle+zip", "application/zip"})
237243
public FileSystemResource getROBundle(@PathVariable("commitid") String commitId,
244+
@RequestParam(name = "part") Optional<String> part,
238245
HttpServletRequest request,
239246
HttpServletResponse response) {
240-
Workflow workflow = getWorkflow(commitId, request);
247+
Workflow workflow = getWorkflow(commitId, request, part);
241248
File bundleDownload = workflowService.getROBundle(workflow.getRetrievedFrom());
242249
response.setHeader("Content-Disposition", "attachment; filename=bundle.zip;");
243250
return new FileSystemResource(bundleDownload);
244251
}
245252

246253
/**
247254
* Get a workflow based on commit ID and extracting path from request
248-
* @param commitId The commit ID of the repository
249-
* @param request The HttpServletRequest from the controller to extract path
250-
* @throws WorkflowNotFoundException If workflow could not be found (404)
255+
*
256+
* @param commitId
257+
* The commit ID of the repository
258+
* @param request
259+
* The HttpServletRequest from the controller to extract path
260+
* @param part2
261+
* @throws WorkflowNotFoundException
262+
* If workflow could not be found (404)
263+
* @throws MultipleWorkflowsException
264+
* If multiple workflow (parts) were found (300)
251265
*/
252-
private Workflow getWorkflow(String commitId, HttpServletRequest request) throws WorkflowNotFoundException {
266+
private Workflow getWorkflow(String commitId, HttpServletRequest request, Optional<String> part)
267+
throws WorkflowNotFoundException {
253268
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
254269
path = WorkflowController.extractPath(path, 3);
255-
return workflowService.findByCommitAndPath(commitId, path);
270+
return workflowService.findByCommitAndPath(commitId, path, part);
256271
}
257272

258273
}

0 commit comments

Comments
 (0)