Commit 8be56d09 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Download PDCI as Excel for matching accessions

- JSP: download from /explore
- APIv1: /acn/download?pdci
parent 41f2b41e
......@@ -458,7 +458,34 @@ public class AccessionController {
downloadService.writeXlsxMCPD(filterInfo.filter, outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
LOG.warn("Download was aborted: {}", e.getMessage());
}
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "pdci" })
public void downloadPdci(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
final long countFiltered = accessionService.countAccessions(filterInfo.filter);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
// Write PDCI to the stream.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-PDCI-%1s.xlsx\"", filterInfo.filterCode));
// response.flushBuffer();
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxPDCI(filterInfo.filter, outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted: {}", e.getMessage());
}
}
......
......@@ -717,6 +717,35 @@ public class ExplorerController extends BaseController implements InitializingBe
}
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/explore/download/pdci", method = RequestMethod.POST)
public void downloadXlsxPDCI(ModelMap model, @RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter,
HttpServletResponse response) throws IOException {
final AppliedFilters appliedFilters = updateFilterWithCrop(null, jsonFilter);
final int countFiltered = genesysService.countAccessions(appliedFilters);
LOG.info("Attempting to download XLSX PDCI for {} accessions", countFiltered);
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
// Write PDCI to the stream.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-PDCI-filtered.xlsx\""));
// response.flushBuffer();
// Write PDCI to the stream.
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxPDCI(AccessionFilter.convert(appliedFilters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
}
}
private AppliedFilters updateFilterWithCrop(String cropName, String jsonFilter) throws IOException {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
......
......@@ -120,6 +120,16 @@
</button>
</form>
</li>
<li>
<form style="display: inline-block" method="post"
action="<c:url value="/download/explore/download/pdci" />">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />"/>
<button class="btn btn-inline " type="submit">
<span><spring:message code="filter.download-pdci"/></span>
</button>
</form>
</li>
</security:authorize>
<li>
<form style="display: inline-block" method="post"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment