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,19 +1212,14 @@ 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();
}
}
private void writeAccessionsGeo(final AccessionFilter filter, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
......@@ -1305,8 +1300,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private class Writer {
int i = 0;
private void processGeo(final CSVWriter csv, final AccessionGeo geo) {
try {
private void processGeo(final CSVWriter csv, final AccessionGeo geo) throws IOException {
final String[] row = new String[8];
// genesysId
row[0] = toStringValue(geo.getAccession().getId());
......@@ -1326,18 +1320,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
row[7] = toStringValue(geo.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
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());
......@@ -1353,9 +1343,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
row[5] = toStringValue(alias.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
if (i++ % 5000 == 0) {
LOG.info("Writing alias DWCA {}", i);
......@@ -1363,8 +1350,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
}
private void processCollect(final CSVWriter csv, final AccessionCollect collect) {
try {
private void processCollect(final CSVWriter csv, final AccessionCollect collect) throws IOException {
final String[] row = new String[7];
// genesysId
row[0] = toStringValue(collect.getAccession().getId());
......@@ -1382,17 +1368,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
row[6] = toStringValue(collect.getVersion());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
if (i++ % 5000 == 0) {
LOG.info("Writing collecting DWCA {}", i);
}
}
private void processCore(final CSVWriter csv, final Accession accession) {
try {
private void processCore(final CSVWriter csv, final Accession accession) throws IOException {
final String[] row = new String[24];
// genesysId
row[0] = toStringValue(accession.getId());
......@@ -1448,9 +1430,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
row[23] = toDateValue(accession.getLastModifiedDate());
csv.writeNext(row);
csv.flush();
} catch (IOException e) {
LOG.warn("Error: {}", e.getMessage());
}
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