CountryApiServiceImpl.java

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

import org.genesys.server.api.v2.facade.CountryApiService;
import org.genesys.server.api.v2.model.impl.CountryDTO;
import org.genesys.server.api.v2.model.impl.VocabularyTermDTO;
import org.genesys.server.model.impl.Country;
import org.genesys.server.service.CountryService;
import org.genesys.server.service.filter.CountryFilter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

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

@Service
@Validated
@Transactional(readOnly = true)
public class CountryApiServiceImpl extends APIFilteredServiceFacadeImpl<CountryService, CountryDTO, Country, CountryFilter> implements CountryApiService {

	@Override
	protected Country convert(CountryDTO source) {
		return mapper.map(source);
	}

	@Override
	protected CountryDTO convert(Country source) {
		return mapper.map(source);
	}

	@Override
	public CountryDTO getCountry(String isoCode) {
		return mapper.map(service.getCountry(isoCode));
	}

	@Override
	public List<CountryDTO> listActive(Locale locale) {
		return mapper.map(service.listActive(locale), mapper::map);
	}

	@Override
	public List<CountryDTO> autocomplete(String ac) {
		return mapper.map(service.autocomplete(ac), mapper::map);
	}

	@Override
	public List<VocabularyTermDTO> autoCompleteTerm(String ac) {
		return mapper.map(service.autoCompleteTerm(ac), mapper::map);
	}

	@Override
	public CountryDetails getDetails(String iso3code) {
		return mapper.map(service.getDetails(iso3code));
	}

	@Override
	public Map<String, String> decode3166Alpha3Terms(Set<String> codes, Locale locale) {
		return service.decode3166Alpha3Terms(codes, locale);
	}

	@Override
	public VocabularyTermDTO get3166Alpha3Term(String code) {
		return mapper.map(service.get3166Alpha3Term(code));
	}
}