Skip to content

Commit 3690c40

Browse files
committed
getPermaLink() use ?part=foo instead of #foo
Added getIdentifier() that gives the old #foo variant - useful for matching with the RDF output and as graph name in the RDF In preparation for #176 to support permalinks for packed workflows. getPermaLink(Format) uses enum instead of strings (which might not match a known format)
1 parent 439971e commit 3690c40

File tree

5 files changed

+95
-41
lines changed

5 files changed

+95
-41
lines changed

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@
1919

2020
package org.commonwl.view.cwl;
2121

22-
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.fasterxml.jackson.databind.ObjectMapper;
24-
import com.fasterxml.jackson.databind.node.ArrayNode;
25-
import com.fasterxml.jackson.databind.node.ObjectNode;
26-
import com.fasterxml.jackson.databind.node.TextNode;
22+
import static org.apache.commons.io.FileUtils.readFileToString;
23+
24+
import java.io.ByteArrayInputStream;
25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.io.StringWriter;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.util.ArrayList;
31+
import java.util.HashMap;
32+
import java.util.Iterator;
33+
import java.util.List;
34+
import java.util.Map;
35+
2736
import org.apache.commons.io.FileUtils;
2837
import org.apache.commons.io.FilenameUtils;
2938
import org.apache.jena.iri.IRI;
@@ -48,15 +57,11 @@
4857
import org.springframework.stereotype.Service;
4958
import org.yaml.snakeyaml.Yaml;
5059

51-
import java.io.ByteArrayInputStream;
52-
import java.io.File;
53-
import java.io.IOException;
54-
import java.io.StringWriter;
55-
import java.nio.file.Files;
56-
import java.nio.file.Path;
57-
import java.util.*;
58-
59-
import static org.apache.commons.io.FileUtils.readFileToString;
60+
import com.fasterxml.jackson.databind.JsonNode;
61+
import com.fasterxml.jackson.databind.ObjectMapper;
62+
import com.fasterxml.jackson.databind.node.ArrayNode;
63+
import com.fasterxml.jackson.databind.node.ObjectNode;
64+
import com.fasterxml.jackson.databind.node.TextNode;
6065

