...
 
Commits (4)
......@@ -439,6 +439,11 @@
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
<artifactId>jackcess</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
......
......@@ -16,16 +16,23 @@
package org.genesys2.server.api.v1;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.persistence.ImageGalleryPersistence;
......@@ -37,6 +44,8 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.worker.ExportPassportData;
import org.genesys2.server.service.worker.ScheduledGLISUpdater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -46,11 +55,15 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/**
* @author Maxym Borodenko
*/
......@@ -90,6 +103,15 @@ public class AdminController {
@Autowired
private ScheduledGLISUpdater scheduledGLISUpdater;
@Autowired
private ExportPassportData exportPassportData;
/** The short filter service. */
@Autowired
protected ShortFilterService shortFilterService;
ObjectMapper mapper = new ObjectMapper();
@PostMapping(value = "/ensure-inst-folders")
public Boolean ensureInstituteFolders() throws Exception {
LOG.info("Ensure institute folders");
......@@ -157,8 +179,36 @@ public class AdminController {
scheduledGLISUpdater.notifyGLIS(from);
return true;
}
@RequestMapping(value = "/download-passport-data", method = RequestMethod.POST)
public void downloadPassportData(@RequestParam(name = "filter") String filters, HttpServletResponse response) throws IOException {
AccessionFilter filter = mapper.readValue(filters, AccessionFilter.class);
// get AccessionFilter from filterCode
ShortFilterService.FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(null, filter, AccessionFilter.class);
File temp = File.createTempFile("passport-data", ".mdb");
try {
LOG.warn("Generate passport data for accessions matching filter: {}", filterInfo.filter);
exportPassportData.exportToAccess(filterInfo.filter, temp);
response.setContentType("application/x-msaccess");
response.setContentLength((int) temp.length());
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1s.mdb\"", filterInfo.filterCode));
InputStream inputStream = new BufferedInputStream(new FileInputStream(temp));
FileCopyUtils.copy(inputStream, response.getOutputStream());
response.flushBuffer();
} catch (Throwable e) {
LOG.warn("Download was aborted: {}", e.getMessage());
} finally {
if (! temp.delete()) {
LOG.warn("Can't delete temporary file: {}", temp.getAbsolutePath());
}
}
}
@PostMapping(value = "/acl", params = { "institutes" })
@Transactional
public void aclFixInstitutesAcl() throws Exception {
......
......@@ -16,7 +16,11 @@
package org.genesys2.server.mvc.admin;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
......@@ -29,6 +33,7 @@ import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang.time.StopWatch;
......@@ -36,6 +41,7 @@ import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
......@@ -71,6 +77,7 @@ import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.service.worker.AccessionCounter;
import org.genesys2.server.service.worker.AccessionProcessor;
import org.genesys2.server.service.worker.ExportPassportData;
import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
import org.genesys2.server.service.worker.InstituteUpdater;
import org.genesys2.server.service.worker.SGSVUpdate;
......@@ -87,6 +94,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -188,6 +196,13 @@ public class AdminController {
@Autowired
private ScheduledGLISUpdater scheduledGLISUpdater;
@Autowired
private ExportPassportData exportPassportData;
/** The short filter service. */
@Autowired
protected ShortFilterService shortFilterService;
@RequestMapping("/")
public String root(Model model) {
return "/admin/index";
......@@ -611,6 +626,35 @@ public class AdminController {
return "redirect:/admin/";
}
@RequestMapping(value = "/download-passport-data", method = RequestMethod.POST)
public void downloadPassportData(@RequestParam(name = "filter") String filters, HttpServletResponse response) throws IOException {
AccessionFilter filter = mapper.readValue(filters, AccessionFilter.class);
// get AccessionFilter from filterCode
ShortFilterService.FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(null, filter, AccessionFilter.class);
File temp = File.createTempFile("passport-data", ".mdb");
try {
LOG.warn("Generate passport data for accessions matching filter: {}", filterInfo.filter);
exportPassportData.exportToAccess(filterInfo.filter, temp);
response.setContentType("application/x-msaccess");
response.setContentLength((int) temp.length());
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1s.mdb\"", filterInfo.filterCode));
InputStream inputStream = new BufferedInputStream(new FileInputStream(temp));
FileCopyUtils.copy(inputStream, response.getOutputStream());
response.flushBuffer();
} catch (Throwable e) {
LOG.warn("Download was aborted: {}", e.getMessage());
} finally {
if (! temp.delete()) {
LOG.warn("Can't delete temporary file: {}", temp.getAbsolutePath());
}
}
}
@Autowired
private AccessionIdRepository accessionIdRepository;
......
......@@ -99,6 +99,12 @@
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
<form method="post" action="<c:url value="/admin/download-passport-data" />">
<input type="text" name="filter" placeholder="{}" value="{}" />
<input type="submit" class="btn btn-default" value="Export to MS Access"/>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
<h3>Dataset</h3>
<form method="post" action="<c:url value="/admin/relinkDatasetAccessions" />">
......