Skip to content

Commit b91b744

Browse files
author
Mark Robinson
committed
Add regeneration of RO bundles if missing
1 parent ecc68d2 commit b91b744

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232

33+
import java.io.File;
3334
import java.io.IOException;
3435
import java.net.URI;
3536
import java.net.URISyntaxException;
@@ -188,8 +189,8 @@ private void addFiles(List<RepositoryContents> repoContents, Path path) throws I
188189
* @throws IOException Any errors in saving
189190
*/
190191
public Path saveToFile(Path directory) throws IOException {
191-
// Save the Research Object Bundle
192-
Path bundleLocation = Files.createTempFile(directory, "bundle", ".zip");
192+
String fileName = "bundle-" + java.util.UUID.randomUUID() + ".zip";
193+
Path bundleLocation = Files.createFile(directory.resolve(fileName));
193194
Bundles.closeAndSaveBundle(bundle, bundleLocation);
194195
return bundleLocation;
195196
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.stereotype.Service;
3030

3131
import java.io.File;
32+
import java.io.IOException;
3233
import java.util.Calendar;
3334
import java.util.Date;
3435

@@ -78,9 +79,9 @@ public Workflow newWorkflowFromGithub(GithubDetails githubInfo) {
7879
workflowModel.setRetrievedFrom(githubInfo);
7980
workflowModel.setLastCommit(latestCommit);
8081

81-
// Create a new research object bundle from Github details
82+
// Create a new research object bundle for the workflow
8283
// This is Async so cannot just call constructor, needs intermediate as per Spring framework
83-
ROBundleFactory.workflowROFromGithub(githubService, githubInfo, latestCommit);
84+
generateROBundle(workflowModel);
8485

8586
// Return this model to be displayed
8687
return workflowModel;
@@ -89,12 +90,24 @@ public Workflow newWorkflowFromGithub(GithubDetails githubInfo) {
8990
logger.error("No workflow could be found");
9091
}
9192
} catch (Exception ex) {
92-
logger.error("Error creating workflow: " + ex.getMessage());
93+
logger.error("Error creating workflow", ex);
9394
}
9495

9596
return null;
9697
}
9798

99+
/**
100+
* Generates the RO bundle for a Workflow and adds it to the model
101+
* @param workflow The workflow model to create a Research Object for
102+
*/
103+
public void generateROBundle(Workflow workflow) {
104+
try {
105+
ROBundleFactory.workflowROFromGithub(githubService, workflow.getRetrievedFrom(), workflow.getLastCommit());
106+
} catch (Exception ex) {
107+
logger.error("Error creating RO Bundle", ex);
108+
}
109+
}
110+
98111
/**
99112
* Removes a workflow and its research object bundle
100113
* @param workflow The workflow to be deleted

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,18 @@ public FileSystemResource downloadROBundle(@PathVariable("workflowID") String wo
205205
throw new WorkflowNotFoundException();
206206
}
207207

208-
// Set a sensible default file name for the browser
209-
response.setHeader("Content-Disposition", "attachment; filename=bundle.zip;");
210-
211-
// Serve the file from the local filesystem
208+
// 404 error with retry if the file on disk does not exist
212209
File bundleDownload = new File(workflowModel.getRoBundle());
210+
if (!bundleDownload.exists()) {
211+
// Clear current RO bundle link and create a new one (async)
212+
workflowModel.setRoBundle(null);
213+
workflowRepository.save(workflowModel);
214+
workflowService.generateROBundle(workflowModel);
215+
throw new WorkflowNotFoundException();
216+
}
217+
213218
logger.info("Serving download for workflow " + workflowID + " [" + bundleDownload.toString() + "]");
219+
response.setHeader("Content-Disposition", "attachment; filename=bundle.zip;");
214220
return new FileSystemResource(bundleDownload);
215221
}
216222

0 commit comments

Comments
 (0)