Skip to content

Commit dc312ce

Browse files
committed
accept nested arrays as well
1 parent 5743b06 commit dc312ce

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,12 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel, Path workflowFile,
412412
CWLStep wfStep = new CWLStep();
413413

414414
IRI workflowPath = iriFactory.construct(url).resolve("./");
415-
IRI runPath = iriFactory.construct(step.get("run").asResource().getURI());
416-
wfStep.setRun(workflowPath.relativize(runPath).toString());
417-
wfStep.setRunType(rdfService.strToRuntype(step.get("runtype").toString()));
415+
Object runValue = step.get("run").asResource().toString();
416+
if (String.class.isAssignableFrom(runValue.getClass())) {
417+
String runPath = (String) runValue;
418+
wfStep.setRun(workflowPath.relativize(runPath).toString());
419+
wfStep.setRunType(rdfService.strToRuntype(step.get("runtype").toString()));
420+
}
418421

419422
if (step.contains("src")) {
420423
CWLElement src = new CWLElement();
@@ -1012,7 +1015,7 @@ private String extractTypes(Object typeNode) {
10121015
} else if (Map.class.isAssignableFrom(typeNode.getClass())) {
10131016
// Type: array and items:
10141017
if (((Map<String, Object>) typeNode).containsKey(ARRAY_ITEMS)) {
1015-
return ((Map<String, String>) typeNode).get(ARRAY_ITEMS) + "[]";
1018+
return extractTypes(((Map<String, String>) typeNode).get(ARRAY_ITEMS)) + "[]";
10161019
}
10171020
}
10181021
}
@@ -1025,10 +1028,10 @@ private String extractTypes(Object typeNode) {
10251028
* @param step The root node of a step
10261029
* @return A string with the run parameter if it exists
10271030
*/
1028-
private String extractRun(Map<String, Object> step) {
1031+
private Object extractRun(Map<String, Object> step) {
10291032
if (step != null) {
10301033
if (step.containsKey(RUN)) {
1031-
return (String) step.get(RUN);
1034+
return step.get(RUN);
10321035
}
10331036
}
10341037
return null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public class CWLStep {
3131

3232
private String label;
3333
private String doc;
34-
private String run;
34+
private Object run;
3535
private CWLProcess runType;
3636
private Map<String, CWLElement> sources;
3737

3838
public CWLStep() {
3939
}
4040

41-
public CWLStep(String label, String doc, String run,
41+
public CWLStep(String label, String doc, Object run,
4242
Map<String, CWLElement> sources) {
4343
this.label = label;
4444
this.doc = doc;
@@ -62,11 +62,11 @@ public void setDoc(String doc) {
6262
this.doc = doc;
6363
}
6464

65-
public String getRun() {
65+
public Object getRun() {
6666
return run;
6767
}
6868

69-
public void setRun(String run) {
69+
public void setRun(Object run) {
7070
this.run = run;
7171
}
7272

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ public void parseWorkflowInlineOptionalTypesNative() throws Exception {
157157

158158
}
159159

160+
/**
161+
* Test native loading parsing of nested array types
162+
*/
163+
@Test
164+
public void parseWorkflowNestedArrayTypes() throws Exception {
165+
CWLService cwlService = new CWLService(rdfService, new CWLTool(), 5242880);
166+
Workflow wkflow = cwlService.parseWorkflowNative(Paths.get("src/test/resources/cwl/nested_array.cwl"),
167+
null);
168+
assertEquals(wkflow.getInputs().get("overlap_files").getType(), "File[][]");
169+
assertEquals(wkflow.getOutputs().get("freq_files").getType(), "File[][]");
170+
assertEquals(true, Map.class.isAssignableFrom(wkflow.getSteps().get("dummy").getRun().getClass()));
171+
}
172+
160173
/**
161174
* Test parsing of a workflow using cwltool
162175
*/
@@ -309,4 +322,4 @@ private void testLobSTRWorkflow(Workflow lobSTR, boolean nativeParsed) throws Ex
309322
}
310323
}
311324

312-
}
325+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cwlVersion: v1.2
2+
class: Workflow
3+
4+
inputs:
5+
overlap_files:
6+
type:
7+
type: array
8+
items:
9+
type: array
10+
items: File
11+
12+
outputs:
13+
freq_files:
14+
type:
15+
type: array
16+
items:
17+
type: array
18+
items: File
19+
outputSource: dummy/freq_files
20+
21+
steps:
22+
dummy:
23+
in:
24+
nested_array: overlap_files
25+
run:
26+
class: ExpressionTool
27+
inputs:
28+
nested_array:
29+
type:
30+
type: array
31+
items:
32+
type: array
33+
items: File
34+
expression: |
35+
${ return {"freq_files": inputs.nested_array }; }
36+
outputs:
37+
freq_files:
38+
type:
39+
type: array
40+
items:
41+
type: array
42+
items: File
43+
out: [ freq_files ]

0 commit comments

Comments
 (0)