Skip to content

Commit 630efa2

Browse files
author
Mark Robinson
committed
Parse run parameters and store their path/type
1 parent 5049b14 commit 630efa2

File tree

6 files changed

+116
-30
lines changed

6 files changed

+116
-30
lines changed

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

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.yaml.snakeyaml.Yaml;
3333

3434
import java.io.IOException;
35+
import java.nio.file.Path;
36+
import java.nio.file.Paths;
3537
import java.util.*;
3638

3739
/**
@@ -49,22 +51,20 @@ public class CWLCollection {
4951
private int singleFileSizeLimit;
5052

5153
// Maps of ID to associated JSON
52-
private Map<String, JsonNode> workflows = new HashMap<>();
54+
private Map<String, JsonNode> cwlDocs = new HashMap<>();
5355

5456
// The main workflow
5557
private String mainWorkflowKey;
5658

5759
// Extension of CWL files
5860
private final String CWL_EXTENSION = "cwl";
5961

60-
// Github API specific strings
61-
private final String DIR = "dir";
62-
private final String FILE = "file";
63-
6462
// CWL specific strings
6563
private final String DOC_GRAPH = "$graph";
6664
private final String CLASS = "class";
6765
private final String WORKFLOW = "Workflow";
66+
private final String COMMANDLINETOOL = "CommandLineTool";
67+
private final String EXPRESSIONTOOL = "ExpressionTool";
6868
private final String STEPS = "steps";
6969
private final String INPUTS = "inputs";
7070
private final String IN = "in";
@@ -117,7 +117,7 @@ private void addDocs(List<RepositoryContents> repoContents) throws IOException {
117117
for (RepositoryContents repoContent : repoContents) {
118118

119119
// Parse subdirectories if they exist
120-
if (repoContent.getType().equals(DIR)) {
120+
if (repoContent.getType().equals(GitHubService.TYPE_DIR)) {
121121

122122
// Get the contents of the subdirectory
123123
GithubDetails githubSubdir = new GithubDetails(githubInfo.getOwner(),
@@ -127,7 +127,7 @@ private void addDocs(List<RepositoryContents> repoContents) throws IOException {
127127
// Add the files in the subdirectory to this new folder
128128
addDocs(subdirectory);
129129

130-
} else if (repoContent.getType().equals(FILE)) {
130+
} else if (repoContent.getType().equals(GitHubService.TYPE_FILE)) {
131131

132132
// Keep track of total file size for limit - only track files which
133133
// will be added to the RO bundle due to being small enough
@@ -155,7 +155,7 @@ private void addDocs(List<RepositoryContents> repoContents) throws IOException {
155155
JsonNode cwlFile = mapper.valueToTree(reader.load(fileContent));
156156

157157
// Add document to those being considered
158-
addDoc(cwlFile, repoContent.getName());
158+
addDoc(cwlFile, repoContent.getPath());
159159
} else {
160160
throw new IOException("File '" + repoContent.getName() + "' is over singleFileSizeLimit - " +
161161
FileUtils.byteCountToDisplaySize(repoContent.getSize()) + "/" +
@@ -181,15 +181,11 @@ private void addDoc(JsonNode newDoc, String fileName) {
181181
if (newDoc.has(DOC_GRAPH)) {
182182
// Add each of the sub documents
183183
for (JsonNode jsonNode : newDoc.get(DOC_GRAPH)) {
184-
if (isWorkflow(jsonNode)) {
185-
workflows.put(extractID(jsonNode), jsonNode);
186-
}
184+
cwlDocs.put(extractID(jsonNode), jsonNode);
187185
}
188186
} else {
189187
// Otherwise just add the document itself with ID of document name
190-
if (isWorkflow(newDoc)) {
191-
workflows.put(fileName, newDoc);
192-
}
188+
cwlDocs.put(fileName, newDoc);
193189
}
194190
}
195191

@@ -204,12 +200,12 @@ private String findMainWorkflow() {
204200

205201
// Store the in degree of each workflow
206202
Map<String, Integer> inDegrees = new HashMap<String, Integer>();
207-
for (String key : workflows.keySet()) {
203+
for (String key : cwlDocs.keySet()) {
208204
inDegrees.put(key, 0);
209205
}
210206

211207
// Loop through documents and calculate in degrees
212-
for (Map.Entry<String, JsonNode> doc : workflows.entrySet()) {
208+
for (Map.Entry<String, JsonNode> doc : cwlDocs.entrySet()) {
213209
JsonNode content = doc.getValue();
214210
if (content.get(CLASS).asText().equals(WORKFLOW)) {
215211
// Parse workflow steps and see whether other workflows are run
@@ -269,16 +265,31 @@ public Workflow getWorkflow() {
269265
return null;
270266
}
271267
}
272-
JsonNode mainWorkflow = workflows.get(mainWorkflowKey);
268+
JsonNode mainWorkflow = cwlDocs.get(mainWorkflowKey);
273269

274270
// Use ID/filename for label if there is no defined one
275271
String label = extractLabel(mainWorkflow);
276272
if (label == null) {
277273
label = mainWorkflowKey;
278274
}
279275

280-
return new Workflow(label, extractDoc(mainWorkflow), getInputs(mainWorkflow),
281-
getOutputs(mainWorkflow), getSteps(mainWorkflow), getDockerLink(mainWorkflow));
276+
Workflow workflowModel = new Workflow(label, extractDoc(mainWorkflow), getInputs(mainWorkflow),
277+
getOutputs(mainWorkflow), getSteps(mainWorkflow), getDockerLink(mainWorkflow));
278+
fillStepRunTypes(workflowModel);
279+
return workflowModel;
280+
}
281+
282+
/**
283+
* Fill the step runtypes based on types of other documents
284+
* @param workflow The workflow model to set runtypes for
285+
*/
286+
private void fillStepRunTypes(Workflow workflow) {
287+
Map<String, CWLStep> steps = workflow.getSteps();
288+
for (CWLStep step : steps.values()) {
289+
Path filePath = Paths.get(githubInfo.getPath()).resolve(step.getRun());
290+
JsonNode runDoc = cwlDocs.get(filePath.toString());
291+
step.setRunType(extractProcess(runDoc));
292+
}
282293
}
283294

