001package fr.ifremer.adagio.core.service.referential.location;
002
003/*
004 * #%L
005 * SIH-Adagio :: Core
006 * $Id: LocationServiceImpl.java 11945 2014-02-07 16:07:23Z bl05b3e $
007 * $HeadURL: https://forge.ifremer.fr/svn/sih-adagio/tags/adagio-3.5.6/core/src/main/java/fr/ifremer/adagio/core/service/referential/location/LocationServiceImpl.java $
008 * %%
009 * Copyright (C) 2012 - 2013 Ifremer
010 * %%
011 * This program is free software: you can redistribute it and/or modify
012 * it under the terms of the GNU Affero General Public License as published by
013 * the Free Software Foundation, either version 3 of the License, or
014 * (at your option) any later version.
015 * 
016 * This program is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
019 * GNU General Public License for more details.
020 * 
021 * You should have received a copy of the GNU Affero General Public License
022 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
023 * #L%
024 */
025
026import javax.annotation.Resource;
027
028import org.springframework.stereotype.Service;
029
030import fr.ifremer.adagio.core.dao.referential.location.LocationExtendDao;
031import fr.ifremer.adagio.core.dao.referential.location.LocationLevelId;
032
033@Service("locationService")
034public class LocationServiceImpl implements LocationService {
035
036    @Resource(name = "locationDao")
037    private LocationExtendDao locationDao;
038
039    @Override
040    public String getLocationLabelByLatLong(Float latitude, Float longitude) {
041        if (longitude == null || latitude == null) {
042            throw new IllegalArgumentException("Arguments 'latitude' and 'longitude' should not be null.");
043        }
044        return locationDao.getLocationLabelByLatLong(latitude, longitude);
045    }
046
047    @Override
048    public Integer getLocationIdByLatLong(Float latitude, Float longitude) {
049        String locationLabel = getLocationLabelByLatLong(latitude, longitude);
050        if (locationLabel == null) {
051            return null;
052        }
053        Integer locationId = locationDao.getLocationIdByLabelAndLocationLevel(locationLabel,
054                new Integer[] { LocationLevelId.RECTANGLE_STATISTIQUE.getValue(), LocationLevelId.RECTANGLE_CGPM_GFCM.getValue(),
055                        LocationLevelId.FAO_ZONE.getValue() });
056        return locationId;
057    }
058
059}