Skip to content

Commit 360875b

Browse files
Set the level date to the actual date rather than parameterized date (#1081)
Set the level date to the actual date rather than parameterized date. Includes integration test. Fixes #662 Supersedes: #1081 --------- Co-authored-by: Adam Korynta <[email protected]>
1 parent 326473a commit 360875b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

cwms-data-api/src/main/java/cwms/cda/data/dao/LocationLevelsDaoImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ public LocationLevel retrieveLocationLevel(String locationLevelName, String pUni
356356
logger.info("Default units are " + defaultUnits);
357357
units = defaultUnits;
358358
}
359-
return new LocationLevel.Builder(locationLevelName, effectiveDate)
359+
Timestamp pEffectiveDate = level.getP_EFFECTIVE_DATE();
360+
ZonedDateTime realEffectiveDate = ZonedDateTime.ofInstant(pEffectiveDate.toInstant(), effectiveDate.getZone());
361+
return new LocationLevel.Builder(locationLevelName, realEffectiveDate)
360362
.withLevelUnitsId(units)
361363
.withAttributeUnitsId(units)
362364
.withInterpolateString(level.getP_INTERPOLATE())

cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java

+38
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,44 @@ void test_location_level() throws Exception {
131131
.body("constant-value",equalTo(1.0F));
132132
}
133133

134+
@Test
135+
void test_retrieve_effective_date() throws Exception {
136+
createLocation("level_with_effect", true, OFFICE);
137+
String levelId = "level_with_effect.Flow.Ave.1Day.Regulating";
138+
ZonedDateTime time = ZonedDateTime.of(2023, 6, 1, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles"));
139+
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
140+
LocationLevel level = new LocationLevel.Builder(levelId, time)
141+
.withOfficeId(OFFICE)
142+
.withConstantValue(1.0)
143+
.withLevelUnitsId("cms")
144+
.build();
145+
levelList.add(level);
146+
DSLContext dsl = dslContext(c, OFFICE);
147+
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
148+
dao.storeLocationLevel(level);
149+
});
150+
151+
ExtractableResponse<Response> response = given()
152+
.log().ifValidationFails(LogDetail.ALL, true)
153+
.accept(Formats.JSONV2)
154+
.contentType(Formats.JSONV2)
155+
.queryParam(Controllers.OFFICE, OFFICE)
156+
.queryParam(LEVEL_ID_MASK, "level_with_effect*")
157+
.queryParam(BEGIN, "2020-06-01T00:00:00Z")
158+
.when()
159+
.redirects().follow(true)
160+
.redirects().max(3)
161+
.get("/levels/")
162+
.then()
163+
.log().ifValidationFails(LogDetail.ALL, true)
164+
.assertThat()
165+
.statusCode(is(HttpServletResponse.SC_OK))
166+
.extract();
167+
168+
assertEquals("2023-06-01T07:00:00Z", response.path("levels[0].level-date"));
169+
}
170+
171+
134172
@Test
135173
void test_retrieve_time_window() throws Exception {
136174
createLocation("level_get_all_loc_1", true, OFFICE);

0 commit comments

Comments
 (0)