6166
/**
6267
* Provides CWL parsing for workflows to gather an overview
@@ -244,7 +249,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
244249
String packedWorkflowID = gitDetails.getPackedId();
245250

246251
// Get paths to workflow
247-
String url = basicModel.getPermalink();
252+
String url = basicModel.getIdentifier();
248253
String localPath = workflowFile.toAbsolutePath().toString();
249254
String gitPath = gitDetails.getPath();
250255
if (packedWorkflowID != null) {

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.taverna.robundle.manifest.PathAnnotation;
4747
import org.apache.taverna.robundle.manifest.PathMetadata;
4848
import org.apache.taverna.robundle.manifest.Proxy;
49+
import org.commonwl.view.WebConfig.Format;
4950
import org.commonwl.view.cwl.CWLTool;
5051
import org.commonwl.view.cwl.CWLValidationException;
5152
import org.commonwl.view.cwl.RDFService;
@@ -137,7 +138,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
137138
// TODO: Make this importedBy/On/From
138139
manifest.setRetrievedBy(appAgent);
139140
manifest.setRetrievedOn(manifest.getCreatedOn());
140-
manifest.setRetrievedFrom(new URI(workflow.getPermalink("ro")));
141+
manifest.setRetrievedFrom(new URI(workflow.getPermalink(Format.ro)));
141142

142143
// Make a directory in the RO bundle to store the files
143144
Path bundleRoot = bundle.getRoot();
@@ -164,12 +165,12 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
164165
File png = graphVizService.getGraph(workflow.getID() + ".png", workflow.getVisualisationDot(), "png");
165166
Files.copy(png.toPath(), bundleRoot.resolve("visualisation.png"));
166167
PathMetadata pngAggr = bundle.getManifest().getAggregation(bundleRoot.resolve("visualisation.png"));
167-
pngAggr.setRetrievedFrom(new URI(workflow.getPermalink("png")));
168+
pngAggr.setRetrievedFrom(new URI(workflow.getPermalink(Format.png)));
168169

169170
File svg = graphVizService.getGraph(workflow.getID() + ".svg", workflow.getVisualisationDot(), "svg");
170171
Files.copy(svg.toPath(), bundleRoot.resolve("visualisation.svg"));
171172
PathMetadata svgAggr = bundle.getManifest().getAggregation(bundleRoot.resolve("visualisation.svg"));
172-
svgAggr.setRetrievedFrom(new URI(workflow.getPermalink("svg")));
173+
svgAggr.setRetrievedFrom(new URI(workflow.getPermalink(Format.svg)));
173174

174175
// Add annotation files
175176
GitDetails wfDetails = workflow.getRetrievedFrom();
@@ -192,7 +193,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
192193
} catch (CWLValidationException ex) {
193194
logger.error("Could not pack workflow when creating Research Object", ex.getMessage());
194195
}
195-
String rdfUrl = workflow.getPermalink();
196+
String rdfUrl = workflow.getIdentifier();
196197
if (rdfService.graphExists(rdfUrl)) {
197198
addAggregation(bundle, manifestAnnotations, "workflow.ttl",
198199
new String(rdfService.getModel(rdfUrl, "TURTLE")));
@@ -314,7 +315,7 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
314315
// Attempt to get authors from cwl description - takes priority
315316
ResultSet descAuthors = rdfService.getAuthors(bundlePath
316317
.resolve(file.getName()).toString().substring(10),
317-
workflow.getPermalink());
318+
workflow.getIdentifier());
318319
if (descAuthors.hasNext()) {
319320
QuerySolution authorSoln = descAuthors.nextSolution();
320321
HashableAgent newAuthor = new HashableAgent();

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

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.Date;
2323
import java.util.Map;
2424

25+
import org.commonwl.view.WebConfig;
26+
import org.commonwl.view.WebConfig.Format;
2527
import org.commonwl.view.cwl.CWLElement;
2628
import org.commonwl.view.cwl.CWLStep;
2729
import org.commonwl.view.git.GitDetails;
@@ -32,6 +34,7 @@
3234

3335
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
3436
import com.fasterxml.jackson.annotation.JsonInclude;
37+
import com.fasterxml.jackson.annotation.JsonProperty;
3538

3639
/**
3740
* Representation of a workflow
@@ -74,6 +77,8 @@ public class Workflow {
7477
// DOT graph of the contents
7578
private String visualisationDot;
7679

80+
private final String permaLinkBase = "https://w3id.org/cwl/view";
81+
7782
public Workflow(String label, String doc, Map<String, CWLElement> inputs,
7883
Map<String, CWLElement> outputs, Map<String, CWLStep> steps, String dockerLink) {
7984
this.label = label;
@@ -213,17 +218,54 @@ public String getRoBundleLink() {
213218
return retrievedFrom.getInternalUrl().replaceFirst("/workflows", "/robundle");
214219
}
215220

216-
public String getPermalink(String format) {
217-
String formatPart = (format == null || format.isEmpty()) ? "" : "?format=" + format;
218-
String packedPart = (retrievedFrom.getPackedId() != null) ? "#" + retrievedFrom.getPackedId() : "";
219-
return "https://w3id.org/cwl/view/git/" + lastCommit +
220-
"/" + retrievedFrom.getPath() + formatPart + packedPart;
221-
}
222-
221+
/**
222+
* Permalink for this workflow. including packed part, but no format
223+
*
224+
* @return
225+
*/
223226
public String getPermalink() {
224227
return getPermalink(null);
225228
}
226229

