From cf63abe18eba798911eea8a6aa2bde9251d98c8f Mon Sep 17 00:00:00 2001 From: Bryson Spilman Date: Fri, 11 Oct 2024 15:37:30 -0700 Subject: [PATCH] CWDB-225 - Updated some descriptions for clarity. Added deletion of measurements to cleanup routine in IT. Code format refactors. --- .../src/main/java/cwms/cda/ApiServlet.java | 2 +- .../cwms/cda/api/MeasurementController.java | 20 ++++++++-------- .../cda/api/MeasurementPatchController.java | 2 +- .../cda/api/MeasurementControllerTestIT.java | 23 +++++++++++++++++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java b/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java index 79d035037..507b32bea 100644 --- a/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java +++ b/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java @@ -529,7 +529,7 @@ protected void configureRoutes() { cdaCrudCache(format("/stream-reaches/{%s}", NAME), new StreamReachController(metrics), requiredRoles,1, TimeUnit.DAYS); String measurements = "/measurements/"; - patch(measurements ,new MeasurementPatchController(metrics)); + patch(measurements, new MeasurementPatchController(metrics)); cdaCrudCache(format(measurements + "{%s}", LOCATION_ID), new cwms.cda.api.MeasurementController(metrics), requiredRoles,5, TimeUnit.MINUTES); cdaCrudCache("/blobs/{blob-id}", diff --git a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java index 377daa3b3..24e8cfad4 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java @@ -86,12 +86,12 @@ private Timer.Context markAndTime(String subject) { @OpenApi( queryParams = { - @OpenApiParam(name = OFFICE_MASK, description = "Office id for filtering measurements."), - @OpenApiParam(name = ID_MASK, description = "Location id for filtering measurements."), - @OpenApiParam(name = MIN_NUMBER, description = "Minimum number for filtering measurements."), - @OpenApiParam(name = MAX_NUMBER, description = "Maximum number for filtering measurements."), - @OpenApiParam(name = MIN_DATE, description = "Minimum date for filtering measurements."), - @OpenApiParam(name = MAX_DATE, description = "Maximum date for filtering measurements."), + @OpenApiParam(name = OFFICE_MASK, description = "Office id mask for filtering measurements. Use null to retrieve measurements for all offices."), + @OpenApiParam(name = ID_MASK, description = "Location id mask for filtering measurements. Use null to retrieve measurements for all locations."), + @OpenApiParam(name = MIN_NUMBER, description = "Minimum measurement number-id for filtering measurements."), + @OpenApiParam(name = MAX_NUMBER, description = "Maximum measurement number-id for filtering measurements."), + @OpenApiParam(name = MIN_DATE, description = "Minimum date for filtering measurements in ISO-8601 format."), + @OpenApiParam(name = MAX_DATE, description = "Maximum date for filtering measurements in ISO-8601 format."), @OpenApiParam(name = UNIT_SYSTEM, description = "Specifies the unit system" + " of the response. Valid values for the unit field are: " + "\n* `EN` Specifies English unit system. Location values will be in the " @@ -196,10 +196,10 @@ public void update(@NotNull Context ctx, @NotNull String locationId) { @OpenApi( queryParams = { @OpenApiParam(name = OFFICE, required = true, description = "Specifies the office of the measurements to delete"), - @OpenApiParam(name = MIN_NUMBER, description = "Specifies the min number of the measurement to delete."), - @OpenApiParam(name = MAX_NUMBER, description = "Specifies the max number of the measurement to delete."), - @OpenApiParam(name = MIN_DATE, description = "Specifies the minimum date of the measurement to delete."), - @OpenApiParam(name = MAX_DATE, description = "Specifies the maximum date of the measurement to delete."), + @OpenApiParam(name = MIN_NUMBER, description = "Specifies the min number-id of the measurement to delete."), + @OpenApiParam(name = MAX_NUMBER, description = "Specifies the max number-id of the measurement to delete."), + @OpenApiParam(name = MIN_DATE, description = "Specifies the minimum date (in ISO-8601 format) of the measurement to delete."), + @OpenApiParam(name = MAX_DATE, description = "Specifies the maximum date (in ISO-8601 format) of the measurement to delete."), }, description = "Delete an existing measurement.", method = HttpMethod.DELETE, diff --git a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java index d5c311e14..ea4bce279 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java @@ -58,7 +58,7 @@ public MeasurementPatchController(MetricRegistry metrics) { @OpenApiContent(from = Measurement.class, type = Formats.JSON) }, required = true), - description = "Update Measurement", + description = "Update Measurement Data. This is not a rename operation. The measurement data is updated with the new data provided.", method = HttpMethod.PATCH, tags = {MeasurementController.TAG}, responses = { diff --git a/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java index 0919032f3..b5421e436 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java @@ -26,6 +26,7 @@ import cwms.cda.api.enums.UnitSystem; import static cwms.cda.data.dao.DaoTest.getDslContext; import cwms.cda.data.dao.DeleteRule; +import cwms.cda.data.dao.MeasurementDao; import cwms.cda.data.dao.StreamDao; import cwms.cda.data.dto.CwmsId; import cwms.cda.data.dto.measurement.Measurement; @@ -59,11 +60,13 @@ final class MeasurementControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = TestAccounts.KeyUser.SPK_NORMAL.getOperatingOffice(); private static final List STREAMS_CREATED = new ArrayList<>(); + private static final List STREAM_LOC_IDS = new ArrayList<>(); @BeforeAll public static void setup() throws SQLException { String testLoc = "StreamLoc321"; // match the stream location name in the json file createLocation(testLoc, true, OFFICE_ID, "STREAM_LOCATION"); + STREAM_LOC_IDS.add(testLoc); createAndStoreTestStream("ImOnThisStream2"); } @@ -103,6 +106,22 @@ public static void tearDown() { } } STREAMS_CREATED.clear(); + for(String measLoc: STREAM_LOC_IDS) + { + try { + CwmsDatabaseContainer db = CwmsDataApiSetupCallback.getDatabaseLink(); + db.connection(c -> { + MeasurementDao measDao = new MeasurementDao(getDslContext(c, OFFICE_ID)); + try { + measDao.deleteMeasurements(OFFICE_ID, measLoc, null, null, null, null, null, null, null, null, null, null, null); + } catch (Exception e) { + // ignore + } + }, CwmsDataApiSetupCallback.getWebUser()); + } catch (SQLException ex) { + throw new RuntimeException(ex); + } + } } @Test @@ -149,7 +168,7 @@ void test_create_retrieve_delete_measurement() throws IOException { .get("/measurements/") .then() .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() + .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) .body("[0].height-unit", equalTo(measurement.getHeightUnit())) .body("[0].flow-unit", equalTo(measurement.getFlowUnit())) @@ -612,7 +631,7 @@ void test_update_does_not_exist() throws Exception { @Test void test_delete_does_not_exist() { TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL; - // Delete a Embankment + // Delete a Measurement given() .log().ifValidationFails(LogDetail.ALL,true) .queryParam(Controllers.OFFICE, user.getOperatingOffice())