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

Moved AppliedFilters converter to AppliedFilters

parent 8ad4bee5
......@@ -29,7 +29,6 @@ import org.genesys2.server.service.ElasticsearchService.Term;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.FilterConstants;
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.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
......@@ -89,7 +88,7 @@ public class ChartsController extends BaseController {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
// 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));
List<Map<String, Object>> resultList = new ArrayList<>();
......
......@@ -60,7 +60,6 @@ import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.TraitService;
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.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -238,7 +237,7 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters tempFilters = new AppliedFilters(storedTransformedFilters);
final GenesysFilter finalFilter = filter;
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()));
counts.add(term.getCount());
}
......@@ -254,7 +253,7 @@ public class ExplorerController extends BaseController implements InitializingBe
tempFilters = new AppliedFilters(storedTransformedFilters);
final GenesysFilter finalFilter2 = filter;
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()));
counts.add(term.getCount());
}
......@@ -326,7 +325,7 @@ public class ExplorerController extends BaseController implements InitializingBe
appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
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);
overviewComposition(model, appliedFilters);
overviewAvailability(model, appliedFilters);
......@@ -382,20 +381,20 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
Map<String, TermResult> pageData = new HashMap<>();
pageData.put("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statsMLS", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS)));
pageData.put("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
pageData.put("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC)));
pageData.put("statsStorage", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
pageData.put("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
pageData.put("statsSGSV", elasticService.termStatistics(Accession.class, AccessionFilter.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("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT)));
pageData.put("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)));
pageData.put("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3)));
pageData.put("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
pageData.put("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE)));
pageData.put("statsMLS", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS)));
pageData.put("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
pageData.put("statsHistoric", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.HISTORIC)));
pageData.put("statsStorage", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
pageData.put("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
pageData.put("statsSGSV", elasticService.termStatistics(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV)));
pageData.put("statsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
pageData.put("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
pageData.put("statsCrops", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
pageData.put("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT)));
return pageData;
}
......@@ -419,7 +418,7 @@ public class ExplorerController extends BaseController implements InitializingBe
List<Long> counts = new ArrayList<>();
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
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()));
counts.add(term.getCount());
}
......@@ -463,7 +462,7 @@ public class ExplorerController extends BaseController implements InitializingBe
if (FilterConstants.HISTORIC.equals(filter.getKey())) {
// 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());
}
booleanFilters.put(filter.getKey(), counts);
......@@ -485,7 +484,7 @@ public class ExplorerController extends BaseController implements InitializingBe
AppliedFilters tempFilters = new AppliedFilters(originalFilters);
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();
Crop crop = cropService.getCrop(cropShortName);
Map<String, Long> values = new HashMap<>();
......@@ -682,7 +681,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream();
try {
genesysService.writeAccessions(AccessionFilter.convert(appliedFilters), outputStream);
genesysService.writeAccessions(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted");
......@@ -710,7 +709,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxMCPD(AccessionFilter.convert(appliedFilters), outputStream);
downloadService.writeXlsxMCPD(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
......@@ -739,7 +738,7 @@ public class ExplorerController extends BaseController implements InitializingBe
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxPDCI(AccessionFilter.convert(appliedFilters), outputStream);
downloadService.writeXlsxPDCI(AppliedFilters.convert(appliedFilters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
......@@ -818,7 +817,7 @@ public class ExplorerController extends BaseController implements InitializingBe
try {
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);
response.setContentType(MediaType.IMAGE_PNG_VALUE);
......@@ -843,35 +842,35 @@ public class ExplorerController extends BaseController implements InitializingBe
}
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("statsInstCountry", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTITUTE_COUNTRY_ISO3)));
model.addAttribute("statsInstCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.INSTCODE)));
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 {
model.addAttribute("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statsOrgCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
model.addAttribute("statsDonorCode", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DONORCODE)));
}
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("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
model.addAttribute("statsMLS", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.MLSSTATUS)));
model.addAttribute("statsAvailable", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.AVAILABLE)));
}
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 {
model.addAttribute("statsStorage", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
model.addAttribute("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
model.addAttribute("statsSGSV", elasticService.termStatistics(Accession.class, AccessionFilter.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV)));
model.addAttribute("statsStorage", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.STORAGE)));
model.addAttribute("statsDuplSite", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.DUPLSITE)));
model.addAttribute("statsSGSV", elasticService.termStatistics(Accession.class, AppliedFilters.convert(appliedFilters), 2, AppliedFiltersConverter.convertTerm(FilterConstants.SGSV)));
}
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("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statsSampStat", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.SAMPSTAT)));
model.addAttribute("statsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
model.addAttribute("statsSpecies", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 20, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
model.addAttribute("statsCrops", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(appliedFilters), 30, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
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)
......
......@@ -42,7 +42,6 @@ import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
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.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
......@@ -120,10 +119,10 @@ public class ProjectController extends BaseController {
model.addAttribute("jsonFilter", filters.toString());
try {
model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.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("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(Accession.class, AppliedFilters.convert(filters), 100, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
} catch (SearchException e) {
LOG.warn(e.getMessage());
}
......@@ -260,7 +259,7 @@ public class ProjectController extends BaseController {
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-accessions-%1$s.zip\"", project.getCode()));
final OutputStream outputStream = response.getOutputStream();
genesysService.writeAccessions(AccessionFilter.convert(filters), outputStream);
genesysService.writeAccessions(AppliedFilters.convert(filters), outputStream);
response.flushBuffer();
}
......@@ -283,7 +282,7 @@ public class ProjectController extends BaseController {
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxMCPD(AccessionFilter.convert(filters), outputStream);
downloadService.writeXlsxMCPD(AppliedFilters.convert(filters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
......@@ -309,7 +308,7 @@ public class ProjectController extends BaseController {
final OutputStream outputStream = response.getOutputStream();
try {
downloadService.writeXlsxPDCI(AccessionFilter.convert(filters), outputStream);
downloadService.writeXlsxPDCI(AppliedFilters.convert(filters), outputStream);
response.flushBuffer();
} catch (EOFException e) {
LOG.warn("Download was aborted", e);
......
......@@ -24,7 +24,6 @@ import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.QAccession;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import com.hazelcast.util.CollectionUtil;
import com.querydsl.core.BooleanBuilder;
......@@ -199,20 +198,6 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
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.
*
......
......@@ -41,6 +41,7 @@ import org.genesys2.server.model.genesys.TraitCode;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -502,6 +503,20 @@ public class FilterHandler {
}
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 {
......
......@@ -233,7 +233,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<FaoInstitute> faoInst = instituteService.autocomplete(ac);
TermResult termResult = null;
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));
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
......@@ -255,7 +255,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<Country> countries = geoService.autocomplete(ac);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......@@ -266,7 +266,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<Country> countries = geoService.autocomplete(ac);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......@@ -276,7 +276,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> genera = taxonomyService.autocompleteGenus(ac, crop);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......@@ -296,7 +296,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> species = taxonomyService.autocompleteSpecies(ac, crop, genus);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......@@ -323,7 +323,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> subtaxa = taxonomyService.autocompleteSubtaxa(ac, crop, genus, species);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......@@ -334,7 +334,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
TermResult termResult = null;
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) {
LOG.error("Error occurred during search", e);
}
......
......@@ -43,14 +43,14 @@ public class AccessionFilterTest {
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.CROPS).addFilterValue(new FilterHandler.LiteralValueFilter("banana")));
LOG.debug("<- {}", filters);
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
LOG.debug("-> {}", pretty.writeValueAsString(af));
assertThat(af.crop, notNullValue());
assertThat(af.crop.stream().findFirst().get(), is("banana"));
// add second value
filter.addFilterValue(new FilterHandler.LiteralValueFilter("cassava"));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.crop.size(), is(2));
assertTrue(af.crop.contains("cassava"));
......@@ -67,14 +67,14 @@ public class AccessionFilterTest {
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.CROPNAME).addFilterValue(new FilterHandler.LiteralValueFilter("banana")));
LOG.debug("<- {}", filters);
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
LOG.debug("-> {}", pretty.writeValueAsString(af));
assertThat(af.cropName, notNullValue());
assertThat(af.cropName, is("banana"));
// 2nd is ignored
filter.addFilterValue(new FilterHandler.LiteralValueFilter("cassava"));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.cropName, is("banana"));
ElasticQueryBuilder esQb = new ElasticQueryBuilder();
......@@ -88,7 +88,7 @@ public class AccessionFilterTest {
filters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter("INS003")));
LOG.debug("<- {}", filters);
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
LOG.debug("-> {}", pretty.writeValueAsString(af));
assertThat(af.holder, notNullValue());
assertThat(af.holder.code, contains("INS003"));
......@@ -104,7 +104,7 @@ public class AccessionFilterTest {
filters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter("INS003")).addFilterValue(
new FilterHandler.LiteralValueFilter("INS099")));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.holder, notNullValue());
assertThat(af.holder.code, containsInAnyOrder("INS003", "INS099"));
......@@ -119,7 +119,7 @@ public class AccessionFilterTest {
filters.add(new AppliedFilter().setFilterName(FilterConstants.ORGCTY_ISO3).addFilterValue(new FilterHandler.LiteralValueFilter("CIV")).addFilterValue(
new FilterHandler.LiteralValueFilter("NGA")));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.origin, notNullValue());
assertThat(af.origin.iso3, containsInAnyOrder("CIV", "NGA"));
......@@ -135,7 +135,7 @@ public class AccessionFilterTest {
AppliedFilter filter;
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.STORAGE).addFilterValue(new FilterHandler.LiteralValueFilter(10)));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.storage, notNullValue());
assertThat(af.storage, contains(10));
......@@ -144,7 +144,7 @@ public class AccessionFilterTest {
LOG.info("=>\n{}", esQb.getQuery());
filter.addFilterValue(new FilterHandler.LiteralValueFilter(12));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.storage, containsInAnyOrder(10, 12));
esQb = new ElasticQueryBuilder();
......@@ -152,7 +152,7 @@ public class AccessionFilterTest {
LOG.info("=>\n{}", esQb.getQuery());
filter.addFilterValue(new FilterHandler.LiteralValueFilter(40));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.storage, containsInAnyOrder(10, 12, 40));
esQb = new ElasticQueryBuilder();
......@@ -166,7 +166,7 @@ public class AccessionFilterTest {
AppliedFilter filter;
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.AVAILABLE).addFilterValue(new FilterHandler.LiteralValueFilter(true)));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.available, notNullValue());
assertThat(af.available, is(true));
......@@ -176,7 +176,7 @@ public class AccessionFilterTest {
filter.getValues().clear();
filter.addFilterValue(new FilterHandler.LiteralValueFilter(false));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.available, is(false));
esQb = new ElasticQueryBuilder();
......@@ -185,7 +185,7 @@ public class AccessionFilterTest {
filter.addFilterValue(new FilterHandler.LiteralValueFilter(true));
LOG.debug("-> {}", pretty.writeValueAsString(filter.getValues()));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.available, nullValue());
}
......@@ -195,13 +195,13 @@ public class AccessionFilterTest {
AppliedFilter filter;
filters.add(filter = new AppliedFilter().setFilterName(FilterConstants.MLSSTATUS).addFilterValue(new FilterHandler.LiteralValueFilter(true)));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.mlsStatus, notNullValue());
assertThat(af.mlsStatus, is(true));
filter.getValues().clear();
filter.addFilterValue(new FilterHandler.LiteralValueFilter(false));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.mlsStatus, is(false));
ElasticQueryBuilder esQb = new ElasticQueryBuilder();
......@@ -210,7 +210,7 @@ public class AccessionFilterTest {
filter.addFilterValue(new FilterHandler.LiteralValueFilter(true));
LOG.debug("-> {}", pretty.writeValueAsString(filter.getValues()));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.mlsStatus, nullValue());
}
......@@ -219,7 +219,7 @@ public class AccessionFilterTest {
AppliedFilters filters = new AppliedFilters();
filters.add(new AppliedFilter().setFilterName(FilterConstants.GEO_ELEVATION).addFilterValue(new FilterHandler.LiteralValueFilter(10)));
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.eq, contains(10d));
......@@ -230,7 +230,7 @@ public class AccessionFilterTest {
filters.clear();
filters.add(new AppliedFilter().setFilterName(FilterConstants.GEO_ELEVATION).addFilterValue(new FilterHandler.MaxValueFilter(10)));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.le, is(10d));
......@@ -241,7 +241,7 @@ public class AccessionFilterTest {
filters.clear();
filters.add(new AppliedFilter().setFilterName(FilterConstants.GEO_ELEVATION).addFilterValue(new FilterHandler.MinValueFilter(10)));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.ge, is(10d));
......@@ -252,7 +252,7 @@ public class AccessionFilterTest {
filters.clear();
filters.add(new AppliedFilter().setFilterName(FilterConstants.GEO_ELEVATION).addFilterValue(new FilterHandler.ValueRangeFilter(-20, 30)));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.ge, is(-20d));
......@@ -264,7 +264,7 @@ public class AccessionFilterTest {
filters.clear();
filters.add(new AppliedFilter().setFilterName(FilterConstants.GEO_ELEVATION).addFilterValue(new FilterHandler.ValueRangeFilter(40, -10)));
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.geo, notNullValue());
assertThat(af.geo.elevation, notNullValue());
assertThat(af.geo.elevation.ge, is(-10d));
......@@ -323,7 +323,7 @@ public class AccessionFilterTest {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-M-d");
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.ge, notNullValue());
assertThat(af.lastModifiedDate.le, notNullValue());
......@@ -333,7 +333,7 @@ public class AccessionFilterTest {
filters = new ObjectMapper().readValue("{\"lastModifiedDate\":[{\"dateRange\":[\"2017-12-12\",\"2018-02-02\"]}]}", AppliedFilters.class);
LOG.debug("Date filter {}", filters);
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.ge, notNullValue());
assertThat(af.lastModifiedDate.le, notNullValue());
......@@ -349,7 +349,7 @@ public class AccessionFilterTest {
AppliedFilters filters = new ObjectMapper().readValue("{\"lastModifiedDate\":[{\"dateMin\":\"2018-01-01\"}]}}", AppliedFilters.class);
LOG.debug("Date filter {}", filters);
AccessionFilter af = AccessionFilter.convert(filters);
AccessionFilter af = AppliedFilters.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.le, nullValue());
assertThat(af.lastModifiedDate.ge, notNullValue());
......@@ -359,7 +359,7 @@ public class AccessionFilterTest {
filters = new ObjectMapper().readValue("{\"lastModifiedDate\":[{\"dateMax\":\"2017-12-12\"}]}", AppliedFilters.class);
LOG.debug("Date filter {}", filters);
af = AccessionFilter.convert(filters);
af = AppliedFilters.convert(filters);
assertThat(af.lastModifiedDate, notNullValue());
assertThat(af.lastModifiedDate.ge, nullValue());
assertThat(af.lastModifiedDate.le, notNullValue());
......
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