Search in sources :

Example 1 with GeocoderException

use of org.opennms.features.poller.remote.gwt.server.geocoding.GeocoderException in project opennms by OpenNMS.

the class DefaultLocationDataService method getLatLng.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public GWTLatLng getLatLng(final OnmsMonitoringLocation def, boolean x) {
    GWTLatLng latLng = null;
    final String coordinateMatchString = "^\\s*[\\-\\d\\.]+\\s*,\\s*[\\-\\d\\.]+\\s*$";
    // first, see if we already have coordinates
    if (def.getLatitude() != null && def.getLongitude() != null) {
        latLng = new GWTLatLng(def.getLatitude(), def.getLongitude());
    }
    // if not, see if geolocation is coordinates
    if (latLng == null) {
        LOG.debug("using geolocation: {}", def.getGeolocation());
        if (def.getGeolocation() != null && def.getGeolocation().matches(coordinateMatchString)) {
            final String[] coordinates = def.getGeolocation().split(",");
            latLng = new GWTLatLng(Double.valueOf(coordinates[0]), Double.valueOf(coordinates[1]));
        }
    }
    // otherwise, try to geocode it
    if (latLng == null && def.getGeolocation() != null && !def.getGeolocation().equals("")) {
        try {
            latLng = m_geocoder.geocode(def.getGeolocation());
            LOG.debug("got coordinates {} for geolocation {}", latLng.getCoordinates(), def.getGeolocation());
        } catch (GeocoderException e) {
            LOG.warn("unable to geocode {}", def.getGeolocation(), e);
        }
    }
    return latLng;
}
Also used : GWTLatLng(org.opennms.features.poller.remote.gwt.client.GWTLatLng) GeocoderException(org.opennms.features.poller.remote.gwt.server.geocoding.GeocoderException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GWTLatLng (org.opennms.features.poller.remote.gwt.client.GWTLatLng)1 GeocoderException (org.opennms.features.poller.remote.gwt.server.geocoding.GeocoderException)1 Transactional (org.springframework.transaction.annotation.Transactional)1