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

Crop filtering, add "jsonFilter" in country, wiews, crop controllers

parent 3dec5ce0
......@@ -61,6 +61,8 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
this.availableFilters.add(new GenesysFilterImpl("lon", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("alt", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("genus", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("taxon", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("crop", FilterType.STRING));
}
@Override
......@@ -79,9 +81,11 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
List<Object> params = new ArrayList<Object>();
StringBuffer sb = new StringBuffer();
sb.append(" from accession a ");
if (jsonTree.has("genus")) {
if (jsonTree.has("crop") || jsonTree.has("genus") || jsonTree.has("taxon")) {
sb.append(" inner join all_taxonomy t on t.Taxon_Code=a.Taxon_Code ");
if (jsonTree.has("crop")) {
sb.append(" inner join croptaxonomy ct on ct.taxonomyId=t.Taxon_Code inner join crop on crop.id=ct.cropId ");
}
}
if (jsonTree.has("lat") || jsonTree.has("lon") || jsonTree.has("alt")) {
sb.append(" inner join all_environment env on env.ALIS_Id=a.id ");
......@@ -90,14 +94,16 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
createQuery(sb, "a.Origin", jsonTree.get("origin"), params);
createQuery(sb, "a.Institute", jsonTree.get("institute"), params);
createQuery(sb, "t.Genus", jsonTree.get("genus"), params);
createQuery(sb, "t.Taxon_Name", jsonTree.get("taxon"), params);
createQuery(sb, "env.LongitudeD", jsonTree.get("lon"), params);
createQuery(sb, "env.LatitudeD", jsonTree.get("lat"), params);
createQuery(sb, "env.Altitude", jsonTree.get("alt"), params);
createQuery(sb, "crop.shortName", jsonTree.get("crop"), params);
LOG.info("Parameter count: " + params.size());
LOG.info("Count query:\n" + sb.toString());
Long totalCount = this.jdbcTemplate.queryForObject("select count(a.id) " + sb.toString(), params.toArray(), Long.class);
Long totalCount = this.jdbcTemplate.queryForObject("select distinct count(a.id) " + sb.toString(), params.toArray(), Long.class);
LOG.info("Total count: " + totalCount);
......@@ -130,7 +136,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// Object[] {}, new BeanPropertyRowMapper<Accession>(Accession.class));
LOG.info("Getting IDs");
List<Long> results = this.jdbcTemplate.queryForList("select a.id " + sb.toString(), params.toArray(), Long.class);
List<Long> results = this.jdbcTemplate.queryForList("select distinct a.id " + sb.toString(), params.toArray(), Long.class);
LOG.info("Getting accessions");
return new PageImpl<Accession>(results.size() == 0 ? new ArrayList<Accession>() : accessionRepository.listById(results), pageable, totalCount);
......
......@@ -144,7 +144,8 @@ public class AccessionController extends BaseController {
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("selection", selectionBean);
model.addAttribute("jsonFilter", "{\"taxon\":[\"" + taxonomy.getTaxonName() + "\"]}");
return "/accession/data";
}
......
......@@ -94,7 +94,8 @@ public class CountryController extends BaseController {
filters.put("filter.countryOfOrigin", country);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"origin\":[\"" + country.getCode3() + "\"]}");
return "/accession/data";
}
}
......@@ -92,6 +92,7 @@ public class CropController extends BaseController {
model.addAttribute("pagedData", accessions);
model.addAttribute("selection", selectionBean);
model.addAttribute("jsonFilter", "{\"crop\":[\"" + crop.getShortName() + "\"]}");
return "/accession/data";
}
......
......@@ -14,7 +14,6 @@
* limitations under the License.
**/
package org.crophub.rest.servlet.controller;
import java.util.HashMap;
......@@ -44,7 +43,7 @@ public class WiewsController extends BaseController {
@Autowired
private SelectionBean selectionBean;
@Autowired
private InstituteService instituteService;
......@@ -91,7 +90,7 @@ public class WiewsController extends BaseController {
if (faoInstitute == null) {
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);
......@@ -102,11 +101,11 @@ public class WiewsController extends BaseController {
filters.put("filter.holdingInstitute", faoInstitute);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"institute\":[\"" + faoInstitute.getCode() + "\"]}");
return "/accession/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) {
......@@ -118,11 +117,12 @@ public class WiewsController extends BaseController {
model.addAttribute("faoInstitute", faoInstitute);
// Taxonomy
Taxonomy taxonomy=taxonomyService.get(genus, species);
_logger.debug("Got "+ taxonomy);
Taxonomy taxonomy = taxonomyService.get(genus, species);
_logger.debug("Got " + taxonomy);
_logger.warn("Searching accessions of: " + faoInstitute);
Page<Accession> accessions = genesysService.listAccessionsByInstituteAndTaxonomy(faoInstitute, taxonomy, new PageRequest(page - 1, 50, new Sort("accessionName")));
Page<Accession> accessions = genesysService.listAccessionsByInstituteAndTaxonomy(faoInstitute, taxonomy, new PageRequest(page - 1, 50, new Sort(
"accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
......@@ -133,7 +133,8 @@ public class WiewsController extends BaseController {
filters.put("filter.holdingInstitute", faoInstitute);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"institute\":[\"" + faoInstitute.getCode() + "\"],\"taxon\":[\"" + taxonomy.getTaxonName() + "\"]}");
return "/accession/data";
}
......
......@@ -181,6 +181,8 @@ selection.add-many.accessionIds=List accession IDs as used in Genesys separated
filters.page.title=Data filters
filters.view=Current filters
filters.data-is-filtered=The data is filtered.
filters.modify-filters=View & Modify filters
filter.taxonomy=Taxonomy
filter.crop=Crop
filter.countryOfOrigin=Country of Origin
......@@ -191,6 +193,7 @@ filter.lat=Latitude
filter.lon=Longitude
filter.alt=Altitude
filter.genus=Genus
filter.taxon=Taxonomy name
search.page.title=Full-text Search
search.no-results=No matches found for your query.
......
......@@ -9,6 +9,6 @@
<li><a href="<c:url value="/geo/" />"><spring:message code="menu.countries" /></a></li>
<li><a href="<c:url value="/wiews/active" />"><spring:message code="menu.institutes" /></a></li>
<li><a href="<c:url value="/sel/" />"><spring:message code="menu.my-list" />
<div id="selcounter">${selection.size() gt 0 ? selection.size() : ''}</div></a></li>
<sup id="selcounter">${selection.size() gt 0 ? selection.size() : ''}</sup></a></li>
</ul>
</div>
\ No newline at end of file
......@@ -11,9 +11,12 @@
<spring:message code="accession.page.data.title" />
</h1>
<%-- <div>
<a href="<c:url value="/geo/${faoInstitute.country.code3.toLowerCase()}" />"><c:out value="${faoInstitute.country.name}" /></a>
</div> --%>
<c:if test="${jsonFilter ne null}">
<div class="clearfix filter-block">
<spring:message code="filters.data-is-filtered" />
<a href="<spring:url value="/acn/filter"><spring:param name="filter" value="${jsonFilter}" /></spring:url>"><spring:message code="filters.modify-filters" /></a>
</div>
</c:if>
<c:if test="${filters ne null}">
<c:forEach items="${filters.keySet()}" var="by">
......@@ -43,14 +46,6 @@
</c:forEach>
</c:if>
<c:if test="${jsonFilter ne null}">
<div class="clearfix filter-block">
Your data is filtered!
<a href="<spring:url value="/acn/filter"><spring:param name="filter" value="${jsonFilter}" /></spring:url>">Modify filter</a>
</div>
</c:if>
<div class="nav-header">
<spring:message code="accessions.number" arguments="${pagedData.totalElements}" />
<br />
......
......@@ -29,7 +29,9 @@
</c:forEach>
<a id="filtersHref" href=""><button>View!</button></a>
<div class="clearfix">
<a id="filtersHref" href=""><button class="btn">View!</button></a>
</div>
<div id="filtersJson">${jsonObject}</div>
......
......@@ -343,13 +343,6 @@ tr.acn .sel.picked {
}
#selcounter {
float: right;
font-size: 70%;
font-weight: bold;
color: White;
position: relative;
right: -0.5em;
top: -0.6em;
}
.btn-primary {
......@@ -370,7 +363,6 @@ tr.acn .sel.picked {
}
.filter-block .filter-name {
width: 20%;
font-weight: bold;
}
.filter-block .filter-values {
......@@ -404,3 +396,7 @@ tr.acn .sel.picked {
margin-bottom: 0;
padding: 0 5px;
}
#filtersJson {
display: none;
}
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