19
19
20
20
package org .commonwl .view .cwl ;
21
21
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 .util .ArrayList ;
29
+ import java .util .HashMap ;
30
+ import java .util .Iterator ;
31
+ import java .util .List ;
32
+ import java .util .Map ;
33
+
27
34
import org .apache .commons .io .FileUtils ;
28
35
import org .apache .commons .io .FilenameUtils ;
36
+ import org .apache .jena .iri .IRI ;
37
+ import org .apache .jena .iri .IRIFactory ;
29
38
import org .apache .jena .ontology .OntModelSpec ;
30
39
import org .apache .jena .query .QuerySolution ;
31
40
import org .apache .jena .query .ResultSet ;
32
41
import org .apache .jena .rdf .model .Model ;
33
42
import org .apache .jena .rdf .model .ModelFactory ;
34
- import org .apache .jena .rdf .model .Statement ;
35
- import org .apache .jena .rdf .model .StmtIterator ;
36
43
import org .apache .jena .riot .RiotException ;
37
44
import org .commonwl .view .docker .DockerService ;
38
45
import org .commonwl .view .git .GitDetails ;
47
54
import org .springframework .stereotype .Service ;
48
55
import org .yaml .snakeyaml .Yaml ;
49
56
50
- import java .io .ByteArrayInputStream ;
51
- import java .io .File ;
52
- import java .io .IOException ;
53
- import java .io .StringWriter ;
54
- import java .nio .file .Path ;
55
- import java .nio .file .Paths ;
56
- import java .util .*;
57
-
58
- import static org .apache .commons .io .FileUtils .readFileToString ;
57
+ import com .fasterxml .jackson .databind .JsonNode ;
58
+ import com .fasterxml .jackson .databind .ObjectMapper ;
59
+ import com .fasterxml .jackson .databind .node .ArrayNode ;
60
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
61
+ import com .fasterxml .jackson .databind .node .TextNode ;
59
62
60
63
/**
61
64
* Provides CWL parsing for workflows to gather an overview
65
68
public class CWLService {
66
69
67
70
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
71
+ private final IRIFactory iriFactory = IRIFactory .iriImplementation ();
68
72
69
73
// Autowired properties/services
70
74
private final RDFService rdfService ;
@@ -273,42 +277,18 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
273
277
String inputName = rdfService .stepNameFromURI (gitPath , input .get ("name" ).toString ());
274
278
275
279
CWLElement wfInput = new CWLElement ();
276
-
277
- // Array types
278
280
if (input .contains ("type" )) {
279
- StmtIterator itr = input .get ("type" ).asResource ().listProperties ();
280
- if (itr .hasNext ()) {
281
- while (itr .hasNext ()) {
282
- Statement complexType = itr .nextStatement ();
283
- if (complexType .getPredicate ().toString ()
284
- .equals ("https://w3id.org/cwl/salad#items" )) {
285
- if (wfInputs .containsKey (inputName )
286
- && wfInputs .get (inputName ).getType ().equals ("?" )) {
287
- wfInput .setType (typeURIToString (complexType .getObject ().toString ()) + "[]?" );
288
- } else {
289
- wfInput .setType (typeURIToString (complexType .getObject ().toString ()) + "[]" );
290
- }
291
- }
292
- }
281
+ String type ;
282
+ if (input .get ("type" ).toString ().equals ("https://w3id.org/cwl/salad#array" )) {
283
+ type = typeURIToString (input .get ("items" ).toString ()) + "[]" ;
293
284
} else {
294
- // Optional types
295
- if (input .get ("type" ).toString ().equals ("https://w3id.org/cwl/salad#null" )) {
296
- if (wfInputs .containsKey (inputName )) {
297
- CWLElement inputInMap = wfInputs .get (inputName );
298
- inputInMap .setType (inputInMap .getType () + "?" );
299
- } else {
300
- wfInput .setType ("?" );
301
- }
302
- } else if (wfInput .getType () != null && wfInput .getType ().equals ("?" )
303
- && !wfInput .getType ().endsWith ("[]" )) {
304
- wfInput .setType (typeURIToString (input .get ("type" ).toString ()) + "?" );
305
- } else {
306
- // Standard type
307
- wfInput .setType (typeURIToString (input .get ("type" ).toString ()));
308
- }
285
+ type = typeURIToString (input .get ("type" ).toString ());
286
+ }
287
+ if (input .contains ("null" )) {
288
+ type += " (Optional)" ;
309
289
}
290
+ wfInput .setType (type );
310
291
}
311
-
312
292
if (input .contains ("format" )) {
313
293
String format = input .get ("format" ).toString ();
314
294
setFormat (wfInput , format );
@@ -330,41 +310,17 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
330
310
CWLElement wfOutput = new CWLElement ();
331
311
332
312
String outputName = rdfService .stepNameFromURI (gitPath , output .get ("name" ).toString ());
333
-
334
- // Array types
335
313
if (output .contains ("type" )) {
336
- StmtIterator itr = output .get ("type" ).asResource ().listProperties ();
337
- if (itr .hasNext ()) {
338
- while (itr .hasNext ()) {
339
- Statement complexType = itr .nextStatement ();
340
- if (complexType .getPredicate ().toString ()
341
- .equals ("https://w3id.org/cwl/salad#items" )) {
342
- if (wfOutputs .containsKey (outputName )
343
- && wfOutputs .get (outputName ).getType ().equals ("?" )) {
344
- wfOutput .setType (typeURIToString (complexType .getObject ().toString ()) + "[]?" );
345
- } else {
346
- wfOutput .setType (typeURIToString (complexType .getObject ().toString ()) + "[]" );
347
- }
348
- }
349
- }
314
+ String type ;
315
+ if (output .get ("type" ).toString ().equals ("https://w3id.org/cwl/salad#array" )) {
316
+ type = typeURIToString (output .get ("items" ).toString ()) + "[]" ;
350
317
} else {
351
- // Standard types
352
- if (wfOutput .getType () != null && wfOutput .getType ().equals ("?" )) {
353
- wfOutput .setType (typeURIToString (output .get ("type" ).toString ()) + "?" );
354
- } else {
355
- wfOutput .setType (typeURIToString (output .get ("type" ).toString ()));
356
- }
357
-
358
- // Optional types
359
- if (output .get ("type" ).toString ().equals ("https://w3id.org/cwl/salad#null" )) {
360
- if (wfOutputs .containsKey (outputName )) {
361
- CWLElement outputInMap = wfOutputs .get (outputName );
362
- outputInMap .setType (outputInMap .getType () + "?" );
363
- } else {
364
- wfOutput .setType ("?" );
365
- }
366
- }
318
+ type = typeURIToString (output .get ("type" ).toString ());
367
319
}
320
+ if (output .contains ("null" )) {
321
+ type += " (Optional)" ;
322
+ }
323
+ wfOutput .setType (type );
368
324
}
369
325
370
326
if (output .contains ("src" )) {
@@ -408,8 +364,10 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
408
364
// Add new step
409
365
CWLStep wfStep = new CWLStep ();
410
366
411
- Path workflowPath = Paths .get (step .get ("wf" ).toString ()).getParent ();
412
- Path runPath = Paths .get (step .get ("run" ).toString ());
367
+ IRI wfStepUri = iriFactory .construct (step .get ("wf" ).asResource ().getURI ());
368
+ IRI workflowPath = wfStepUri .resolve ("./" );
369
+
370
+ IRI runPath = iriFactory .construct (step .get ("run" ).asResource ().getURI ());
413
371
wfStep .setRun (workflowPath .relativize (runPath ).toString ());
414
372
wfStep .setRunType (rdfService .strToRuntype (step .get ("runtype" ).toString ()));
415
373
@@ -538,9 +496,9 @@ private void setFormat(CWLElement inputOutput, String format) {
538
496
rdfService .addToOntologies (ontModel );
539
497
}
540
498
String formatLabel = rdfService .getOntLabel (format );
541
- inputOutput .setType (inputOutput .getType () + " ( " + formatLabel + ") " );
499
+ inputOutput .setType (inputOutput .getType () + " [ " + formatLabel + "] " );
542
500
} catch (RiotException ex ) {
543
- inputOutput .setType (inputOutput .getType () + " ( format) " );
501
+ inputOutput .setType (inputOutput .getType () + " [ format] " );
544
502
}
545
503
}
546
504
0 commit comments