Commit 23d537ce authored by Matija Obreza's avatar Matija Obreza

Merge branch 'master' into staging

parents ff9411c8 cabaec62
......@@ -50,9 +50,13 @@ public interface AccessionListRepository extends JpaRepository<AccessionList, Lo
@Query(nativeQuery=true, value="select count(acceid) from accelistitems where listid = ?1")
int sizeOf(AccessionList list);
@Query(nativeQuery=true, value="select count(distinct acceid) from accelistitems where listid in (?1)")
int distinctCount(List<AccessionList> accessionLists);
@Query("from AccessionList al where al.shared=1 order by al.title asc")
List<AccessionList> findShared();
@Query("select uuid from AccessionList al where al.title=?1")
UUID getUUIDByTitle(String title);
}
......@@ -55,6 +55,13 @@ public interface AccessionListService {
int sizeOf(AccessionList accessionList);
/**
* Number of unique accessions in all lists
* @param accessionLists
* @return the number of unique accessions in all lists
*/
int distinctCount(List<AccessionList> accessionLists);
List<AccessionList> findShared();
UUID getUUIDByTitle(String title);
......
......@@ -168,6 +168,16 @@ public class AccessionListServiceImpl implements AccessionListService {
return accessionListRepository.sizeOf(list);
}
/* (non-Javadoc)
* @see org.genesys2.server.service.AccessionListService#distinctCount(java.util.List)
*/
@Override
public int distinctCount(List<AccessionList> accessionLists) {
if (accessionLists.size() == 0)
return 0;
return accessionListRepository.distinctCount(accessionLists);
}
@Override
@PreAuthorize("isAuthenticated()")
public List<AccessionList> findShared() {
......
......@@ -16,19 +16,27 @@
package org.genesys2.server.servlet.controller;
import java.util.UUID;
import java.util.Set;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.impl.AccessionList;
import org.genesys2.server.model.impl.Project;
import org.genesys2.server.service.AccessionListService;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.ProjectService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
......@@ -53,6 +61,9 @@ public class ProjectController extends BaseController {
@Autowired
private AccessionListService accessionListService;
@Autowired
private ElasticService elasticService;
@Autowired
ContentService contentService;
......@@ -72,18 +83,49 @@ public class ProjectController extends BaseController {
}
@RequestMapping("/{code}")
public String viewProject(ModelMap modelMap, @PathVariable(value = "code") String code) {
public String viewProject(ModelMap model, @PathVariable(value = "code") String code) {
Project project = projectService.getProjectByCode(code);
if (project != null) {
modelMap.addAttribute("project", project);
modelMap.addAttribute("accessionLists", accessionListService.getLists(project.getAccessionLists()));
modelMap.addAttribute("blurp", contentService.getArticle(project, "blurp", getLocale()));
model.addAttribute("project", project);
List<AccessionList> accessionLists = accessionListService.getLists(project.getAccessionLists());
model.addAttribute("accessionLists", accessionLists);
model.addAttribute("blurp", contentService.getArticle(project, "blurp", getLocale()));
// Statistics
int countByProject = accessionListService.distinctCount(accessionLists);
model.addAttribute("countByProject", countByProject);
if (countByProject > 0) {
AppliedFilters filters = projectFilters(project);
model.addAttribute("jsonFilter", filters.toString());
try {
model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(filters, FilterConstants.CROPS, 5));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(filters, FilterConstants.TAXONOMY_GENUS, 5));
model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(filters, FilterConstants.TAXONOMY_GENUSSPECIES, 5));
model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(filters, FilterConstants.ORGCTY_ISO3, 100));
} catch (SearchException e) {
_logger.warn(e.getMessage());
}
}
} else {
throw new ResourceNotFoundException("No project with code " + code);
}
return "/project/view";
}
private AppliedFilters projectFilters(Project project) {
AppliedFilters filters = new AppliedFilters();
AppliedFilter listsFilter = new AppliedFilter().setFilterName(FilterConstants.LISTS);
for (UUID uuid : project.getAccessionLists()) {
listsFilter.addFilterValue(new FilterHandler.LiteralValueFilter(uuid.toString()));
}
filters.add(listsFilter);
return filters;
}
@RequestMapping("/add-project")
public String addProject(ModelMap modelMap) {
modelMap.addAttribute("project", new Project());
......@@ -98,8 +140,7 @@ public class ProjectController extends BaseController {
@RequestMapping("/update-project")
public String update(ModelMap modelMap, @ModelAttribute("project") Project p, @RequestParam("blurp") String aboutBody,
@RequestParam(value = "summary", required = false) String summary,
@RequestParam(value = "accessionListTitle", required = false) List<String> titles) {
@RequestParam(value = "summary", required = false) String summary, @RequestParam(value = "accessionListTitle", required = false) List<String> titles) {
_logger.debug("Updating project " + p.getCode());
Project project = null;
......@@ -117,8 +158,10 @@ public class ProjectController extends BaseController {
Set<String> titlesWithoutDuplicates = new LinkedHashSet<String>(titles);
List<UUID> projectAccessionLists = new ArrayList<UUID>();
for (String title: titlesWithoutDuplicates) {
projectAccessionLists.add(accessionListService.getUUIDByTitle(title));
for (String title : titlesWithoutDuplicates) {
if (StringUtils.isNotBlank(title)) {
projectAccessionLists.add(accessionListService.getUUIDByTitle(title));
}
}
project.setAccessionLists(projectAccessionLists);
......@@ -144,6 +187,42 @@ public class ProjectController extends BaseController {
return StringUtils.EMPTY;
}
@RequestMapping("/{code}/data")
public String viewProjectData(ModelMap model, @PathVariable(value = "code") String code) {
Project project = projectService.getProjectByCode(code);
if (project != null && project.getAccessionLists().size() > 0) {
AppliedFilters filters = projectFilters(project);
model.addAttribute("filter", filters.toString());
return "redirect:/explore";
} else {
throw new ResourceNotFoundException();
}
}
@RequestMapping("/{code}/data/map")
public String viewProjectMap(ModelMap model, @PathVariable(value = "code") String code) {
Project project = projectService.getProjectByCode(code);
if (project != null && project.getAccessionLists().size() > 0) {
AppliedFilters filters = projectFilters(project);
model.addAttribute("filter", filters.toString());
return "redirect:/explore/map";
} else {
throw new ResourceNotFoundException();
}
}
@RequestMapping("/{code}/overview")
public String overview(ModelMap model, @PathVariable(value = "code") String code) throws UnsupportedEncodingException {
Project project = projectService.getProjectByCode(code);
if (project != null && project.getAccessionLists().size() > 0) {
AppliedFilters filters = projectFilters(project);
return "forward:/explore/overview?filter=" + URLEncoder.encode(filters.toString(), "UTF8");
} else {
throw new ResourceNotFoundException();
}
}
protected Locale getLocale() {
return LocaleContextHolder.getLocale();
}
......
......@@ -181,7 +181,7 @@ faoInstitutes.page.data.title=Accessions in {0}
faoInstitute.accessions.at=Accessions at {0}
faoInstitutes.viewAll=View all registered institutes
faoInstitutes.viewActiveOnly=View institutes with accessions in Genesys
faoInstitute.no-accessions-registered=Please get in touch with us if you can facilitate in providing data from this institiute.
faoInstitute.no-accessions-registered=Please get in touch with us if you can facilitate in providing data from this institute.
faoInstitute.institute-not-current=This record is archived.
faoInstitute.view-current-institute=Navigate to {0}.
faoInstitute.country=Country
......
......@@ -29,25 +29,138 @@
<!-- Project text -->
<cms:blurb blurb="${blurp}" />
<c:if test="${fn:length(accessionLists) gt 0}">
<div class="content-section-2015">
<h3>
<div class="content-section-2015">
<h3>
<span>
<spring:message code="heading.general-info" />
</span>
</h3>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<ul class="funny-list statistics">
<li class="clearfix odd">
<span class="stats-number">
<fmt:formatNumber value="${countByProject}" />
</span>
<spring:message code="faoInstitutes.stat.accessionCount" />
</li>
</ul>
<c:if test="${countByProject gt 0}">
<a class="btn btn-primary" title="<spring:message code="faoInstitute.data-title" arguments="${project.name}" />" href="<c:url value="/project/${project.code}/data" />">
<span class="glyphicon glyphicon-list"></span>
<spring:message code="view.accessions" />
</a>
<a class="btn btn-default" title="<spring:message code="faoInstitute.overview-title" arguments="${project.name}" />" href="<c:url value="/project/${project.code}/overview" />">
<span class="glyphicon glyphicon-eye-open"></span>
<spring:message code="data-overview.short" />
</a>
</c:if>
</div>
</div>
<c:if test="${statisticsCrop ne null and statisticsCrop.totalCount gt 0}">
<h4>
<span>
<spring:message code="faoInstitute.stat-by-crop" />
</span>
</h4>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<local:term-result termResult="${statisticsCrop}" type="crop" />
</div>
</div>
</c:if>
<c:if test="${statisticsGenus ne null and statisticsGenus.totalCount gt 0}">
<h4>
<span>
<spring:message code="faoInstitute.stat-by-genus" />
</span>
</h4>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<local:term-result termResult="${statisticsGenus}" type="genus" />
</div>
</div>
</c:if>
<c:if test="${statisticsTaxonomy ne null and statisticsTaxonomy.totalCount gt 0}">
<h4>
<span>
<spring:message code="project.accessionLists" />
<spring:message code="faoInstitute.stat-by-species" />
</span>
</h3>
</h4>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<ul>
<c:forEach items="${accessionLists}" var="accessionList">
<local:term-result termResult="${statisticsTaxonomy}" type="species" />
</div>
</div>
</c:if>
<c:if test="${statisticsOrigCty ne null and statisticsOrigCty.totalCount gt 0}">
<h4>
<span>
<spring:message code="accession.orgCty" />
</span>
</h4>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<local:term-result termResult="${statisticsOrigCty}" type="country" />
</div>
</div>
</c:if>
<c:if test="${fn:length(accessionLists) gt 0}">
<div class="content-section-2015">
<h3>
<span>
<spring:message code="project.accessionLists" />
</span>
</h3>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<ul>
<c:forEach items="${accessionLists}" var="accessionList">
<li>
<a href="<c:url value="/explore"><c:param name="filter" value='{"lists":["${accessionList.uuid}"]}' /></c:url>">
<c:out value="${accessionList.title}" />
</a>
</li>
</c:forEach>
</ul>
</div>
</div>
</div>
</c:if>
<c:if test="${countByProject gt 0}">
<div class="content-section-2015">
<h3>
<span>
<spring:message code="heading.see-also" />
</span>
</h3>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<ul class="see-also">
<li>
<a href="<c:url value="/explore"><c:param name="filter" value='{"lists":["${accessionList.uuid}"]}' /></c:url>"><c:out value="${accessionList.title}" /></a>
<a href="<c:url value="/project/${project.code}/data/map" />">
<spring:message code="see-also.map" />
</a>
</li>
</c:forEach>
</ul>
<li>
<a href="<c:url value="/project/${project.code}/overview" />">
<spring:message code="see-also.overview" />
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</c:if>
</c:if>
</body>
</html>
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