284295
/**
@@ -295,7 +306,7 @@ private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
295306
// Explicit ID and other fields within each input list
296307
for (JsonNode step : steps) {
297308
CWLStep stepObject = new CWLStep(extractLabel(step), extractDoc(step),
298-
extractTypes(step), getInputs(step), getOutputs(step));
309+
extractTypes(step), extractRun(step), getInputs(step), getOutputs(step));
299310
returnMap.put(extractID(step), stepObject);
300311
}
301312
} else if (steps.getClass() == ObjectNode.class) {
@@ -305,7 +316,8 @@ private Map<String, CWLStep> getSteps(JsonNode cwlDoc) {
305316
Map.Entry<String, JsonNode> stepNode = iterator.next();
306317
JsonNode stepJson = stepNode.getValue();
307318
CWLStep stepObject = new CWLStep(extractLabel(stepJson), extractDoc(stepJson),
308-
extractTypes(stepJson), getInputs(stepJson), getOutputs(stepJson));
319+
extractTypes(stepJson), extractRun(stepJson), getInputs(stepJson),
320+
getOutputs(stepJson));
309321
returnMap.put(stepNode.getKey(), stepObject);
310322
}
311323
}
@@ -710,12 +722,23 @@ private String extractRun(JsonNode stepNode) {
710722
}
711723

712724
/**
713-
* Identify a JsonNode as a workflow
714-
* @param rootNode The root node
715-
* @return Whether or not the node is a workflow
725+
* Extract the class parameter from a node representing a document
726+
* @param rootNode The root node of a cwl document
727+
* @return Which process this document represents
716728
*/
717-
private boolean isWorkflow(JsonNode rootNode) {
718-
return (rootNode.has(CLASS)
719-
&& rootNode.get(CLASS).asText().equals(WORKFLOW));
729+
private CWLProcess extractProcess(JsonNode rootNode) {
730+
if (rootNode != null) {
731+
if (rootNode.has(CLASS)) {
732+
switch(rootNode.get(CLASS).asText()) {
733+
case WORKFLOW:
734+
return CWLProcess.WORKFLOW;
735+
case COMMANDLINETOOL:
736+
return CWLProcess.COMMANDLINETOOL;
737+
case EXPRESSIONTOOL:
738+
return CWLProcess.EXPRESSIONTOOL;
739+
}
740+
}
741+
}
742+
return null;
720743
}
721744
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
/**
23+
* Enum for possible CWL processes
24+
*/
25+
public enum CWLProcess {
26+
WORKFLOW,
27+
COMMANDLINETOOL,
28+
EXPRESSIONTOOL;
29+
30+
@Override
31+
public String toString() {
32+
String defaultString = super.toString();
33+
return defaultString.substring(0, 1) + defaultString.substring(1).toLowerCase();
34+
}
35+
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ public class CWLStep {
2929
private String label;
3030
private String doc;
3131
private String type;
32+
private String run;
33+
private CWLProcess runType;
3234
private Map<String, CWLElement> inputs;
3335
private Map<String, CWLElement> outputs;
3436

35-
public CWLStep(String label, String doc, String type,
37+
public CWLStep(String label, String doc, String type, String run,
3638
Map<String, CWLElement> inputs, Map<String, CWLElement> outputs) {
3739
this.label = label;
3840
this.doc = doc;
3941
this.type = type;
42+
this.run = run;
4043
this.inputs = inputs;
4144
this.outputs = outputs;
4245
}
@@ -65,6 +68,22 @@ public void setType(String type) {
6568
this.type = type;
6669
}
6770

71+
public String getRun() {
72+
return run;
73+
}
74+
75+
public void setRun(String run) {
76+
this.run = run;
77+
}
78+
79+
public CWLProcess getRunType() {
80+
return runType;
81+
}
82+
83+
public void setRunType(CWLProcess runType) {
84+
this.runType = runType;
85+
}
86+
6887
public Map<String, CWLElement> getInputs() {
6988
return inputs;
7089
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
121121
for (RepositoryContents repoContent : repoContents) {
122122

123123
// Parse subdirectories if they exist
124-
if (repoContent.getType().equals("dir")) {
124+
if (repoContent.getType().equals(GitHubService.TYPE_DIR)) {
125125

126126
// Get the contents of the subdirectory
127127
GithubDetails githubSubdir = new GithubDetails(githubInfo.getOwner(),
@@ -136,7 +136,7 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
136136
addFiles(subdirectory, subdirPath);
137137

138138
// Otherwise this is a file so add to the bundle
139-
} else if (repoContent.getType().equals("file")) {
139+
} else if (repoContent.getType().equals(GitHubService.TYPE_FILE)) {
140140

141141
try {
142142
// Where to store the new file in bundle

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
@Service
4949
public class GitHubService {
5050

51+
// Github API specific strings
52+
public static final String TYPE_DIR = "dir";
53+
public static final String TYPE_FILE = "file";
54+
5155
// Github API services
5256
private final ContentsService contentsService;
5357
private final UserService userService;

src/main/resources/templates/workflow.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,17 @@ <h2>Steps</h2>
226226
<th>ID</th>
227227
<th>Label</th>
228228
<th>Doc</th>
229+
<th>Runs</th>
229230
</thead>
230231
<tbody>
231232
<tr th:each="step : ${workflow.steps}">
232233
<td th:text="${step.key}">ID</td>
233234
<td th:text="${step.value.label}">Label</td>
234235
<td th:text="${step.value.doc}">Description</td>
236+
<td>
237+
<span th:text="${step.value.run}">run.cwl</span>
238+
(<span th:text="${step.value.runType}">Workflow</span>)
239+
</td>
235240
</tr>
236241
</tbody>
237242
</table>

0 commit comments

Comments
 (0)