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

Removing old /accession/explore

parent 8847132d
...@@ -38,7 +38,8 @@ public interface TaxonomyService { ...@@ -38,7 +38,8 @@ public interface TaxonomyService {
Taxonomy2 get(Long id); Taxonomy2 get(Long id);
Taxonomy2 get(String genus, String species); Taxonomy2 get(String genus);
Taxonomy2 get(String genus, String species);
} }
...@@ -173,4 +173,9 @@ public class TaxonomyServiceImpl implements TaxonomyService { ...@@ -173,4 +173,9 @@ public class TaxonomyServiceImpl implements TaxonomyService {
public long countTaxonomy2() { public long countTaxonomy2() {
return taxonomy2Repository.count(); return taxonomy2Repository.count();
} }
@Override
public Taxonomy2 get(String genus) {
return taxonomy2Repository.findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(genus, "sp.", "", "", "");
}
} }
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
package org.genesys2.server.servlet.controller; package org.genesys2.server.servlet.controller;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.CropService; import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
...@@ -27,9 +27,6 @@ import org.genesys2.server.service.InstituteService; ...@@ -27,9 +27,6 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService; import org.genesys2.server.service.TaxonomyService;
import org.genesys2.spring.ResourceNotFoundException; import org.genesys2.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.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;
...@@ -131,25 +128,15 @@ public class AccessionController extends BaseController { ...@@ -131,25 +128,15 @@ public class AccessionController extends BaseController {
@RequestParam(value = "page", required = false, defaultValue = "1") int page) { @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
// Taxonomy // Taxonomy
long taxGenusId; Taxonomy2 taxonomy = taxonomyService.get(genus);
try { if (taxonomy == null) {
taxGenusId = taxonomyService.getTaxonomy2Id(genus);
} catch (NullPointerException e) {
throw new ResourceNotFoundException("No taxonomy with genus=" + genus); throw new ResourceNotFoundException("No taxonomy with genus=" + genus);
} }
HashMap<Object, Object> filters = new HashMap<Object, Object>(); model.addAttribute("filter", "{\"genus\":[\"" + taxonomy.getGenus() + "\"]}");
filters.put("filter.genus", genus); model.addAttribute("page", page);
model.addAttribute("filters", filters);
Page<Accession> accessions = genesysService.listAccessionsByTaxGenus(taxGenusId, new PageRequest(page - 1, 50, new Sort("accessionName"))); return "redirect:/explore";
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("jsonFilter", "{\"genusId\":[\"" + taxGenusId + "\"]}");
return "/accession/explore";
} }
/** /**
...@@ -167,26 +154,15 @@ public class AccessionController extends BaseController { ...@@ -167,26 +154,15 @@ public class AccessionController extends BaseController {
@RequestParam(value = "page", required = false, defaultValue = "1") int page) { @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
// Taxonomy // Taxonomy
long taxSpeciesId; Taxonomy2 taxonomy = taxonomyService.get(genus, species);
try { if (taxonomy == null) {
taxSpeciesId = taxonomyService.getTaxonomy2Id(genus, species); throw new ResourceNotFoundException("No taxonomy with genus=" + genus);
} catch (NullPointerException e) {
throw new ResourceNotFoundException("No taxonomy with genus=" + genus + " and species=" + species);
} }
HashMap<Object, Object> filters = new HashMap<Object, Object>(); model.addAttribute("filter", "{\"genus\":[\"" + taxonomy.getGenus() + "\"], \"species\":[\"" + taxonomy.getSpecies() + "\"]}");
model.addAttribute("filters", filters); model.addAttribute("page", page);
filters.put("filter.taxSpecies", genus + " " + species);
Page<Accession> accessions = genesysService.listAccessionsByTaxSpecies(taxSpeciesId, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("jsonFilter", "{\"speciesId\":[\"" + taxSpeciesId + "\"]}");
return "/accession/explore"; return "redirect:/explore";
} }
} }
...@@ -122,14 +122,9 @@ public class CountryController extends BaseController { ...@@ -122,14 +122,9 @@ public class CountryController extends BaseController {
if (country == null) { if (country == null) {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
model.addAttribute("pagedData", genesysService.listAccessionsByOrigin(country, new PageRequest(page - 1, 50, new Sort("accessionName"))));
model.addAttribute("filter", "{\"orgCty\":[\"" + country.getCode3() + "\"]}");
HashMap<Object, Object> filters = new HashMap<Object, Object>(); return "redirect:/explore";
filters.put("filter.countryOfOrigin", country);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", "{\"orgCty\":[\"" + country.getCode3() + "\"]}");
return "/accession/explore";
} }
} }
...@@ -98,18 +98,9 @@ public class CropController extends BaseController { ...@@ -98,18 +98,9 @@ public class CropController extends BaseController {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
HashMap<Object, Object> filters = new HashMap<Object, Object>(); model.addAttribute("filter", "{\"crop\":[\"" + crop.getShortName() + "\"]}");
filters.put("filter.crop", crop);
model.addAttribute("filters", filters);
_logger.warn("Listing acns"); return "redirect:/explore";
Page<Accession> accessions = genesysService.listAccessionsByCrop(crop, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("jsonFilter", "{\"crop\":[\"" + crop.getShortName() + "\"]}");
return "/accession/explore";
} }
@RequestMapping("/{shortName}/descriptors") @RequestMapping("/{shortName}/descriptors")
......
...@@ -191,12 +191,12 @@ public class ExplorerController extends BaseController { ...@@ -191,12 +191,12 @@ public class ExplorerController extends BaseController {
List<GenesysFilterService.GenesysFilter> additionalFilters = filterService.selectFilters(selectedFilters); List<GenesysFilterService.GenesysFilter> additionalFilters = filterService.selectFilters(selectedFilters);
model.addAttribute("additionalFilters", additionalFilters); model.addAttribute("additionalFilters", additionalFilters);
if (ArrayUtils.contains(selectedFilters, "crop")) { if (ArrayUtils.contains(selectedFilters, "crop")) {
_logger.debug("Adding crop list"); _logger.debug("Adding crop list");
model.addAttribute("crops", cropService.list(getLocale())); model.addAttribute("crops", cropService.list(getLocale()));
} }
return "/accession/additional-filter"; return "/accession/additional-filter";
} }
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="accession.page.data.title" /></title>
</head>
<body>
<h1>
<spring:message code="accession.page.data.title" />
</h1>
<div class="main-col-header clearfix">
<div class="nav-header">
<c:if test="${pagedData.totalElements le 100000}">
<form class="pull-right form-horizontal" method="post" action="/explore/dwca">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="crop" value="${crop.shortName}" />
<input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />" />
<div class="row" style="margin-top: 2em;">
<div class="col-sm-4">
<button class="btn btn-default" type="submit"><spring:message code="filter.download-dwca" /></button>
</div>
</div>
</form>
</c:if>
<div class="results"><spring:message code="accessions.number" arguments="${pagedData.totalElements}" />
<a href="<c:url value="/explore/map"><c:param name="crop" value="${crop.shortName}" /><c:param name="filter">${jsonFilter}</c:param></c:url>">Map</a>
</div>
<div class="pagination">
<spring:message code="paged.pageOfPages" arguments="${pagedData.number+1},${pagedData.totalPages}" />
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number eq 0 ? 1 : pagedData.number}" /><spring:param name="filter" value="${jsonFilter}" /><spring:param name="pick" value="${jsonPick}" /></spring:url>"><spring:message code="pagination.previous-page" /></a>
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number+2}" /><spring:param name="filter" value="${jsonFilter}" /><spring:param name="pick" value="${jsonPick}" /></spring:url>"><spring:message code="pagination.next-page" /></a>
</div>
</div>
</div>
<div class="applied-filters">
<c:if test="${filters ne null}">
<c:forEach items="${filters.keySet()}" var="by">
<c:set value="${filters[by].getClass().simpleName}" var="clazz" />
<div>
<spring:message code="${by}" />: <b>
<c:choose>
<c:when test="${clazz eq 'Taxonomy'}">
${filters[by].taxonName}
</c:when>
<c:when test="${clazz eq 'Crop'}">
<a href="<c:url value="/c/${filters[by].shortName}" />">${filters[by].getName(pageContext.response.locale)}</a>
</c:when>
<c:when test="${clazz eq 'Country'}">
<a href="<c:url value="/geo/${filters[by].code3.toLowerCase()}" />"><c:out value="${filters[by].getName(pageContext.response.locale)}" /></a>
</c:when>
<c:when test="${clazz eq 'FaoInstitute'}">
<a href="<c:url value="/wiews/${filters[by].code.toLowerCase()}" />"><c:out value="${filters[by].fullName}" /></a>
</c:when>
<c:when test="${clazz eq 'Organization'}">
<a href="<c:url value="/org/${filters[by].slug}" />"><c:out value="${filters[by].title}" /></a>
</c:when>
<c:otherwise>
${filters[by]}
</c:otherwise>
</c:choose>
</b>
</div>
<c:remove var="clazz" />
</c:forEach>
</c:if>
<a href="<spring:url value="/explore/filter"><spring:param name="crop" value="${crop.shortName}" /><spring:param name="filter" value="${jsonFilter}" /><spring:param name="pick" value="${jsonPick}" /></spring:url>"><spring:message code="filters.modify-filters" /></a>
</div>
<table class="accessions">
<thead>
<tr>
<td class="idx-col"></td>
<td />
<td><spring:message code="accession.accessionName" /></td>
<td><spring:message code="accession.taxonomy" /></td>
<td class="notimportant"><spring:message code="accession.origin" /></td>
<td class="notimportant"><spring:message code="accession.sampleStatus" /></td>
<td class="notimportant"><spring:message code="accession.holdingInstitute" /></td>
<%-- <td><spring:message code="accession.holdingCountry" /></td>
--%>
</tr>
</thead>
<tbody>
<c:forEach items="${pagedData.content}" var="accession" varStatus="status">
<tr class="acn ${status.count % 2 == 0 ? 'even' : 'odd'}">
<td class="idx-col">${status.count + pagedData.size * pagedData.number}</td>
<td class="sel" x-aid="${accession.id}"></td>
<td><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.accessionName}" /></b></a></td>
<%-- <td><a href="<c:url value="/acn/t/${accession.taxonomy.genus}/${accession.taxonomy.species}" />"><c:out value="${accession.taxonomy.taxonName}" /></a></td> --%>
<td><c:out value="${accession.taxonomy.taxonName}" /></td>
<%-- <td class="notimportant"><a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />"><c:out value="${accession.countryOfOrigin.name}" /></a></td> --%>
<td class="notimportant"><c:out value="${accession.countryOfOrigin.getName(pageContext.response.locale)}" /></td>
<td class="notimportant"><spring:message code="accession.sampleStatus.${accession.sampleStatus}" /></td>
<td class="notimportant"><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>
</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