diff --git a/src/main/java/org/mskcc/cellranger/controller/CellRangerController.java b/src/main/java/org/mskcc/cellranger/controller/CellRangerController.java index a1def93..0e4a478 100644 --- a/src/main/java/org/mskcc/cellranger/controller/CellRangerController.java +++ b/src/main/java/org/mskcc/cellranger/controller/CellRangerController.java @@ -190,17 +190,25 @@ public Map getCellRangerSample(@RequestParam("project") String p public Map getCellRangerFile( @RequestParam("project") String project, @RequestParam("run") String run, @RequestParam("sample") String sample, - @RequestParam("type") String type) { + @RequestParam("type") String type, + @RequestParam(required = false, defaultValue = "true") Boolean download) { log.info(String.format("Retrieving cell ranger output file for run: %s, project: %s, sample: %s, type: %s", run, project, sample, type)); final String webSummaryPath = getCellRangerOutputPath(run, sample, project, type, WEB_SUMMARY_PATH); - final String data = readFile(webSummaryPath); - String status = String.format("File not found: %s", webSummaryPath); - if(data != null){ - status = String.format("Retrieved data from %s", webSummaryPath); + + File f = new File(webSummaryPath); + if(!f.exists() || f.isDirectory()) { + String errMessage = String.format("File not found: %s (run=%s project=%s sample=%s type=%s)", + webSummaryPath, run, project, sample, type); + return createErrorResponse(errMessage, true); } + + String status = String.format("Retrieved data from %s", webSummaryPath); Map resp = createSuccessResponse(status); - resp.put(API_DATA, data); + if(download){ + final String data = readFile(webSummaryPath); + resp.put(API_DATA, data); + } return resp; } diff --git a/src/test/java/org/mskcc/cellranger/controller/CellRangerControllerTest.java b/src/test/java/org/mskcc/cellranger/controller/CellRangerControllerTest.java index 43b9dc8..20714aa 100644 --- a/src/test/java/org/mskcc/cellranger/controller/CellRangerControllerTest.java +++ b/src/test/java/org/mskcc/cellranger/controller/CellRangerControllerTest.java @@ -189,7 +189,7 @@ public void getCellRangerFile_success() { log.error(String.format("Failed to test %s. Error: %s", type, e.getMessage())); } - Map response = cellRangerController.getCellRangerFile(PROJECT, RUN, SAMPLE, type.toString()); + Map response = cellRangerController.getCellRangerFile(PROJECT, RUN, SAMPLE, type.toString(), true); assertNotNull(response.get("data")); } }