diff --git a/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java b/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java index ff23602077..d681878e4f 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java @@ -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())) { + 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); diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java index a0ff351a24..40d1293695 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java @@ -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),