public GeolocCity geolocByCityAndCountry(final String city, final String country) { GeolocCity geolocCity = null; String addressParam = encodeGoogleAddress(null, null, city, country); GoogleGeoCode geoCode = geolocGoogleWithAddress(addressParam); if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) { logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage()); engineSettingService.flagSettingGoogleGeolocationApiOverQuota(); return geolocCity; } if (geoCode != null) { geolocCity = new GeolocCity(); geolocCity.setCity(city); geolocCity.setCountry(country); geolocCity.setJson(SerializationHelper.serialize(geoCode)); geolocCity.setLatitude(geoCode.getLatitude()); geolocCity.setLongitude(geoCode.getLongitude()); if (city == null) { // SANITY CHECK : DON'T SAVE A CITY AS NULL TOO MANY TIME GeolocCity geolocCityCheck = geolocDao.getGeolocCityByCountryWithNullCity(country); if (geolocCityCheck == null) { try { geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity); } catch (Exception e) { logger.error( "Can't save GeolocCity: City: '" + geolocCity.getCity() + "', Country: '" + geolocCity.getCountry() + "'", e); } } } else { try { geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity); } catch (Exception e) { logger.error( "Can't save GeolocCity: City: '" + geolocCity.getCity() + "', Country: '" + geolocCity.getCountry() + "'", e); } } } return geolocCity; }
public GeolocCity getGeolocCityByCountryWithNullCity(final String country, Object... params) { return geolocDao.getGeolocCityByCountryWithNullCity(country, params); }