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

Fixed sort in filterService, other minor changes

parent 357d9c0c
......@@ -25,13 +25,19 @@ import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.impl.FaoInstitute;
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;
import org.springframework.data.jpa.repository.Query;
public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query(countQuery="select count(*) from accession")
List<Accession> findAll();
@Query(countQuery="select count(*) from accession a where a.institute = ?1")
Page<Accession> findByInstitute(FaoInstitute institute, Pageable pageable);
@Query(countQuery="select count(*) from accession a where a.genus = ?1")
Page<Accession> findByGenus(String genus, Pageable pageable);
List<Accession> findByInstitute(FaoInstitute institute);
......@@ -80,7 +86,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
Page<Accession> findById(Collection<Long> accessionIds, Pageable pageable);
@Query("from Accession a where a.id in ( ?1 )")
List<Accession> listById(Collection<Long> accessionIds);
List<Accession> listById(Collection<Long> accessionIds, Sort sort);
Page<Accession> findByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable);
......
......@@ -69,6 +69,7 @@ public interface GenesysService {
List<Metadata> listMetadata(Accession accession);
Page<Metadata> listMetadata(Pageable pageable);
Page<Metadata> listDatasets(FaoInstitute faoInstitute, Pageable pageable);
Metadata getMetadata(long metadataId);
......@@ -101,6 +102,8 @@ public interface GenesysService {
Page<Accession> listAccessionsByTaxonomy(Taxonomy taxonomy, Pageable pageable);
Page<Accession> listAccessionsByGenus(String genus, Pageable pageable);
Page<Accession> listAccessions(Pageable pageable);
Page<Accession> listAccessionsByCrop(Crop crop, Pageable pageable);
......@@ -129,5 +132,4 @@ public interface GenesysService {
void refreshMetadataMethods();
}
......@@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
......@@ -132,7 +133,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
LOG.info("Parameter count: " + params.size());
LOG.info("Count query:\n" + sb.toString());
Long totalCount = this.jdbcTemplate.queryForObject("select distinct count(a.id) " + sb.toString(), params.toArray(), Long.class);
Long totalCount = this.jdbcTemplate.queryForObject("select count(a.id) " + sb.toString(), params.toArray(), Long.class);
LOG.info("Total count: " + totalCount);
......@@ -165,10 +166,14 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// Object[] {}, new BeanPropertyRowMapper<Accession>(Accession.class));
LOG.info("Getting IDs");
List<Long> results = this.jdbcTemplate.queryForList("select distinct a.id " + sb.toString(), params.toArray(), Long.class);
List<Long> results = this.jdbcTemplate.queryForList("select 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);
return new PageImpl<Accession>(results.size() == 0 ? new ArrayList<Accession>() : accessionRepository.listById(results,
// TODO Consider processing the pageable.getSort
new Sort("accessionName")),
// -- TODO
pageable, totalCount);
}
private void createQuery(StringBuffer sb, String dbName, JsonNode fieldQuery, List<Object> params) {
......
......@@ -329,6 +329,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public Page<Accession> listAccessionsByTaxonomy(Taxonomy taxonomy, Pageable pageable) {
return accessionRepository.findByTaxonomy(taxonomy, pageable);
}
@Override
public Page<Accession> listAccessionsByGenus(String genus, Pageable pageable) {
return accessionRepository.findByGenus(genus, pageable);
}
@Override
public Page<Accession> listAccessions(Pageable pageable) {
......
......@@ -141,6 +141,33 @@ public class AccessionController extends BaseController {
return "/accession/data";
}
/**
* View by Taxonomy
*
* @param model
* @param wiewsCode
* @param genus
* @param species
* @param page
* @return
*/
@RequestMapping("/t/{genus}")
public String viewDataByGenus(ModelMap model, @PathVariable(value = "genus") String genus,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.genus", genus);
model.addAttribute("filters", filters);
Page<Accession> accessions = genesysService.listAccessionsByGenus(genus, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("selection", selectionBean);
return "/accession/data";
}
/**
* View by Taxonomy
*
......@@ -155,20 +182,25 @@ public class AccessionController extends BaseController {
public String viewDataByGenusSpecies(ModelMap model, @PathVariable(value = "genus") String genus, @PathVariable(value = "species") String species,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
// Taxonomy
Taxonomy taxonomy = taxonomyService.get(genus, species);
_logger.debug("Got " + taxonomy);
HashMap<Object, Object> filters = new HashMap<Object, Object>();
filters.put("filter.taxonomy", taxonomy);
model.addAttribute("filters", filters);
_logger.debug("Got " + taxonomy);
filters.put("filter.taxonomy", taxonomy);
Page<Accession> accessions = genesysService.listAccessionsByTaxonomy(taxonomy, new PageRequest(page - 1, 50, new Sort("accessionName")));
_logger.info("Got: " + accessions);
model.addAttribute("pagedData", accessions);
model.addAttribute("selection", selectionBean);
model.addAttribute("jsonFilter", "{\"taxon\":[\"" + taxonomy.getTaxonName() + "\"]}");
if (taxonomy != null) {
model.addAttribute("jsonFilter", "{\"taxon\":[\"" + taxonomy.getTaxonName() + "\"]}");
}
return "/accession/data";
}
......
......@@ -23,7 +23,7 @@
<c:forEach items="${accessions}" 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.getName(pageContext.response.locale)}" /></td>
<td><c:out value="${accession.countryOfOrigin.getName(pageContext.response.locale)}" /></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.getName(pageContext.response.locale)}" /></a></td>
......
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