Commit 589831b8 authored by Matija Obreza's avatar Matija Obreza
Browse files

Crop descriptors

parent c82d9bbb
......@@ -17,10 +17,14 @@
package org.crophub.rest.common.persistence.domain;
import org.crophub.rest.common.model.genesys.Parameter;
import org.crophub.rest.common.model.impl.Crop;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ParameterRepository extends JpaRepository<Parameter, Long> {
// List<Parameter> findAllByCrop(Crop crop);
//
Page<Parameter> findByCrop(Crop crop, Pageable pageable);
// List<Parameter> findAllByCategory(Category category);
}
......@@ -5,6 +5,7 @@ import java.util.List;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.genesys.Parameter;
import org.crophub.rest.common.model.impl.Crop;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -12,6 +13,8 @@ public interface TraitService {
Page<Parameter> listTraits(Pageable pageable);
Page<Parameter> listTraits(Crop crop, Pageable pageable);
Parameter getTrait(long traitId);
List<Method> getTraitMethods(Parameter trait);
......
......@@ -240,6 +240,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
return parameterRepository.findAll(pageable);
}
@Override
public Page<Parameter> listTraits(Crop crop, Pageable pageable) {
return parameterRepository.findByCrop(crop, pageable);
}
@Override
public Parameter getTrait(long traitId) {
return parameterRepository.findOne(traitId);
......
......@@ -14,7 +14,6 @@
* limitations under the License.
**/
package org.crophub.rest.servlet.controller;
import java.util.HashMap;
......@@ -23,6 +22,7 @@ import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.impl.Crop;
import org.crophub.rest.common.service.CropService;
import org.crophub.rest.common.service.GenesysService;
import org.crophub.rest.common.service.TraitService;
import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
......@@ -43,13 +43,16 @@ public class CropController extends BaseController {
@Autowired
private SelectionBean selectionBean;
@Autowired
private CropService cropService;
@Autowired
private GenesysService genesysService;
@Autowired
private TraitService traitService;
@RequestMapping("/{shortName}")
public String view(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.debug("Viewing crop " + shortName);
......@@ -89,7 +92,21 @@ public class CropController extends BaseController {
model.addAttribute("accessions", accessions);
model.addAttribute("selection", selectionBean);
return "/accession/data";
}
@RequestMapping("/{shortName}/descriptors")
public String viewDescriptors(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing crop " + shortName);
Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("crop", crop);
model.addAttribute("traits", traitService.listTraits(crop, new PageRequest(page - 1, 50, new Sort("title"))));
return "/descr/index";
}
}
......@@ -99,6 +99,7 @@ user.create-new-account=Create an account
crop.croplist=Crop list
crop.page.profile.title={0} profile
crop.taxonomy-rules=Taxonomic rules
crop.view-descriptors=View crop descriptors...
activity.recent-activity=Recent activity
......
......@@ -25,7 +25,7 @@
${filters[by].taxonName}
</c:when>
<c:when test="${clazz eq 'Crop'}">
${filters[by].name}
<a href="<c:url value="/c/${filters[by].shortName}" />">${filters[by].name}</a>
</c:when>
<c:when test="${clazz eq 'Country'}">
<a href="<c:url value="/geo/${filters[by].code3.toLowerCase()}" />"><c:out value="${filters[by].name}" /></a>
......
......@@ -20,6 +20,13 @@
<div class="free-text">
<c:out value="${crop.description}" />
</div>
<div>
<a href="<c:url value="/c/${crop.shortName}/data" />"><spring:message code="view.accessions" /></a>
</div>
<div>
<a href="<c:url value="/c/${crop.shortName}/descriptors" />"><spring:message code="crop.view-descriptors" /></a>
</div>
<h4><spring:message code="crop.taxonomy-rules" /></h4>
<ul class="funny-list">
......@@ -34,7 +41,6 @@
</div>
--%>
<a href="<c:url value="/c/${crop.shortName}/data" />"><spring:message code="view.accessions" /></a>
<h3><spring:message code="taxonomy-list" /></h3>
<ul class="funny-list">
......
......@@ -8,7 +8,7 @@
</head>
<body>
<h1><c:out value="${trait.title}" /></h1>
<div><a href="<c:url value="/c/${trait.crop.shortName}" />">${trait.crop.name}</a> trait</div>
<div><a href="<c:url value="/c/${trait.crop.shortName}" />/descriptors">${trait.crop.name}</a> trait</div>
<h4>Methods</h4>
<table>
......
......@@ -7,7 +7,11 @@
<title><spring:message code="metadata.page.title" /></title>
</head>
<body>
<c:if test="${crop ne null}">
<div>
<spring:message code="filter.crop" />: <b><a href="<c:url value="/c/${crop.shortName}" />">${crop.name}</a></b>
</div>
</c:if>
<div class="nav-header">
<spring:message code="paged.totalElements" arguments="${traits.totalElements}" />
<br />
......
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