Skip to content

Commit 9929cfa

Browse files
authored
Merge pull request #175 from common-workflow-language/permalinks-ui
Show permalinks in HTML
2 parents ec30452 + b23cd02 commit 9929cfa

File tree

7 files changed

+269
-57
lines changed

7 files changed

+269
-57
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/researchobject/ROBundleService.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,33 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22+
import static org.apache.commons.io.FileUtils.readFileToString;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.net.URI;
27+
import java.net.URISyntaxException;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.nio.file.Paths;
31+
import java.util.ArrayList;
32+
import java.util.HashSet;
33+
import java.util.List;
34+
import java.util.Set;
35+
import java.util.regex.Matcher;
36+
import java.util.regex.Pattern;
37+
2238
import org.apache.commons.io.FileUtils;
2339
import org.apache.commons.io.FilenameUtils;
2440
import org.apache.jena.query.QuerySolution;
2541
import org.apache.jena.query.ResultSet;
2642
import org.apache.taverna.robundle.Bundle;
2743
import org.apache.taverna.robundle.Bundles;
28-
import org.apache.taverna.robundle.manifest.*;
44+
import org.apache.taverna.robundle.manifest.Agent;
45+
import org.apache.taverna.robundle.manifest.Manifest;
46+
import org.apache.taverna.robundle.manifest.PathAnnotation;
47+
import org.apache.taverna.robundle.manifest.PathMetadata;
48+
import org.apache.taverna.robundle.manifest.Proxy;
2949
import org.commonwl.view.cwl.CWLTool;
3050
import org.commonwl.view.cwl.CWLValidationException;
3151
import org.commonwl.view.cwl.RDFService;
@@ -42,22 +62,6 @@
4262
import org.springframework.beans.factory.annotation.Value;
4363
import org.springframework.stereotype.Service;
4464

45-
import java.io.File;
46-
import java.io.IOException;
47-
import java.net.URI;
48-
import java.net.URISyntaxException;
49-
import java.nio.file.Files;
50-
import java.nio.file.Path;
51-
import java.nio.file.Paths;
52-
import java.util.ArrayList;
53-
import java.util.HashSet;
54-
import java.util.List;
55-
import java.util.Set;
56-
import java.util.regex.Matcher;
57-
import java.util.regex.Pattern;
58-
59-
import static org.apache.commons.io.FileUtils.readFileToString;
60-
6165
/**
6266
* Service handling Research Object Bundles
6367
*/
@@ -197,8 +201,11 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
197201

198202
// Git2prov history
199203
List<Path> history = new ArrayList<>();
200-
history.add(Paths.get("http://git2prov.org/git2prov?giturl=" +
201-
gitInfo.getRepoUrl() + "&serialization=PROV-JSON"));
204+
// FIXME: Below is a a hack to pretend the URI is a Path
205+
String git2prov = "http://git2prov.org/git2prov?giturl=" + gitInfo.getRepoUrl()
206+
+ "&serialization=PROV-JSON";
207+
Path git2ProvPath = bundle.getRoot().relativize(bundle.getRoot().resolve(git2prov));
208+
history.add(git2ProvPath);
202209
bundle.getManifest().setHistory(history);
203210

204211
} catch (URISyntaxException ex) {
@@ -246,11 +253,13 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
246253
try {
247254
// Where to store the new file
248255
Path bundleFilePath = bundlePath.resolve(file.getName());
249-
Path gitPath = Paths.get(gitDetails.getPath()).resolve(file.getName());
250-
256+
Path gitFolder = Paths.get(gitDetails.getPath());
257+
String relativePath = gitFolder.resolve(file.getName()).toString();
258+
Path gitPath = bundlePath.getRoot().resolve(relativePath); // would start with /
259+
251260
// Get direct URL permalink
252261
URI rawURI = new URI("https://w3id.org/cwl/view/git/" + workflow.getLastCommit() +
253-
"/" + gitPath + "?format=raw");
262+
gitPath + "?format=raw");
254263

255264
// Variable to store file contents and aggregation
256265
String fileContent = null;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
package org.commonwl.view.workflow;
2121

22-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23-
import com.fasterxml.jackson.annotation.JsonInclude;
22+
import java.util.Date;
23+
import java.util.Map;
24+
2425
import org.commonwl.view.cwl.CWLElement;
2526
import org.commonwl.view.cwl.CWLStep;
2627
import org.commonwl.view.git.GitDetails;
@@ -29,8 +30,8 @@
2930
import org.springframework.data.mongodb.core.mapping.Document;
3031
import org.springframework.format.annotation.DateTimeFormat;
3132

32-
import java.util.Date;
33-
import java.util.Map;
33+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34+
import com.fasterxml.jackson.annotation.JsonInclude;
3435

3536
/**
3637
* Representation of a workflow
@@ -223,4 +224,8 @@ public String getPermalink() {
223224
return getPermalink(null);
224225
}
225226

227+
public boolean isPacked() {
228+
return retrievedFrom.getPackedId() != null;
229+
}
230+
226231
}

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
}

src/main/resources/static/css/main-20170616.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,42 @@ polygon.hover {
287287
font-style: italic;
288288
margin-bottom: 30px;
289289
}
290+
291+
@media screen {
292+
.permalink {
293+
overflow: hidden;
294+
text-overflow: ellipsis;
295+
}
296+
}
297+
298+
.help {
299+
color: #9af;
300+
}
301+
302+
@media print {
303+
.help {
304+
display: none !important;
305+
}
306+
}
307+
308+
#permalink {
309+
font-size: smaller;
310+
font-family: Consolas, Inconsolata, monospace;
311+
312+
overflow: hidden;
313+
white-space: nowrap;
314+
}
315+
316+
/**
317+
* Already showing HTML
318+
*/
319+
#format-html {
320+
display: none;
321+
}
322+
/**
323+
* Workaround (not really) for
324+
* https://github.com/common-workflow-language/cwlviewer/issues/166
325+
*/
326+
#format-json {
327+
display: none;
328+
}

0 commit comments

Comments
 (0)