Skip to content

Commit 7d9cd28

Browse files
committed
ID handling fixes for local URIs in RDF
1 parent 6c56c57 commit 7d9cd28

File tree

4 files changed

+77
-56
lines changed

4 files changed

+77
-56
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,22 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
186186
String packedWorkflowID) throws CWLValidationException {
187187

188188
// Get RDF representation from cwltool
189-
String path = workflowFile.toPath().toAbsolutePath().toString();
190189
String url = gitDetails.getUrl().replace("https://", "");
190+
String localPath = workflowFile.toPath().toAbsolutePath().toString();
191+
String gitPath = gitDetails.getPath();
191192
if (packedWorkflowID != null) {
192193
if (packedWorkflowID.charAt(0) != '#') {
193-
path += "#";
194+
localPath += "#";
194195
url += "#";
196+
gitPath += "#";
195197
}
196-
path += packedWorkflowID;
198+
localPath += packedWorkflowID;
197199
url += packedWorkflowID;
200+
gitPath += packedWorkflowID;
198201
}
199202

200203
if (!rdfService.graphExists(url)) {
201-
String rdf = cwlTool.getRDF(path);
204+
String rdf = cwlTool.getRDF(localPath);
202205

203206
// Create a workflow model from RDF representation
204207
Model model = ModelFactory.createDefaultModel();
@@ -211,7 +214,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
211214
// Base workflow details
212215
String label = FilenameUtils.getName(url);
213216
String doc = null;
214-
ResultSet labelAndDoc = rdfService.getLabelAndDoc(url);
217+
ResultSet labelAndDoc = rdfService.getLabelAndDoc(gitPath, url);
215218
if (labelAndDoc.hasNext()) {
216219
QuerySolution labelAndDocSoln = labelAndDoc.nextSolution();
217220
if (labelAndDocSoln.contains("label")) {
@@ -224,10 +227,10 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
224227

225228
// Inputs
226229
Map<String, CWLElement> wfInputs = new HashMap<>();
227-
ResultSet inputs = rdfService.getInputs(url);
230+
ResultSet inputs = rdfService.getInputs(gitPath, url);
228231
while (inputs.hasNext()) {
229232
QuerySolution input = inputs.nextSolution();
230-
String inputName = rdfService.stepNameFromURI(url, input.get("name").toString());
233+
String inputName = rdfService.stepNameFromURI(gitPath, input.get("name").toString());
231234

232235
CWLElement wfInput = new CWLElement();
233236

@@ -281,12 +284,12 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
281284

282285
// Outputs
283286
Map<String, CWLElement> wfOutputs = new HashMap<>();
284-
ResultSet outputs = rdfService.getOutputs(url);
287+
ResultSet outputs = rdfService.getOutputs(gitPath, url);
285288
while (outputs.hasNext()) {
286289
QuerySolution output = outputs.nextSolution();
287290
CWLElement wfOutput = new CWLElement();
288291

289-
String outputName = rdfService.stepNameFromURI(url, output.get("name").toString());
292+
String outputName = rdfService.stepNameFromURI(gitPath, output.get("name").toString());
290293

291294
// Array types
292295
if (output.contains("type")) {
@@ -325,7 +328,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
325328
}
326329

327330
if (output.contains("src")) {
328-
wfOutput.addSourceID(rdfService.stepNameFromURI(url,
331+
wfOutput.addSourceID(rdfService.stepNameFromURI(gitPath,
329332
output.get("src").toString()));
330333
}
331334
if (output.contains("format")) {
@@ -344,15 +347,15 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
344347

345348
// Steps
346349
Map<String, CWLStep> wfSteps = new HashMap<>();
347-
ResultSet steps = rdfService.getSteps(url);
350+
ResultSet steps = rdfService.getSteps(gitPath, url);
348351
while (steps.hasNext()) {
349352
QuerySolution step = steps.nextSolution();
350-
String uri = rdfService.stepNameFromURI(url, step.get("step").toString());
353+
String uri = rdfService.stepNameFromURI(gitPath, step.get("step").toString());
351354
if (wfSteps.containsKey(uri)) {
352355
// Already got step details, add extra source ID
353356
if (step.contains("src")) {
354357
CWLElement src = new CWLElement();
355-
src.addSourceID(rdfService.stepNameFromURI(url, step.get("src").toString()));
358+
src.addSourceID(rdfService.stepNameFromURI(gitPath, step.get("src").toString()));
356359
wfSteps.get(uri).getSources().put(
357360
step.get("stepinput").toString(), src);
358361
} else if (step.contains("default")) {
@@ -372,16 +375,16 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
372375

373376
if (step.contains("src")) {
374377
CWLElement src = new CWLElement();
375-
src.addSourceID(rdfService.stepNameFromURI(url, step.get("src").toString()));
378+
src.addSourceID(rdfService.stepNameFromURI(gitPath, step.get("src").toString()));
376379
Map<String, CWLElement> srcList = new HashMap<>();
377-
srcList.put(rdfService.stepNameFromURI(url,
380+
srcList.put(rdfService.stepNameFromURI(gitPath,
378381
step.get("stepinput").toString()), src);
379382
wfStep.setSources(srcList);
380383
} else if (step.contains("default")) {
381384
CWLElement src = new CWLElement();
382385
src.setDefaultVal(rdfService.formatDefault(step.get("default").toString()));
383386
Map<String, CWLElement> srcList = new HashMap<>();
384-
srcList.put(rdfService.stepNameFromURI(url,
387+
srcList.put(rdfService.stepNameFromURI(gitPath,
385388
step.get("stepinput").toString()), src);
386389
wfStep.setSources(srcList);
387390
}
@@ -396,7 +399,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
396399
}
397400

398401
// Docker link
399-
ResultSet dockerResult = rdfService.getDockerLink(url);
402+
ResultSet dockerResult = rdfService.getDockerLink(gitPath, url);
400403
String dockerLink = null;
401404
if (dockerResult.hasNext()) {
402405
QuerySolution docker = dockerResult.nextSolution();
@@ -413,7 +416,7 @@ public Workflow parseWorkflowWithCwltool(GitDetails gitDetails,
413416

414417
// Generate DOT graph
415418
StringWriter graphWriter = new StringWriter();
416-
RDFDotWriter RDFDotWriter = new RDFDotWriter(graphWriter, rdfService);
419+
RDFDotWriter RDFDotWriter = new RDFDotWriter(graphWriter, rdfService, gitPath);
417420
try {
418421
RDFDotWriter.writeGraph(url);
419422
workflowModel.setVisualisationDot(graphWriter.toString());

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

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void addToOntologies(Model model) {
6666
*/
6767
public void storeModel(String graphName, Model model) {
6868
DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(rdfService);
69-
accessor.putModel(graphName, model);
69+
accessor.putModel(rdfService + graphName, model);
7070
}
7171

7272
/**
@@ -106,17 +106,19 @@ public boolean ontPropertyExists(String ontUri) {
106106
* @param workflowURI The URI of the workflow
107107
* @return Result set with label and doc strings
108108
*/
109-
public ResultSet getLabelAndDoc(String workflowURI) {
109+
public ResultSet getLabelAndDoc(String path, String workflowURI) {
110110
ParameterizedSparqlString labelQuery = new ParameterizedSparqlString();
111111
labelQuery.setCommandText(queryCtx +
112112
"SELECT ?label ?doc\n" +
113113
"WHERE {\n" +
114-
" GRAPH ?wf {" +
114+
" GRAPH ?graphName {" +
115115
" OPTIONAL { ?wf sld:label|rdfs:label ?label }\n" +
116116
" OPTIONAL { ?wf sld:doc|rdfs:comment ?doc }\n" +
117+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
117118
" }" +
118119
"}");
119-
labelQuery.setIri("wf", workflowURI);
120+
labelQuery.setLiteral("wfFilter", path + "$");
121+
labelQuery.setIri("graphName", rdfService + workflowURI);
120122
return runQuery(labelQuery);
121123
}
122124

@@ -149,21 +151,23 @@ public String getOntLabel(String ontologyURI) {
149151
* @param workflowURI URI of the workflow
150152
* @return The result set of inputs
151153
*/
152-
public ResultSet getInputs(String workflowURI) {
154+
public ResultSet getInputs(String path, String workflowURI) {
153155
ParameterizedSparqlString inputsQuery = new ParameterizedSparqlString();
154156
inputsQuery.setCommandText(queryCtx +
155157
"SELECT ?name ?type ?format ?label ?doc\n" +
156158
"WHERE {\n" +
157-
" GRAPH ?wf {" +
159+
" GRAPH ?graphName {" +
158160
" ?wf rdf:type cwl:Workflow .\n" +
159161
" ?wf cwl:inputs ?name .\n" +
160162
" OPTIONAL { ?name sld:type ?type }\n" +
161163
" OPTIONAL { ?name cwl:format ?format }\n" +
162164
" OPTIONAL { ?name sld:label|rdfs:label ?label }\n" +
163165
" OPTIONAL { ?name sld:doc|rdfs:comment ?doc }\n" +
166+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
164167
" }" +
165168
"}");
166-
inputsQuery.setIri("wf", workflowURI);
169+
inputsQuery.setLiteral("wfFilter", path + "$");
170+
inputsQuery.setIri("graphName", rdfService + workflowURI);
167171
return runQuery(inputsQuery);
168172
}
169173

@@ -172,21 +176,23 @@ public ResultSet getInputs(String workflowURI) {
172176
* @param workflowURI URI of the workflow
173177
* @return The result set of outputs
174178
*/
175-
public ResultSet getOutputs(String workflowURI) {
179+
public ResultSet getOutputs(String path, String workflowURI) {
176180
ParameterizedSparqlString outputsQuery = new ParameterizedSparqlString();
177181
outputsQuery.setCommandText(queryCtx +
178182
"SELECT ?name ?type ?format ?label ?doc\n" +
179183
"WHERE {\n" +
180-
" GRAPH ?wf {" +
184+
" GRAPH ?graphName {" +
181185
" ?wf rdf:type cwl:Workflow .\n" +
182186
" ?wf cwl:outputs ?name .\n" +
183187
" OPTIONAL { ?name sld:type ?type }\n" +
184188
" OPTIONAL { ?name cwl:format ?format }\n" +
185189
" OPTIONAL { ?name sld:label|rdfs:label ?label }\n" +
186190
" OPTIONAL { ?name sld:doc|rdfs:comment ?doc }\n" +
191+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
187192
" }" +
188193
"}");
189-
outputsQuery.setIri("wf", workflowURI);
194+
outputsQuery.setLiteral("wfFilter", path + "$");
195+
outputsQuery.setIri("graphName", rdfService + workflowURI);
190196
return runQuery(outputsQuery);
191197
}
192198

@@ -195,7 +201,7 @@ public ResultSet getOutputs(String workflowURI) {
195201
* @param workflowURI URI of the workflow
196202
* @return The result set of steps
197203
*/
198-
public ResultSet getSteps(String workflowURI) {
204+
public ResultSet getSteps(String path, String workflowURI) {
199205
ParameterizedSparqlString stepQuery = new ParameterizedSparqlString();
200206
stepQuery.setCommandText(queryCtx +
201207
"SELECT ?step ?run ?runtype ?label ?doc ?stepinput ?default ?src\n" +
@@ -210,9 +216,11 @@ public ResultSet getSteps(String workflowURI) {
210216
" }\n" +
211217
" OPTIONAL { ?run sld:label|rdfs:label ?label }\n" +
212218
" OPTIONAL { ?run sld:doc|rdfs:comment ?doc }\n" +
219+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
213220
" }" +
214221
"}");
215-
stepQuery.setIri("wf", workflowURI);
222+
stepQuery.setLiteral("wfFilter", path + "$");
223+
stepQuery.setIri("graphName", rdfService + workflowURI);
216224
return runQuery(stepQuery);
217225
}
218226

@@ -221,18 +229,20 @@ public ResultSet getSteps(String workflowURI) {
221229
* @param workflowURI URI of the workflow
222230
* @return The result set of step links
223231
*/
224-
public ResultSet getStepLinks(String workflowURI) {
232+
public ResultSet getStepLinks(String path, String workflowURI) {
225233
ParameterizedSparqlString linkQuery = new ParameterizedSparqlString();
226234
linkQuery.setCommandText(queryCtx +
227235
"SELECT ?src ?dest ?default\n" +
228236
"WHERE {\n" +
229-
" GRAPH ?wf {" +
237+
" GRAPH ?graphName {" +
230238
" ?wf Workflow:steps ?step .\n" +
231239
" ?step cwl:in ?dest .\n" +
232240
" { ?dest cwl:source ?src } UNION { ?dest cwl:default ?default }\n" +
241+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
233242
" }" +
234243
"}");
235-
linkQuery.setIri("wf", workflowURI);
244+
linkQuery.setLiteral("wfFilter", path + "$");
245+
linkQuery.setIri("graphName", rdfService + workflowURI);
236246
return runQuery(linkQuery);
237247
}
238248

@@ -241,18 +251,20 @@ public ResultSet getStepLinks(String workflowURI) {
241251
* @param workflowURI URI of the workflow
242252
* @return The result set of steps
243253
*/
244-
public ResultSet getOutputLinks(String workflowURI) {
254+
public ResultSet getOutputLinks(String path, String workflowURI) {
245255
ParameterizedSparqlString linkQuery = new ParameterizedSparqlString();
246256
linkQuery.setCommandText(queryCtx +
247257
"SELECT ?src ?dest\n" +
248258
"WHERE {\n" +
249-
" GRAPH ?wf {" +
259+
" GRAPH ?graphName {" +
250260
" ?wf rdf:type cwl:Workflow .\n" +
251261
" ?wf cwl:outputs ?dest .\n" +
252262
" ?dest cwl:outputSource ?src\n" +
263+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
253264
" }" +
254265
"}");
255-
linkQuery.setIri("wf", workflowURI);
266+
linkQuery.setLiteral("wfFilter", path + "$");
267+
linkQuery.setIri("graphName", rdfService + workflowURI);
256268
return runQuery(linkQuery);
257269
}
258270

@@ -261,19 +273,21 @@ public ResultSet getOutputLinks(String workflowURI) {
261273
* @param workflowURI URI of the workflow
262274
* @return Result set of docker hint and pull link
263275
*/
264-
public ResultSet getDockerLink(String workflowURI) {
276+
public ResultSet getDockerLink(String path, String workflowURI) {
265277
ParameterizedSparqlString dockerQuery = new ParameterizedSparqlString();
266278
dockerQuery.setCommandText(queryCtx +
267279
"SELECT ?docker ?pull\n" +
268280
"WHERE {\n" +
269-
" GRAPH ?wf {" +
281+
" GRAPH ?graphName {" +
270282
" ?wf rdf:type cwl:Workflow .\n" +
271283
" { ?wf cwl:requirements ?docker } UNION { ?wf cwl:hints ?docker} .\n" +
272284
" ?docker rdf:type cwl:DockerRequirement\n" +
273285
" OPTIONAL { ?docker DockerRequirement:dockerPull ?pull }\n" +
286+
" FILTER(regex(str(?wf), ?wfFilter, \"i\" ))" +
274287
" }" +
275288
"}");
276-
dockerQuery.setIri("wf", workflowURI);
289+
dockerQuery.setLiteral("wfFilter", path + "$");
290+
dockerQuery.setIri("graphName", rdfService + workflowURI);
277291
return runQuery(dockerQuery);
278292
}
279293

@@ -284,6 +298,7 @@ public ResultSet getDockerLink(String workflowURI) {
284298
* @return The step ID
285299
*/
286300
public String stepNameFromURI(String baseUrl, String uri) {
301+
uri = uri.substring(uri.indexOf(baseUrl));
287302
uri = uri.replace(baseUrl, "");
288303
uri = uri.replace("#", "/");
289304
uri = uri.substring(1);

0 commit comments

Comments
 (0)