Skip to content

Commit 5e8ca27

Browse files
authored
Merge pull request #51 from common-workflow-language/graphviz-serverside
Swap to serverside GraphViz rendering
2 parents 53d82d6 + 49f137a commit 5e8ca27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3106
-23371
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
<java.version>1.8</java.version>
2525
</properties>
2626

27+
<repositories>
28+
<repository>
29+
<id>jitpack.io</id>
30+
<url>https://jitpack.io</url>
31+
</repository>
32+
</repositories>
33+
2734
<dependencies>
2835
<dependency>
2936
<groupId>org.springframework.boot</groupId>
@@ -57,6 +64,11 @@
5764
<artifactId>snakeyaml</artifactId>
5865
<version>1.7</version>
5966
</dependency>
67+
<dependency>
68+
<groupId>com.github.jabbalaci</groupId>
69+
<artifactId>graphviz-java-api</artifactId>
70+
<version>f9bf94896776de6e98b5004e819b63fb4c15b15d</version>
71+
</dependency>
6072
<dependency>
6173
<groupId>org.apache.taverna.language</groupId>
6274
<artifactId>taverna-robundle</artifactId>

src/main/java/org/commonwl/viewer/services/ROBundleFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public class ROBundleFactory {
5353
@Autowired
5454
public ROBundleFactory(@Value("${applicationName}") String applicationName,
5555
@Value("${applicationURL}") String applicationURL,
56-
@Value("${storageLocation}") Path storageLocation,
56+
@Value("${graphvizStorage}") Path graphvizStorage,
5757
WorkflowRepository workflowRepository) {
5858
this.applicationName = applicationName;
5959
this.applicationURL = applicationURL;
60-
this.storageLocation = storageLocation;
60+
this.storageLocation = graphvizStorage;
6161
this.workflowRepository = workflowRepository;
6262
}
6363

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.viewer.web;
2121

22+
import com.github.jabbalaci.graphviz.GraphViz;
2223
import org.apache.commons.lang.StringUtils;
2324
import org.commonwl.viewer.domain.GithubDetails;
2425
import org.commonwl.viewer.domain.Workflow;
@@ -29,6 +30,7 @@
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.beans.factory.annotation.Value;
3234
import org.springframework.core.io.FileSystemResource;
3335
import org.springframework.stereotype.Controller;
3436
import org.springframework.validation.BindingResult;
@@ -40,6 +42,7 @@
4042
import javax.servlet.http.HttpServletResponse;
4143
import javax.validation.Valid;
4244
import java.io.File;
45+
import java.io.IOException;
4346

4447
@Controller
4548
public class WorkflowController {
@@ -214,4 +217,67 @@ public FileSystemResource downloadROBundle(@PathVariable("workflowID") String wo
214217
logger.info("Serving download for workflow " + workflowID + " [" + bundleDownload.toString() + "]");
215218
return new FileSystemResource(bundleDownload);
216219
}
220+
221+
/**
222+
* Download a generated DOT graph for a workflow as an svg
223+
* @param workflowID The ID of the workflow to download the graph for
224+
*/
225+
@RequestMapping(value = "/workflows/{workflowID}/graph/svg",
226+
method = RequestMethod.GET,
227+
produces = "image/svg+xml")
228+
@ResponseBody
229+
public FileSystemResource getGraphAsSvg(@Value("${graphvizStorage}") String graphvizStorage,
230+
@PathVariable("workflowID") String workflowID) throws IOException {
231+
232+
// Get workflow from database
233+
Workflow workflowModel = workflowRepository.findOne(workflowID);
234+
235+
// 404 error if workflow does not exist
236+
if (workflowModel == null) {
237+
throw new WorkflowNotFoundException();
238+
}
239+
240+
// Generate graphviz image if it does not already exist
241+
File out = new File(graphvizStorage + "/" + workflowID + ".svg");
242+
if (!out.exists()) {
243+
GraphViz gv = new GraphViz();
244+
gv.decreaseDpi();
245+
gv.decreaseDpi();
246+
gv.decreaseDpi();
247+
gv.writeGraphToFile(gv.getGraph(workflowModel.getDotGraph(), "svg", "dot"), out.getAbsolutePath());
248+
}
249+
250+
// Output the graph image
251+
return new FileSystemResource(out);
252+
}
253+
254+
/**
255+
* Download a generated DOT graph for a workflow as a png
256+
* @param workflowID The ID of the workflow to download the graph for
257+
*/
258+
@RequestMapping(value = "/workflows/{workflowID}/graph/png",
259+
method = RequestMethod.GET,
260+
produces = "image/png")
261+
@ResponseBody
262+
public FileSystemResource getGraphAsPng(@Value("${graphvizStorage}") String graphvizStorage,
263+
@PathVariable("workflowID") String workflowID) throws IOException {
264+
265+
// Get workflow from database
266+
Workflow workflowModel = workflowRepository.findOne(workflowID);
267+
268+
// 404 error if workflow does not exist
269+
if (workflowModel == null) {
270+
throw new WorkflowNotFoundException();
271+
}
272+
273+
// Generate graphviz image if it does not already exist
274+
File out = new File(graphvizStorage + "/" + workflowID + ".png");
275+
if (!out.exists()) {
276+
GraphViz gv = new GraphViz();
277+
gv.writeGraphToFile(gv.getGraph(workflowModel.getDotGraph(), "png", "dot"), out.getAbsolutePath());
278+
}
279+
280+
// Output the graph image
281+
return new FileSystemResource(out);
282+
}
217283
}

src/main/resources/application.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ applicationName = Common Workflow Language Viewer
77
applicationURL = http://view.commonwl.org
88

99
# Path to a directory in which the RO Bundles will be stored
10-
storageLocation = /tmp
10+
bundleStorage = /tmp
11+
12+
# Path to a directory in which graphviz images will be stored
13+
graphvizStorage = /tmp
1114

1215
# How long to cache workflows in days before checking for changes via Github
1316
cacheDays = 1

src/main/resources/static/bower_components/d3/.bower.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/resources/static/bower_components/d3/CONTRIBUTING.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/resources/static/bower_components/d3/LICENSE

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/resources/static/bower_components/d3/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/resources/static/bower_components/d3/bower.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)