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

Browse by taxonomy

parent f181a68c
......@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.List;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -36,6 +37,12 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select count(a) from Accession a where a.institute = ?1")
long countByInstitute(FaoInstitute institute);
@Query("select t.genus, count(a) as x from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by x desc")
List<Object[]> statisticsGenusInInstitute(FaoInstitute institute);
@Query("select taxonomy, count(a) as x from Accession a where a.institute = ?1 group by a.taxonomy order by x desc")
List<Object[]> statisticsTaxonomyInInstitute(FaoInstitute institute);
@Query("select count(a) from Accession a where a.origin = ?1")
long countByOrigin(String isoCode3);
......@@ -66,4 +73,6 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("from Accession a where a.id in ( ?1 )")
Page<Accession> findById(Collection<Long> accessionIds, Pageable pageable);
Page<Accession> findByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable);
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.crophub.rest.common.persistence.domain;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {
Taxonomy getByGenusAndSpecies(String genus, String species);
}
......@@ -12,6 +12,7 @@ import org.crophub.rest.common.model.genesys.AllAcqExchange;
import org.crophub.rest.common.model.genesys.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
......@@ -60,4 +61,10 @@ public interface GenesysService {
Page<Accession> listAccessions(Collection<Long> accessionIds, Pageable pageable);
List<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute);
List<Object[]> statisticsTaxonomyByInstitute(FaoInstitute faoInstitute);
Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable);
}
package org.crophub.rest.common.service;
import org.crophub.rest.common.model.genesys.Taxonomy;
public interface TaxonomyService {
Taxonomy get(String genus, String species);
}
......@@ -14,6 +14,7 @@ import org.crophub.rest.common.model.genesys.AllAcqExchange;
import org.crophub.rest.common.model.genesys.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.crophub.rest.common.persistence.domain.AccessionBreedingRepository;
......@@ -167,4 +168,19 @@ public class GenesysServiceImpl implements GenesysService {
List<Method> methods = metadataMethodRepository.listMetadataMethods(metadata);
return traitValueRepository.getValues(metadata, methods, accessions);
}
@Override
public List<Object[]> statisticsGenusByInstitute(FaoInstitute institute) {
return accessionRepository.statisticsGenusInInstitute(institute);
}
@Override
public List<Object[]> statisticsTaxonomyByInstitute(FaoInstitute institute) {
return accessionRepository.statisticsTaxonomyInInstitute(institute);
}
@Override
public Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable) {
return accessionRepository.findByInstituteAndTaxonomy(institute, taxonomy, pageable);
}
}
package org.crophub.rest.common.service.impl;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.crophub.rest.common.persistence.domain.TaxonomyRepository;
import org.crophub.rest.common.service.TaxonomyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class TaxonomyServiceImpl implements TaxonomyService {
@Autowired
private TaxonomyRepository taxonomyRepository;
@Override
public Taxonomy get(String genus, String species) {
return taxonomyRepository.getByGenusAndSpecies(genus, species);
}
}
package org.crophub.rest.servlet.controller;
import java.util.HashMap;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.genesys.Taxonomy;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.crophub.rest.common.service.GenesysService;
import org.crophub.rest.common.service.InstituteService;
import org.crophub.rest.common.service.TaxonomyService;
import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -21,17 +25,19 @@ public class WiewsController extends BaseController {
@Autowired
private InstituteService instituteService;
@Autowired
private GenesysService genesysService;
@Autowired
private TaxonomyService taxonomyService;
@RequestMapping("/")
public String view(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("faoInstitutes", instituteService.list(new PageRequest(page - 1, 50, new Sort("code"))));
return "/wiews/index";
}
@RequestMapping("/active")
public String viewGenesys(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("activeOnly", true);
......@@ -39,7 +45,6 @@ public class WiewsController extends BaseController {
return "/wiews/index";
}
@RequestMapping("/{wiewsCode}")
public String view(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
_logger.debug("Viewing country " + wiewsCode);
......@@ -48,16 +53,17 @@ public class WiewsController extends BaseController {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("countByInstitute", genesysService.countByInstitute(faoInstitute));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute));
return "/wiews/details";
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -72,4 +78,32 @@ public class WiewsController extends BaseController {
return "/wiews/data";
}
@RequestMapping("/{wiewsCode}/t/{genus}/{species}")
public String viewDataByGenusSpecies(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @PathVariable(value = "genus") String genus,
@PathVariable(value = "species") String species, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
// Taxonomy
Taxonomy taxonomy=taxonomyService.get(genus, species);
_logger.debug("Got "+ taxonomy);
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.taxonomy", taxonomy);
model.addAttribute("filters", filters);
_logger.warn("Searching accessions of: " + faoInstitute);
Page<Accession> accessions = genesysService.listAccessionsByInstituteAndTaxonomy(faoInstitute, taxonomy, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("accessions", accessions);
return "/wiews/data";
}
}
......@@ -95,7 +95,7 @@ country.page.profile.title=Country profile: {0}
country.page.list.title=Country list
country.page.not-current=This is a historic entry.
country.page.faoInstitutes={0} institutes registered in WIEWS
country.stat.countByLocation={0} accessions held by institutes in this country
country.stat.countByLocation={0} accessions at institutes in this country
country.stat.countByOrigin={0} accessions registered in Genesys come from this country.
country.statistics=Country statistics
country.accessions.from=Accessions collected in {0}
......@@ -106,7 +106,7 @@ faoInstitutes.stat.accessionCount=Accessions in Genesys: {0}.
faoInstitute.accessionCount={0} accessions in Genesys.
faoInstitute.statistics=Institute statistics
faoInstitutes.page.data.title=Accessions in {0}
faoInstitute.accessions.at=Accessions held at {0}
faoInstitute.accessions.at=Accessions at {0}
faoInstitutes.viewAll=View all registered institutes
faoInstitutes.viewActiveOnly=View institutes with accessions in Genesys
faoInstitute.no-accessions-registered=Please get in touch with us if you can facilitate in providing data from this institiute.
......@@ -149,3 +149,6 @@ selection.clear=Clear the list
selection.empty-list-warning=You have not added any accessions to the list.
selection.add-many=Check and add
selection.add-many.accessionIds=List accession IDs as used in Genesys separated by space or new line.
filter.taxonomy=Taxonomy
......@@ -15,6 +15,13 @@
<a href="<c:url value="/geo/${faoInstitute.country.code3.toLowerCase()}" />"><c:out value="${faoInstitute.country.name}" /></a>
</div> --%>
<c:if test="${filters ne null}">
<c:forEach items="${filters.keySet()}" var="by">
<div><spring:message code="${by}" />: <b>${filters[by].taxonName}</b></div>
</c:forEach>
</c:if>
<div class="nav-header">
<spring:message code="accessions.number" arguments="${accessions.totalElements}" />
<br />
......
......@@ -8,19 +8,21 @@
</head>
<body>
<h1>
<img class="country-flag bigger" src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" />
<img class="country-flag bigger" src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" />
<c:out value="${faoInstitute.fullName}" />
<small><c:out value="${faoInstitute.code}" /></small>
<small><c:out value="${faoInstitute.code}" /></small>
</h1>
<c:if test="${countByInstitute eq 0}">
<div class="alert"><spring:message code="faoInstitute.no-accessions-registered" /></div>
<div class="alert">
<spring:message code="faoInstitute.no-accessions-registered" />
</div>
</c:if>
<%-- <c:if test="${not faoInstitutes.current}">
<div class="alert"><spring:message code="faoInstitutes.page.not-current"/></div>
</c:if> --%>
<div>
<%-- <img src="http://genesys-pgr.org/images/flags/${faoInstitute.country.code3.toUpperCase()}.png" /> --%>
<a href="<c:url value="/geo/${faoInstitute.country.code3.toLowerCase()}" />"><c:out value="${faoInstitute.country.name}" /></a>
......@@ -41,9 +43,11 @@
<div>
<a href="<c:out value="${faoInstitute.url}" />"><c:out value="${faoInstitute.url}" /></a>
</div>
<h3><spring:message code="faoInstitute.statistics" /></h3>
<h3>
<spring:message code="faoInstitute.statistics" />
</h3>
<div>
<spring:message code="faoInstitutes.stat.accessionCount" arguments="${countByInstitute}" />
<c:if test="${countByInstitute gt 0}">
......@@ -51,5 +55,26 @@
</c:if>
</div>
<div class="clearfix" style="margin-top: 2em;">
<div class="pull-left" style="margin-right: 3em;">
<h4>By Genus</h4>
<ul class="funny-list statistics">
<c:forEach items="${statisticsGenus}" var="stat" varStatus="status">
<li><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <c:out value="${stat[0]}" /></li>
</c:forEach>
</ul>
</div>
<div class="pull-left" style="margin-right: 3em;">
<h4>By Species</h4>
<ul class="funny-list statistics">
<c:forEach items="${statisticsTaxonomy}" var="stat" varStatus="status">
<li><span class="stats-number"><fmt:formatNumber value="${stat[1]}" /></span> <a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}/t/${stat[0].genus}/${stat[0].species}" />"><c:out value="${stat[0].taxonName}" /></a></li>
</c:forEach>
</ul>
</div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -214,4 +214,13 @@ body {
.dropdown-menu {
background-color: #303030;
}
ul.statistics .stats-number {
display: inline-block;
text-align: right;
margin-left: 2em;
width: 4em;
float: right;
}
\ No newline at end of file
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