Commit 7d9b2596 authored by Matija Obreza's avatar Matija Obreza

Merge branch '448-downloadservice-with-es' into 'master'

Resolve "DownloadService with ES"

Closes #448

See merge request genesys-pgr/genesys-server!399
parents 3412bfc2 9cca900c
......@@ -45,6 +45,8 @@ public interface DownloadService {
void writeXlsxMCPD(JPQLQuery<Long> queryAccessionId, OutputStream outputStream, String filters, String dataSource) throws IOException;
void writeXlsxMCPD(IDownloadAction action, OutputStream outputStream, String filters, String dataSource) throws IOException;
void writeXlsxPDCI(AccessionFilter accessionFilter, OutputStream outputStream) throws IOException;
void writeXlsxDescriptor(List<Descriptor> descriptors, OutputStream outputStream) throws IOException;
......@@ -59,6 +61,8 @@ public interface DownloadService {
void writeXlsxGenesys1Descriptors(Crop crop, OutputStream outputStream) throws IOException;
public static interface IDownloadAction {
void apply(AccessionService.IAccessionBatchAction action) throws Exception;
}
}
......@@ -198,13 +198,20 @@ public class DownloadServiceImpl implements DownloadService {
@Override
public void writeXlsxMCPD(AccessionFilter filter, OutputStream outputStream) throws IOException {
final String dataSource = baseUrl + "/explore?filter=" + filter.toString();
if (filter.isFulltextQuery()) {
throw new IOException("Cannot download MCPD when using full-text queries.");
writeXlsxMCPD((action) -> {
try {
accessionProcessor.process(filter, action, null);
LOG.warn("Done streaming MCPD rows");
} catch (Exception e) {
LOG.warn("Error generating: {}", e.getMessage());
}
}, outputStream, filter.toString(), dataSource);
} else {
writeXlsxMCPD(filter.buildPredicate(), outputStream, filter.toString(), dataSource);
}
final String dataSource = baseUrl + "/explore?filter=" + filter.toString();
writeXlsxMCPD(filter.buildPredicate(), outputStream, filter.toString(), dataSource);
}
@Override
......@@ -222,9 +229,21 @@ public class DownloadServiceImpl implements DownloadService {
writeXlsxMCPD(query, outputStream, filters, dataSource);
}
@Override
public void writeXlsxMCPD(JPQLQuery<Long> queryAccessionId, OutputStream outputStream, String filters, String dataSource) throws IOException {
writeXlsxMCPD((action) -> {
try {
accessionProcessor.process(queryAccessionId, action, null);
LOG.warn("Done streaming MCPD rows");
} catch (Exception e) {
LOG.warn("Error generating: {}", e.getMessage());
}
}, outputStream, filters, dataSource);
}
@Override
public void writeXlsxMCPD(IDownloadAction action, OutputStream outputStream, String filters, String dataSource) throws IOException {
XSSFWorkbook template = new XSSFWorkbook(getClass().getResourceAsStream("/template/download/MCPD.xlsx"));
POIXMLProperties props = template.getProperties();
......@@ -269,17 +288,13 @@ public class DownloadServiceImpl implements DownloadService {
// Write accession information
final Writer writer = new Writer();
try {
accessionProcessor.process(queryAccessionId, (accessions) -> {
for (Accession accession: accessions) {
writer.processMCPD(sheet, wbStyles, accession);
}
return accessions;
}, null);
LOG.warn("Done streaming MCPD rows");
} catch (Exception e) {
LOG.warn("Error generating: {}", e.getMessage());
}
action.apply((accessions) -> {
for (Accession accession : accessions) {
writer.processMCPD(sheet, wbStyles, accession);
}
return accessions;
});
});
// ((SXSSFSheet) sheet).flushRows();
......@@ -774,10 +789,6 @@ public class DownloadServiceImpl implements DownloadService {
@Override
public void writeXlsxPDCI(final AccessionFilter filter, final OutputStream outputStream) throws IOException {
if (filter.isFulltextQuery()) {
throw new IOException("Cannot download MCPD when using full-text queries.");
}
XSSFWorkbook template = new XSSFWorkbook(getClass().getResourceAsStream("/template/download/PDCI.xlsx"));
// keep 1000 rows in memory, exceeding rows will be flushed to disk
......
......@@ -1052,10 +1052,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
// TODO FIXME Need proper term URLs
public void writeAccessions(final AccessionFilter filter, final OutputStream outputStream) throws Exception {
if (filter.isFulltextQuery()) {
throw new IOException("Cannot download DWC-A when using full-text queries.");
}
// UTF8 is used for encoding entry names
final ZipOutputStream zos = new ZipOutputStream(outputStream);
zos.setComment("Genesys Accessions filter=" + filter);
......
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