Skip to content

Commit f8a81a5

Browse files
authored
Merge pull request #147 from common-workflow-language/api-fixes
API Fixes
2 parents c047fca + f8cf2dd commit f8a81a5

File tree

7 files changed

+187
-65
lines changed

7 files changed

+187
-65
lines changed

src/main/java/org/commonwl/view/cwl/CWLElement.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ public void setFormat(String format) {
7373
this.format = format;
7474
}
7575

76-
public List<String> getSourceID() {
77-
return sourceID;
78-
}
79-
80-
public void setSourceID(List<String> sourceID) {
81-
this.sourceID = sourceID;
82-
}
83-
8476
public List<String> getSourceIDs() {
8577
return sourceID;
8678
}

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
453453
queued = workflowService.getQueuedWorkflow(gitDetails);
454454
if (queued == null) {
455455
// Validation
456-
WorkflowForm workflowForm = new WorkflowForm(gitDetails.getUrl());
456+
WorkflowForm workflowForm = new WorkflowForm(gitDetails.getUrl(), gitDetails.getBranch(), gitDetails.getPath());
457457
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(workflowForm, "errors");
458458
workflowFormValidator.validateAndParse(workflowForm, errors);
459459
if (!errors.hasErrors()) {

src/main/java/org/commonwl/view/workflow/WorkflowForm.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public class WorkflowForm {
3232
public WorkflowForm() {}
3333

3434
public WorkflowForm(String url) {
35-
if (url != null) {
36-
this.url = trimTrailingSlashes(url);
37-
}
35+
setUrl(url);
36+
}
37+
38+
public WorkflowForm(String url, String branch, String path) {
39+
setUrl(url);
40+
this.branch = branch;
41+
this.path = path;
3842
}
3943

4044
public String getUrl() {

src/main/java/org/commonwl/view/workflow/WorkflowFormValidator.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.view.workflow;
2121

22+
import org.apache.commons.lang.StringUtils;
2223
import org.commonwl.view.git.GitDetails;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
@@ -68,32 +69,50 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
6869
// If not null and isn't just whitespace
6970
if (!e.hasErrors()) {
7071

72+
// Override if specific branch or path is given in the form
73+
String branch = null;
74+
String path = null;
75+
if (!isEmptyOrWhitespace(form.getBranch())) {
76+
branch = form.getBranch();
77+
}
78+
if (!isEmptyOrWhitespace(form.getPath())) {
79+
path = form.getPath();
80+
}
81+
7182
// Github URL
7283
Matcher m = githubCwlPattern.matcher(form.getUrl());
7384
if (m.find()) {
7485
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
75-
return new GitDetails(repoUrl, m.group(3), m.group(4));
86+
if (branch == null) branch = m.group(3);
87+
if (path == null) path = m.group(4);
88+
return new GitDetails(repoUrl, branch, path);
7689
}
7790

7891
// Gitlab URL
7992
m = gitlabCwlPattern.matcher(form.getUrl());
8093
if (m.find()) {
8194
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
82-
return new GitDetails(repoUrl, m.group(3), m.group(4));
95+
if (branch == null) branch = m.group(3);
96+
if (path == null) path = m.group(4);
97+
return new GitDetails(repoUrl, branch, path);
8398
}
8499

85100
// Github Dir URL
86101
m = githubDirPattern.matcher(form.getUrl());
87102
if (m.find()) {
88103
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
89-
return new GitDetails(repoUrl, m.group(3), m.group(4));
104+
if (branch == null) branch = m.group(3);
105+
if (path == null) path = m.group(4);
106+
return new GitDetails(repoUrl, branch, path);
90107
}
91108

92109
// Gitlab Dir URL
93110
m = gitlabDirPattern.matcher(form.getUrl());
94111
if (m.find()) {
95112
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
96-
return new GitDetails(repoUrl, m.group(3), m.group(4));
113+
if (branch == null) branch = m.group(3);
114+
if (path == null) path = m.group(4);
115+
return new GitDetails(repoUrl, branch, path);
97116
}
98117

99118
// General Git details if didn't match the above
@@ -110,4 +129,15 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
110129
// Errors will stop this being used anyway
111130
return null;
112131
}
132+
133+
/**
134+
* Checks if a string is empty or whitespace
135+
* @param str The string to be checked
136+
* @return Whether the string is empty or whitespace
137+
*/
138+
private boolean isEmptyOrWhitespace(String str) {
139+
return (str == null ||
140+
str.length() == 0 ||
141+
StringUtils.isWhitespace(str));
142+
}
113143
}

src/main/java/org/commonwl/view/workflow/WorkflowRESTController.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ public Page<Workflow> searchWorkflowsJson(Model model,
8888
/**
8989
* Create a new workflow from the given URL
9090
* @param url The URL of the workflow
91+
* @param branch The branch where the workflow can be found
92+
* @param path The path within the repository to the workflow file
9193
* @return Appropriate response code and optional JSON string with message
9294
*/
9395
@PostMapping(value = "/workflows", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
94-
public ResponseEntity<?> newWorkflowFromGithubURLJson(@RequestParam(value="url") String url,
95-
HttpServletResponse response) {
96+
public ResponseEntity<?> newWorkflowFromGitURLJson(@RequestParam(value="url") String url,
97+
@RequestParam(value="branch", required=false) String branch,
98+
@RequestParam(value="path", required=false) String path,
99+
HttpServletResponse response) {
96100

97-
// Run validator which checks the github URL is valid
98-
WorkflowForm workflowForm = new WorkflowForm(url);
101+
// Run validator which checks the URL is valid
102+
WorkflowForm workflowForm = new WorkflowForm(url, branch, path);
99103
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(workflowForm, "errors");
100104
GitDetails gitInfo = workflowFormValidator.validateAndParse(workflowForm, errors);
101105

0 commit comments

Comments
 (0)