Esempio n. 1
0
  public GeolocAddress geolocByLatitudeLongitude(final String latitude, final String longitude) {
    GeolocAddress geolocAddress = null;
    GoogleGeoCode geoCode = geolocGoogleWithLatitudeLongitude(latitude, longitude);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocAddress;
    }

    if (geoCode != null && geoCode.getResults().size() > 0) {
      GoogleGeoCodeResult googleGeoCodeResult = geoCode.getResults().get(0);
      String formatedAdress = googleGeoCodeResult.getFormattedAddress();
      formatedAdress = formatedAdress.replace(" ", "+").replace("\"", "+");

      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(googleGeoCodeResult.getAddress());
      geolocAddress.setPostalCode(googleGeoCodeResult.getPostalCode());
      geolocAddress.setCity(googleGeoCodeResult.getCity());
      geolocAddress.setCountry(googleGeoCodeResult.getCountryCode());
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAdress);
      geolocAddress.setLatitude(latitude);
      geolocAddress.setLongitude(longitude);

      // SANITY CHECK : DON'T SAVE AN ADDRESS WHICH ALREADY EXIST BUT WAS LOCATED WITH LAT/LONG
      // DIFFERENT
      GeolocAddress geolocGeolocAddress =
          geolocDao.getGeolocAddressByFormatedAddress(formatedAdress);
      if (geolocGeolocAddress == null) {
        geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
      }
    }
    return geolocAddress;
  }
Esempio n. 2
0
  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;
  }
Esempio n. 3
0
  public GeolocAddress geolocByAddress(
      final String address, final String postalCode, final String city, final String country) {
    GeolocAddress geolocAddress = null;
    String formatedAddress = encodeGoogleAddress(address, postalCode, city, country);
    GoogleGeoCode geoCode = geolocGoogleWithAddress(formatedAddress);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocAddress;
    }

    if (geoCode != null) {
      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(address);
      geolocAddress.setPostalCode(postalCode);
      geolocAddress.setCity(city);
      geolocAddress.setCountry(country);
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAddress);
      geolocAddress.setLatitude(geoCode.getLatitude());
      geolocAddress.setLongitude(geoCode.getLongitude());
      geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
    }
    return geolocAddress;
  }
Esempio n. 4
0
 public void deleteGeolocAddress(final GeolocAddress geolocCity) {
   geolocDao.deleteGeolocAddress(geolocCity);
 }
Esempio n. 5
0
 public GeolocAddress saveOrUpdateGeolocAddress(final GeolocAddress geolocCity) {
   return geolocDao.saveOrUpdateGeolocAddress(geolocCity);
 }
Esempio n. 6
0
 public GeolocAddress getGeolocAddressByLatitudeAndLongitude(
     final String latitude, final String longitude, Object... params) {
   return geolocDao.getGeolocAddressByLatitudeAndLongitude(latitude, longitude, params);
 }
Esempio n. 7
0
 public GeolocAddress getGeolocAddressByFormatedAddress(
     final String formatedAddress, Object... params) {
   return geolocDao.getGeolocAddressByFormatedAddress(formatedAddress, params);
 }
Esempio n. 8
0
 public void deleteGeolocCity(final GeolocCity geolocCity) {
   geolocDao.deleteGeolocCity(geolocCity);
 }
Esempio n. 9
0
 public GeolocCity saveOrUpdateGeolocCity(final GeolocCity geolocCity) {
   return geolocDao.saveOrUpdateGeolocCity(geolocCity);
 }
Esempio n. 10
0
 public GeolocCity getGeolocCityByCountryWithNullCity(final String country, Object... params) {
   return geolocDao.getGeolocCityByCountryWithNullCity(country, params);
 }
Esempio n. 11
0
 public GeolocCity getGeolocCityByCityAndCountry(
     final String city, final String country, Object... params) {
   return geolocDao.getGeolocCityByCityAndCountry(city, country, params);
 }