@Override public String toString() { return "OnmsGeolocation[" + this.asAddressString() + "]"; }
private boolean isAddressEqual(OnmsGeolocation other) { return Objects.equals(asAddressString(), other.asAddressString()); }
@Override public Map<Integer, Coordinates> resolve(Collection<Integer> nodeIds) { if (nodeIds == null || nodeIds.isEmpty()) { return new HashMap<>(); // nothing to do } // Lookup all nodes and gather the address string final Criteria criteria = new CriteriaBuilder(OnmsNode.class).in("id", nodeIds).toCriteria(); final Map<Integer, String> nodeIdAddressMap = nodeDao.findMatching(criteria).stream() .filter(n -> getGeoLocation(n) != null) .filter(n -> getGeoLocation(n).getLatitude() == null && getGeoLocation(n).getLongitude() == null) .filter(n -> !Strings.isNullOrEmpty(getGeoLocation(n).asAddressString())) .collect(Collectors.toMap(OnmsNode::getId, n -> n.getAssetRecord().getGeolocation().asAddressString())); return resolve(nodeIdAddressMap); }
@Override public Map<Integer, Coordinates> resolve(Collection<Integer> nodeIds) { if (nodeIds == null || nodeIds.isEmpty()) { return new HashMap<>(); // nothing to do } // Lookup all nodes and gather the address string final Criteria criteria = new CriteriaBuilder(OnmsNode.class).in("id", nodeIds).toCriteria(); final Map<Integer, String> nodeIdAddressMap = nodeDao.findMatching(criteria).stream() .filter(n -> getGeoLocation(n) != null) .filter(n -> getGeoLocation(n).getLatitude() == null && getGeoLocation(n).getLongitude() == null) .filter(n -> !Strings.isNullOrEmpty(getGeoLocation(n).asAddressString())) .collect(Collectors.toMap(OnmsNode::getId, n -> n.getAssetRecord().getGeolocation().asAddressString())); return resolve(nodeIdAddressMap); }
protected void updateGeolocation(GeolocationResolver geolocationResolver, OnmsNode node) { Objects.requireNonNull(geolocationResolver); Objects.requireNonNull(node); // Only resolve long/lat if not already set and an address is set final OnmsGeolocation geolocation = node.getAssetRecord().getGeolocation(); if (geolocation != null && geolocation.getLatitude() == null && geolocation.getLatitude() == null && !Strings.isNullOrEmpty(geolocation.asAddressString())) { final Coordinates coordinates = geolocationResolver.resolve(geolocation.asAddressString()); if (coordinates != null) { geolocation.setLongitude(coordinates.getLongitude()); geolocation.setLatitude(coordinates.getLatitude()); nodeDao.saveOrUpdate(node); } else { LOG.warn("Could not resolve address string '{}' for node with id {}", geolocation.asAddressString(), node.getId()); } } }