Skip to content

Commit

Permalink
add elevation units instead of assuming meters
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkorynta committed Jun 6, 2024
1 parent a1209e9 commit 967576e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
23 changes: 20 additions & 3 deletions cwms-data-api/src/main/java/cwms/cda/data/dto/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -159,6 +161,10 @@ public Double getElevation() {
return elevation;
}

public String getElevationUnits() {
return elevationUnits;
}

public String getMapLabel() {
return mapLabel;
}
Expand Down Expand Up @@ -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
Expand All @@ -205,7 +212,7 @@ public int hashCode() {
getLocationType(), getLocationKind(), getNation(), getStateInitial(),
getCountyName(), getHorizontalDatum(), getPublishedLongitude(),
getPublishedLatitude(), getVerticalDatum(), getElevation(), getMapLabel(),
getBoundingOfficeId(), getOfficeId());
getBoundingOfficeId(), getOfficeId(), getElevationUnits());
}

@Override
Expand All @@ -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() + '\''
Expand Down Expand Up @@ -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<String, Consumer<Object>> propertyFunctionMap = new HashMap<>();

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private Location buildTestLocation() {
.withPublishedLatitude(50.0)
.withPublishedLongitude(50.0)
.withDescription("for testing")
.withElevationUnits("m")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 967576e

Please sign in to comment.