Commit 6d406e72 authored by Matija Obreza's avatar Matija Obreza
Browse files

Moved AppliedFilters converter to AppliedFilters

parent 8ad4bee5
...@@ -29,7 +29,6 @@ import org.genesys2.server.service.ElasticsearchService.Term; ...@@ -29,7 +29,6 @@ import org.genesys2.server.service.ElasticsearchService.Term;
import org.genesys2.server.service.ElasticsearchService.TermResult; import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.FilterConstants; import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GeoService; import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter; import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.genesys2.server.service.impl.FilterHandler; import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters; import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
...@@ -89,7 +88,7 @@ public class ChartsController extends BaseController { ...@@ -89,7 +88,7 @@ public class ChartsController extends BaseController {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
// Load all term results // Load all term results
TermResult countryStatistics = elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), Integer.MAX_VALUE, AppliedFiltersConverter.convertTerm( TermResult countryStatistics = elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), Integer.MAX_VALUE, AppliedFiltersConverter.convertTerm(
FilterConstants.INSTITUTE_COUNTRY_ISO2)); FilterConstants.INSTITUTE_COUNTRY_ISO2));
List<Map<String, Object>> resultList = new ArrayList<>(); List<Map<String, Object>> resultList = new ArrayList<>();
......
...@@ -60,7 +60,6 @@ import org.genesys2.server.service.GeoService; ...@@ -60,7 +60,6 @@ import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.MappingService; import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.TraitService; import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.UrlShortenerService; import org.genesys2.server.service.UrlShortenerService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter; import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.genesys2.server.service.impl.FilterHandler; import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter; import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
...@@ -238,7 +237,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -238,7 +237,7 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters tempFilters = new AppliedFilters(storedTransformedFilters); AppliedFilters tempFilters = new AppliedFilters(storedTransformedFilters);
final GenesysFilter finalFilter = filter; final GenesysFilter finalFilter = filter;
tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(finalFilter.getKey())); tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(finalFilter.getKey()));
for (Term term : elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) { for (Term term : elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) {
options.add(Integer.valueOf(term.getTerm())); options.add(Integer.valueOf(term.getTerm()));
counts.add(term.getCount()); counts.add(term.getCount());
} }
...@@ -254,7 +253,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -254,7 +253,7 @@ public class ExplorerController extends BaseController implements InitializingBe
tempFilters = new AppliedFilters(storedTransformedFilters); tempFilters = new AppliedFilters(storedTransformedFilters);
final GenesysFilter finalFilter2 = filter; final GenesysFilter finalFilter2 = filter;
tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(finalFilter2.getKey())); tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(finalFilter2.getKey()));
for (Term term : elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) { for (Term term : elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) {
options.add(Integer.valueOf(term.getTerm())); options.add(Integer.valueOf(term.getTerm()));
counts.add(term.getCount()); counts.add(term.getCount());
} }
...@@ -326,7 +325,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -326,7 +325,7 @@ public class ExplorerController extends BaseController implements InitializingBe
appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
model.addAttribute("appliedFilters", getAppliedFilters(tempFilters)); model.addAttribute("appliedFilters", getAppliedFilters(tempFilters));
model.addAttribute("accessionCount", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 10, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)).getTotal()); model.addAttribute("accessionCount", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 10, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)).getTotal());
overviewInstitutes(model, appliedFilters); overviewInstitutes(model, appliedFilters);
overviewComposition(model, appliedFilters); overviewComposition(model, appliedFilters);
overviewAvailability(model, appliedFilters); overviewAvailability(model, appliedFilters);
...@@ -382,20 +381,20 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -382,20 +381,20 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
Map<String, TermResult> pageData = new HashMap<>(); Map<String, TermResult> pageData = new HashMap<>();
pageData.put("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE))); pageData.put("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)));
pageData.put("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3))); pageData.put("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3)));
pageData.put("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3))); pageData.put("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
pageData.put("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE))); pageData.put("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE)));
pageData.put("statsMLS", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS))); pageData.put("statsMLS", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS)));
pageData.put("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE))); pageData.put("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
pageData.put("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC))); pageData.put("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC)));
pageData.put("statsStorage", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE))); pageData.put("statsStorage", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
pageData.put("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE))); pageData.put("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
pageData.put("statsSGSV", elasticService.termStatistics(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV))); pageData.put("statsSGSV", elasticService.termStatistics(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV)));
pageData.put("statsGenus", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS))); pageData.put("statsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
pageData.put("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES))); pageData.put("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
pageData.put("statsCrops", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS))); pageData.put("statsCrops", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
pageData.put("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT))); pageData.put("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT)));
return pageData; return pageData;
} }
...@@ -419,7 +418,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -419,7 +418,7 @@ public class ExplorerController extends BaseController implements InitializingBe
List<Long> counts = new ArrayList<>(); List<Long> counts = new ArrayList<>();
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
appliedFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(filter.getKey())); appliedFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(filter.getKey()));
for (Term term : elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) { for (Term term : elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) {
options.add(Integer.valueOf(term.getTerm())); options.add(Integer.valueOf(term.getTerm()));
counts.add(term.getCount()); counts.add(term.getCount());
} }
...@@ -463,7 +462,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -463,7 +462,7 @@ public class ExplorerController extends BaseController implements InitializingBe
if (FilterConstants.HISTORIC.equals(filter.getKey())) { if (FilterConstants.HISTORIC.equals(filter.getKey())) {
// Handle this // Handle this
} }
for (Term term : elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) { for (Term term : elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(filter.getKey())).getTerms()) {
counts.put(term.getTerm(), term.getCount()); counts.put(term.getTerm(), term.getCount());
} }
booleanFilters.put(filter.getKey(), counts); booleanFilters.put(filter.getKey(), counts);
...@@ -485,7 +484,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -485,7 +484,7 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters tempFilters = new AppliedFilters(originalFilters); AppliedFilters tempFilters = new AppliedFilters(originalFilters);
tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(FilterConstants.CROPS)); tempFilters.removeIf(appliedFilter -> appliedFilter.getKey().equals(FilterConstants.CROPS));
for (Term term : elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)).getTerms()) { for (Term term : elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(tempFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)).getTerms()) {
String cropShortName = term.getTerm(); String cropShortName = term.getTerm();
Crop crop = cropService.getCrop(cropShortName); Crop crop = cropService.getCrop(cropShortName);
Map<String, Long> values = new HashMap<>(); Map<String, Long> values = new HashMap<>();
...@@ -682,7 +681,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -682,7 +681,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
try { try {
genesysService.writeAccessions(AccessionFilter.convert(appliedFilters), outputStream); genesysService.writeAccessions(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer(); response.flushBuffer();
} catch (EOFException e) { } catch (EOFException e) {
LOG.warn("Download was aborted"); LOG.warn("Download was aborted");
...@@ -710,7 +709,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -710,7 +709,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
try { try {
downloadService.writeXlsxMCPD(AccessionFilter.convert(appliedFilters), outputStream); downloadService.writeXlsxMCPD(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer(); response.flushBuffer();
} catch (EOFException e) { } catch (EOFException e) {
LOG.warn("Download was aborted", e); LOG.warn("Download was aborted", e);
...@@ -739,7 +738,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -739,7 +738,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
try { try {
downloadService.writeXlsxPDCI(AccessionFilter.convert(appliedFilters), outputStream); downloadService.writeXlsxPDCI(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer(); response.flushBuffer();
} catch (EOFException e) { } catch (EOFException e) {
LOG.warn("Download was aborted", e); LOG.warn("Download was aborted", e);
...@@ -818,7 +817,7 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -818,7 +817,7 @@ public class ExplorerController extends BaseController implements InitializingBe
try { try {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
byte[] image = mappingService.getTile(AccessionFilter.convert(appliedFilters), zoom, x, y); byte[] image = mappingService.getTile(AppliedFilters.convert(appliedFilters), zoom, x, y);
image = ColorUtil.changeColor(color, image); image = ColorUtil.changeColor(color, image);
response.setContentType(MediaType.IMAGE_PNG_VALUE); response.setContentType(MediaType.IMAGE_PNG_VALUE);
...@@ -843,35 +842,35 @@ public class ExplorerController extends BaseController implements InitializingBe ...@@ -843,35 +842,35 @@ public class ExplorerController extends BaseController implements InitializingBe
} }
private void overviewInstitutes(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewInstitutes(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE))); model.addAttribute("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)));
model.addAttribute("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3))); model.addAttribute("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3)));
} }
private void overviewSources(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewSources(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3))); model.addAttribute("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
model.addAttribute("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE))); model.addAttribute("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE)));
} }
private void overviewAvailability(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewAvailability(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsMLS", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS))); model.addAttribute("statsMLS", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS)));
model.addAttribute("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE))); model.addAttribute("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
} }
private void overviewHistoric(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewHistoric(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC))); model.addAttribute("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC)));
} }
private void overviewManagement(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewManagement(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsStorage", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE))); model.addAttribute("statsStorage", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
model.addAttribute("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE))); model.addAttribute("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
model.addAttribute("statsSGSV", elasticService.termStatistics(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV))); model.addAttribute("statsSGSV", elasticService.termStatistics(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV)));
} }
private void overviewComposition(ModelMap model, AppliedFilters appliedFilters) throws SearchException { private void overviewComposition(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsGenus", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS))); model.addAttribute("statsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
model.addAttribute("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES))); model.addAttribute("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
model.addAttribute("statsCrops", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS))); model.addAttribute("statsCrops", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
model.addAttribute("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT))); model.addAttribute("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT)));
} }
@RequestMapping(value = "/explore/shorten-url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/explore/shorten-url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
......
...@@ -42,7 +42,6 @@ import org.genesys2.server.service.ElasticsearchService; ...@@ -42,7 +42,6 @@ import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.FilterConstants; import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.ProjectService; import org.genesys2.server.service.ProjectService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter; import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.genesys2.server.service.impl.FilterHandler; import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter; import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
...@@ -120,10 +119,10 @@ public class ProjectController extends BaseController { ...@@ -120,10 +119,10 @@ public class ProjectController extends BaseController {
model.addAttribute("jsonFilter", filters.toString()); model.addAttribute("jsonFilter", filters.toString());
try { try {
model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS))); model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS))); model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES))); model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 100, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3))); model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 100, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
} catch (SearchException e) { } catch (SearchException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }
...@@ -260,7 +259,7 @@ public class ProjectController extends BaseController { ...@@ -260,7 +259,7 @@ public class ProjectController extends BaseController {
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1$s.zip\"", project.getCode())); response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1$s.zip\"", project.getCode()));
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
genesysService.writeAccessions(AccessionFilter.convert(filters), outputStream); genesysService.writeAccessions(AppliedFilters.convert(filters), outputStream);
response.flushBuffer(); response.flushBuffer();
} }
...@@ -283,7 +282,7 @@ public class ProjectController extends BaseController { ...@@ -283,7 +282,7 @@ public class ProjectController extends BaseController {
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
try { try {
downloadService.writeXlsxMCPD(AccessionFilter.convert(filters), outputStream); downloadService.writeXlsxMCPD(AppliedFilters.convert(filters), outputStream);
response.flushBuffer(); response.flushBuffer();
} catch (EOFException e) { } catch (EOFException e) {
LOG.warn("Download was aborted", e); LOG.warn("Download was aborted", e);
...@@ -309,7 +308,7 @@ public class ProjectController extends BaseController { ...@@ -309,7 +308,7 @@ public class ProjectController extends BaseController {
final OutputStream outputStream = response.getOutputStream(); final OutputStream outputStream = response.getOutputStream();
try { try {
downloadService.writeXlsxPDCI(AccessionFilter.convert(filters), outputStream); downloadService.writeXlsxPDCI(AppliedFilters.convert(filters), outputStream);
response.flushBuffer(); response.flushBuffer();
} catch (EOFException e) { } catch (EOFException e) {
LOG.warn("Download was aborted", e); LOG.warn("Download was aborted", e);
......
...@@ -24,7 +24,6 @@ import org.genesys.blocks.model.filters.StringFilter; ...@@ -24,7 +24,6 @@ import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter; import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.QAccession; import org.genesys2.server.model.genesys.QAccession;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import com.hazelcast.util.CollectionUtil; import com.hazelcast.util.CollectionUtil;
import com.querydsl.core.BooleanBuilder; import com.querydsl.core.BooleanBuilder;
...@@ -199,20 +198,6 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -199,20 +198,6 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
return and; return and;
} }
/**
* Convert.
*
* @param filters the filters
* @return the accession filter
*/
public static AccessionFilter convert(AppliedFilters filters) {
try {
return AppliedFiltersConverter.convert(filters);
} catch (Throwable e) {
throw new RuntimeException("Could not convert filters", e);
}
}
/** /**
* Historic. * Historic.
* *
......
...@@ -41,6 +41,7 @@ import org.genesys2.server.model.genesys.TraitCode; ...@@ -41,6 +41,7 @@ import org.genesys2.server.model.genesys.TraitCode;
import org.genesys2.server.service.FilterConstants; import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.TraitService; import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.filter.AccessionFilter; import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -502,6 +503,20 @@ public class FilterHandler { ...@@ -502,6 +503,20 @@ public class FilterHandler {
} }
return null; return null;
} }
/**
* Convert.
*
* @param filters the filters
* @return the accession filter
*/
public static AccessionFilter convert(AppliedFilters filters) {
try {
return AppliedFiltersConverter.convert(filters);
} catch (Throwable e) {
throw new RuntimeException("Could not convert filters", e);
}
}
} }
public static class AppliedFilter { public static class AppliedFilter {
......
...@@ -233,7 +233,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -233,7 +233,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<FaoInstitute> faoInst = instituteService.autocomplete(ac); final List<FaoInstitute> faoInst = instituteService.autocomplete(ac);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm( termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(
FilterConstants.INSTCODE)); FilterConstants.INSTCODE));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
...@@ -255,7 +255,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -255,7 +255,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<Country> countries = geoService.autocomplete(ac); final List<Country> countries = geoService.autocomplete(ac);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
...@@ -266,7 +266,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -266,7 +266,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<Country> countries = geoService.autocomplete(ac); final List<Country> countries = geoService.autocomplete(ac);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
...@@ -276,7 +276,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -276,7 +276,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> genera = taxonomyService.autocompleteGenus(ac, crop); final List<String> genera = taxonomyService.autocompleteGenus(ac, crop);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
...@@ -296,7 +296,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -296,7 +296,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> species = taxonomyService.autocompleteSpecies(ac, crop, genus); final List<String> species = taxonomyService.autocompleteSpecies(ac, crop, genus);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SPECIES)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SPECIES));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
...@@ -323,7 +323,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -323,7 +323,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> subtaxa = taxonomyService.autocompleteSubtaxa(ac, crop, genus, species); final List<String> subtaxa = taxonomyService.autocompleteSubtaxa(ac, crop, genus, species);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SUBTAXA)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SUBTAXA));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
...@@ -334,7 +334,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -334,7 +334,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> taxa = taxonomyService.autocompleteTaxonomy(ac); final List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
TermResult termResult = null; TermResult termResult = null;
try { try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SCINAME)); termResult = elasticsearchService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 20000, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_SCINAME));
} catch (SearchException e) { } catch (SearchException e) {
LOG.error("Error occurred during search", e); LOG.error("Error occurred during search", e);
} }
......
...@@ -43,14 +43,14 @@ public class AccessionFilterTest { ...@@ -43,14 +43,14 @@ public class AccessionFilterTest {
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.CROPS).addFilterValue(new FilterHandler.LiteralValueFilter("banana"))); filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.CROPS).addFilterValue(new FilterHandler.LiteralValueFilter("banana")));
LOG.debug("<- {}", filters); LOG.debug("<- {}", filters);
AccessionFilter af = AccessionFilter.convert(filters); AccessionFilter af = AppliedFilters.convert(filters);
LOG.debug("-> {}", pretty.writeValueAsString(af)); LOG.debug("-> {}", pretty.writeValueAsString(af));
assertThat(af.crop, notNullValue()); assertThat(af.crop, notNullValue());
assertThat(af.crop.stream().findFirst().get(), is("banana")); assertThat(af.crop.stream().findFirst().get(), is("banana"));