CountryApiService.java

/*
 * Copyright 2024 Global Country 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.api.v2.facade;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.model.JsonViews;
import org.genesys.server.api.v2.model.impl.CountryDTO;
import org.genesys.server.api.v2.model.impl.FaoInstituteDTO;
import org.genesys.server.api.v2.model.impl.ITPGRFAStatusDTO;
import org.genesys.server.api.v2.model.impl.VocabularyTermDTO;
import org.genesys.server.model.impl.Country;
import org.genesys.server.service.ElasticsearchService;
import org.genesys.server.service.filter.CountryFilter;

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

public interface CountryApiService extends APIFilteredServiceFacade<CountryDTO, Country, CountryFilter> {

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

	List<CountryDTO> listActive(Locale locale);

	List<CountryDTO> autocomplete(String ac);

	List<VocabularyTermDTO> autoCompleteTerm(String ac);

	CountryDetails getDetails(String iso3code);

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

		@JsonUnwrapped
		public CountryDTO country;
		@JsonIgnoreProperties("country")
		public ITPGRFAStatusDTO itpgrfa;

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

		public static CountryDetails from(CountryDTO country, ITPGRFAStatusDTO itpgrfaStatus, Long accessionCount, Long countByLocation, List<FaoInstituteDTO> faoInstitutes, List<FaoInstituteDTO> 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;
		}
	}

	Map<String, String> decode3166Alpha3Terms(Set<String> codes, Locale locale);

	VocabularyTermDTO get3166Alpha3Term(String code);
}