Commit 8847132d authored by Matija Obreza's avatar Matija Obreza
Browse files

Redirect to /explore with filters where possible

Added "species" filter
parent 091eac8f
......@@ -28,6 +28,9 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
@Query("select distinct t.genus from Taxonomy2 t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page);
@Query("select distinct t.species from Taxonomy2 t where t.species like ?1")
List<String> autocompleteSpecies(String term, Pageable page);
@Query("select distinct t.taxonName from Taxonomy2 t where t.taxonName like ?1")
List<String> autocompleteTaxonomy(String term, Pageable page);
......@@ -38,4 +41,5 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
List<Taxonomy2> findByGenusAndSpecies(String genus, String species);
List<Taxonomy2> findByGenusAndSpeciesAndSubtaxa(String genus, String species, String subtaxa);
}
......@@ -24,6 +24,8 @@ public interface TaxonomyService {
List<String> autocompleteGenus(String term);
List<String> autocompleteSpecies(String term);
List<String> autocompleteTaxonomy(String term);
long getTaxonomy2Id(String genus);
......@@ -36,4 +38,7 @@ public interface TaxonomyService {
Taxonomy2 get(Long id);
Taxonomy2 get(String genus, String species);
}
......@@ -73,7 +73,7 @@ public class DirectMysqlQuery {
}
protected DirectMysqlQuery join(ObjectNode jsonTree) {
if (hasFilter(jsonTree, "crop") || hasFilter(jsonTree, "genus") || hasFilter(jsonTree, "taxon")) {
if (hasFilter(jsonTree, "crop") || hasFilter(jsonTree, "genus") || hasFilter(jsonTree, "species") || hasFilter(jsonTree, "taxon")) {
innerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
if (hasFilter(jsonTree, "crop")) {
innerJoin("croptaxonomy", "ct", "ct.taxonomyId=t.id");
......@@ -112,6 +112,7 @@ public class DirectMysqlQuery {
createQuery(whereBuffer, "a.available", jsonTree.get("available"), params);
createQuery(whereBuffer, "org.slug", jsonTree.get("organization"), params);
createQuery(whereBuffer, "t.genus", jsonTree.get("genus"), params);
createQuery(whereBuffer, "t.species", jsonTree.get("species"), params);
createQuery(whereBuffer, "t.taxonName", jsonTree.get("taxon"), params);
createQuery(whereBuffer, "geo.longitude", jsonTree.get("longitude"), params);
createQuery(whereBuffer, "geo.latitude", jsonTree.get("latitude"), params);
......
......@@ -110,6 +110,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
this.availableFilters.add(new GenesysI18nListFilterImpl<Integer>("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 GenesysAutocompleteFilterImpl("genus", "/explore/ac/genus"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("species", "/explore/ac/species"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("taxon", "/explore/ac/taxonomy"));
this.availableFilters.add(new GenesysAutocompleteFilterImpl("orgCty", "/explore/ac/country"));
......@@ -227,6 +228,9 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
*/
@Override
public List<LabelValue<String>> autocomplete(String filter, String ac) {
if (LOG.isDebugEnabled())
LOG.debug("Autocomplete " + filter + " ac=" + ac);
List<LabelValue<String>> completed = new ArrayList<LabelValue<String>>();
if ("instCode".equalsIgnoreCase(filter)) {
List<FaoInstitute> faoInst = searchService.autocomplete(ac, FaoInstitute.class);
......@@ -240,8 +244,13 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
} else if ("genus".equalsIgnoreCase(filter)) {
List<String> genera = taxonomyService.autocompleteGenus(ac);
for (String genus : genera) {
completed.add(new LabelValue<String>(genus, genus));
for (String value : genera) {
completed.add(new LabelValue<String>(value, value));
}
} else if ("species".equalsIgnoreCase(filter)) {
List<String> species = taxonomyService.autocompleteSpecies(ac);
for (String value : species) {
completed.add(new LabelValue<String>(value, value));
}
} else if ("taxonomy".equalsIgnoreCase(filter)) {
List<String> taxa = taxonomyService.autocompleteTaxonomy(ac);
......
......@@ -49,6 +49,11 @@ public class TaxonomyServiceImpl implements TaxonomyService {
return taxonomy2Repository.autocompleteGenus(term + "%", new PageRequest(0, 10));
}
@Override
public List<String> autocompleteSpecies(String term) {
return taxonomy2Repository.autocompleteSpecies(term + "%", new PageRequest(0, 10));
}
@Override
public List<String> autocompleteTaxonomy(String term) {
return taxonomy2Repository.autocompleteTaxonomy("%" + term + "%", new PageRequest(0, 10));
......@@ -94,10 +99,10 @@ public class TaxonomyServiceImpl implements TaxonomyService {
Taxonomy2 speciesTaxa = internalEnsure(genus, species, "", "", "");
taxSpeciesId = speciesTaxa.getId();
taxGenusId = speciesTaxa.getTaxGenus();
} else if (! StringUtils.equals(species, "sp.") && (subtaxa.equals("") && spAuthor.equals("") && subtAuthor.equals(""))) {
} else if (!StringUtils.equals(species, "sp.") && (subtaxa.equals("") && spAuthor.equals("") && subtAuthor.equals(""))) {
Taxonomy2 genusTaxa = internalEnsure(genus, "sp.", "", "", "");
taxGenusId = genusTaxa.getId();
taxSpeciesId=genusTaxa.getId();
taxSpeciesId = genusTaxa.getId();
}
// Loop it a bit if required
......@@ -159,6 +164,11 @@ public class TaxonomyServiceImpl implements TaxonomyService {
return tax.getId();
}
@Override
public Taxonomy2 get(String genus, String species) {
return taxonomy2Repository.findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(genus, species, "", "", "");
}
@Override
public long countTaxonomy2() {
return taxonomy2Repository.count();
......
......@@ -226,7 +226,7 @@ public class ExplorerController extends BaseController {
@RequestMapping(value = "/explore/ac/{field}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<LabelValue<String>> autocomplete(@PathVariable("field") String filter, @RequestParam(value = "term", required = false) String ac) {
public List<LabelValue<String>> autocomplete(@PathVariable("field") String filter, @RequestParam(value = "term", required = true) String ac) {
return filterService.autocomplete(filter, ac);
}
......
......@@ -18,11 +18,9 @@ package org.genesys2.server.servlet.controller;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.ContentService;
......@@ -32,7 +30,6 @@ import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -147,27 +144,18 @@ public class OrganizationController extends BaseController {
return "redirect:/org/" + organization.getSlug();
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String slug,
@RequestMapping("/{orgSlug}/data")
public String viewData(ModelMap model, @PathVariable(value = "orgSlug") String orgSlug,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing organization " + slug);
Organization organization = organizationService.getOrganization(slug);
_logger.debug("Viewing organization " + orgSlug);
Organization organization = organizationService.getOrganization(orgSlug);
if (organization == null) {
throw new ResourceNotFoundException();
}
_logger.warn("Searching accessions of: " + organization);
Page<Accession> accessions = genesysService.listAccessionsByOrganization(organization, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.organization", organization);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"organization\":[\"" + organization.getSlug() + "\"]}");
return "/accession/explore";
model.addAttribute("filter", "{\"organization\":[\"" + organization.getSlug() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
}
......@@ -23,7 +23,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GenesysService;
......@@ -160,18 +160,9 @@ public class WiewsController extends BaseController {
throw new ResourceNotFoundException();
}
_logger.warn("Searching accessions of: " + faoInstitute);
Page<Accession> accessions = genesysService.listAccessionsByInstitute(faoInstitute, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.holdingInstitute", faoInstitute);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"instCode\":[\"" + faoInstitute.getCode() + "\"]}");
return "/accession/explore";
model.addAttribute("filter", "{\"instCode\":[\"" + faoInstitute.getCode() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/t/{genus}/{species:.+}")
......@@ -182,26 +173,18 @@ public class WiewsController extends BaseController {
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
// Taxonomy
long taxonomyId = taxonomyService.getTaxonomy2Id(genus, species);
_logger.debug("Got " + taxonomyId);
_logger.warn("Searching accessions of: " + faoInstitute);
Page<Accession> accessions = genesysService.listAccessionsByInstituteAndSpecies(faoInstitute, taxonomyId, new PageRequest(page - 1, 50, new Sort(
"accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.taxonomy", taxonomyId);
filters.put("filter.holdingInstitute", faoInstitute);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"instCode\":[\"" + faoInstitute.getCode() + "\"],\"species\":[\"" + taxonomyId + "\"]}");
Taxonomy2 taxonomy2 = taxonomyService.get(genus, species);
if (taxonomy2 == null) {
throw new ResourceNotFoundException();
}
_logger.debug("Got " + taxonomy2);
return "/accession/explore";
model.addAttribute("filter", "{\"instCode\":[\"" + faoInstitute.getCode() + "\"],\"genus\":[\"" + taxonomy2.getGenus() + "\"],\"species\":[\""
+ taxonomy2.getSpecies() + "\"]}");
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping(value = "/{wiewsCode}/dwca", method = RequestMethod.POST)
......
......@@ -331,6 +331,7 @@ filter.latitude=Latitude
filter.longitude=Longitude
filter.elevation=Elevation
filter.genus=Genus
filter.species=Species
filter.taxSpecies=Species
filter.taxon=Taxonomical name
filter.inSvalbard=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