GeoService.java

/*
 * Copyright 2018 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.genesys.server.service;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.genesys.blocks.model.JsonViews;
import org.genesys.server.model.impl.Country;
import org.genesys.server.model.impl.FaoInstitute;
import org.genesys.server.model.impl.ITPGRFAStatus;
import org.genesys.server.model.vocab.VocabularyTerm;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.node.ArrayNode;

public interface GeoService {

	// List<Region> findAllSubregions(Region region);
	//
	// List<Country> findAllCountriesInRegion(Region region);
	//
	// List<Region> findContinents();

	/**
	 * Update ISO countries
	 *
	 * @throws IOException
	 */
	void updateCountryData() throws IOException;

	/**
	 * Get country by ISO CODE (either 2 or 3)
	 *
	 * @param isoCode
	 * @return
	 */
	Country getCountry(String isoCode);

	/**
	 * Tries to find country by ISO CODE2, ISO CODE3, Country name and
	 * translations
	 *
	 * @param findCountry
	 * @return
	 */
	Country findCountry(String countryString);

	List<Country> listAll();

	void updateBlurb(Country country, String blurb, Locale locale) throws CRMException;

	List<Country> listAll(Locale locale);

	/**
	 * Lists only "current" entries
	 *
	 * @param locale
	 * @return
	 */
	List<Country> listActive(Locale locale);

	Country getCountryByRefnameId(long refnameId);

	List<Long> listCountryRefnameIds();

	void updateCountryNames(String isoCode3, String jsonTranslations);

	Country updateCountryWiki(String code3, String wiki);

	/**
	 * Get active country, following "replacedBy" where possible.
	 *
	 * @param ISO3
	 *            code
	 * @return
	 */
	Country getCurrentCountry(String code3);

	ArrayNode toJson(List<FaoInstitute> members);

	/**
	 * Lists members to the ITPGRFA
	 *
	 * @param locale
	 * @return
	 */
	List<Country> listITPGRFA(Locale locale);

	/**
	 * Upsert country ITPGRGA status
	 *
	 * @param country
	 * @param contractingParty
	 * @param membership
	 * @param membershipBy
	 * @param nameOfNFP
	 * @return
	 */
	ITPGRFAStatus updateITPGRFA(Country country, String contractingParty, String membership, String membershipBy);

	ITPGRFAStatus getITPGRFAStatus(Country country);

	long countActive();

	String filteredKml(String jsonFilter);

	List<Country> autocomplete(String ac);

	List<VocabularyTerm> autoCompleteTerm(String ac);

	/**
	 * Gets coordinates of bounding box
	 *
	 * @param filters
	 *            the filters
	 * @return coordinates
	 */
	String getBoundingBox(Set<String> iso3Codes);

	CountryDetails getDetails(String iso3code);

	public static class CountryDetails implements Serializable {
		private static final long serialVersionUID = -1556370638451781192L;

		@JsonUnwrapped
		public Country country;
		@JsonIgnoreProperties("country")
		public ITPGRFAStatus itpgrfa;

		@JsonView({ JsonViews.Public.class })
		public List<FaoInstitute> faoInstitutes;
		public List<FaoInstitute> genesysInstitutes;
		@JsonView({ JsonViews.Public.class })
		public Map<String, ElasticsearchService.TermResult> overview;
		public Long accessionCount;
		public Long countByLocation;

		public static CountryDetails from(Country country, ITPGRFAStatus itpgrfaStatus, Long accessionCount, Long countByLocation, List<FaoInstitute> faoInstitutes, List<FaoInstitute> genesysInstitutes, Map<String, ElasticsearchService.TermResult> overview) {
			CountryDetails countryDetails = new CountryDetails();
			countryDetails.country = country;
			countryDetails.itpgrfa = itpgrfaStatus;
			countryDetails.accessionCount = accessionCount;
			countryDetails.countByLocation = countByLocation;
			countryDetails.faoInstitutes = faoInstitutes;
			countryDetails.genesysInstitutes = genesysInstitutes;
			countryDetails.overview = overview;

			return countryDetails;
		}
	}

	Page<VocabularyTerm> list3166Alpha2Terms(Pageable page);
	Page<VocabularyTerm> list3166Alpha3Terms(Pageable page);
	Map<String, String> decode3166Alpha3Terms(Set<String> codes, Locale locale);
	Page<VocabularyTerm> list3166NumericTerms(Pageable page);

	VocabularyTerm get3166Alpha2Term(String code);
	VocabularyTerm get3166Alpha3Term(String code);
	VocabularyTerm get3166NumericTerm(String code);

}