26
26
import com .fasterxml .jackson .databind .node .TextNode ;
27
27
import org .apache .commons .io .FileUtils ;
28
28
import org .apache .commons .io .FilenameUtils ;
29
+ import org .apache .jena .ontology .OntModelSpec ;
29
30
import org .apache .jena .query .QuerySolution ;
30
31
import org .apache .jena .query .ResultSet ;
31
32
import org .apache .jena .rdf .model .Model ;
32
33
import org .apache .jena .rdf .model .ModelFactory ;
33
34
import org .apache .jena .rdf .model .Statement ;
34
35
import org .apache .jena .rdf .model .StmtIterator ;
36
+ import org .apache .jena .riot .RiotException ;
35
37
import org .commonwl .view .docker .DockerService ;
36
38
import org .commonwl .view .github .GitHubService ;
37
39
import org .commonwl .view .github .GithubDetails ;
@@ -187,9 +189,6 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
187
189
String packedWorkflowID ) throws CWLValidationException {
188
190
189
191
// Get RDF representation from cwltool
190
- String graphName = String .format ("github.com/%s/%s/%s/%s" , githubInfo .getOwner (),
191
- githubInfo .getRepoName (), latestCommit , githubInfo .getPath ());
192
-
193
192
String url = String .format ("https://cdn.rawgit.com/%s/%s/%s/%s" , githubInfo .getOwner (),
194
193
githubInfo .getRepoName (), latestCommit , githubInfo .getPath ());
195
194
if (packedWorkflowID != null ) {
@@ -199,21 +198,21 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
199
198
url += packedWorkflowID ;
200
199
}
201
200
202
- if (!rdfService .graphExists (graphName )) {
201
+ if (!rdfService .graphExists (url )) {
203
202
String rdf = cwlTool .getRDF (url );
204
203
205
204
// Create a workflow model from RDF representation
206
205
Model model = ModelFactory .createDefaultModel ();
207
206
model .read (new ByteArrayInputStream (rdf .getBytes ()), null , "TURTLE" );
208
207
209
208
// Store the model
210
- rdfService .storeModel (graphName , model );
209
+ rdfService .storeModel (url , model );
211
210
}
212
211
213
212
// Base workflow details
214
213
String label = FilenameUtils .getName (githubInfo .getPath ());
215
214
String doc = null ;
216
- ResultSet labelAndDoc = rdfService .getLabelAndDoc (graphName , url );
215
+ ResultSet labelAndDoc = rdfService .getLabelAndDoc (url );
217
216
if (labelAndDoc .hasNext ()) {
218
217
QuerySolution labelAndDocSoln = labelAndDoc .nextSolution ();
219
218
if (labelAndDocSoln .contains ("label" )) {
@@ -226,7 +225,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
226
225
227
226
// Inputs
228
227
Map <String , CWLElement > wfInputs = new HashMap <>();
229
- ResultSet inputs = rdfService .getInputs (graphName , url );
228
+ ResultSet inputs = rdfService .getInputs (url );
230
229
while (inputs .hasNext ()) {
231
230
QuerySolution input = inputs .nextSolution ();
232
231
String inputName = rdfService .stepNameFromURI (url , input .get ("name" ).toString ());
@@ -268,6 +267,10 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
268
267
}
269
268
}
270
269
270
+ if (input .contains ("format" )) {
271
+ String format = input .get ("format" ).toString ();
272
+ setFormat (wfInput , format );
273
+ }
271
274
if (input .contains ("label" )) {
272
275
wfInput .setLabel (input .get ("label" ).toString ());
273
276
}
@@ -279,7 +282,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
279
282
280
283
// Outputs
281
284
Map <String , CWLElement > wfOutputs = new HashMap <>();
282
- ResultSet outputs = rdfService .getOutputs (graphName , url );
285
+ ResultSet outputs = rdfService .getOutputs (url );
283
286
while (outputs .hasNext ()) {
284
287
QuerySolution output = outputs .nextSolution ();
285
288
CWLElement wfOutput = new CWLElement ();
@@ -326,6 +329,10 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
326
329
wfOutput .addSourceID (rdfService .stepNameFromURI (url ,
327
330
output .get ("src" ).toString ()));
328
331
}
332
+ if (output .contains ("format" )) {
333
+ String format = output .get ("format" ).toString ();
334
+ setFormat (wfOutput , format );
335
+ }
329
336
if (output .contains ("label" )) {
330
337
wfOutput .setLabel (output .get ("label" ).toString ());
331
338
}
@@ -338,7 +345,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
338
345
339
346
// Steps
340
347
Map <String , CWLStep > wfSteps = new HashMap <>();
341
- ResultSet steps = rdfService .getSteps (graphName , url );
348
+ ResultSet steps = rdfService .getSteps (url );
342
349
while (steps .hasNext ()) {
343
350
QuerySolution step = steps .nextSolution ();
344
351
String uri = rdfService .stepNameFromURI (url , step .get ("step" ).toString ());
@@ -390,7 +397,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
390
397
}
391
398
392
399
// Docker link
393
- ResultSet dockerResult = rdfService .getDockerLink (graphName , url );
400
+ ResultSet dockerResult = rdfService .getDockerLink (url );
394
401
String dockerLink = null ;
395
402
if (dockerResult .hasNext ()) {
396
403
QuerySolution docker = dockerResult .nextSolution ();
@@ -407,7 +414,7 @@ public Workflow parseWorkflowWithCwltool(GithubDetails githubInfo,
407
414
408
415
// Generate DOT graph
409
416
StringWriter graphWriter = new StringWriter ();
410
- RDFDotWriter RDFDotWriter = new RDFDotWriter (graphWriter , rdfService , graphName );
417
+ RDFDotWriter RDFDotWriter = new RDFDotWriter (graphWriter , rdfService );
411
418
try {
412
419
RDFDotWriter .writeGraph (url );
413
420
workflowModel .setVisualisationDot (graphWriter .toString ());
@@ -470,6 +477,26 @@ public WorkflowOverview getWorkflowOverview(GithubDetails githubInfo) throws IOE
470
477
471
478
}
472
479
480
+ /**
481
+ * Set the format for an input or output, handling ontologies
482
+ * @param inputOutput The input or output CWL Element
483
+ * @param format The format URI
484
+ */
485
+ private void setFormat (CWLElement inputOutput , String format ) {
486
+ inputOutput .setFormat (format );
487
+ try {
488
+ if (!rdfService .ontPropertyExists (format )) {
489
+ Model ontModel = ModelFactory .createOntologyModel (OntModelSpec .OWL_MEM );
490
+ ontModel .read (format , null , "RDF/XML" );
491
+ rdfService .addToOntologies (ontModel );
492
+ }
493
+ String formatLabel = rdfService .getOntLabel (format );
494
+ inputOutput .setType (inputOutput .getType () + " (" + formatLabel + " format)" );
495
+ } catch (RiotException ex ) {
496
+ inputOutput .setType (inputOutput .getType () + " (format)" );
497
+ }
498
+ }
499
+
473
500
/**
474
501
* Convert RDF URI for a type to a name
475
502
* @param uri The URI for the type
0 commit comments