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

Display the links between Organizations and WIEWS Institutes

parent 0f430471
......@@ -50,7 +50,7 @@ public class Organization extends BusinessModel {
@Field(name = "body", store = Store.NO)
private String title;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = FaoInstitute.class)
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = FaoInstitute.class)
@JoinTable(name = "organizationinstitute", joinColumns = @JoinColumn(name = "organizationId"), inverseJoinColumns = @JoinColumn(name = "instituteId"))
@OrderBy("code")
private List<FaoInstitute> members = new ArrayList<FaoInstitute>();
......
......@@ -48,4 +48,5 @@ public interface FaoInstituteRepository extends
@Query("from FaoInstitute fi where fi.pgrActivity=true")
Page<FaoInstitute> listInstitutes(Pageable pageable);
}
......@@ -16,11 +16,21 @@
package org.genesys2.server.persistence.domain;
import java.util.List;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface OrganizationRepository extends JpaRepository<Organization, Long> {
Organization findBySlug(String slug);
@Query("select o.members from Organization o where o = ?1 order by code")
List<FaoInstitute> findInstitutesByOrganization(Organization organization);
@Query("select distinct o from Organization o join o.members m where m = ?1")
List<Organization> getOrganizations(FaoInstitute faoInstitute);
}
......@@ -22,6 +22,7 @@ import java.util.Locale;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -49,5 +50,7 @@ public interface InstituteService {
void updateCountryRefs();
List<Organization> getOrganizations(FaoInstitute faoInstitute);
}
......@@ -16,8 +16,10 @@
package org.genesys2.server.service;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -41,4 +43,6 @@ public interface OrganizationService {
*/
Organization create(String slug, String title);
List<FaoInstitute> getMembers(Organization organization);
}
......@@ -26,9 +26,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.persistence.domain.CountryRepository;
import org.genesys2.server.persistence.domain.FaoInstituteRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.InstituteService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -63,6 +65,9 @@ public class InstituteServiceImpl implements InstituteService {
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
private OrganizationRepository organizationRepository;
@Override
public Page<FaoInstitute> list(Pageable pageable) {
return instituteRepository.listInstitutes(pageable);
......@@ -115,4 +120,11 @@ public class InstituteServiceImpl implements InstituteService {
public void updateCountryRefs() {
genesysLowlevelRepository.updateFaoInstituteCountries();
}
@Override
public List<Organization> getOrganizations(FaoInstitute faoInstitute) {
if (faoInstitute == null)
throw new NullPointerException("faoInstitute");
return organizationRepository.getOrganizations(faoInstitute);
}
}
......@@ -16,10 +16,12 @@
package org.genesys2.server.service.impl;
import java.util.List;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.persistence.domain.FaoInstituteRepository;
import org.genesys2.server.persistence.domain.OrganizationRepository;
......@@ -87,4 +89,11 @@ public class OrganizationServiceImpl implements OrganizationService {
return organization;
}
@Override
public List<FaoInstitute> getMembers(Organization organization) {
if (organization == null)
throw new NullPointerException("organization");
return organizationRepository.findInstitutesByOrganization(organization);
}
}
......@@ -16,9 +16,14 @@
package org.genesys2.server.servlet.controller;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GenesysService;
......@@ -70,18 +75,25 @@ public class OrganizationController extends BaseController {
if (organization == null) {
throw new ResourceNotFoundException();
}
_logger.debug("Has: " + organization.getMembers());
List<FaoInstitute> members=organizationService.getMembers(organization);
_logger.debug("Has: " + members.size());
// Sort members by country
final Locale locale = getLocale();
Collections.sort(members, new Comparator<FaoInstitute>() {
@Override
public int compare(FaoInstitute o1, FaoInstitute o2) {
return o1.getCountry().getName(locale).compareTo(o2.getCountry().getName(locale));
}
});
model.addAttribute("organization", organization);
model.addAttribute("members", members);
model.addAttribute("blurp", contentService.getArticle(organization, "blurp", getLocale()));
// model.addAttribute("countByInstitute",
// genesysService.countByInstitute(faoInstitute));
// model.addAttribute("statisticsGenus",
// genesysService.statisticsGenusByInstitute(faoInstitute));
// model.addAttribute("statisticsTaxonomy",
// genesysService.statisticsTaxonomyByInstitute(faoInstitute));
return "/organization/details";
}
......
......@@ -79,6 +79,7 @@ public class WiewsController extends BaseController {
throw new ResourceNotFoundException();
}
model.addAttribute("faoInstitute", faoInstitute);
model.addAttribute("organizations", instituteService.getOrganizations(faoInstitute));
model.addAttribute("blurp", contentService.getArticle(faoInstitute, "blurp", getLocale()));
......
......@@ -131,6 +131,7 @@ faoInstitute.code=WIEWS Code
faoInstitute.email=Contact email
faoInstitute.acronym=Acronym
faoInstitute.url=Web link
faoInstitute.member-of-organizations-and-networks=Organizations and Networks:
view.accessions=View accessions...
paged.pageOfPages=Page {0} of {1}
......
......@@ -25,8 +25,15 @@
</div>
<c:set value="" var="countryName" />
<ul class="funny-list">
<c:forEach items="${organization.members}" var="faoInstitute" varStatus="status">
<c:forEach items="${members}" var="faoInstitute" varStatus="status">
<c:if test="${countryName ne faoInstitute.country.getName(pageContext.response.locale)}">
<c:set var="countryName" value="${faoInstitute.country.getName(pageContext.response.locale)}" />
<li class="hoofdleter"><c:out value="${countryName}" />
<%-- <small><a href="#letter-top"><spring:message code="jump-to-top" /></a></small> --%>
</li>
</c:if>
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}"><a class="show pull-left" href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}" />"><b><c:out value="${faoInstitute.code}" /></b> <c:out value="${faoInstitute.fullName}" /></a>
<div class="pull-right">
<spring:message code="faoInstitute.accessionCount" arguments="${faoInstitute.accessionCount}" />
......
......@@ -65,6 +65,17 @@
<a href="<c:out value="${faoInstitute.url}" />"><c:out value="${faoInstitute.url}" /></a>
</div>
</div>
<c:if test="${organizations.size() gt 0}">
<div class="row" style="">
<div class="col-sm-12">
<spring:message code="faoInstitute.member-of-organizations-and-networks" />
<c:forEach items="${organizations}" var="organization">
<a href="<c:url value="/org/${organization.slug}" />"><c:out value="${organization.title}" /></a>
</c:forEach>
</div>
</div>
</c:if>
</div>
......
......@@ -229,11 +229,12 @@ img.country-flag.bigger {
height: 50px;
}
li.hoofdleter {
ul li.hoofdleter {
font-size: 150%;
font-weight: bold;
list-style-type: none;
margin: 1em 0 0.5em;
padding: 0;
}
html:not([dir="rtl"]) li.hoofdleter small {
......
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