Commit 912417f5 authored by Matija Obreza's avatar Matija Obreza
Browse files

Crop descriptor categories, descriptor selection

parent b70f588c
......@@ -20,6 +20,7 @@ import java.util.List;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.impl.Crop;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
......@@ -32,4 +33,7 @@ public interface MethodRepository extends JpaRepository<Method, Long> {
@Query("select distinct m from Method m where m.id in ( ?1 )")
List<Method> findByIds(List<Long> oids);
@Query("select m from Method m where m.parameter.crop = ?1")
List<Method> findByCrop(Crop crop);
}
......@@ -16,15 +16,21 @@
package org.genesys2.server.persistence.domain;
import java.util.Collection;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.impl.Crop;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ParameterRepository extends JpaRepository<Parameter, Long> {
Page<Parameter> findByCrop(Crop crop, Pageable pageable);
Collection<? extends Parameter> findByCropAndCategory(Crop crop, ParameterCategory pc, Sort sort);
// List<Parameter> findAllByCategory(Category category);
}
......@@ -28,7 +28,7 @@ public interface GenesysFilterService {
Page<Accession> listAccessions(JsonNode jsonTree, Pageable pageable);
List<? extends GenesysFilter> listAvailableFilters();
List<GenesysFilter> listAvailableFilters();
public static interface GenesysFilter {
......
......@@ -16,13 +16,16 @@
package org.genesys2.server.service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -80,4 +83,12 @@ public interface TraitService {
Map<String, Long> getMethodStatistics(Method method);
List<ParameterCategory> listCategories();
Map<ParameterCategory, List<Parameter>> mapTraits(Crop crop, List<ParameterCategory> parameterCategories);
Map<Long, List<Method>> mapMethods(Crop crop);
Collection<GenesysFilter> generateFilters(List<Long> methodIds);
}
......@@ -53,7 +53,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
private static final Log LOG = LogFactory.getLog(GenesysFilterServiceImpl.class);
private ArrayList<GenesysFilterImpl> availableFilters;
private ArrayList<GenesysFilter> availableFilters;
@Autowired
private TraitValueRepository traitValueRepository;
......@@ -75,7 +75,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
public GenesysFilterServiceImpl() {
this.availableFilters = new ArrayList<GenesysFilterImpl>();
this.availableFilters = new ArrayList<GenesysFilter>();
// "origin", "institute", "lat", "lon", "alt", "genus"
this.availableFilters.add(new GenesysFilterImpl("origin", FilterType.FIXEDSTRING, 3));
this.availableFilters.add(new GenesysFilterImpl("institute", FilterType.FIXEDSTRING, 6));
......@@ -92,7 +92,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
@Override
public List<? extends GenesysFilter> listAvailableFilters() {
public List<GenesysFilter> listAvailableFilters() {
return Collections.unmodifiableList(this.availableFilters);
}
......
......@@ -24,6 +24,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
......@@ -50,6 +51,7 @@ import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.genesys.TraitCode;
......@@ -73,19 +75,25 @@ import org.genesys2.server.persistence.domain.MetadataMethodRepository;
import org.genesys2.server.persistence.domain.MetadataRepository;
import org.genesys2.server.persistence.domain.MethodRepository;
import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.persistence.domain.ParameterCategoryRepository;
import org.genesys2.server.persistence.domain.ParameterRepository;
import org.genesys2.server.persistence.domain.SvalbardRepository;
import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.security.AuthUserDetails;
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter;
import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.repository.query.Param;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -155,6 +163,9 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Autowired
private AccessionAliasRepository accessionAliasRepository;
@Autowired
private ParameterCategoryRepository parameterCategoryRepository;
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
......@@ -1133,4 +1144,54 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
} else
return null;
}
@Override
public List<ParameterCategory> listCategories() {
return parameterCategoryRepository.findAll(new Sort(new Order(Direction.ASC, "id")));
}
@Override
public Map<ParameterCategory, List<Parameter>> mapTraits(Crop crop, List<ParameterCategory> parameterCategories) {
if (parameterCategories == null || parameterCategories.size() == 0)
return null;
HashMap<ParameterCategory, List<Parameter>> catTraits = new HashMap<ParameterCategory, List<Parameter>>();
for (ParameterCategory pc : parameterCategories) {
ArrayList<Parameter> traits;
catTraits.put(pc, traits = new ArrayList<Parameter>());
traits.addAll(parameterRepository.findByCropAndCategory(crop, pc, new Sort(new Order("title"))));
}
return catTraits;
}
@Override
public Map<Long, List<Method>> mapMethods(Crop crop) {
HashMap<Long, List<Method>> paramMethods = new HashMap<Long, List<Method>>();
for (Method method : methodRepository.findByCrop(crop)) {
List<Method> list = paramMethods.get(method.getParameter().getId());
if (list == null) {
paramMethods.put(method.getParameter().getId(), list = new ArrayList<Method>());
}
list.add(method);
}
return paramMethods;
}
@Override
public Collection<GenesysFilter> generateFilters(List<Long> methodIds) {
List<GenesysFilter> filters = new ArrayList<GenesysFilter>();
for (long methodId : methodIds) {
Method method = methodRepository.findOne(methodId);
if (method == null) {
continue;
}
filters.add(new GenesysFilterServiceImpl.GenesysFilterImpl("gm:" + method.getId(),
method.getFieldType() == 1 || method.getFieldType() == 2 ? FilterType.NUMERIC : FilterType.STRING));
}
return filters;
}
}
......@@ -16,12 +16,17 @@
package org.genesys2.server.servlet.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TraitService;
import org.genesys2.spring.ResourceNotFoundException;
......@@ -54,6 +59,9 @@ public class CropController extends BaseController {
@Autowired
private TraitService traitService;
@Autowired
private GenesysFilterService filterService;
@RequestMapping("/{shortName}")
public String view(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.debug("Viewing crop " + shortName);
......@@ -114,6 +122,40 @@ public class CropController extends BaseController {
return "/accession/data";
}
@RequestMapping(value = "/{shortName}/data/descriptors", method = RequestMethod.GET)
public String viewDescriptors(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.warn("Viewing crop descriptors " + shortName);
Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("crop", crop);
List<ParameterCategory> parameterCategories = traitService.listCategories();
model.addAttribute("categories", parameterCategories);
model.addAttribute("descriptors", traitService.mapTraits(crop, parameterCategories));
model.addAttribute("methods", traitService.mapMethods(crop));
return "/filter/cropdescriptors";
}
@RequestMapping(value = "/{shortName}/data/descriptors", method = RequestMethod.POST)
public String selectDescriptors(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("methods") List<Long> methodIds) {
_logger.warn("Viewing crop descriptors " + shortName);
Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
// What filters do we support?
List<GenesysFilter> availableFilters = new ArrayList<GenesysFilter>();
availableFilters.addAll(filterService.listAvailableFilters());
availableFilters.addAll(traitService.generateFilters(methodIds));
model.addAttribute("availableFilters", availableFilters);
return "/filter/index";
}
@RequestMapping("/{shortName}/descriptors")
public String viewDescriptors(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="filters.page.title" /></title>
</head>
<body>
<h1><spring:message code="filters.view" /></h1>
<form method="post" action="">
<div id="allfilters">
<c:forEach items="${categories}" var="category">
<c:if test="${descriptors[category].size() gt 0}">
<h2><c:out value="${crop.getName(pageContext.request.locale)}:" /> <c:out value="${category.getName(pageContext.request.locale)}" /></h2>
<c:forEach items="${descriptors[category]}" var="descriptor">
<c:if test="${methods[descriptor.id].size() gt 0}">
<div class="row filter-block">
<div class="col-lg-3">
<div dir="ltr"><c:out value="${descriptor.title}" /></div>
</div>
<div class="col-lg-9">
<c:forEach items="${methods[descriptor.id]}" var="method">
<div><label><input type="checkbox" style="margin-right: 1em;" name="methods" value="${method.id}" /><span dir="ltr"><c:out value="${method.method}" /></span></label></div>
</c:forEach>
</div>
</div>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
<div class="clearfix">
<a id="filtersHref" href=""><button class="btn btn-green pull-left">View!</button></a>
</div>
</div>
</form>
</body>
</html>
\ No newline at end of file
......@@ -14,7 +14,7 @@
<div class="clearfix filter-block">
<div class="pull-left filter-name"><spring:message code="filter.${filter.name}" /></div>
<div class="pull-left" id="filter-${filter.name}">
<div class="pull-left" id="filter-${filter.name.replace(':', '_')}">
<c:choose>
<c:when test="${filter.type=='NUMERIC'}">
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span1 form-control" type="text" /><input class="span1 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
......@@ -44,7 +44,10 @@
<script type="text/javascript">
jQuery(document).ready(function() {
// alert('${jsonString}');
var filters=$.parseJSON('${jsonString}');
var filters={};
try {
// filters=$.parseJSON('${jsonString}');
} catch (e) {filters={}; console.error(e);}
// debugger;
console.log("Filters: " +JSON.stringify(filters));
......@@ -82,7 +85,7 @@ jQuery(document).ready(function() {
},
addFilterValue: function(element) {
var name=$(element).closest(".clearfix").attr("x-filtername");
var name=$(element).closest(".clearfix").attr("x-filtername").replace('_',':');
//debugger;
var a=null, b=null;
var inputs=$(element).parent().children("input");
......@@ -147,7 +150,7 @@ jQuery(document).ready(function() {
}
};
[<c:forEach items="${availableFilters}" var="filter" varStatus="status">${status.index gt 0 ? ',' : ''} "${filter.name}"</c:forEach> ].forEach(function(name) {
[<c:forEach items="${availableFilters}" var="filter" varStatus="status">${status.index gt 0 ? ',' : ''} "${filter.name.replace(':','_')}"</c:forEach> ].forEach(function(name) {
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
});
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="filters.page.title" /></title>
</head>
<body>
<h1><spring:message code="filters.view" /></h1>
<div id="allfilters">
<c:forEach items="${categories}" var="category">
<c:if test="${descriptors[category].size() gt 0}">
<h2><c:out value="${crop.getName(pageContext.request.locale)}:" /> <c:out value="${category.getName(pageContext.request.locale)}" /></h2>
<c:forEach items="${descriptors[category]}" var="descriptor">
<c:if test="${methods[descriptor.id].size() gt 0}">
<div class="row filter-block">
<div class="col-lg-3">
<div dir="ltr"><c:out value="${descriptor.title}" /></div>
</div>
<div class="col-lg-9">
<c:forEach items="${methods[descriptor.id]}" var="method">
<div><label><input type="checkbox" style="margin-right: 1em;" name="methods" value="gm:${method.id}" /><span dir="ltr"><c:out value="${method.method}" /></span></label></div>
</c:forEach>
</div>
</div>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
<div class="clearfix">
<a id="filtersHref" href=""><button class="btn btn-green pull-left">View!</button></a>
</div>
</div>
</body>
</html>
\ 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