Commit 31b108a4 authored by Matija Obreza's avatar Matija Obreza
Browse files

Download MCPD for instititute

parent f63920a6
......@@ -226,6 +226,7 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
@Override
public void listAccessions(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.innerJoin("acce", "acce", "acce.id=a.id");
directQuery.outerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
......@@ -238,7 +239,7 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, a.uuid, a.instCode, a.acceNumb, t.genus, t.species, t.taxonName, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.historic, a.storage, a.sampStat, a.duplSite, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate"));
.getQuery("a.id, a.uuid, a.instCode, a.acceNumb, t.genus, t.species, t.taxonName, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.historic, a.storage, a.sampStat, a.duplSite, acce.createdBy, acce.createdDate, acce.lastModifiedBy, acce.lastModifiedDate"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
......
......@@ -320,8 +320,8 @@ public class ExplorerController extends BaseController {
final int countFiltered = genesysService.countAccessions(appliedFilters);
_logger.info("Attempting to download DwCA for " + countFiltered + " accessions");
if (countFiltered > 100000) {
throw new RuntimeException("Refusing to export more than 100,000 entries");
if (countFiltered > DOWNLOAD_LIMIT) {
throw new RuntimeException("Refusing to export more than " + DOWNLOAD_LIMIT + " entries");
}
response.setContentType("application/zip");
......
......@@ -16,6 +16,7 @@
package org.genesys2.server.servlet.controller;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
......@@ -30,6 +31,7 @@ import javax.servlet.http.HttpServletResponse;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
......@@ -46,6 +48,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -61,7 +64,7 @@ public class WiewsController extends BaseController {
@Autowired
private InstituteService instituteService;
@Autowired
private OrganizationService organizationService;
......@@ -77,6 +80,9 @@ public class WiewsController extends BaseController {
@Autowired
private GeoService geoService;
@Autowired
private DownloadService downloadService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("pagedData", instituteService.listPGRInstitutes(new PageRequest(page - 1, 50, new Sort("code"))));
......@@ -167,10 +173,9 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String blurp,
@RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto,
@RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs,
@RequestParam (value = "allowMaterialRequests",required = false,defaultValue = "false") boolean allowMaterialRequests,
@RequestParam("codeSVGS")String codeSVGS) {
@RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto, @RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs,
@RequestParam(value = "allowMaterialRequests", required = false, defaultValue = "false") boolean allowMaterialRequests,
@RequestParam("codeSVGS") String codeSVGS) {
_logger.debug("Updating institite " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -184,7 +189,7 @@ public class WiewsController extends BaseController {
instituteService.updateSettings(faoInstitute, settings);
instituteService.setUniqueAcceNumbs(faoInstitute, uniqueAcceNumbs);
instituteService.setAllowMaterialRequests(faoInstitute, allowMaterialRequests);
instituteService.setCodeSGSV(faoInstitute,codeSVGS);
instituteService.setCodeSGSV(faoInstitute, codeSVGS);
return "redirect:/wiews/" + wiewsCode;
}
......@@ -202,7 +207,6 @@ public class WiewsController extends BaseController {
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/overview")
public String overview(HttpServletRequest request, @PathVariable(value = "wiewsCode") String wiewsCode) throws UnsupportedEncodingException {
......@@ -211,9 +215,10 @@ public class WiewsController extends BaseController {
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
AppliedFilters appliedFilters=new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
return "forward:/explore/overview?filter=" + URLEncoder.encode(appliedFilters.toString(), "UTF8");
}
......@@ -262,8 +267,8 @@ public class WiewsController extends BaseController {
return "redirect:/explore";
}
@RequestMapping(value = "/{wiewsCode}/dwca", method = RequestMethod.POST)
public void viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, HttpServletResponse response) throws IOException {
@RequestMapping(value = "/{wiewsCode}/download", method = RequestMethod.POST, params = { "dwca" })
public void downloadDwca(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, HttpServletResponse response) throws IOException {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
......@@ -271,7 +276,7 @@ public class WiewsController extends BaseController {
_logger.warn("Searching accessions of: " + faoInstitute);
// Create JSON filter
final AppliedFilters appliedFilters=new AppliedFilters();
final AppliedFilters appliedFilters = new AppliedFilters();
final AppliedFilter arr = new AppliedFilter().setFilterName(FilterConstants.INSTCODE);
arr.addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode()));
appliedFilters.add(arr);
......@@ -284,4 +289,33 @@ public class WiewsController extends BaseController {
genesysService.writeAccessions(appliedFilters, outputStream);
response.flushBuffer();
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{wiewsCode}/download", method = RequestMethod.POST, params = { "mcpd" })
public void downloadMcpd(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, HttpServletResponse response) throws IOException {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
_logger.warn("Searching accessions of: " + faoInstitute);
// Create JSON filter
final AppliedFilters appliedFilters = new AppliedFilters();
final AppliedFilter arr = new AppliedFilter().setFilterName(FilterConstants.INSTCODE);
arr.addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode()));
appliedFilters.add(arr);
// Write MCPD to the stream.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1$s.xlsx\"", faoInstitute.getCode()));
response.flushBuffer();
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxMCPD(appliedFilters, outputStream);
response.flushBuffer();
} catch (EOFException e) {
_logger.warn("Download was aborted", e);
}
}
}
......@@ -30,13 +30,12 @@
</form>
</div>
<div class="col-sm-12 col-md-6 text-right" style="padding-top: 12px">
<c:if test="${pagedData.totalElements le 100000}">
<c:if test="${pagedData.totalElements le 200000}">
<form style="display: inline-block" method="post" action="<c:url value="/download/explore/dwca" />">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />" />
<button class="btn btn-default" type="submit"><spring:message code="filter.download-dwca" /></button>
</form>
</c:if>
<security:authorize access="isAuthenticated()">
<form style="display: inline-block" method="post" action="<c:url value="/download/explore/download/mcpd" />">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
......@@ -44,6 +43,7 @@
<button class="btn btn-default" type="submit"><spring:message code="filter.download-mcpd" /></button>
</form>
</security:authorize>
</c:if>
<a class="btn btn-default" href="<c:url value="/explore/overview"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span class="glyphicon glyphicon-eye-open"></span><span><spring:message code="data-overview.short" /></span></a>
<a class="btn btn-default" href="<c:url value="/explore/map"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span class="glyphicon glyphicon-globe"></span><span><spring:message code="maps.view-map" /></span></a>
</div>
......
......@@ -173,11 +173,14 @@
<c:if test="${countByInstitute gt 0}">
<form class="form-horizontal" method="post" action="/wiews/${faoInstitute.code}/dwca">
<form class="form-horizontal" method="post" action="/download/wiews/${faoInstitute.code}/download">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="row" style="margin-top: 2em;">
<div class="col-sm-4">
<button class="btn btn-primary" type="submit"><spring:message code="metadata.download-dwca" /></button>
<security:authorize access="isAuthenticated()">
<button name="mcpd" class="btn btn-primary" type="submit"><spring:message code="filter.download-mcpd" /></button>
</security:authorize>
<button name="dwca" class="btn btn-default" type="submit"><spring:message code="metadata.download-dwca" /></button>
</div>
</div>
</form>
......
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