Skip to content

Commit 8bd8c4a

Browse files
committed
support more complex types
1 parent 59588d3 commit 8bd8c4a

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,18 @@ private CWLElement getDetails(Object inputOutput) {
815815
// Shorthand notation "id: type" - no label/doc/other params
816816
if (inputOutput.getClass() == String.class) {
817817
details.setType((String) inputOutput);
818-
} else {
819-
details.setLabel(extractLabel((Map<String, Object>) inputOutput));
820-
details.setDoc(extractDoc((Map<String, Object>) inputOutput));
821-
extractSource((Map<String, Object>) inputOutput).forEach(details::addSourceID);
822-
details.setDefaultVal(extractDefault((Map<String, Object>) inputOutput));
818+
} else if (List.class.isAssignableFrom(inputOutput.getClass())) {
819+
details.setType(this.extractTypes(inputOutput));
820+
} else if (Map.class.isAssignableFrom(inputOutput.getClass())) {
821+
Map<String, Object> iOMap = (Map<String, Object>) inputOutput;
822+
details.setLabel(extractLabel(iOMap));
823+
details.setDoc(extractDoc(iOMap));
824+
extractSource(iOMap).forEach(details::addSourceID);
825+
details.setDefaultVal(extractDefault(iOMap));
823826

824827
// Type is only for inputs
825-
if (((Map<String, Object>) inputOutput).containsKey(TYPE)) {
826-
details.setType(extractTypes(((Map<String, Object>) inputOutput).get(TYPE)));
828+
if (iOMap.containsKey(TYPE)) {
829+
details.setType(extractTypes(iOMap.get(TYPE)));
827830
}
828831
}
829832

@@ -966,7 +969,7 @@ private String extractTypes(Object typeNode) {
966969
// Multiple types, build a string to represent them
967970
StringBuilder typeDetails = new StringBuilder();
968971
boolean optional = false;
969-
for (Object type : (List<String>) typeNode) {
972+
for (Object type : (List<Object>) typeNode) {
970973
if (type.getClass() == String.class) {
971974
// This is a simple type
972975
if (((String) type).equals("null")) {
@@ -981,8 +984,13 @@ private String extractTypes(Object typeNode) {
981984
// This is a verbose type with sub-fields broken down into type: and other
982985
// params
983986
if (((Map<String, Object>) type).get(TYPE).equals(ARRAY)) {
984-
typeDetails.append((String) ((Map<String, Object>) type).get(ARRAY_ITEMS));
985-
typeDetails.append("[], ");
987+
Object items = ((Map<String, Object>) type).get(ARRAY_ITEMS);
988+
if (items.getClass() == String.class) {
989+
typeDetails.append(items);
990+
typeDetails.append("[], ");
991+
} else {
992+
typeDetails.append(type.toString() + ", ");
993+
}
986994
} else {
987995
typeDetails.append((String) ((Map<String, Object>) type).get(TYPE));
988996
}

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
import java.io.ByteArrayInputStream;
4343
import java.io.File;
4444
import java.io.IOException;
45+
import java.io.InputStream;
46+
import java.net.URI;
47+
import java.net.URL;
48+
import java.nio.file.Path;
4549
import java.nio.file.Paths;
4650
import java.util.List;
4751
import java.util.Map;
@@ -134,19 +138,24 @@ public void parseLobSTRv1WorkflowNative() throws Exception {
134138
testLobSTRWorkflow(lobSTRv1, true);
135139
}
136140

137-
/**
138-
* Test native loading parsing of optional inline types
139-
*/
140-
@Test
141-
public void parseWorkflowInlineOptionalTypesNative() throws Exception {
142-
CWLService cwlService = new CWLService(rdfService, new CWLTool(), 5242880);
143-
Workflow wkflow = cwlService.parseWorkflowNative(
144-
Paths.get("src/test/resources/cwl/oneline_optional_types.cwl"), null);
145-
assertEquals(wkflow.getInputs().get("qualified_phred_quality").getType(), "int?");
146-
assertEquals(wkflow.getInputs().get("ncrna_tab_file").getType(), "File?");
147-
assertEquals(wkflow.getInputs().get("reverse_reads").getType(), "File?");
148-
149-
}
141+
/**
142+
* Test native loading parsing of optional inline types
143+
*/
144+
@Test
145+
public void parseWorkflowInlineOptionalTypesNative() throws Exception {
146+
CWLService cwlService = new CWLService(rdfService, new CWLTool(), 5242880);
147+
// URI uri = new URI("https://github.com/emo-bon/pipeline-v5/raw/develop/workflows/gos_wf.cwl");
148+
// InputStream is = uri.toURL().openStream();
149+
// Workflow wkflow = cwlService.parseWorkflowNative(is, null, uri.toURL().getFile());
150+
Workflow wkflow = cwlService.parseWorkflowNative(Paths.get("src/test/resources/cwl/oneline_optional_types.cwl"),
151+
null);
152+
assertEquals(wkflow.getInputs().get("qualified_phred_quality").getType(), "int?");
153+
assertEquals(wkflow.getInputs().get("ncrna_tab_file").getType(), "File?");
154+
assertEquals(wkflow.getInputs().get("reverse_reads").getType(), "File?");
155+
assertEquals(wkflow.getInputs().get("ssu_tax").getType(), "string, File");
156+
assertEquals(wkflow.getInputs().get("rfam_models").getType(), "{type=array, items=[string, File]}");
157+
158+
}
150159

151160
/**
152161
* Test parsing of a workflow using cwltool

src/test/resources/cwl/oneline_optional_types.cwl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ inputs:
55
ncrna_tab_file: {type: File?}
66
reverse_reads: File?
77
qualified_phred_quality: { type: int? }
8-
8+
ssu_tax: [string, File]
9+
rfam_models:
10+
type:
11+
- type: array
12+
items: [string, File]
13+
914
steps: []
1015

1116
outputs: []

0 commit comments

Comments
 (0)