boolean addressEqual = isAddressEqual(mergeWith); if (!addressEqual) { setLatitude(null); setLongitude(null); setCity(mergeWith.getCity()); setAddress1(mergeWith.getAddress1()); setAddress2(mergeWith.getAddress2()); setZip(mergeWith.getZip()); setCountry(mergeWith.getCountry()); setState(mergeWith.getState()); if (mergeWith.getLongitude() != null) { setLongitude(mergeWith.getLongitude()); if (mergeWith.getLatitude() != null) { setLatitude(mergeWith.getLatitude());
@Override public String toString() { return "OnmsGeolocation[" + this.asAddressString() + "]"; }
public String asAddressString() { final StringBuilder sb = new StringBuilder(); if (hasText(this.getAddress1())) { sb.append(this.getAddress1()); if (hasText(this.getAddress2())) { sb.append(" ").append(this.getAddress2()); if (hasText(this.getCity())) { if (sb.length() > 0) sb.append(", "); sb.append(this.getCity()); if (hasText(this.getState())) { if (sb.length() > 0) sb.append(", "); sb.append(this.getState()); if (hasText(this.getZip())) { if (hasText(this.getState())) { sb.append(" "); } else if (sb.length() > 0) { sb.append(", "); sb.append(this.getZip()); if (hasText(this.getCountry())) { if (sb.length() > 0) sb.append(", "); sb.append(this.getCountry());
@Override public DisplayStatus evaluate(final HttpServletRequest request, final Object target) { if (target instanceof OnmsNode) { final OnmsNode node = (OnmsNode)target; if (node.getAssetRecord() != null && node.getAssetRecord().getGeolocation() != null) { final OnmsGeolocation geolocation = node.getAssetRecord().getGeolocation(); if (geolocation.getLongitude() != null && geolocation.getLatitude() != null) { return DisplayStatus.DISPLAY_LINK; } } } return DisplayStatus.NO_DISPLAY; }
.add("division", getDivision()) .add("department", getDepartment()) .add("address1", m_geolocation == null ? null : m_geolocation.getAddress1()) .add("address2", m_geolocation == null ? null : m_geolocation.getAddress2()) .add("city", m_geolocation == null ? null : m_geolocation.getCity()) .add("state", m_geolocation == null ? null : m_geolocation.getState()) .add("zip", m_geolocation == null ? null : m_geolocation.getZip()) .add("country", m_geolocation == null ? null : m_geolocation.getCountry()) .add("longitude", m_geolocation == null ? null : m_geolocation.getLongitude()) .add("latitude", m_geolocation == null ? null : m_geolocation.getLatitude()) .add("building", getBuilding()) .add("floor", getFloor())
@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()); } } }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public Double getLatitude() { return m_geolocation == null ? null : m_geolocation.getLatitude(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public Double getLongitude() { return m_geolocation == null ? null : m_geolocation.getLongitude(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getAddress1() { return m_geolocation == null ? null : m_geolocation.getAddress1(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getState() { return m_geolocation == null ? null : m_geolocation.getState(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getZip() { return m_geolocation == null ? null : m_geolocation.getZip(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getAddress2() { return m_geolocation == null ? null : m_geolocation.getAddress2(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getCity() { return m_geolocation == null ? null : m_geolocation.getCity(); }
/** * PROXY METHOD: do not delete until {@link OnmsGeolocation} is truly a separate table, or projection mapping will fail. */ @Transient @Deprecated @XmlElement public String getCountry() { return m_geolocation == null ? null : m_geolocation.getCountry(); }
@Override public DisplayStatus evaluate(final HttpServletRequest request, final Object target) { if (target instanceof OnmsNode) { final OnmsNode node = (OnmsNode)target; if (node.getAssetRecord() != null && node.getAssetRecord().getGeolocation() != null) { final OnmsGeolocation geolocation = node.getAssetRecord().getGeolocation(); if (geolocation.getLongitude() != null && geolocation.getLatitude() != null) { return DisplayStatus.DISPLAY_LINK; } } } return DisplayStatus.NO_DISPLAY; }
private static AddressInfo toAddressInfo(OnmsGeolocation input) { if (input != null) { AddressInfo addressInfo = new AddressInfo(); addressInfo.setAddress1(input.getAddress1()); addressInfo.setAddress2(input.getAddress2()); addressInfo.setCity(input.getCity()); addressInfo.setCountry(input.getCountry()); addressInfo.setState(input.getState()); addressInfo.setZip(input.getZip()); return addressInfo; } return null; } }
@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 ItemProvider<String> getItemProvider() { return node -> { Double latitude = node.getAssetRecord().getGeolocation().getLatitude(); return latitude == null ? null : latitude.toString(); }; } }),
@Override public ItemProvider<String> getItemProvider() { return node -> { Double longitude = node.getAssetRecord().getGeolocation().getLongitude(); return longitude == null ? null : longitude.toString(); }; } }),