Skip to content

Commit 52572cf

Browse files
author
Mark Robinson
committed
Generate RO bundle for containing path when requesting single file
1 parent f46a67a commit 52572cf

File tree

5 files changed

+10
-65
lines changed

5 files changed

+10
-65
lines changed

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -216,67 +216,6 @@ private void fillStepRunTypes(Workflow workflow, Map<String, JsonNode> packedFil
216216
}
217217
}
218218

219-
/**
220-
* Find the main workflow object in the group of files being considered
221-
* by finding the minimal inDegree in a graph of run: parameters within steps
222-
* @return The file name/key of the workflow
223-
224-
private String findMainWorkflow() {
225-
// Store the in degree of each workflow
226-
Map<String, Integer> inDegrees = new HashMap<String, Integer>();
227-
for (Map.Entry<String, JsonNode> doc : cwlDocs.entrySet()) {
228-
if (doc.getValue().get(CLASS).asText().equals(WORKFLOW)) {
229-
inDegrees.put(doc.getKey(), 0);
230-
}
231-
}
232-
233-
// Loop through documents and calculate in degrees
234-
for (Map.Entry<String, JsonNode> doc : cwlDocs.entrySet()) {
235-
JsonNode content = doc.getValue();
236-
if (inDegrees.containsKey(doc.getKey())) {
237-
// Parse workflow steps and see whether other workflows are run
238-
JsonNode steps = content.get(STEPS);
239-
if (steps.getClass() == ArrayNode.class) {
240-
// Explicit ID and other fields within each input list
241-
for (JsonNode step : steps) {
242-
String run = FilenameUtils.getName(extractRun(step));
243-
if (run != null && inDegrees.containsKey(run)) {
244-
inDegrees.put(run, inDegrees.get(run) + 1);
245-
}
246-
}
247-
} else if (steps.getClass() == ObjectNode.class) {
248-
// ID is the key of each object
249-
Iterator<Map.Entry<String, JsonNode>> iterator = steps.fields();
250-
while (iterator.hasNext()) {
251-
Map.Entry<String, JsonNode> stepNode = iterator.next();
252-
JsonNode stepJson = stepNode.getValue();
253-
String run = FilenameUtils.getName(extractRun(stepJson));
254-
if (run != null && inDegrees.containsKey(run)) {
255-
inDegrees.put(run, inDegrees.get(run) + 1);
256-
}
257-
}
258-
}
259-
}
260-
}
261-
262-
// Find a workflow with minimum inDegree and return
263-
int minVal = Integer.MAX_VALUE;
264-
String minKey = null;
265-
for (Map.Entry<String, Integer> inDegree : inDegrees.entrySet()) {
266-
if (inDegree.getValue() < minVal) {
267-
minKey = inDegree.getKey();
268-
minVal = inDegree.getValue();
269-
}
270-
271-
// Early escape if minVal is already minimal
272-
if (minVal == 0) {
273-
return minKey;
274-
}
275-
}
276-
277-
return minKey;
278-
}
279-
280219
/**
281220
* Get the steps for a particular document
282221
* @param cwlDoc The document to get steps for

src/main/java/org/commonwl/viewer/researchobject/ROBundleFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.viewer.researchobject;
2121

22+
import org.apache.commons.io.FilenameUtils;
2223
import org.commonwl.viewer.github.GitHubService;
2324
import org.commonwl.viewer.github.GithubDetails;
2425
import org.commonwl.viewer.workflow.Workflow;
@@ -77,8 +78,12 @@ public void workflowROFromGithub(GitHubService githubService, GithubDetails gith
7778
throws IOException, InterruptedException {
7879
logger.info("Creating Research Object Bundle");
7980

81+
// Get the whole containing folder, not just the workflow itself
82+
GithubDetails roDetails = new GithubDetails(githubInfo.getOwner(), githubInfo.getRepoName(),
83+
githubInfo.getBranch(), FilenameUtils.getPath(githubInfo.getPath()));
84+
8085
// Create a new Research Object Bundle with Github contents
81-
ROBundle bundle = new ROBundle(githubService, githubInfo, commitSha,
86+
ROBundle bundle = new ROBundle(githubService, roDetails, commitSha,
8287
applicationName, applicationURL, singleFileSizeLimit);
8388

8489
// Save the bundle to the storage location in properties

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public ModelAndView getWorkflowByGithubDetails(@Value("${applicationURL}") Strin
153153
workflowFormValidator.validateAndParse(workflowForm, errors);
154154
if (errors.hasErrors()) {
155155
redirectAttrs.addFlashAttribute("errors", errors);
156-
return new ModelAndView("redirect:/");
156+
return new ModelAndView("redirect:/?url=https://github.com/" +
157+
owner + "/" + repoName + "/tree/" + branch + "/" + path);
157158
} else {
158159
workflowModel = workflowService.createWorkflow(githubDetails);
159160
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public GithubDetails validateAndParse(WorkflowForm form, Errors e) {
7575
}
7676
} else {
7777
logger.error("The Github URL " + form.getGithubURL() + " is not valid");
78-
e.rejectValue("githubURL", "githubURL.invalid");
78+
e.rejectValue("githubURL", "githubURL.invalid", "You must enter a valid Github URL to a .cwl file");
7979
}
8080
} else {
8181
logger.error("Github URL is empty");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class WorkflowService {
4545
private final GitHubService githubService;
4646
private final CWLService cwlService;
4747
private final WorkflowRepository workflowRepository;
48-
private final org.commonwl.viewer.researchobject.ROBundleFactory ROBundleFactory;
48+
private final ROBundleFactory ROBundleFactory;
4949
private final GraphVizService graphVizService;
5050
private final int cacheDays;
5151

0 commit comments

Comments
 (0)