Skip to content

Commit 92a7d06

Browse files
committed
Permalinks for graph names in SPARQL store
1 parent adb6b8c commit 92a7d06

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
244244
String packedWorkflowID = gitDetails.getPackedId();
245245

246246
// Get paths to workflow
247-
String url = gitDetails.getUrl(latestCommit).replace("https://", "");
247+
String url = basicModel.getPermalink();
248248
String localPath = workflowFile.toAbsolutePath().toString();
249249
String gitPath = gitDetails.getPath();
250250
if (packedWorkflowID != null) {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void addToOntologies(Model model) {
6969
*/
7070
public byte[] getModel(String graphName, String format) {
7171
DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(rdfService);
72-
Model model = accessor.getModel(rdfService + graphName);
72+
Model model = accessor.getModel(graphName);
7373
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
7474
model.write(outputStream, format);
7575
return outputStream.toByteArray();
@@ -82,7 +82,7 @@ public byte[] getModel(String graphName, String format) {
8282
*/
8383
public void storeModel(String graphName, Model model) {
8484
DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(rdfService);
85-
accessor.putModel(rdfService + graphName, model);
85+
accessor.putModel(graphName, model);
8686
}
8787

8888
/**
@@ -93,7 +93,7 @@ public void storeModel(String graphName, Model model) {
9393
public boolean graphExists(String graphName) {
9494
ParameterizedSparqlString graphQuery = new ParameterizedSparqlString();
9595
graphQuery.setCommandText("ASK WHERE { GRAPH ?graphName { ?s ?p ?o } }");
96-
graphQuery.setIri("graphName", rdfService + graphName);
96+
graphQuery.setIri("graphName", graphName);
9797
Query query = QueryFactory.create(graphQuery.toString());
9898
try (QueryExecution qexec = QueryExecutionFactory.createServiceRequest(rdfService, query)) {
9999
return qexec.execAsk();
@@ -136,7 +136,7 @@ public ResultSet getLabelAndDoc(String path, String workflowURI) {
136136
" }" +
137137
"}");
138138
labelQuery.setLiteral("wfFilter", path + "$");
139-
labelQuery.setIri("graphName", rdfService + workflowURI);
139+
labelQuery.setIri("graphName", workflowURI);
140140
return runQuery(labelQuery);
141141
}
142142

@@ -200,7 +200,7 @@ public ResultSet getInputs(String path, String workflowURI) {
200200
" }" +
201201
"}");
202202
inputsQuery.setLiteral("wfFilter", path + "$");
203-
inputsQuery.setIri("graphName", rdfService + workflowURI);
203+
inputsQuery.setIri("graphName", workflowURI);
204204
return runQuery(inputsQuery);
205205
}
206206

@@ -240,7 +240,7 @@ public ResultSet getOutputs(String path, String workflowURI) {
240240
" }" +
241241
"}");
242242
outputsQuery.setLiteral("wfFilter", path + "$");
243-
outputsQuery.setIri("graphName", rdfService + workflowURI);
243+
outputsQuery.setIri("graphName", workflowURI);
244244
return runQuery(outputsQuery);
245245
}
246246

@@ -269,7 +269,7 @@ public ResultSet getSteps(String path, String workflowURI) {
269269
" }" +
270270
"}");
271271
stepQuery.setLiteral("wfFilter", path + "$");
272-
stepQuery.setIri("graphName", rdfService + workflowURI);
272+
stepQuery.setIri("graphName", workflowURI);
273273
return runQuery(stepQuery);
274274
}
275275

@@ -291,7 +291,7 @@ public ResultSet getStepLinks(String path, String workflowURI) {
291291
" }" +
292292
"}");
293293
linkQuery.setLiteral("wfFilter", path + "$");
294-
linkQuery.setIri("graphName", rdfService + workflowURI);
294+
linkQuery.setIri("graphName", workflowURI);
295295
return runQuery(linkQuery);
296296
}
297297

@@ -313,7 +313,7 @@ public ResultSet getOutputLinks(String path, String workflowURI) {
313313
" }" +
314314
"}");
315315
linkQuery.setLiteral("wfFilter", path + "$");
316-
linkQuery.setIri("graphName", rdfService + workflowURI);
316+
linkQuery.setIri("graphName", workflowURI);
317317
return runQuery(linkQuery);
318318
}
319319

@@ -337,7 +337,7 @@ public ResultSet getDockerLink(String path, String workflowURI) {
337337
" }" +
338338
"}");
339339
dockerQuery.setLiteral("wfFilter", path + "$");
340-
dockerQuery.setIri("graphName", rdfService + workflowURI);
340+
dockerQuery.setIri("graphName", workflowURI);
341341
return runQuery(dockerQuery);
342342
}
343343

@@ -372,7 +372,7 @@ public ResultSet getAuthors(String path, String fileUri) {
372372
" }" +
373373
"}");
374374
linkQuery.setLiteral("wfFilter", path + "$");
375-
linkQuery.setIri("graphName", rdfService + fileUri);
375+
linkQuery.setIri("graphName", fileUri);
376376
return runQuery(linkQuery);
377377
}
378378

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
124124

125125
// Simplified attribution for RO bundle
126126
try {
127-
String packedId = workflow.getRetrievedFrom().getPackedId();
128-
String packedPart = (packedId != null) ? "#" + packedId : "";
129-
String id = "https://w3id.org/cwl/v/git/" + workflow.getLastCommit() +
130-
"/" + workflow.getRetrievedFrom().getPath();
131-
manifest.setId(new URI(id + packedPart));
127+
manifest.setId(new URI(workflow.getPermalink()));
132128

133129
// Tool attribution in createdBy
134130
manifest.setCreatedBy(appAgent);
@@ -137,7 +133,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
137133
// TODO: Make this importedBy/On/From
138134
manifest.setRetrievedBy(appAgent);
139135
manifest.setRetrievedOn(manifest.getCreatedOn());
140-
manifest.setRetrievedFrom(new URI(id + "?format=ro" + packedPart));
136+
manifest.setRetrievedFrom(new URI(workflow.getPermalink("ro")));
141137

142138
// Make a directory in the RO bundle to store the files
143139
Path bundleRoot = bundle.getRoot();
@@ -164,14 +160,12 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
164160
File png = graphVizService.getGraph(workflow.getID() + ".png", workflow.getVisualisationDot(), "png");
165161
Files.copy(png.toPath(), bundleRoot.resolve("visualisation.png"));
166162
PathMetadata pngAggr = bundle.getManifest().getAggregation(bundleRoot.resolve("visualisation.png"));
167-
pngAggr.setRetrievedFrom(new URI("https://w3id.org/cwl/v/git/" + workflow.getLastCommit()
168-
+ "/" + workflow.getRetrievedFrom().getPath() + "?format=png"));
163+
pngAggr.setRetrievedFrom(new URI(workflow.getPermalink("png")));
169164

170165
File svg = graphVizService.getGraph(workflow.getID() + ".svg", workflow.getVisualisationDot(), "svg");
171166
Files.copy(svg.toPath(), bundleRoot.resolve("visualisation.svg"));
172167
PathMetadata svgAggr = bundle.getManifest().getAggregation(bundleRoot.resolve("visualisation.svg"));
173-
svgAggr.setRetrievedFrom(new URI("https://w3id.org/cwl/v/git/" + workflow.getLastCommit()
174-
+ "/" + workflow.getRetrievedFrom().getPath() + "?format=svg"));
168+
svgAggr.setRetrievedFrom(new URI(workflow.getPermalink("svg")));
175169

176170
// Add annotation files
177171
GitDetails wfDetails = workflow.getRetrievedFrom();
@@ -194,7 +188,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
194188
} catch (CWLValidationException ex) {
195189
logger.error("Could not pack workflow when creating Research Object", ex.getMessage());
196190
}
197-
String rdfUrl = wfDetails.getUrl(workflow.getLastCommit()).replace("https://", "");
191+
String rdfUrl = workflow.getPermalink();
198192
if (rdfService.graphExists(rdfUrl)) {
199193
addAggregation(bundle, manifestAnnotations, "workflow.ttl",
200194
new String(rdfService.getModel(rdfUrl, "TURTLE")));
@@ -303,17 +297,15 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
303297
}
304298

305299
try {
306-
String url = workflow.getRetrievedFrom()
307-
.getUrl(workflow.getLastCommit()).replace("https://", "");
308-
309300
// Add authors from git commits to the file
310301
Set<HashableAgent> fileAuthors = gitService.getAuthors(gitRepo,
311302
gitPath.toString());
312303

313304
if (cwl) {
314305
// Attempt to get authors from cwl description - takes priority
315306
ResultSet descAuthors = rdfService.getAuthors(bundlePath
316-
.resolve(file.getName()).toString().substring(10), url);
307+
.resolve(file.getName()).toString().substring(10),
308+
workflow.getPermalink());
317309
if (descAuthors.hasNext()) {
318310
QuerySolution authorSoln = descAuthors.nextSolution();
319311
HashableAgent newAuthor = new HashableAgent();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,16 @@ public String getRoBundle() {
211211
public String getRoBundleLink() {
212212
return retrievedFrom.getInternalUrl().replaceFirst("/workflows", "/robundle");
213213
}
214+
215+
public String getPermalink(String format) {
216+
String formatPart = (format != null && !format.isEmpty()) ? "?format=" + format : "";
217+
String packedPart = (retrievedFrom.getPackedId() != null) ? "#" + retrievedFrom.getPackedId() : "";
218+
return "https://w3id.org/cwl/v/git/" + lastCommit +
219+
"/" + retrievedFrom.getPath() + formatPart + packedPart;
220+
}
221+
222+
public String getPermalink() {
223+
return getPermalink(null);
224+
}
225+
214226
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void goToRawUrl(@PathVariable("commitid") String commitId,
100100
public byte[] getRdfAsTurtle(@PathVariable("commitid") String commitId,
101101
HttpServletRequest request) {
102102
Workflow workflow = getWorkflow(commitId, request);
103-
String rdfUrl = workflow.getRetrievedFrom().getUrl(commitId).replace("https://", "");
103+
String rdfUrl = workflow.getPermalink();
104104
if (rdfService.graphExists(rdfUrl)) {
105105
return rdfService.getModel(rdfUrl, "TURTLE");
106106
} else {
@@ -118,7 +118,7 @@ public byte[] getRdfAsTurtle(@PathVariable("commitid") String commitId,
118118
public byte[] getRdfAsJsonLd(@PathVariable("commitid") String commitId,
119119
HttpServletRequest request) {
120120
Workflow workflow = getWorkflow(commitId, request);
121-
String rdfUrl = workflow.getRetrievedFrom().getUrl(commitId).replace("https://", "");
121+
String rdfUrl = workflow.getPermalink();
122122
if (rdfService.graphExists(rdfUrl)) {
123123
return rdfService.getModel(rdfUrl, "JSON-LD");
124124
} else {
@@ -136,7 +136,7 @@ public byte[] getRdfAsJsonLd(@PathVariable("commitid") String commitId,
136136
public byte[] getRdfAsRdfXml(@PathVariable("commitid") String commitId,
137137
HttpServletRequest request) {
138138
Workflow workflow = getWorkflow(commitId, request);
139-
String rdfUrl = workflow.getRetrievedFrom().getUrl(commitId).replace("https://", "");
139+
String rdfUrl = workflow.getPermalink();
140140
if (rdfService.graphExists(rdfUrl)) {
141141
return rdfService.getModel(rdfUrl, "RDFXML");
142142
} else {

0 commit comments

Comments
 (0)