Skip to content

Commit c8fa3d0

Browse files
author
Mark Robinson
committed
Support for multiple sources for inputs as an array
1 parent aef8559 commit c8fa3d0

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

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

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private CWLElement getDetails(JsonNode inputOutput) {
267267
} else {
268268
details.setLabel(extractLabel(inputOutput));
269269
details.setDoc(extractDoc(inputOutput));
270-
details.addSourceID(extractOutputSource(inputOutput));
270+
extractOutputSource(inputOutput).forEach(details::addSourceID);
271271
details.setDefaultVal(extractDefault(inputOutput));
272272

273273
// Type is only for inputs
@@ -318,38 +318,66 @@ private String extractDefault(JsonNode node) {
318318
}
319319

320320
/**
321-
* Extract the outputSource from a node
322-
* @param node The node to have the label extracted from
323-
* @return The string for the outputSource of the node
321+
* Extract the source or outputSource from a node
322+
* @param node The node to have the sources extracted from
323+
* @return A list of strings for the sources
324324
*/
325-
private String extractOutputSource(JsonNode node) {
325+
private List<String> extractOutputSource(JsonNode node) {
326326
if (node != null) {
327-
String source = null;
327+
List<String> sources = new ArrayList<String>();
328+
JsonNode sourceNode = null;
329+
330+
// outputSource and source treated the same
328331
if (node.has("outputSource")) {
329-
source = node.get("outputSource").asText();
332+
sourceNode = node.get("outputSource");
330333
} else if (node.has("source")) {
331-
source = node.get("source").asText();
334+
sourceNode = node.get("source");
332335
}
333336

334-
// Get step ID from a SALAD ID
335-
if (source != null) {
336-
// Strip leading # if it exists
337-
if (source.charAt(0) == '#') {
338-
source = source.substring(1);
337+
if (sourceNode != null) {
338+
// Single source
339+
if (sourceNode.getClass() == TextNode.class) {
340+
sources.add(stepIDFromSource(sourceNode.asText()));
339341
}
340-
341-
// Get segment before / (step ID)
342-
int slashSplit = source.indexOf("/");
343-
if (slashSplit != -1) {
344-
source = source.substring(0, slashSplit);
342+
// Can be an array of multiple sources
343+
if (sourceNode.getClass() == ArrayNode.class) {
344+
for (JsonNode source : sourceNode) {
345+
sources.add(stepIDFromSource(source.asText()));
346+
}
345347
}
346348
}
347349

348-
return source;
350+
return sources;
349351
}
350352
return null;
351353
}
352354

355+
/**
356+
* Gets just the step ID from source of format 'stepID/outputID'
357+
* @param source The source
358+
* @return The step ID
359+
*/
360+
private String stepIDFromSource(String source) {
361+
if (source != null) {
362+
// Strip leading # if it exists
363+
if (source.charAt(0) == '#') {
364+
source = source.substring(1);
365+
}
366+
367+
// Get segment before / (step ID)
368+
int slashSplit = source.indexOf("/");
369+
if (slashSplit != -1) {
370+
source = source.substring(0, slashSplit);
371+
} else {
372+
int dotSplit = source.indexOf(".");
373+
if (dotSplit != -1) {
374+
source = "#" + source.substring(0, dotSplit);
375+
}
376+
}
377+
}
378+
return source;
379+
}
380+
353381
/**
354382
* Extract the doc or description from a node
355383
* @param node The node to have the doc/description extracted from

0 commit comments

Comments
 (0)