Skip to content

Commit 9eee686

Browse files
author
Mark Robinson
committed
Add penultimate links for steps
1 parent 8801806 commit 9eee686

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private Map<String, CWLElement> getInputsOutputs(JsonNode inputsOutputs) {
231231
Map<String, CWLElement> returnMap = new HashMap<>();
232232

233233
if (inputsOutputs.getClass() == ArrayNode.class) {
234-
// Explicit ID and other fields within each input list
234+
// Explicit ID and other fields within each ilist
235235
for (JsonNode inputOutput : inputsOutputs) {
236236
String id = inputOutput.get("id").asText();
237237
returnMap.put(id, getDetails(inputOutput));
@@ -261,13 +261,11 @@ private CWLElement getDetails(JsonNode inputOutput) {
261261
if (inputOutput.getClass() == TextNode.class) {
262262
details.setType(inputOutput.asText());
263263
} else {
264-
if (extractLabel(inputOutput) != null) {
265-
details.setLabel(extractLabel(inputOutput));
266-
}
264+
details.setLabel(extractLabel(inputOutput));
265+
details.setDoc(extractDoc(inputOutput));
267266

268-
if (extractDoc(inputOutput) != null) {
269-
details.setDoc(extractDoc(inputOutput));
270-
}
267+
// OutputSource is only for outputs of the overall workflow
268+
details.setSourceID(extractOutputSource(inputOutput));
271269

272270
// Type is only for inputs
273271
if (inputOutput.has("type")) {
@@ -304,6 +302,39 @@ private String extractLabel(JsonNode node) {
304302
return null;
305303
}
306304

305+
/**
306+
* Extract the outputSource from a node
307+
* @param node The node to have the label extracted from
308+
* @return The string for the outputSource of the node
309+
*/
310+
private String extractOutputSource(JsonNode node) {
311+
if (node != null) {
312+
String source = null;
313+
if (node.has("outputSource")) {
314+
source = node.get("outputSource").asText();
315+
} else if (node.has("source")) {
316+
source = node.get("source").asText();
317+
}
318+
319+
// Get step ID from a SALAD ID
320+
if (source != null) {
321+
// Strip leading # if it exists
322+
if (source.charAt(0) == '#') {
323+
source = source.substring(1);
324+
}
325+
326+
// Get segment before / (step ID)
327+
int slashSplit = source.indexOf("/");
328+
if (slashSplit != -1) {
329+
source = source.substring(0, slashSplit);
330+
}
331+
}
332+
333+
return source;
334+
}
335+
return null;
336+
}
337+
307338
/**
308339
* Extract the doc or description from a node
309340
* @param node The node to have the doc/description extracted from

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
package org.commonwl.viewer.domain;
2121

2222
/**
23-
* Represents the input or output of a workflow/tool
23+
* Represents the input/output/step of a workflow/tool
2424
*/
2525
public class CWLElement {
2626

2727
private String label;
2828
private String doc;
2929
private String type;
30+
private String sourceID;
3031

3132
public String getLabel() {
3233
return label;
@@ -52,4 +53,12 @@ public void setType(String type) {
5253
this.type = type;
5354
}
5455

56+
public String getSourceID() {
57+
return sourceID;
58+
}
59+
60+
public void setSourceID(String sourceID) {
61+
this.sourceID = sourceID;
62+
}
63+
5564
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,13 @@ private void writeOutputs(Workflow workflow) throws IOException {
153153
private void writeSteps(Workflow workflow) throws IOException {
154154
// Write each of the steps as a node
155155
for (Map.Entry<String, CWLElement> step : workflow.getSteps().entrySet()) {
156-
writeLine(step.getKey());
156+
writeLine(" \"" + step.getKey() + "\"");
157+
}
158+
159+
// Write the links between nodes
160+
// Write links between outputs and penultimate steps
161+
for (Map.Entry<String, CWLElement> output : workflow.getOutputs().entrySet()) {
162+
writeLine(" \"" + output.getValue().getSourceID() + "\" -> \"" + output.getKey() + "\"");
157163
}
158164
}
159165

0 commit comments

Comments
 (0)