Skip to content

Commit 80462d0

Browse files
committed
Refactor packed workflow ID to be part of retrievedFrom ID
1 parent 30dc589 commit 80462d0

File tree

10 files changed

+46
-28
lines changed

10 files changed

+46
-28
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
189189
// Construct the rest of the workflow model
190190
Workflow workflowModel = new Workflow(label, extractDoc(cwlFile), getInputs(cwlFile),
191191
getOutputs(cwlFile), getSteps(cwlFile), null);
192-
workflowModel.setPackedWorkflowID(packedWorkflowId);
193192

194193
workflowModel.setCwltoolVersion(cwlTool.getVersion());
195194

@@ -223,7 +222,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
223222
File workflowFile) throws CWLValidationException {
224223
GitDetails gitDetails = basicModel.getRetrievedFrom();
225224
String latestCommit = basicModel.getLastCommit();
226-
String packedWorkflowID = basicModel.getPackedWorkflowID();
225+
String packedWorkflowID = gitDetails.getPackedId();
227226

228227
// Get paths to workflow
229228
String url = gitDetails.getUrl(latestCommit).replace("https://", "");
@@ -488,13 +487,19 @@ public WorkflowOverview getWorkflowOverview(File file) throws IOException {
488487
JsonNode cwlFile = yamlStringToJson(readFileToString(file));
489488

490489
// If the CWL file is packed there can be multiple workflows in a file
490+
int packedCount = 0;
491491
if (cwlFile.has(DOC_GRAPH)) {
492492
// Packed CWL, find the first subelement which is a workflow and take it
493493
for (JsonNode jsonNode : cwlFile.get(DOC_GRAPH)) {
494494
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW) {
495495
cwlFile = jsonNode;
496+
packedCount++;
496497
}
497498
}
499+
if (packedCount > 1) {
500+
return new WorkflowOverview("/" + file.getName(), "Packed file",
501+
"contains " + packedCount + " workflows");
502+
}
498503
}
499504

500505
// Can only make an overview if this is a workflow

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow, File workflo
7979
newWorkflow.setRetrievedFrom(tempWorkflow.getRetrievedFrom());
8080
newWorkflow.setRetrievedOn(new Date());
8181
newWorkflow.setLastCommit(tempWorkflow.getLastCommit());
82-
newWorkflow.setPackedWorkflowID(tempWorkflow.getPackedWorkflowID());
8382
newWorkflow.setCwltoolVersion(cwlToolVersion);
8483

8584
workflowRepository.save(newWorkflow);

src/main/java/org/commonwl/view/git/GitDetails.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class GitDetails implements Serializable {
3434
private String repoUrl;
3535
private String branch;
3636
private String path;
37+
private String packedId;
3738

3839
public GitDetails(String repoUrl, String branch, String path) {
3940
this.repoUrl = repoUrl;
@@ -67,6 +68,14 @@ public void setBranch(String branch) {
6768
this.branch = branch;
6869
}
6970

71+
public String getPackedId() {
72+
return packedId;
73+
}
74+
75+
public void setPackedId(String packedId) {
76+
this.packedId = packedId;
77+
}
78+
7079
public String getPath() {
7180
return path;
7281
}
@@ -139,13 +148,14 @@ public String getUrl() {
139148
* @return The URL
140149
*/
141150
public String getInternalUrl() {
151+
String packedPart = packedId == null ? "" : "%23" + packedId;
142152
String pathPart = path.equals("/") ? "" : "/" + path;
143153
switch (getType()) {
144154
case GITHUB:
145155
case GITLAB:
146-
return "/workflows/" + normaliseUrl(repoUrl).replace(".git", "") + "/blob/" + branch + pathPart;
156+
return "/workflows/" + normaliseUrl(repoUrl).replace(".git", "") + "/blob/" + branch + pathPart + packedPart;
147157
default:
148-
return "/workflows/" + normaliseUrl(repoUrl) + "/" + branch + pathPart;
158+
return "/workflows/" + normaliseUrl(repoUrl) + "/" + branch + pathPart + packedPart;
149159
}
150160
}
151161

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
171171

172172
// Get URL to run cwltool
173173
String rawUrl = wfDetails.getRawUrl();
174-
String packedWorkflowID = workflow.getPackedWorkflowID();
174+
String packedWorkflowID = wfDetails.getPackedId();
175175
if (packedWorkflowID != null) {
176176
if (packedWorkflowID.charAt(0) != '#') {
177177
rawUrl += "#";

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ public class Workflow {
5454
// Used for caching purposes
5555
private String lastCommit;
5656

57-
// If schema salad packed, the workflow ID
58-
private String packedWorkflowID;
59-
6057
// A String which represents the path to a RO bundle
6158
// Path types cannot be stored using Spring Data, unfortunately
6259
private String roBundlePath;
@@ -164,14 +161,6 @@ public void setLastCommit(String lastCommit) {
164161
this.lastCommit = lastCommit;
165162
}
166163

167-
public String getPackedWorkflowID() {
168-
return packedWorkflowID;
169-
}
170-
171-
public void setPackedWorkflowID(String packedWorkflowID) {
172-
this.packedWorkflowID = packedWorkflowID;
173-
}
174-
175164
public String getDockerLink() {
176165
return dockerLink;
177166
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,13 @@ public static GitDetails getGitDetails(String domain, String owner, String repoN
413413
default:
414414
throw new WorkflowNotFoundException();
415415
}
416-
return new GitDetails(repoUrl, branch, path);
416+
String[] pathSplit = path.split("#");
417+
GitDetails details = new GitDetails(repoUrl, branch, path);
418+
if (pathSplit.length > 1) {
419+
details.setPath(pathSplit[pathSplit.length - 2]);
420+
details.setPackedId(pathSplit[pathSplit.length - 1]);
421+
}
422+
return details;
417423
}
418424

419425
/**

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
7070
if (!e.hasErrors()) {
7171

7272
// Override if specific branch or path is given in the form
73+
String repoUrl = null;
7374
String branch = null;
7475
String path = null;
7576
if (!isEmptyOrWhitespace(form.getBranch())) {
@@ -82,37 +83,44 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
8283
// Github URL
8384
Matcher m = githubCwlPattern.matcher(form.getUrl());
8485
if (m.find()) {
85-
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
86+
repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
8687
if (branch == null) branch = m.group(3);
8788
if (path == null) path = m.group(4);
88-
return new GitDetails(repoUrl, branch, path);
8989
}
9090

9191
// Gitlab URL
9292
m = gitlabCwlPattern.matcher(form.getUrl());
9393
if (m.find()) {
94-
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
94+
repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
9595
if (branch == null) branch = m.group(3);
9696
if (path == null) path = m.group(4);
97-
return new GitDetails(repoUrl, branch, path);
9897
}
9998

10099
// Github Dir URL
101100
m = githubDirPattern.matcher(form.getUrl());
102101
if (m.find()) {
103-
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
102+
repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
104103
if (branch == null) branch = m.group(3);
105104
if (path == null) path = m.group(4);
106-
return new GitDetails(repoUrl, branch, path);
107105
}
108106

109107
// Gitlab Dir URL
110108
m = gitlabDirPattern.matcher(form.getUrl());
111109
if (m.find()) {
112-
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
110+
repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
113111
if (branch == null) branch = m.group(3);
114112
if (path == null) path = m.group(4);
115-
return new GitDetails(repoUrl, branch, path);
113+
}
114+
115+
// Split off packed ID if present
116+
if (repoUrl != null) {
117+
String[] pathSplit = path.split("#");
118+
GitDetails details = new GitDetails(repoUrl, branch, path);
119+
if (pathSplit.length > 1) {
120+
details.setPath(pathSplit[pathSplit.length - 2]);
121+
details.setPackedId(pathSplit[pathSplit.length - 1]);
122+
}
123+
return details;
116124
}
117125

118126
// General Git details if didn't match the above

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
328328

329329
// Set origin details
330330
basicModel.setRetrievedOn(new Date());
331+
gitInfo.setPackedId(packedWorkflowId);
331332
basicModel.setRetrievedFrom(gitInfo);
332333
basicModel.setLastCommit(latestCommit);
333334

src/main/resources/templates/workflow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ <h2>Steps</h2>
233233
<td th:text="${step.key}">ID</td>
234234
<td>
235235
<div th:if="${step.value.runType != null}">
236-
<a th:if="${step.value.runType.name() == 'WORKFLOW'}" th:href="${step.value.run}" th:text="${step.value.run}" class="subworkflow">workflow.cwl</a>
236+
<a th:if="${step.value.runType.name() == 'WORKFLOW'}" th:href="@{${step.value.run}}" th:text="${step.value.run}" class="subworkflow">workflow.cwl</a>
237237
<span th:unless="${step.value.runType.name() == 'WORKFLOW'}" th:text="${step.value.run}">cmdlinetool.cwl</span>
238238
(<span th:text="${step.value.runType}">Workflow</span>)
239239
</div>

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void parseWorkflowWithCwltool() throws Exception {
128128
"549c973ccc01781595ce562dea4cedc6c9540fe0", "workflows/make-to-cwl/dna.cwl");
129129
Workflow basicModel = new Workflow(null, null, null, null, null, null);
130130
basicModel.setRetrievedFrom(gitInfo);
131-
basicModel.setPackedWorkflowID("main");
131+
gitInfo.setPackedId("main");
132132
basicModel.setLastCommit("549c973ccc01781595ce562dea4cedc6c9540fe0");
133133

134134
// Parse the workflow

0 commit comments

Comments
 (0)