Commit 5a77ee81 authored by Matija Obreza's avatar Matija Obreza
Browse files

Accession data of countries and institutes

parent 7c839fcc
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/country/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/index.jsp=UTF-8 encoding//src/main/webapp/WEB-INF/jsp/wiews/index.jsp=UTF-8
encoding//src/test/resources=UTF-8 encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
...@@ -36,7 +36,7 @@ import org.crophub.rest.common.model.impl.FaoInstitute; ...@@ -36,7 +36,7 @@ import org.crophub.rest.common.model.impl.FaoInstitute;
public class Accession implements java.io.Serializable { public class Accession implements java.io.Serializable {
private static final long serialVersionUID = -7630113633534038876L; private static final long serialVersionUID = -7630113633534038876L;
private Long id; private Long id;
// private String instituteCode; private String instituteCode;
private FaoInstitute institute; private FaoInstitute institute;
private String accNumbHi; private String accNumbHi;
private Taxonomy taxonomy; private Taxonomy taxonomy;
...@@ -68,7 +68,7 @@ public class Accession implements java.io.Serializable { ...@@ -68,7 +68,7 @@ public class Accession implements java.io.Serializable {
} }
@ManyToOne(cascade = {}, optional = false) @ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "Institute", referencedColumnName="code", nullable = false) @JoinColumn(name = "instituteId", nullable = false)
public FaoInstitute getInstitute() { public FaoInstitute getInstitute() {
return this.institute; return this.institute;
} }
...@@ -77,14 +77,14 @@ public class Accession implements java.io.Serializable { ...@@ -77,14 +77,14 @@ public class Accession implements java.io.Serializable {
this.institute = institute; this.institute = institute;
} }
// @Column(name = "Institute", length = 6) @Column(name = "Institute", length = 6)
// public String getInstituteCode() { public String getInstituteCode() {
// return instituteCode; return instituteCode;
// } }
//
// public void setInstituteCode(final String instituteCode) { public void setInstituteCode(final String instituteCode) {
// this.instituteCode = instituteCode; this.instituteCode = instituteCode;
// } }
@Column(name = "ACC_Numb_HI", nullable = false, length = 128) @Column(name = "ACC_Numb_HI", nullable = false, length = 128)
public String getAccessionName() { public String getAccessionName() {
......
...@@ -26,7 +26,7 @@ import javax.persistence.Table; ...@@ -26,7 +26,7 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
@Entity @Entity
@Table(name = "taxonomy", uniqueConstraints = { @UniqueConstraint(columnNames = { @Table(name = "all_taxonomy", uniqueConstraints = { @UniqueConstraint(columnNames = {
"genus", "species" }) }) "genus", "species" }) })
public class Taxonomy implements java.io.Serializable { public class Taxonomy implements java.io.Serializable {
...@@ -49,7 +49,7 @@ public class Taxonomy implements java.io.Serializable { ...@@ -49,7 +49,7 @@ public class Taxonomy implements java.io.Serializable {
@Id @Id
@GeneratedValue @GeneratedValue
@Column(unique = true, nullable = false) @Column(name="Taxon_Code", unique = true, nullable = false)
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
...@@ -76,7 +76,7 @@ public class Taxonomy implements java.io.Serializable { ...@@ -76,7 +76,7 @@ public class Taxonomy implements java.io.Serializable {
this.species = species; this.species = species;
} }
@Column(nullable = false, length = 128) @Column(name="Taxon_Name", nullable = false, length = 128)
public String getTaxonName() { public String getTaxonName() {
return this.taxonName; return this.taxonName;
} }
......
...@@ -47,19 +47,18 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable { ...@@ -47,19 +47,18 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable {
private String email; private String email;
private String acronym; private String acronym;
private Country country; private Country country;
private long accessionCount;
public FaoInstitute() { public FaoInstitute() {
} }
public FaoInstitute(final String institute, final String fullName, public FaoInstitute(final String institute, final String fullName, final String email) {
final String email) {
this.code = institute; this.code = institute;
this.fullName = fullName; this.fullName = fullName;
this.email = email; this.email = email;
} }
public FaoInstitute(final String institute, final String fullName, public FaoInstitute(final String institute, final String fullName, final String type, final String url, final String email) {
final String type, final String url, final String email) {
this.code = institute; this.code = institute;
this.fullName = fullName; this.fullName = fullName;
this.type = type; this.type = type;
...@@ -124,9 +123,7 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable { ...@@ -124,9 +123,7 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable {
@Override @Override
public String toString() { public String toString() {
return MessageFormat.format( return MessageFormat.format("FaoInst id={0,number,#} code={1} fullName={2}", id, code, fullName);
"FaoInst id={0,number,#} code={1} fullName={2}", id, code,
fullName);
} }
@Column(length = 50) @Column(length = 50)
...@@ -147,4 +144,13 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable { ...@@ -147,4 +144,13 @@ public class FaoInstitute extends GeoEntity implements java.io.Serializable {
public void setCountry(final Country country) { public void setCountry(final Country country) {
this.country = country; this.country = country;
} }
public long getAccessionCount() {
return accessionCount;
}
public void setAccessionCount(long accessionCount) {
this.accessionCount = accessionCount;
}
} }
...@@ -58,5 +58,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> { ...@@ -58,5 +58,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a.taxonomy, count(a) as total from Accession a where a.genus in ( ?1 ) group by a.taxonomy order by total desc") @Query("select a.taxonomy, count(a) as total from Accession a where a.genus in ( ?1 ) group by a.taxonomy order by total desc")
List<Object[]> statisticsTaxonomy(List<String> genus); List<Object[]> statisticsTaxonomy(List<String> genus);
List<Accession> findByOrigin(String origin); // List<Accession> findByOrigin(String origin);
Page<Accession> findByOrigin(String isoCode3, Pageable pageable);
} }
...@@ -32,4 +32,7 @@ public interface FaoInstituteRepository extends ...@@ -32,4 +32,7 @@ public interface FaoInstituteRepository extends
List<String> findTypes(); List<String> findTypes();
List<FaoInstitute> findByCountry(Country country, Sort sort); List<FaoInstitute> findByCountry(Country country, Sort sort);
@Query("from FaoInstitute fi where fi.country = ?1 and fi.accessionCount > 0")
List<FaoInstitute> findByCountryActive(Country country, Sort sort);
} }
package org.crophub.rest.common.service; package org.crophub.rest.common.service;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute; import org.crophub.rest.common.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface GenesysService { public interface GenesysService {
...@@ -10,4 +14,8 @@ public interface GenesysService { ...@@ -10,4 +14,8 @@ public interface GenesysService {
long countByLocation(String isoCode3); long countByLocation(String isoCode3);
Page<Accession> listAccessionsByOrigin(Country country, Pageable pageable);
Page<Accession> listAccessionsByInstitute(FaoInstitute faoInstitute, Pageable pageable);
} }
...@@ -37,4 +37,6 @@ public interface InstituteService { ...@@ -37,4 +37,6 @@ public interface InstituteService {
List<FaoInstitute> listByCountry(Country country); List<FaoInstitute> listByCountry(Country country);
List<FaoInstitute> listByCountryActive(Country country);
} }
package org.crophub.rest.common.service.impl; package org.crophub.rest.common.service.impl;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute; import org.crophub.rest.common.model.impl.FaoInstitute;
import org.crophub.rest.common.persistence.domain.AccessionRepository; import org.crophub.rest.common.persistence.domain.AccessionRepository;
import org.crophub.rest.common.persistence.domain.MethodRepository; import org.crophub.rest.common.persistence.domain.MethodRepository;
import org.crophub.rest.common.service.GenesysService; import org.crophub.rest.common.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -36,4 +40,14 @@ public class GenesysServiceImpl implements GenesysService { ...@@ -36,4 +40,14 @@ public class GenesysServiceImpl implements GenesysService {
public long countByLocation(String isoCode3) { public long countByLocation(String isoCode3) {
return accessionRepository.countByLocation(isoCode3); return accessionRepository.countByLocation(isoCode3);
} }
@Override
public Page<Accession> listAccessionsByOrigin(Country country, Pageable pageable) {
return accessionRepository.findByOrigin(country.getCode3(), pageable);
}
@Override
public Page<Accession> listAccessionsByInstitute(FaoInstitute faoInstitute, Pageable pageable) {
return accessionRepository.findByInstitute(faoInstitute, pageable);
}
} }
...@@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -76,6 +77,12 @@ public class InstituteServiceImpl implements InstituteService { ...@@ -76,6 +77,12 @@ public class InstituteServiceImpl implements InstituteService {
return instituteRepository.findByCountry(country, new Sort("code")); return instituteRepository.findByCountry(country, new Sort("code"));
} }
@Override
public List<FaoInstitute> listByCountryActive(Country country) {
return instituteRepository.findByCountryActive(country, new Sort(Direction.DESC, "accessionCount", "code"));
}
/** /**
* Update local FaoInstitute with data from WIEWS database * Update local FaoInstitute with data from WIEWS database
* *
......
...@@ -6,10 +6,13 @@ import org.crophub.rest.common.service.GeoService; ...@@ -6,10 +6,13 @@ import org.crophub.rest.common.service.GeoService;
import org.crophub.rest.common.service.InstituteService; import org.crophub.rest.common.service.InstituteService;
import org.crophub.spring.ResourceNotFoundException; import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller @Controller
@RequestMapping("/geo") @RequestMapping("/geo")
...@@ -23,8 +26,7 @@ public class CountryController extends BaseController { ...@@ -23,8 +26,7 @@ public class CountryController extends BaseController {
@Autowired @Autowired
private GenesysService genesysService; private GenesysService genesysService;
@RequestMapping @RequestMapping
public String view(ModelMap model) { public String view(ModelMap model) {
model.addAttribute("countries", geoService.listAll()); model.addAttribute("countries", geoService.listAll());
...@@ -40,12 +42,29 @@ public class CountryController extends BaseController { ...@@ -40,12 +42,29 @@ public class CountryController extends BaseController {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
model.addAttribute("country", country); model.addAttribute("country", country);
// All institutes
model.addAttribute("faoInstitutes", instituteService.listByCountry(country)); model.addAttribute("faoInstitutes", instituteService.listByCountry(country));
// Active ones
model.addAttribute("genesysInstitutes", instituteService.listByCountryActive(country));
model.addAttribute("countByOrigin", genesysService.countByOrigin(country.getCode3())); model.addAttribute("countByOrigin", genesysService.countByOrigin(country.getCode3()));
model.addAttribute("countByLocation", genesysService.countByLocation(country.getCode3())); model.addAttribute("countByLocation", genesysService.countByLocation(country.getCode3()));
return "/country/details"; return "/country/details";
} }
@RequestMapping("/{country}/data")
public String viewData(ModelMap model, @PathVariable(value = "country") String countryStr, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + countryStr);
Country country = geoService.getCountry(countryStr);
if (country==null) {
throw new ResourceNotFoundException();
}
model.addAttribute("country", country);
model.addAttribute("accessions", genesysService.listAccessionsByOrigin(country, new PageRequest(page - 1, 50, new Sort("accessionName"))));
return "/country/data";
}
} }
package org.crophub.rest.servlet.controller; package org.crophub.rest.servlet.controller;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.impl.FaoInstitute; import org.crophub.rest.common.model.impl.FaoInstitute;
import org.crophub.rest.common.service.GenesysService; import org.crophub.rest.common.service.GenesysService;
import org.crophub.rest.common.service.InstituteService; import org.crophub.rest.common.service.InstituteService;
import org.crophub.spring.ResourceNotFoundException; import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -43,4 +45,22 @@ public class WiewsController extends BaseController { ...@@ -43,4 +45,22 @@ public class WiewsController extends BaseController {
return "/wiews/details"; 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) {
_logger.debug("Viewing country " + wiewsCode);
FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
_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("accessions", accessions);
return "/wiews/data";
}
} }
...@@ -83,10 +83,31 @@ country.page.profile.title=Country profile: {0} ...@@ -83,10 +83,31 @@ country.page.profile.title=Country profile: {0}
country.page.list.title=Country list country.page.list.title=Country list
country.page.not-current=This is a historic entry. country.page.not-current=This is a historic entry.
country.page.faoInstitutes=Organizations registered in WIEWS country.page.faoInstitutes=Organizations registered in WIEWS
country.stat.countByLocation={0} accessions held by institutes in this country. country.stat.countByLocation={0} accessions held by institutes in this country
country.stat.countByOrigin={0} accessions registered in Genesys come from this country. country.stat.countByOrigin={0} accessions registered in Genesys come from this country.
country.statistics=Country statistics country.statistics=Country statistics
country.accessions.from=Accessions collected in {0}
faoInstitutes.page.list.title=WIEWS Institutes faoInstitutes.page.list.title=WIEWS Institutes
faoInstitutes.page.profile.title=WIEWS {0} faoInstitutes.page.profile.title=WIEWS {0}
faoInstitutes.stat.accessionCount=Accessions in Genesys: {0}. 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}
view.accessions=View accessions...
paged.pageOfPages=Page {0} of {1}
accessions.number={0} accessions
accession.accessionName=Accession
accession.origin=Country of origin
accession.holdingInstitute=Holding institute
accession.holdingCountry=Location
accession.taxonomy=Taxonomy
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="country.page.profile.title" arguments="${country.name}" argumentSeparator="|" /></title>
</head>
<body>
<c:if test="${country eq null}">
<div class="alert alert-error">
<spring:message code="data.error.404" />
</div>
</c:if>
<h1>
<spring:message code="country.accessions.from" arguments="${country.name}" />
</h1>
<a href="<c:url value="/geo/${country.code3.toLowerCase()}" />"><c:out value="${country.name}" /></a>
<div class="nav-header">
<spring:message code="accessions.number" arguments="${accessions.totalElements}" />
<br />
<spring:message code="paged.pageOfPages" arguments="${accessions.number+1},${accessions.totalPages}" />
<a href="?page=${accessions.number}">⇇ Previous</a>
<a href="?page=${accessions.number + 2}">Next ⇉</a>
</div>
<table>
<thead>
<tr>
<td><spring:message code="accession.accessionName" /></td>
<td><spring:message code="accession.origin" /></td>
<td><spring:message code="accession.taxonomy" /></td>
<td><spring:message code="accession.holdingInstitute" /></td>
<td><spring:message code="accession.holdingCountry" /></td>
</tr>
</thead>
<tbody>
<c:forEach items="${accessions.content}" var="accession" varStatus="status">
<tr>
<td><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.accessionName}" /></b></a></td>
<td><c:out value="${country.name}" /></td>
<td><c:out value="${accession.taxonomy.taxonName}" /></td>
<td><a href="<c:url value="/wiews/${accession.institute.code.toLowerCase()}" />"><c:out value="${accession.institute.code}" /></a></td>
<td><a href="<c:url value="/geo/${accession.institute.country.code3.toLowerCase()}" />"><c:out value="${accession.institute.country.name}" /></a></td>
</tr>
</c:forEach>
</tbody>
</table>
<div class="nav-header">
<a href="?page=${accessions.number}">⇇ Previous</a> <a href="?page=${accessions.number + 2}">Next ⇉</a>
</div>
</body>
</html>
\ No newline at end of file
...@@ -24,13 +24,22 @@ ...@@ -24,13 +24,22 @@
<c:out value="${country.code2}" /> <c:out value="${country.code2}" />
</div> </div>
<h2><spring:message code="country.statistics" /></h2> <h3><spring:message code="country.statistics" /></h3>
<div><spring:message code="country.stat.countByOrigin" arguments="${countByOrigin}" /></div> <div>
<div><spring:message code="country.stat.countByLocation" arguments="${countByLocation}" /></div> <spring:message code="country.stat.countByOrigin" arguments="${countByOrigin}" />
<a href="<c:url value="/geo/${country.code3.toLowerCase()}/data" />"><spring:message code="view.accessions" /></a>
<h3> </div>
<h3><spring:message code="country.stat.countByLocation" arguments="${countByLocation}" /></h3>
<ul>
<c:forEach items="${genesysInstitutes}" var="faoInstitute" varStatus="status">
<li><a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}" />"><b><c:out value="${faoInstitute.code}" /></b> <c:out value="${faoInstitute.fullName}" /></a> <spring:message code="faoInstitute.accessionCount" arguments="${faoInstitute.accessionCount}" /></li>
</c:forEach>
</ul>
<h4>
<spring:message code="country.page.faoInstitutes" /> <spring:message code="country.page.faoInstitutes" />
</h3> </h4>
<ul> <ul>
<c:forEach items="${faoInstitutes}" var="faoInstitute" varStatus="status"> <c:forEach items="${faoInstitutes}" var="faoInstitute" varStatus="status">
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="faoInstitutes.page.data.title" arguments="${faoInstitute.code}" argumentSeparator="|" /></title>
</head>
<body>
<h1>
<spring:message code="faoInstitute.accessions.at" arguments="${faoInstitute.fullName}" argumentSeparator="||," />
</h1>
<div>
<spring:message code="accessions.number" arguments="${accessions.totalElements}" />
</div>
<div>
<a href="<c:url value="/geo/${faoInstitute.country.code3.toLowerCase()}" />"><c:out value="${faoInstitute.country.name}" /></a>
</div>