Skip to content

Commit 654c124

Browse files
author
Mark Robinson
committed
Add support for source and default parameters within steps
1 parent 9eee686 commit 654c124

File tree

5 files changed

+137
-12
lines changed

5 files changed

+137
-12
lines changed

src/main/java/org/commonwl/viewer/domain/CWLCollection.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,28 @@ public Workflow getWorkflow() {
173173
* @param cwlDoc The document to get steps for
174174
* @return A map of step IDs and details related to them
175175
*/
176-
private Map<String, CWLElement> getSteps(JsonNode cwlDoc) {
176+
private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
177177
if (cwlDoc != null && cwlDoc.has("steps")) {
178-
Map<String, CWLElement> returnMap = new HashMap<>();
178+
Map<String, CWLStep> returnMap = new HashMap<>();
179179

180180
JsonNode steps = cwlDoc.get("steps");
181181
if (steps.getClass() == ArrayNode.class) {
182182
// Explicit ID and other fields within each input list
183183
for (JsonNode step : steps) {
184184
String id = step.get("id").asText();
185-
returnMap.put(id, getDetails(step));
185+
CWLStep stepObject = new CWLStep(extractID(step), extractDoc(step),
186+
extractTypes(step), getInputs(step), getOutputs(step));
187+
returnMap.put(id, stepObject);
186188
}
187189
} else if (steps.getClass() == ObjectNode.class) {
188190
// ID is the key of each object
189191
Iterator<Map.Entry<String, JsonNode>> iterator = steps.fields();
190192
while (iterator.hasNext()) {
191193
Map.Entry<String, JsonNode> stepNode = iterator.next();
192-
returnMap.put(stepNode.getKey(), getDetails(stepNode.getValue()));
194+
JsonNode stepJson = stepNode.getValue();
195+
CWLStep stepObject = new CWLStep(extractID(stepJson), extractDoc(stepJson),
196+
extractTypes(stepJson), getInputs(stepJson), getOutputs(stepJson));
197+
returnMap.put(stepNode.getKey(), stepObject);
193198
}
194199
}
195200

@@ -263,9 +268,8 @@ private CWLElement getDetails(JsonNode inputOutput) {
263268
} else {
264269
details.setLabel(extractLabel(inputOutput));
265270
details.setDoc(extractDoc(inputOutput));
266-
267-
// OutputSource is only for outputs of the overall workflow
268271
details.setSourceID(extractOutputSource(inputOutput));
272+
details.setDefaultVal(extractDefault(inputOutput));
269273

270274
// Type is only for inputs
271275
if (inputOutput.has("type")) {
@@ -302,6 +306,18 @@ private String extractLabel(JsonNode node) {
302306
return null;
303307
}
304308

309+
/**
310+
* Extract the default value from a node
311+
* @param node The node to have the label extracted from
312+
* @return The string for the default value of the node
313+
*/
314+
private String extractDefault(JsonNode node) {
315+
if (node != null && node.has("default")) {
316+
return node.get("default").asText();
317+
}
318+
return null;
319+
}
320+
305321
/**
306322
* Extract the outputSource from a node
307323
* @param node The node to have the label extracted from

src/main/java/org/commonwl/viewer/domain/CWLElement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CWLElement {
2828
private String doc;
2929
private String type;
3030
private String sourceID;
31+
private String defaultVal;
3132

3233
public String getLabel() {
3334
return label;
@@ -61,4 +62,11 @@ public void setSourceID(String sourceID) {
6162
this.sourceID = sourceID;
6263
}
6364

65+
public String getDefaultVal() {
66+
return defaultVal;
67+
}
68+
69+
public void setDefaultVal(String defaultVal) {
70+
this.defaultVal = defaultVal;
71+
}
6472
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.commonwl.viewer.domain;
21+
22+
import java.util.Map;
23+
24+
/**
25+
* Represents a step of a workflow
26+
*/
27+
public class CWLStep {
28+
29+
private String label;
30+
private String doc;
31+
private String type;
32+
private Map<String, CWLElement> inputs;
33+
private Map<String, CWLElement> outputs;
34+
35+
public CWLStep(String label, String doc, String type,
36+
Map<String, CWLElement> inputs, Map<String, CWLElement> outputs) {
37+
this.label = label;
38+
this.doc = doc;
39+
this.type = type;
40+
this.inputs = inputs;
41+
this.outputs = outputs;
42+
}
43+
44+
public String getLabel() {
45+
return label;
46+
}
47+
48+
public void setLabel(String label) {
49+
this.label = label;
50+
}
51+
52+
public String getDoc() {
53+
return doc;
54+
}
55+
56+
public void setDoc(String doc) {
57+
this.doc = doc;
58+
}
59+
60+
public String getType() {
61+
return type;
62+
}
63+
64+
public void setType(String type) {
65+
this.type = type;
66+
}
67+
68+
public Map<String, CWLElement> getInputs() {
69+
return inputs;
70+
}
71+
72+
public void setInputs(Map<String, CWLElement> inputs) {
73+
this.inputs = inputs;
74+
}
75+
76+
public Map<String, CWLElement> getOutputs() {
77+
return outputs;
78+
}
79+
80+
public void setOutputs(Map<String, CWLElement> outputs) {
81+
this.outputs = outputs;
82+
}
83+
84+
}

src/main/java/org/commonwl/viewer/domain/Workflow.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public class Workflow {
6060
private String doc;
6161
private Map<String, CWLElement> inputs;
6262
private Map<String, CWLElement> outputs;
63-
private Map<String, CWLElement> steps;
63+
private Map<String, CWLStep> steps;
6464

6565
// DOT graph of the contents
6666
private String dotGraph;
6767

6868
public Workflow(String label, String doc, Map<String, CWLElement> inputs,
69-
Map<String, CWLElement> outputs, Map<String, CWLElement> steps) {
69+
Map<String, CWLElement> outputs, Map<String, CWLStep> steps) {
7070
this.label = label;
7171
this.doc = doc;
7272
this.inputs = inputs;
@@ -122,11 +122,11 @@ public void setOutputs(Map<String, CWLElement> outputs) {
122122
this.outputs = outputs;
123123
}
124124

125-
public Map<String, CWLElement> getSteps() {
125+
public Map<String, CWLStep> getSteps() {
126126
return steps;
127127
}
128128

129-
public void setSteps(Map<String, CWLElement> steps) {
129+
public void setSteps(Map<String, CWLStep> steps) {
130130
this.steps = steps;
131131
}
132132

src/main/java/org/commonwl/viewer/services/DotWriter.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.commonwl.viewer.services;
2121

2222
import org.commonwl.viewer.domain.CWLElement;
23+
import org.commonwl.viewer.domain.CWLStep;
2324
import org.commonwl.viewer.domain.Workflow;
2425

2526
import java.io.IOException;
@@ -152,14 +153,30 @@ private void writeOutputs(Workflow workflow) throws IOException {
152153
*/
153154
private void writeSteps(Workflow workflow) throws IOException {
154155
// Write each of the steps as a node
155-
for (Map.Entry<String, CWLElement> step : workflow.getSteps().entrySet()) {
156+
for (Map.Entry<String, CWLStep> step : workflow.getSteps().entrySet()) {
156157
writeLine(" \"" + step.getKey() + "\"");
157158
}
158159

159160
// Write the links between nodes
160161
// Write links between outputs and penultimate steps
161162
for (Map.Entry<String, CWLElement> output : workflow.getOutputs().entrySet()) {
162-
writeLine(" \"" + output.getValue().getSourceID() + "\" -> \"" + output.getKey() + "\"");
163+
writeLine(" \"" + output.getValue().getSourceID() + "\" -> \"" + output.getKey() + "\";");
164+
}
165+
166+
// Write links between the remaining steps
167+
int defaultCount = 0;
168+
for (Map.Entry<String, CWLStep> step : workflow.getSteps().entrySet()) {
169+
for (Map.Entry<String, CWLElement> input : step.getValue().getInputs().entrySet()) {
170+
String sourceID = input.getValue().getSourceID();
171+
String defaultVal = input.getValue().getDefaultVal();
172+
if (sourceID != null) {
173+
writeLine(" \"" + sourceID + "\" -> \"" + step.getKey() + "\";");
174+
} else if (defaultVal != null) {
175+
defaultCount++;
176+
writeLine(" \"default" + defaultCount + "\" [label=\"" + defaultVal + "\", fillcolor=\"#D5AEFC\"]");
177+
writeLine(" \"default" + defaultCount + "\" -> \"" + step.getKey() + "\";");
178+
}
179+
}
163180
}
164181
}
165182

0 commit comments

Comments
 (0)