Commit 898de00e authored by Matija Obreza's avatar Matija Obreza

ITPGRFA country status model

parent 365284b5
......@@ -18,6 +18,9 @@ package org.genesys2.server.model.impl;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import javax.persistence.Column;
......@@ -184,4 +187,13 @@ public class Country extends BusinessModel {
public void setReplacedBy(Country replacedBy) {
this.replacedBy = replacedBy;
}
public static void sort(List<Country> all, final Locale locale) {
Collections.sort(all, new Comparator<Country>() {
@Override
public int compare(Country o1, Country o2) {
return o1.getName(locale).compareTo(o2.getName(locale));
}
});
}
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model.impl;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.AuditedModel;
/**
* Current country status in the ITPGRFA.
*/
@Entity
@Table(name = "itpgrfa", uniqueConstraints = { @UniqueConstraint(name="ITPGRFA_Country", columnNames = { "countryId" }) })
public class ITPGRFAStatus extends AuditedModel {
private static final long serialVersionUID = 2766536505832914090L;
/**
* Country
*/
@OneToOne(cascade = {}, optional = false)
@JoinColumn(name = "countryId")
private Country country;
/**
* Contracting party
*/
@Column(name = "cp", length = 100)
private String contractingParty;
/**
* Membership
*/
@Column(name = "membership", length = 50)
private String membership;
/**
* Membership type
*/
@Column(name = "membershipBy", length = 50)
private String membershipBy;
/**
* Name of National Focal Point
*/
@Column(name = "nfp", length = 200)
private String nameOfNFP;
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
public String getContractingParty() {
return contractingParty;
}
public void setContractingParty(String contractingParty) {
this.contractingParty = contractingParty;
}
public String getMembership() {
return membership;
}
public void setMembership(String membership) {
this.membership = membership;
}
public String getMembershipBy() {
return membershipBy;
}
public void setMembershipBy(String membershipBy) {
this.membershipBy = membershipBy;
}
public String getNameOfNFP() {
return nameOfNFP;
}
public void setNameOfNFP(String nameOfNFP) {
this.nameOfNFP = nameOfNFP;
}
}
......@@ -51,6 +51,9 @@ public interface CountryRepository extends JpaRepository<Country, Long> {
@Query("select distinct c.refnameId from Country c where c.refnameId is not null")
List<Long> listRefnameIds();
@Query("select distinct itpgrfa.country from ITPGRFAStatus itpgrfa where itpgrfa.country.current = true")
List<Country> findITPGRFA();
// @Query("select distinct c from Country c where c.region in ( ?1 )")
// List<Country> findByRegions(List<Region> regions);
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.impl.ITPGRFAStatus;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ITPGRFAStatusRepository extends JpaRepository<ITPGRFAStatus, Long> {
}
......@@ -75,4 +75,12 @@ public interface GeoService {
ArrayNode toJson(List<FaoInstitute> members);
/**
* Lists members to the ITPGRFA
*
* @param locale
* @return
*/
List<Country> listITPGRFA(Locale locale);
}
......@@ -75,14 +75,16 @@ public class GeoServiceImpl implements GeoService {
@Override
public List<Country> listActive(final Locale locale) {
List<Country> all = countryRepository.findByCurrent(true);
Collections.sort(all, new Comparator<Country>() {
@Override
public int compare(Country o1, Country o2) {
return o1.getName(locale).compareTo(o2.getName(locale));
}
});
return all;
List<Country> countries = countryRepository.findByCurrent(true);
Country.sort(countries, locale);
return countries;
}
@Override
public List<Country> listITPGRFA(Locale locale) {
List<Country> countries = countryRepository.findITPGRFA();
Country.sort(countries, locale);
return countries;
}
@Override
......
......@@ -62,6 +62,12 @@ public class CountryController extends BaseController {
model.addAttribute("countries", geoService.listActive(getLocale()));
return "/country/index";
}
@RequestMapping("/treaty")
public String viewITPGRFA(ModelMap model) {
model.addAttribute("countries", geoService.listITPGRFA(getLocale()));
return "/country/index";
}
@RequestMapping("/{country}")
public String view(ModelMap model, @PathVariable(value = "country") String countryStr) {
......
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