230+
/**
231+
* Permalink for a particular representation of this workflow. Note that
232+
* resolving the permalink will use the official deployment of the CWL Viewer.
233+
*
234+
* @see {@link https://w3id.org/cwl/view}
235+
* @param format
236+
* Format of representation, or <code>null</code> for format-neutral
237+
* permalink that supports content negotiation.
238+
* @return A Permalink identifying the representation of this workflow.
239+
*/
240+
public String getPermalink(WebConfig.Format format) {
241+
242+
String packedPart = "";
243+
String formatPartSep = "?";
244+
String formatPart = "";
245+
if (retrievedFrom.getPackedId() != null && !Format.raw.equals(format)) {
246+
// No need for ?part= for ?format=raw
247+
packedPart = "?part=" + retrievedFrom.getPackedId();
248+
formatPartSep = "&";
249+
}
250+
if (format != null) {
251+
formatPart = formatPartSep + "format=" + format.name();
252+
}
253+
return permaLinkBase + "/git/" + lastCommit +
254+
"/" + retrievedFrom.getPath() + packedPart + formatPart;
255+
}
256+
257+
/**
258+
* RDF identifier, uses #hash for parts
259+
*
260+
* @return
261+
*/
262+
@JsonProperty(value = "@id", index = 0)
263+
public String getIdentifier() {
264+
String packedPart = (retrievedFrom.getPackedId() != null) ? "#" + retrievedFrom.getPackedId() : "";
265+
return permaLinkBase + "/git/" + lastCommit + "/" + retrievedFrom.getPath() + packedPart;
266+
267+
}
268+
227269
public boolean isPacked() {
228270
return retrievedFrom.getPackedId() != null;
229271
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
543543
return new ModelAndView("loading", "queued", queued);
544544
} else {
545545
return new ModelAndView("workflow", "workflow", workflowModel).addObject("formats",
546-
WebConfig.formats.values());
546+
WebConfig.Format.values());
547547
}
548548
}
549549
}

src/test/java/org/commonwl/view/researchobject/ROBundleServiceTest.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotNull;
24+
import static org.junit.Assert.assertNull;
25+
import static org.junit.Assert.assertTrue;
26+
import static org.mockito.Matchers.any;
27+
import static org.mockito.Matchers.anyBoolean;
28+
import static org.mockito.Matchers.anyObject;
29+
import static org.mockito.Matchers.anyString;
30+
import static org.mockito.Mockito.when;
31+
32+
import java.io.File;
33+
import java.net.URI;
34+
import java.nio.file.Path;
35+
import java.util.HashSet;
36+
import java.util.List;
37+
import java.util.Set;
38+
2239
import org.apache.jena.query.ResultSet;
2340
import org.apache.taverna.robundle.Bundle;
2441
import org.apache.taverna.robundle.Bundles;
@@ -42,17 +59,6 @@
4259
import org.mockito.invocation.InvocationOnMock;
4360
import org.mockito.stubbing.Answer;
4461

45-
import java.io.File;
46-
import java.net.URI;
47-
import java.nio.file.Path;
48-
import java.util.HashSet;
49-
import java.util.List;
50-
import java.util.Set;
51-
52-
import static org.junit.Assert.*;
53-
import static org.mockito.Matchers.*;
54-
import static org.mockito.Mockito.when;
55-
5662
public class ROBundleServiceTest {
5763

5864
private static ROBundleService roBundleService;
@@ -113,9 +119,9 @@ public void setUp() throws Exception {
113119
when(lobSTRdraft3.getID()).thenReturn("testID");
114120
when(lobSTRdraft3.getRetrievedFrom()).thenReturn(lobSTRdraft3Details);
115121
when(lobSTRdraft3.getLastCommit()).thenReturn("933bf2a1a1cce32d88f88f136275535da9df0954");
116-
when(lobSTRdraft3.getPermalink()).thenReturn("https://w3id.org/cwl/view/git/" +
122+
when(lobSTRdraft3.getIdentifier()).thenReturn("https://w3id.org/cwl/view/git/" +
117123
"933bf2a1a1cce32d88f88f136275535da9df0954/workflows/lobSTR/lobSTR-workflow.cwl");
118-
when(lobSTRdraft3.getPermalink(anyString())).thenAnswer(new Answer<String>() {
124+
when(lobSTRdraft3.getPermalink(any())).thenAnswer(new Answer<String>() {
119125
@Override
120126
public String answer(InvocationOnMock invocation) throws Throwable {
121127
Object[] args = invocation.getArguments();

0 commit comments

Comments
 (0)