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<>();
......
......@@ -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);
}
......
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