Commit 62e0194c authored by Matija Obreza's avatar Matija Obreza

Fix: Don't swallow Exceptions when producing DwC-A

parent c8d947bf
......@@ -522,7 +522,7 @@ public class AccessionController {
}
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "dwca" })
public void downloadDwca(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadDwca(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws Exception {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......
......@@ -150,7 +150,7 @@ public class InstituteController {
}
@RequestMapping(value = "/{wiewsCode}/download", method = RequestMethod.POST, params = { "dwca" })
public void downloadDwca(@PathVariable(value = "wiewsCode", required = true) String wiewsCode, HttpServletResponse response) throws IOException {
public void downloadDwca(@PathVariable(value = "wiewsCode", required = true) String wiewsCode, HttpServletResponse response) throws Exception {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new NotFoundElement();
......
......@@ -684,7 +684,7 @@ public class ExplorerController extends BaseController implements InitializingBe
try {
genesysService.writeAccessions(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
} catch (Exception e) {
LOG.warn("Download was aborted");
}
}
......
......@@ -244,7 +244,7 @@ public class ProjectController extends BaseController {
@RequestMapping(value = "/{code}/download", method = RequestMethod.POST, params = { "dwca" })
public void downloadDwca(ModelMap model, @PathVariable(value = "code") String code, HttpServletResponse response) throws IOException {
public void downloadDwca(ModelMap model, @PathVariable(value = "code") String code, HttpServletResponse response) throws Exception {
final Project project = projectService.getProjectByCode(code);
if (project == null || project.getAccessionLists().size() == 0) {
throw new NotFoundElement();
......
......@@ -186,10 +186,10 @@ public class SelectionController extends BaseController {
* @param cropName
* @param jsonFilter
* @param response
* @throws IOException
* @throws Exception
*/
@RequestMapping(value = "/dwca", method = RequestMethod.POST)
public void dwca(ModelMap model, HttpServletResponse response) throws IOException {
public void dwca(ModelMap model, HttpServletResponse response) throws Exception {
// Create JSON filter
AccessionFilter filter=new AccessionFilter();
filter.id = new HashSet<>();
......
......@@ -447,7 +447,7 @@ public class WiewsController extends BaseController {
}
@RequestMapping(value = "/{wiewsCode}/download", method = RequestMethod.POST, params = { "dwca" })
public void downloadDwca(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, HttpServletResponse response) throws IOException {
public void downloadDwca(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, HttpServletResponse response) throws Exception {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new NotFoundElement();
......
......@@ -16,7 +16,6 @@
package org.genesys2.server.service;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.List;
......@@ -153,7 +152,7 @@ public interface GenesysService {
long countDatasets(FaoInstitute faoInstitute);
void writeAccessions(AccessionFilter filter, OutputStream outputStream) throws IOException;
void writeAccessions(AccessionFilter filter, OutputStream outputStream) throws Exception;
List<AccessionGeo> listAccessionsGeo(Set<Long> copy);
......
......@@ -1050,7 +1050,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
// TODO FIXME Need proper term URLs
public void writeAccessions(final AccessionFilter filter, final OutputStream outputStream) throws IOException {
public void writeAccessions(final AccessionFilter filter, final OutputStream outputStream) throws Exception {
// UTF8 is used for encoding entry names
final ZipOutputStream zos = new ZipOutputStream(outputStream);
zos.setComment("Genesys Accessions filter=" + filter);
......@@ -1203,7 +1203,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
bw.flush();
}
private void writeAccessionsCore(final AccessionFilter filter, ZipOutputStream zos) throws IOException {
private void writeAccessionsCore(final AccessionFilter filter, ZipOutputStream zos) throws Exception {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "doi", "genus", "species", "spAuthor", "subtaxa", "subtAuthor", "fullTaxa", "origCty", "acqSrc", "acqDate", "mlsStat", "available", "historic",
......@@ -1212,18 +1212,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
final Writer writer = new Writer();
// Write accession information
try {
accessionProcessor.process(filter, (accessions) -> {
for (Accession accession: accessions) {
writer.processCore(csv, accession);
}
return accessions;
});
} catch (Exception e) {
LOG.error(e.getMessage(), e);
} finally {
csv.flush();
}
accessionProcessor.process(filter, (accessions) -> {
for (Accession accession: accessions) {
writer.processCore(csv, accession);
}
return accessions;
});
csv.flush();
}
private void writeAccessionsGeo(final AccessionFilter filter, ZipOutputStream zos) throws IOException {
......@@ -1305,57 +1300,49 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private class Writer {
int i = 0;
private void processGeo(final CSVWriter csv, final AccessionGeo geo) {
try {
final String[] row = new String[8];
// genesysId
row[0] = toStringValue(geo.getAccession().getId());
// latitude
row[1] = toStringValue(geo.getLatitude());
// longitude
row[2] = toStringValue(geo.getLongitude());
// elevation
row[3] = toStringValue(geo.getElevation());
// datum
row[4] = geo.getDatum();
// uncertainty
row[5] = toStringValue(geo.getUncertainty());
// method
row[6] = geo.getMethod();
// version
row[7] = toStringValue(geo.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
private void processGeo(final CSVWriter csv, final AccessionGeo geo) throws IOException {
final String[] row = new String[8];
// genesysId
row[0] = toStringValue(geo.getAccession().getId());
// latitude
row[1] = toStringValue(geo.getLatitude());
// longitude
row[2] = toStringValue(geo.getLongitude());
// elevation
row[3] = toStringValue(geo.getElevation());
// datum
row[4] = geo.getDatum();
// uncertainty
row[5] = toStringValue(geo.getUncertainty());
// method
row[6] = geo.getMethod();
// version
row[7] = toStringValue(geo.getVersion());
csv.writeNext(row);
csv.flush();
if (i++ % 5000 == 0) {
LOG.info("Writing geo DWCA {}", i);
}
}
private void processAliases(final CSVWriter csv, final List<AccessionAlias> aliases) {
private void processAliases(final CSVWriter csv, final List<AccessionAlias> aliases) throws IOException {
for (AccessionAlias alias : aliases) {
try {
final String[] row = new String[6];
// genesysId
row[0] = toStringValue(alias.getAccession().getId());
// instCode
row[1] = alias.getUsedBy();
// name
row[2] = alias.getName();
// aliasType
row[3] = alias.getAliasType().name();
// lang
row[4] = alias.getLang();
// version
row[5] = toStringValue(alias.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
final String[] row = new String[6];
// genesysId
row[0] = toStringValue(alias.getAccession().getId());
// instCode
row[1] = alias.getUsedBy();
// name
row[2] = alias.getName();
// aliasType
row[3] = alias.getAliasType().name();
// lang
row[4] = alias.getLang();
// version
row[5] = toStringValue(alias.getVersion());
csv.writeNext(row);
csv.flush();
if (i++ % 5000 == 0) {
LOG.info("Writing alias DWCA {}", i);
......@@ -1363,95 +1350,87 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
}
private void processCollect(final CSVWriter csv, final AccessionCollect collect) {
try {
final String[] row = new String[7];
// genesysId
row[0] = toStringValue(collect.getAccession().getId());
// collMissId
row[1] = collect.getCollMissId();
// collNumb
row[2] = collect.getCollNumb();
// collDate
row[3] = collect.getCollDate();
// collSrc
row[4] = toStringValue(collect.getCollSrc());
// collSite
row[5] = collect.getCollSite();
// version
row[6] = toStringValue(collect.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
private void processCollect(final CSVWriter csv, final AccessionCollect collect) throws IOException {
final String[] row = new String[7];
// genesysId
row[0] = toStringValue(collect.getAccession().getId());
// collMissId
row[1] = collect.getCollMissId();
// collNumb
row[2] = collect.getCollNumb();
// collDate
row[3] = collect.getCollDate();
// collSrc
row[4] = toStringValue(collect.getCollSrc());
// collSite
row[5] = collect.getCollSite();
// version
row[6] = toStringValue(collect.getVersion());
csv.writeNext(row);
csv.flush();
if (i++ % 5000 == 0) {
LOG.info("Writing collecting DWCA {}", i);
}
}
private void processCore(final CSVWriter csv, final Accession accession) {
try {
final String[] row = new String[24];
// genesysId
row[0] = toStringValue(accession.getId());
// uuid
row[1] = toStringValue(accession.getUuid());
// instCode
row[2] = accession.getInstituteCode();
// acceNumb
row[3] = accession.getAccessionNumber();
// doi
row[4] = accession.getDoi();
// genus
row[5] = accession.getGenus();
if (accession.getTaxonomy() != null) {
// species
row[6] = toStringValue(accession.getTaxonomy().getSpecies());
// spAuthor
row[7] = toStringValue(accession.getTaxonomy().getSpAuthor());
// subtaxa
row[8] = toStringValue(accession.getTaxonomy().getSubtaxa());
// subtAuthor
row[9] = toStringValue(accession.getTaxonomy().getSubtAuthor());
// fullTaxa
row[10] = toStringValue(accession.getTaxonomy().getTaxonName());
}
// origCty
row[11] = accession.getOrigCty();
// acqSrc
row[12] = accession.getAcquisitionSource();
// acqDate
row[13] = accession.getAcquisitionDate();
// mlsStat
row[14] = toStringValue(accession.getMlsStatus());
// available
row[15] = toStringValue(accession.getAvailable());
// historic
row[16] = toStringValue(accession.getHistoric());
// storage
row[17] = accession.getStorageStr();
// sampStat
row[18] = toStringValue(accession.getSampStat());
// duplSite
row[19] = accession.getDuplSiteStr();
// createdBy
row[20] = toStringValue(accession.getCreatedBy());
// createdDate
row[21] = toDateValue(accession.getCreatedDate());
// lastModifiedBy
row[22] = toStringValue(accession.getLastModifiedBy());
// lastModifiedDate
row[23] = toDateValue(accession.getLastModifiedDate());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
private void processCore(final CSVWriter csv, final Accession accession) throws IOException {
final String[] row = new String[24];
// genesysId
row[0] = toStringValue(accession.getId());
// uuid
row[1] = toStringValue(accession.getUuid());
// instCode
row[2] = accession.getInstituteCode();
// acceNumb
row[3] = accession.getAccessionNumber();
// doi
row[4] = accession.getDoi();
// genus
row[5] = accession.getGenus();
if (accession.getTaxonomy() != null) {
// species
row[6] = toStringValue(accession.getTaxonomy().getSpecies());
// spAuthor
row[7] = toStringValue(accession.getTaxonomy().getSpAuthor());
// subtaxa
row[8] = toStringValue(accession.getTaxonomy().getSubtaxa());
// subtAuthor
row[9] = toStringValue(accession.getTaxonomy().getSubtAuthor());
// fullTaxa
row[10] = toStringValue(accession.getTaxonomy().getTaxonName());
}
// origCty
row[11] = accession.getOrigCty();
// acqSrc
row[12] = accession.getAcquisitionSource();
// acqDate
row[13] = accession.getAcquisitionDate();
// mlsStat
row[14] = toStringValue(accession.getMlsStatus());
// available
row[15] = toStringValue(accession.getAvailable());
// historic
row[16] = toStringValue(accession.getHistoric());
// storage
row[17] = accession.getStorageStr();
// sampStat
row[18] = toStringValue(accession.getSampStat());
// duplSite
row[19] = accession.getDuplSiteStr();
// createdBy
row[20] = toStringValue(accession.getCreatedBy());
// createdDate
row[21] = toDateValue(accession.getCreatedDate());
// lastModifiedBy
row[22] = toStringValue(accession.getLastModifiedBy());
// lastModifiedDate
row[23] = toDateValue(accession.getLastModifiedDate());
csv.writeNext(row);
csv.flush();
if (i++ % 5000 == 0) {
LOG.info("Writing core DWCA {}", i);
}
......
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