Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ public void getAll(@NotNull Context ctx) {

String office = ctx.queryParam(OFFICE);
String unit = ctx.queryParamAsClass(UNIT, String.class).getOrDefault(UnitSystem.SI.getValue());
if (!unit.equalsIgnoreCase(UnitSystem.SI.getValue()) && !unit.equalsIgnoreCase(UnitSystem.EN.getValue())) {
Comment thread
rma-rripken marked this conversation as resolved.
throw new IllegalArgumentException(String.format("Provided unit system is not supported: %s", unit));
}
String datum = ctx.queryParam(DATUM);
String begin = ctx.queryParam(BEGIN);
String end = ctx.queryParam(END);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,79 @@ enum GetAllTestLegacy {
}
}

@Test
void test_get_constants_over_time() throws Exception {
String locId = "level_get_constants_test";
String levelId = locId + ".Stor.Ave.1Day.Regulating";
createLocation(locId, true, OFFICE);
final ZonedDateTime time = ZonedDateTime.of(2023, 6, 1, 0, 0, 0, 0, ZoneId.of("America"
+ "/Los_Angeles"));
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> {
LocationLevel level = new ConstantLocationLevel.Builder(levelId, time)
.withOfficeId(OFFICE)
.withConstantValue(1.0)
.withLevelUnitsId("ac-ft")
.build();
LocationLevel level2 = new ConstantLocationLevel.Builder(levelId, time.plusDays(1))
.withOfficeId(OFFICE)
.withConstantValue(2.0)
.withLevelUnitsId("ac-ft")
.build();
DSLContext dsl = dslContext(c, OFFICE);
LocationLevelsDaoImpl dao = new LocationLevelsDaoImpl(dsl);
dao.storeLocationLevel(level);
dao.storeLocationLevel(level2);
});

Instant startTime = Instant.parse("2023-06-01T00:00:00Z");
Instant endTime = Instant.parse("2023-06-02T12:00:00Z");

// get location level constants over time
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(START, startTime.toString())
.queryParam(END, endTime.toString())
.queryParam(LEVEL_ID_MASK, levelId)
.queryParam(UNIT, "EN")
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/levels/")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("levels.size()", is(2))
.body("levels[0].constant-value", equalTo(1.0f))
.body("levels[1].constant-value", equalTo(2.0f))
;

// get location level constants over time
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(Formats.JSONV2)
.contentType(Formats.JSONV2)
.queryParam(Controllers.OFFICE, OFFICE)
.queryParam(START, startTime.toString())
.queryParam(END, "2023-06-01T12:00:00Z")
.queryParam(LEVEL_ID_MASK, levelId)
.queryParam(UNIT, "EN")
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/levels/")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("levels.size()", is(1))
.body("levels[0].constant-value", equalTo(1.0f))
;
}

enum GetAllTestNewAliases {
DEFAULT(Formats.DEFAULT, Formats.JSONV2),
JSON(Formats.JSON, Formats.JSONV2),
Expand Down
Loading