Exemplo 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;
  }
Exemplo 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;
  }
Exemplo 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;
  }
Exemplo n.º 4
0
 public void deleteGeolocAddress(final GeolocAddress geolocCity) {
   geolocDao.deleteGeolocAddress(geolocCity);
 }
Exemplo n.º 5
0
 public GeolocAddress saveOrUpdateGeolocAddress(final GeolocAddress geolocCity) {
   return geolocDao.saveOrUpdateGeolocAddress(geolocCity);
 }
Exemplo n.º 6
0
 public GeolocAddress getGeolocAddressByLatitudeAndLongitude(
     final String latitude, final String longitude, Object... params) {
   return geolocDao.getGeolocAddressByLatitudeAndLongitude(latitude, longitude, params);
 }
Exemplo n.º 7
0
 public GeolocAddress getGeolocAddressByFormatedAddress(
     final String formatedAddress, Object... params) {
   return geolocDao.getGeolocAddressByFormatedAddress(formatedAddress, params);
 }
Exemplo n.º 8
0
 public void deleteGeolocCity(final GeolocCity geolocCity) {
   geolocDao.deleteGeolocCity(geolocCity);
 }
Exemplo n.º 9
0
 public GeolocCity saveOrUpdateGeolocCity(final GeolocCity geolocCity) {
   return geolocDao.saveOrUpdateGeolocCity(geolocCity);
 }
Exemplo n.º 10
0
 public GeolocCity getGeolocCityByCountryWithNullCity(final String country, Object... params) {
   return geolocDao.getGeolocCityByCountryWithNullCity(country, params);
 }
Exemplo n.º 11
0
 public GeolocCity getGeolocCityByCityAndCountry(
     final String city, final String country, Object... params) {
   return geolocDao.getGeolocCityByCityAndCountry(city, country, params);
 }