Skip to content

Commit 2124289

Browse files
authored
Merge pull request #11 from common-workflow-language/nonexistant-workflow
Prevent IndexOutOfBoundsException when no workflow exists
2 parents 0ae5984 + aac971d commit 2124289

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>org.commonwl</groupId>
7-
<artifactId>cwlviewer</artifactId>
7+
<artifactId>cwlvisualiser</artifactId>
88
<version>0.0.1-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ private void findMainWorkflow() {
144144
public Workflow getWorkflow() {
145145
if (mainWorkflowIndex < 0) {
146146
findMainWorkflow();
147+
148+
// If it is still less than 0 there is no workflow to be found
149+
if (mainWorkflowIndex < 0) {
150+
return null;
151+
}
147152
}
148153
JsonNode mainWorkflow = cwlDocs.get(mainWorkflowIndex);
149154
return new Workflow(extractLabel(mainWorkflow), extractDoc(mainWorkflow),

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,20 @@ public Workflow workflowFromGithub(String githubURL) {
6666

6767
// Get the workflow model
6868
Workflow workflowModel = cwlFiles.getWorkflow();
69-
workflowModel.setRetrievedOn(new Date());
70-
workflowModel.setRetrievedFrom(githubInfo);
69+
if (workflowModel != null) {
70+
// Set origin details
71+
workflowModel.setRetrievedOn(new Date());
72+
workflowModel.setRetrievedFrom(githubInfo);
7173

72-
// Save to the MongoDB database
73-
workflowRepository.save(workflowModel);
74+
// Save to the MongoDB database
75+
workflowRepository.save(workflowModel);
7476

75-
// Return this model to be displayed
76-
return workflowModel;
77+
// Return this model to be displayed
78+
return workflowModel;
7779

80+
} else {
81+
System.out.println("Error: no workflow could be found");
82+
}
7883
} catch (IOException ex) {
7984
System.out.println("Error: " + ex.getMessage());
8085
}

src/main/java/org/commonwl/viewer/web/WorkflowController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, B
6666
// Create a workflow from the github URL
6767
Workflow newWorkflow = workflowFactory.workflowFromGithub(workflowForm.getGithubURL());
6868

69+
// Runtime error
70+
if (newWorkflow == null) {
71+
bindingResult.rejectValue("githubURL", "githubURL.parsingError");
72+
return new ModelAndView("index");
73+
}
74+
6975
// Return new workflow along with the workflow view
7076
return new ModelAndView("workflow", "workflow", newWorkflow);
7177
}

src/main/resources/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
githubURL.emptyOrWhitespace = URL may not be empty
33
githubURL.invalid = You must enter a valid Github directory URL
44
githubURL.apiError = API Error - does the specified Github directory exist?
5-
githubURL.missingWorkflow = No .cwl files were found in the specified Github directory
5+
githubURL.missingWorkflow = No .cwl files were found in the specified Github directory
6+
githubURL.parsingError = The workflow could not be parsed from the given URL

0 commit comments

Comments
 (0)