diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java index 49f343207..750c92be7 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/LocationsDaoImpl.java @@ -169,6 +169,7 @@ private Location buildLocation(Record loc) { ) .withLocationType(loc.get(AV_LOC.LOCATION_TYPE)) .withElevation(loc.get(AV_LOC.ELEVATION)) + .withElevationUnits(loc.get(AV_LOC.UNIT_ID)) .withVerticalDatum(loc.get(AV_LOC.VERTICAL_DATUM)) .withPublicName(loc.get(AV_LOC.PUBLIC_NAME)) .withLongName(loc.get(AV_LOC.LONG_NAME)) @@ -218,7 +219,8 @@ public void storeLocation(Location location) throws IOException { connection(dsl, c -> { setOffice(c,location); CwmsDbLoc locJooq = CwmsDbServiceLookup.buildCwmsDb(CwmsDbLoc.class, c); - String elevationUnits = Unit.METER.getValue(); + String elevationUnits = location.getElevationUnits() == null ? + Unit.METER.getValue() : location.getElevationUnits(); locJooq.store(c, location.getOfficeId(), location.getName(), location.getStateInitial(), location.getCountyName(), location.getTimezoneName(), location.getLocationType(), @@ -246,7 +248,8 @@ public void renameLocation(String oldLocationName, Location renamedLocation) connection(dsl, c -> { setOffice(c,renamedLocation); CwmsDbLoc locJooq = CwmsDbServiceLookup.buildCwmsDb(CwmsDbLoc.class, c); - String elevationUnits = Unit.METER.getValue(); + String elevationUnits = renamedLocation.getElevationUnits() == null ? + Unit.METER.getValue() : renamedLocation.getElevationUnits(); locJooq.rename(c, renamedLocation.getOfficeId(), oldLocationName, renamedLocation.getName(), renamedLocation.getStateInitial(), renamedLocation.getCountyName(), renamedLocation.getTimezoneName(), diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/Location.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/Location.java index 32a4dc67b..d73e76856 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dto/Location.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/Location.java @@ -57,6 +57,7 @@ public final class Location extends CwmsDTO { private final Double elevation; private final String mapLabel; private final String boundingOfficeId; + private final String elevationUnits; private Location(Builder builder) { super(builder.officeId); @@ -81,6 +82,7 @@ private Location(Builder builder) { this.elevation = builder.elevation; this.mapLabel = builder.mapLabel; this.boundingOfficeId = builder.boundingOfficeId; + this.elevationUnits = builder.elevationUnits; } public String getName() { @@ -159,6 +161,10 @@ public Double getElevation() { return elevation; } + public String getElevationUnits() { + return elevationUnits; + } + public String getMapLabel() { return mapLabel; } @@ -195,7 +201,8 @@ && getHorizontalDatum().equals(location.getHorizontalDatum()) && Objects.equals(getElevation(), location.getElevation()) && Objects.equals(getMapLabel(), location.getMapLabel()) && Objects.equals(getBoundingOfficeId(), location.getBoundingOfficeId()) - && getOfficeId().equals(location.getOfficeId()); + && getOfficeId().equals(location.getOfficeId()) + && Objects.equals(getElevationUnits(), location.getElevationUnits()); } @Override @@ -205,7 +212,7 @@ public int hashCode() { getLocationType(), getLocationKind(), getNation(), getStateInitial(), getCountyName(), getHorizontalDatum(), getPublishedLongitude(), getPublishedLatitude(), getVerticalDatum(), getElevation(), getMapLabel(), - getBoundingOfficeId(), getOfficeId()); + getBoundingOfficeId(), getOfficeId(), getElevationUnits()); } @Override @@ -229,7 +236,8 @@ public String toString() { + ", publishedLongitude=" + publishedLongitude + ", publishedLatitude=" + publishedLatitude + ", verticalDatum='" + verticalDatum + '\'' - + ", elevation=" + elevation + + ", elevation=" + elevation + '\'' + + ", elevationUnits=" + elevationUnits + '\'' + ", mapLabel='" + mapLabel + '\'' + ", boundingOfficeId='" + boundingOfficeId + '\'' + ", officeId='" + getOfficeId() + '\'' @@ -261,6 +269,7 @@ public static class Builder { private Double elevation; private String mapLabel; private String boundingOfficeId; + private String elevationUnits; private static final String MISSING_NAME_ERROR_MSG = "Location name is a required field"; private final Map> propertyFunctionMap = new HashMap<>(); @@ -306,6 +315,7 @@ public Builder(Location location) { this.elevation = location.getElevation(); this.mapLabel = location.getMapLabel(); this.boundingOfficeId = location.getBoundingOfficeId(); + this.elevationUnits = location.getElevationUnits(); buildPropertyFunctions(); } @@ -351,6 +361,8 @@ private void buildPropertyFunctions() { propertyFunctionMap.put("map-label", mapLabelVal -> withMapLabel((String) mapLabelVal)); propertyFunctionMap.put("bounding-office-id", boundingOfficeIdVal -> withBoundingOfficeId((String) boundingOfficeIdVal)); + propertyFunctionMap.put("elevation-units", + elevUnits -> withElevationUnits((String) elevUnits)); } @JsonIgnore @@ -467,6 +479,11 @@ public Builder withElevation(Double elevation) { return this; } + public Builder withElevationUnits(String elevationUnits) { + this.elevationUnits = elevationUnits; + return this; + } + public Builder withMapLabel(String mapLabel) { this.mapLabel = mapLabel; return this; diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dto/LocationTest.java b/cwms-data-api/src/test/java/cwms/cda/data/dto/LocationTest.java index 9b8330415..81e685ec8 100644 --- a/cwms-data-api/src/test/java/cwms/cda/data/dto/LocationTest.java +++ b/cwms-data-api/src/test/java/cwms/cda/data/dto/LocationTest.java @@ -112,6 +112,7 @@ private Location buildTestLocation() { .withPublishedLatitude(50.0) .withPublishedLongitude(50.0) .withDescription("for testing") + .withElevationUnits("m") .build(); } diff --git a/cwms-data-api/src/test/resources/cwms/cda/api/location_create_spk.json b/cwms-data-api/src/test/resources/cwms/cda/api/location_create_spk.json index b7a223333..41fb92f10 100644 --- a/cwms-data-api/src/test/resources/cwms/cda/api/location_create_spk.json +++ b/cwms-data-api/src/test/resources/cwms/cda/api/location_create_spk.json @@ -14,7 +14,8 @@ "horizontal-datum": "NGVD-29", "published-longitude": 38.5816, "published-latitude": -121.4944, - "elevation": 0.0, + "elevation": 0.2, + "elevation-units": "m", "map-label": "label", "bounding-office-id": "SPK", "office-id": "SPK"