Commit 57067017 authored by Matija Obreza's avatar Matija Obreza
Browse files

Filter by subtaxa

parent b1b725b0
......@@ -16,8 +16,11 @@ public class Taxonomy {
// Enable non-indexed access to genus+species
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String genusSpecies;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String spAuthor;
private String subtax;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String subtaxa;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String subtAuthor;
public static Taxonomy from(Taxonomy2 taxonomy) {
......@@ -30,7 +33,7 @@ public class Taxonomy {
t.species = taxonomy.getSpecies();
t.genusSpecies = taxonomy.getGenus() + " " + taxonomy.getSpecies();
t.spAuthor = StringUtils.defaultIfBlank(taxonomy.getSpAuthor(), null);
t.subtax = StringUtils.defaultIfBlank(taxonomy.getSubtaxa(), null);
t.subtaxa = StringUtils.defaultIfBlank(taxonomy.getSubtaxa(), null);
t.subtAuthor = StringUtils.defaultIfBlank(taxonomy.getSubtAuthor(), null);
return t;
}
......@@ -75,12 +78,12 @@ public class Taxonomy {
this.spAuthor = spAuthor;
}
public String getSubtax() {
return subtax;
public String getSubtaxa() {
return subtaxa;
}
public void setSubtax(String subtax) {
this.subtax = subtax;
public void setSubtaxa(String subtax) {
this.subtaxa = subtax;
}
public String getSubtAuthor() {
......
......@@ -44,6 +44,21 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
@Query("select distinct t.taxonName from Taxonomy2 t where lower(t.taxonName) like lower(?1)")
List<String> autocompleteTaxonomy(String term, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1)")
List<String> autocompleteSubtaxa(String string, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t join t.cropTaxonomies ct where lower(t.subtaxa) like lower(?1) and ct.crop = ?2")
List<String> autocompleteSubtaxaByCrop(String string, Crop crop, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.genus in (?2)")
List<String> autocompleteSubtaxaByGenus(String string, List<String> genus, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.species in (?2)")
List<String> autocompleteSubtaxaBySpecies(String string, List<String> species, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where lower(t.subtaxa) like lower(?1) and t.genus in (?2) and t.species in (?3)")
List<String> autocompleteSubtaxaByGenusAndSpecies(String string, List<String> genus, List<String> species, Pageable page);
@Query("select t from Taxonomy2 t where lower(t.genus) = lower(?1) and lower(t.species) = lower(?2) and lower(t.spAuthor) = lower(?3) and lower(t.subtaxa) = lower(?4) and lower(t.subtAuthor) = lower(?5)")
Taxonomy2 findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(String genus, String species, String spAuthor, String subtaxa, String subtAuthor);
......
......@@ -54,6 +54,8 @@ public interface FilterConstants {
public static final String TAXONOMY_GENUS = "taxonomy.genus";
public static final String TAXONOMY_SUBTAXA = "taxonomy.subtaxa";
public static final String ID = "id";
public static final String DUPLSITE = "duplSite";
......
......@@ -45,4 +45,6 @@ public interface TaxonomyService {
Taxonomy2 internalEnsure(String genus, String species, String spAuthor, String subtaxa, String subtAuthor) throws InterruptedException;
List<String> autocompleteSubtaxa(String ac, Crop crop, List<String> genus, List<String> species);
}
......@@ -99,7 +99,7 @@ public class DirectMysqlQuery {
protected DirectMysqlQuery join(AppliedFilters filters) {
if (hasFilter(filters, FilterConstants.CROPS) || hasFilter(filters, FilterConstants.TAXONOMY_GENUS)
|| hasFilter(filters, FilterConstants.TAXONOMY_SPECIES) || hasFilter(filters, FilterConstants.TAXONOMY_SCINAME)) {
|| hasFilter(filters, FilterConstants.TAXONOMY_SPECIES) || hasFilter(filters, FilterConstants.TAXONOMY_SUBTAXA) || hasFilter(filters, FilterConstants.TAXONOMY_SCINAME)) {
innerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
......@@ -173,6 +173,7 @@ public class DirectMysqlQuery {
createQuery(whereBuffer, "org.slug", filters.get(FilterConstants.INSTITUTE_NETWORK), params);
createQuery(whereBuffer, "t.genus", filters.get(FilterConstants.TAXONOMY_GENUS), params);
createQuery(whereBuffer, "t.species", filters.get(FilterConstants.TAXONOMY_SPECIES), params);
createQuery(whereBuffer, "t.subtaxa", filters.get(FilterConstants.TAXONOMY_SUBTAXA), params);
createQuery(whereBuffer, "t.taxonName", filters.get(FilterConstants.TAXONOMY_SCINAME), params);
createQuery(whereBuffer, "geo.longitude", filters.get(FilterConstants.GEO_LONGITUDE), params);
createQuery(whereBuffer, "geo.latitude", filters.get(FilterConstants.GEO_LATITUDE), params);
......
......@@ -82,18 +82,19 @@ public class FilterHandler {
this.availableFilters.add(new BasicFilter(FilterConstants.CROPS, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
110, 120, 130, 200, 300, 400, 410, 411, 412, 413, 414, 415, 416, 420, 421, 422, 423, 500, 600, 999 }));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_GENUS, "/explore/ac/genus"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SPECIES, "/explore/ac/species"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SCINAME, "/explore/ac/taxonomy"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_GENUS, "/explore/ac/"+FilterConstants.TAXONOMY_GENUS));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SPECIES, "/explore/ac/"+FilterConstants.TAXONOMY_SPECIES));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SUBTAXA, "/explore/ac/"+FilterConstants.TAXONOMY_SUBTAXA));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.TAXONOMY_SCINAME, "/explore/ac/"+FilterConstants.TAXONOMY_SCINAME));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.ORGCTY_ISO3, "/explore/ac/country"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3, "/explore/ac/country"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.ORGCTY_ISO3, "/explore/ac/"+FilterConstants.ORGCTY_ISO3));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3, "/explore/ac/"+FilterConstants.ORGCTY_ISO3));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LATITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_LONGITUDE, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.GEO_ELEVATION, DataType.NUMERIC));
this.availableFilters.add(new BasicFilter(FilterConstants.INSTITUTE_NETWORK, DataType.STRING));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTCODE, "/explore/ac/instCode"));
this.availableFilters.add(new AutocompleteFilter(FilterConstants.INSTCODE, "/explore/ac/" + FilterConstants.INSTCODE));
this.availableFilters.add(new BasicFilter(FilterConstants.ACCENUMB, DataType.STRING).setAnalyzed(true));
this.availableFilters.add(new BasicFilter(FilterConstants.ALIAS, DataType.STRING).setAnalyzed(true));
this.availableFilters.add(new BasicFilter(FilterConstants.SGSV, DataType.BOOLEAN));
......
......@@ -157,22 +157,22 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
final List<LabelValue<String>> completed = new ArrayList<LabelValue<String>>();
if ("instCode".equalsIgnoreCase(filter)) {
if (FilterConstants.INSTCODE.equalsIgnoreCase(filter)) {
final List<FaoInstitute> faoInst = instituteService.autocomplete(ac);
for (final FaoInstitute inst : faoInst) {
completed.add(new LabelValue<String>(inst.getCode(), inst.getCode() + ", " + inst.getFullName()));
}
} else if ("country".equalsIgnoreCase(filter)) {
} else if (FilterConstants.ORGCTY_ISO3.equalsIgnoreCase(filter)) {
final List<Country> countries = geoService.autocomplete(ac);
for (final Country c : countries) {
completed.add(new LabelValue<String>(c.getCode3(), c.getCode3() + ", " + c.getName()));
}
} else if ("genus".equalsIgnoreCase(filter)) {
} else if (FilterConstants.TAXONOMY_GENUS.equalsIgnoreCase(filter)) {
final List<String> genera = taxonomyService.autocompleteGenus(ac, crop);
for (final String value : genera) {
completed.add(new LabelValue<String>(value, value));
}
} else if ("species".equalsIgnoreCase(filter)) {
} else if (FilterConstants.TAXONOMY_SPECIES.equalsIgnoreCase(filter)) {
List<String> genus = new ArrayList<>();
AppliedFilter genusFilter = filters.get(FilterConstants.TAXONOMY_GENUS);
......@@ -186,7 +186,28 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
for (final String value : species) {
completed.add(new LabelValue<String>(value, value));
}
} else if ("taxonomy".equalsIgnoreCase(filter)) {
} else if (FilterConstants.TAXONOMY_SUBTAXA.equalsIgnoreCase(filter)) {
List<String> genus = new ArrayList<>();
List<String> species = new ArrayList<>();
AppliedFilter genusFilter = filters.get(FilterConstants.TAXONOMY_GENUS);
if (genusFilter != null) {
Set<FilterValue> elements = genusFilter.getValues();
for (FilterValue fv : elements)
genus.add((String) ((LiteralValueFilter) fv).getValue());
}
AppliedFilter speciesFilter = filters.get(FilterConstants.TAXONOMY_SPECIES);
if (speciesFilter != null) {
Set<FilterValue> elements = speciesFilter.getValues();
for (FilterValue fv : elements)
species.add((String) ((LiteralValueFilter) fv).getValue());
}
final List<String> subtaxa = taxonomyService.autocompleteSubtaxa(ac, crop, genus, species);
for (final String value : subtaxa) {
completed.add(new LabelValue<String>(value, value));
}
} else if (FilterConstants.TAXONOMY_SCINAME.equalsIgnoreCase(filter)) {
final List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
for (final String taxonomy : taxa) {
completed.add(new LabelValue<String>(taxonomy, taxonomy));
......
......@@ -67,11 +67,33 @@ public class TaxonomyServiceImpl implements TaxonomyService {
List<String> strings;
if (!genus.isEmpty()) {
strings = taxonomy2Repository.autocompleteSpeciesByGenus(term + "%", genus, new PageRequest(0, 10));
strings = taxonomy2Repository.autocompleteSpeciesByGenus("%" + term + "%", genus, new PageRequest(0, 10));
} else if (crop != null) {
strings = taxonomy2Repository.autocompleteSpeciesByCrop(term + "%", crop, new PageRequest(0, 10));
strings = taxonomy2Repository.autocompleteSpeciesByCrop("%" + term + "%", crop, new PageRequest(0, 10));
} else {
strings = taxonomy2Repository.autocompleteSpecies(term + "%", new PageRequest(0, 10));
strings = taxonomy2Repository.autocompleteSpecies("%" + term + "%", new PageRequest(0, 10));
}
return strings;
}
@Override
public List<String> autocompleteSubtaxa(String term, Crop crop, List<String> genus, List<String> species) {
List<String> strings;
if (!genus.isEmpty() && !species.isEmpty()) {
LOG.debug("Genus=" + genus + " sp=" + species);
strings = taxonomy2Repository.autocompleteSubtaxaByGenusAndSpecies("%" + term + "%", genus, species, new PageRequest(0, 10));
} else if (!species.isEmpty()) {
LOG.debug("sp=" + species);
strings = taxonomy2Repository.autocompleteSubtaxaBySpecies("%" + term + "%", species, new PageRequest(0, 10));
} else if (!genus.isEmpty()) {
LOG.debug("Genus=" + genus);
strings = taxonomy2Repository.autocompleteSubtaxaByGenus("%" + term + "%", genus, new PageRequest(0, 10));
} else if (crop != null) {
strings = taxonomy2Repository.autocompleteSubtaxaByCrop(term + "%", crop, new PageRequest(0, 10));
} else {
strings = taxonomy2Repository.autocompleteSubtaxa("%" + term + "%", new PageRequest(0, 10));
}
return strings;
......
......@@ -285,7 +285,7 @@ public class ExplorerController extends BaseController {
return "/accession/modal";
}
@RequestMapping(value = "/explore/ac/{field}", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/explore/ac/{field:.+}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<LabelValue<String>> autocomplete(@PathVariable("field") String filter, @RequestParam(value = "term", required = true) String ac,
@RequestParam(value = "jsonFilter", required = false, defaultValue = "{}") String jsonFilter) throws IOException {
......
......@@ -355,6 +355,7 @@ filter.geo.longitude=Longitude
filter.geo.elevation=Elevation
filter.taxonomy.genus=Genus
filter.taxonomy.species=Species
filter.taxonomy.subtaxa=Subtaxa
filter.taxSpecies=Species
filter.taxonomy.sciName=Scientific name
filter.sgsv=Safety duplicated in Svalbard
......
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