From 87859c167796206f633e07a08ba90613c477998c Mon Sep 17 00:00:00 2001 From: Bryson Spilman Date: Thu, 17 Oct 2024 09:06:15 -0700 Subject: [PATCH] CWDB-225 - Updated to de-support update/PATCH for measurements. --- .../src/main/java/cwms/cda/ApiServlet.java | 2 - .../cwms/cda/api/MeasurementController.java | 2 +- .../cda/api/MeasurementPatchController.java | 89 ------- .../cwms/cda/data/dao/MeasurementDao.java | 89 ------- .../cda/api/MeasurementControllerTestIT.java | 237 +----------------- .../cda/data/dao/MeasurementDaoTestIT.java | 28 --- .../cwms/cda/api/measurement_updated.json | 49 ---- .../cwms/cda/api/measurements_updated.json | 100 -------- 8 files changed, 3 insertions(+), 593 deletions(-) delete mode 100644 cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java delete mode 100644 cwms-data-api/src/test/resources/cwms/cda/api/measurement_updated.json delete mode 100644 cwms-data-api/src/test/resources/cwms/cda/api/measurements_updated.json 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 a82856116..4082bc32c 100644 --- a/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java +++ b/cwms-data-api/src/main/java/cwms/cda/ApiServlet.java @@ -31,7 +31,6 @@ import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.PROJECT_ID; import static cwms.cda.api.Controllers.WATER_USER; -import cwms.cda.api.MeasurementPatchController; import static io.javalin.apibuilder.ApiBuilder.crud; import static io.javalin.apibuilder.ApiBuilder.delete; import static io.javalin.apibuilder.ApiBuilder.get; @@ -542,7 +541,6 @@ protected void configureRoutes() { cdaCrudCache(format("/stream-reaches/{%s}", NAME), new StreamReachController(metrics), requiredRoles,1, TimeUnit.DAYS); String measurements = "/measurements/"; - 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 24e8cfad4..72df06b33 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 @@ -189,7 +189,7 @@ public void create(Context ctx) { @Override public void update(@NotNull Context ctx, @NotNull String locationId) { try (final Timer.Context ignored = markAndTime(GET_ONE)) { - throw new UnsupportedOperationException("Not supported with required location Id"); + throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } } 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 deleted file mode 100644 index ea4bce279..000000000 --- a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementPatchController.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024 Hydrologic Engineering Center - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package cwms.cda.api; - -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Timer; -import static cwms.cda.api.Controllers.STATUS_204; -import static cwms.cda.data.dao.JooqDao.getDslContext; -import cwms.cda.data.dao.MeasurementDao; -import cwms.cda.data.dto.measurement.Measurement; -import cwms.cda.formatters.ContentType; -import cwms.cda.formatters.Formats; -import io.javalin.http.Context; -import io.javalin.http.Handler; -import io.javalin.plugin.openapi.annotations.HttpMethod; -import io.javalin.plugin.openapi.annotations.OpenApi; -import io.javalin.plugin.openapi.annotations.OpenApiContent; -import io.javalin.plugin.openapi.annotations.OpenApiRequestBody; -import io.javalin.plugin.openapi.annotations.OpenApiResponse; -import java.util.List; -import javax.servlet.http.HttpServletResponse; -import org.jetbrains.annotations.NotNull; -import org.jooq.DSLContext; - -public final class MeasurementPatchController implements Handler { - - private final MetricRegistry metrics; - - public MeasurementPatchController(MetricRegistry metrics) { - this.metrics = metrics; - } - - @OpenApi( - requestBody = @OpenApiRequestBody( - content = { - @OpenApiContent(isArray = true, from = Measurement.class, type = Formats.JSONV1), - @OpenApiContent(from = Measurement.class, type = Formats.JSON) - }, - required = true), - 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 = { - @OpenApiResponse(status = STATUS_204, description = "Measurement(s) successfully updated.") - } - ) - @Override - public void handle(@NotNull Context ctx) throws Exception { - try (Timer.Context ignored = markAndTime()) { - String formatHeader = ctx.req.getContentType(); - ContentType contentType = Formats.parseHeader(formatHeader, Measurement.class); - DSLContext dsl = getDslContext(ctx); - MeasurementDao dao = new MeasurementDao(dsl); - List measurements = MeasurementController.parseMeasurements(ctx, contentType); - if(measurements.size() == 1) { - dao.updateMeasurement(measurements.get(0)); - ctx.status(HttpServletResponse.SC_OK).json("Updated Measurement"); - } else { - dao.updateMeasurements(measurements); - ctx.status(HttpServletResponse.SC_OK).json("Updated Measurements"); - } - } - } - - private Timer.Context markAndTime() { - return Controllers.markAndTime(metrics, getClass().getName(), Controllers.UPDATE); - } -} diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/MeasurementDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/MeasurementDao.java index 3dc762322..6be46ee21 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/MeasurementDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/MeasurementDao.java @@ -61,7 +61,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.TimeZone; -import java.util.stream.Collectors; import mil.army.usace.hec.metadata.location.LocationTemplate; import org.jooq.DSLContext; @@ -71,13 +70,11 @@ import org.jooq.impl.DSL; import usace.cwms.db.dao.util.OracleTypeMap; import usace.cwms.db.jooq.codegen.packages.CWMS_STREAM_PACKAGE; -import static usace.cwms.db.jooq.codegen.tables.AV_STREAMFLOW_MEAS.AV_STREAMFLOW_MEAS; import usace.cwms.db.jooq.codegen.udt.records.STREAMFLOW_MEAS2_T; import usace.cwms.db.jooq.codegen.udt.records.STREAMFLOW_MEAS2_TAB_T; public final class MeasurementDao extends JooqDao { static final XmlMapper XML_MAPPER = buildXmlMapper(); - public static final String IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY = "measurement.ignoreExistingCheckForBulkUpdate"; public MeasurementDao(DSLContext dsl) { super(dsl); @@ -151,63 +148,6 @@ private void storeMeasurementsJooq(Connection conn, List measuremen } } - /** - * Updates an existing measurement - * @param measurement - the measurement to update - */ - public void updateMeasurement(Measurement measurement) { - connection(dsl, conn -> { - setOffice(conn, measurement.getOfficeId()); - verifyMeasurementExists(conn, measurement); - storeMeasurementJooq(conn, measurement, false); - }); - } - - /** - * Updates a list of existing measurements - * @param measurements - the measurements to update - */ - public void updateMeasurements(List measurements) - { - connection(dsl, conn -> { - if(!measurements.isEmpty()) { - List> measurementsByOffice = new ArrayList<>(measurements.stream() - .collect(Collectors.groupingBy(Measurement::getOfficeId)) - .values()); - for (List measurementsList : measurementsByOffice) { - Measurement measurement = measurements.get(0); - String officeId = measurement.getOfficeId(); - setOffice(conn, officeId); - //group measurementsList by locationId - List> measurementsByLocation = new ArrayList<>(measurementsList.stream() - .collect(Collectors.groupingBy(Measurement::getLocationId)) - .values()); - for (List locationMeasurements : measurementsByLocation) { - String locationId = locationMeasurements.get(0).getLocationId(); - verifyMeasurementsExists(conn, officeId, locationId, locationMeasurements); - storeMeasurementsJooq(conn, locationMeasurements, false); - } - } - } - }); - } - - // Helper method to retrieve existing measurement numbers from the database - private List getExistingMeasurementNumbers(Connection conn, String officeId, String locationId, List measurementNumbers) { - usace.cwms.db.jooq.codegen.tables.AV_STREAMFLOW_MEAS view = AV_STREAMFLOW_MEAS; - return getDslContext(conn, officeId) - .selectDistinct(view.LOCATION_ID, view.OFFICE_ID, view.MEAS_NUMBER) - .from(view) - .where(view.LOCATION_ID.eq(locationId) - .and(view.OFFICE_ID.eq(officeId)) - .and(view.MEAS_NUMBER.in(measurementNumbers))) - .groupBy(view.LOCATION_ID, view.OFFICE_ID, view.MEAS_NUMBER) - .fetch() - .stream() - .map(r -> r.get(view.MEAS_NUMBER)) - .collect(Collectors.toList()); - } - /** * Delete a measurement * @@ -229,14 +169,6 @@ public void deleteMeasurements(String officeId, String locationId, Instant minDa }); } - private void verifyMeasurementExists(Connection conn, Measurement measurement) { - List measurements = retrieveMeasurementsJooq(conn, measurement.getOfficeId(), measurement.getLocationId(), UnitSystem.EN.toString(), - null, null, null, null, measurement.getNumber(), measurement.getNumber(), null, null, null, null, OracleTypeMap.GMT_TIME_ZONE); - if (measurements.isEmpty() || measurements.stream().noneMatch(lt -> lt.getNumber().equals(measurement.getNumber()))) { - throw new NotFoundException("Could not find measurement."); - } - } - private void verifyMeasurementsExists(Connection conn, String officeId, String locationId, String minNum, String maxNum) { List measurements = retrieveMeasurementsJooq(conn, officeId, locationId, UnitSystem.EN.toString(), null, null, null, null, minNum, maxNum, null, null, null, null, OracleTypeMap.GMT_TIME_ZONE); @@ -245,27 +177,6 @@ private void verifyMeasurementsExists(Connection conn, String officeId, String l } } - private void verifyMeasurementsExists(Connection conn, String officeId, String locationId, List locationMeasurements) { - List measurementNumbers = locationMeasurements.stream() - .map(Measurement::getNumber) - .collect(Collectors.toList()); - - // Retrieve existing measurements from the database - List missingNumbers = new ArrayList<>(); - if(!Boolean.getBoolean(IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY)) - { - List existingNumbers = getExistingMeasurementNumbers(conn, officeId, locationId, measurementNumbers); - missingNumbers = new ArrayList<>(measurementNumbers); - // Find missing numbers - missingNumbers.removeAll(existingNumbers); - } - - if (!missingNumbers.isEmpty()) { - throw new NotFoundException("Could not find measurements " + String.join(",", missingNumbers) + - " for " + locationId + " in office " + officeId + "."); - } - } - static String toDbXml(List measurements) throws JsonProcessingException { MeasurementsXmlDto xmlDto = convertMeasurementsToXmlDto(measurements); return XML_MAPPER.writeValueAsString(xmlDto); 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 ff18faae0..b3df125b7 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 @@ -54,7 +54,6 @@ import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.assertNotNull; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.*; @@ -96,7 +95,6 @@ static void createAndStoreTestStream(String testLoc) throws SQLException { @AfterAll public static void tearDown() { - System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY); for (Stream stream : TEST_STREAMS) { try { CwmsDatabaseContainer db = CwmsDataApiSetupCallback.getDatabaseLink(); @@ -218,86 +216,6 @@ void test_create_retrieve_delete_measurement() throws IOException { .body("[0].usgs-measurement.air-temp", equalTo(measurement.getUsgsMeasurement().getAirTemp().floatValue())) .body("[0].usgs-measurement.water-temp", equalTo(measurement.getUsgsMeasurement().getWaterTemp().floatValue())); - - InputStream resourceUpdated = this.getClass().getResourceAsStream("/cwms/cda/api/measurement_updated.json"); - assertNotNull(resourceUpdated); - String jsonUpdated = IOUtils.toString(resourceUpdated, StandardCharsets.UTF_8); - assertNotNull(jsonUpdated); - Measurement updatedMeasurement = Formats.parseContent(new ContentType(Formats.JSON), jsonUpdated, Measurement.class); - - //Update the Measurement - given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .contentType(Formats.JSON) - .body(jsonUpdated) - .header(AUTH_HEADER, user.toHeaderValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .patch("/measurements/") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); - - // Retrieve the Updated Measurement and assert that it exists with updated values - given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .queryParam(Controllers.OFFICE_MASK, updatedMeasurement.getId().getOfficeId()) - .queryParam(Controllers.ID_MASK, updatedMeasurement.getLocationId()) - .queryParam(Controllers.MIN_NUMBER, number) - .queryParam(Controllers.MAX_NUMBER, number) - .queryParam(Controllers.UNIT_SYSTEM, UnitSystem.EN.getValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .get("/measurements/") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) - .body("[0].height-unit", equalTo(updatedMeasurement.getHeightUnit())) - .body("[0].flow-unit", equalTo(updatedMeasurement.getFlowUnit())) - .body("[0].temp-unit", equalTo(updatedMeasurement.getTempUnit())) - .body("[0].velocity-unit", equalTo(updatedMeasurement.getVelocityUnit())) - .body("[0].area-unit", equalTo(updatedMeasurement.getAreaUnit())) - .body("[0].used", equalTo(updatedMeasurement.isUsed())) - .body("[0].agency", equalTo(updatedMeasurement.getAgency())) - .body("[0].party", equalTo(updatedMeasurement.getParty())) - .body("[0].wm-comments", equalTo(updatedMeasurement.getWmComments())) - .body("[0].instant", equalTo(updatedMeasurement.getInstant().toString())) - .body("[0].number", equalTo(updatedMeasurement.getNumber())) - .body("[0].id.name", equalTo(updatedMeasurement.getLocationId())) - .body("[0].id.office-id", equalTo(updatedMeasurement.getOfficeId())) - .body("[0].streamflow-measurement.gage-height", equalTo(updatedMeasurement.getStreamflowMeasurement().getGageHeight().floatValue())) - .body("[0].streamflow-measurement.flow", equalTo(updatedMeasurement.getStreamflowMeasurement().getFlow().floatValue())) - .body("[0].streamflow-measurement.quality", equalTo(updatedMeasurement.getStreamflowMeasurement().getQuality())) - .body("[0].supplemental-streamflow-measurement.channel-flow", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getChannelFlow().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-flow", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankFlow().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-max-depth", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankMaxDepth().floatValue())) - .body("[0].supplemental-streamflow-measurement.channel-max-depth", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getChannelMaxDepth().floatValue())) - .body("[0].supplemental-streamflow-measurement.avg-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getAvgVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.surface-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getSurfaceVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.max-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMaxVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.effective-flow-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getEffectiveFlowArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.cross-sectional-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getCrossSectionalArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.mean-gage", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMeanGage().floatValue())) - .body("[0].supplemental-streamflow-measurement.top-width", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getTopWidth().floatValue())) - .body("[0].supplemental-streamflow-measurement.main-channel-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMainChannelArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankArea().floatValue())) - .body("[0].usgs-measurement.remarks", equalTo(updatedMeasurement.getUsgsMeasurement().getRemarks())) - .body("[0].usgs-measurement.current-rating", equalTo(updatedMeasurement.getUsgsMeasurement().getCurrentRating())) - .body("[0].usgs-measurement.control-condition", equalTo(updatedMeasurement.getUsgsMeasurement().getControlCondition())) - .body("[0].usgs-measurement.flow-adjustment", equalTo(updatedMeasurement.getUsgsMeasurement().getFlowAdjustment())) - .body("[0].usgs-measurement.shift-used", equalTo(updatedMeasurement.getUsgsMeasurement().getShiftUsed().floatValue())) - .body("[0].usgs-measurement.percent-difference", equalTo(updatedMeasurement.getUsgsMeasurement().getPercentDifference().floatValue())) - .body("[0].usgs-measurement.delta-height", equalTo(updatedMeasurement.getUsgsMeasurement().getDeltaHeight().floatValue())) - .body("[0].usgs-measurement.delta-time", equalTo(updatedMeasurement.getUsgsMeasurement().getDeltaTime().floatValue())) - .body("[0].usgs-measurement.air-temp", equalTo(updatedMeasurement.getUsgsMeasurement().getAirTemp().floatValue())) - .body("[0].usgs-measurement.water-temp", equalTo(updatedMeasurement.getUsgsMeasurement().getWaterTemp().floatValue())); - // Delete the Measurement given() .log().ifValidationFails(LogDetail.ALL, true) @@ -337,7 +255,6 @@ void test_create_retrieve_delete_measurement() throws IOException { @Test @MinimumSchema(MINIMUM_SCHEMA) void test_create_retrieve_delete_measurement_multiple() throws IOException { - System.setProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY, String.valueOf(true)); InputStream resource = this.getClass().getResourceAsStream("/cwms/cda/api/measurements.json"); assertNotNull(resource); String json = IOUtils.toString(resource, StandardCharsets.UTF_8); @@ -458,127 +375,6 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .body("[1].usgs-measurement.air-temp", equalTo(measurement2.getUsgsMeasurement().getAirTemp().floatValue())) .body("[1].usgs-measurement.water-temp", equalTo(measurement2.getUsgsMeasurement().getWaterTemp().floatValue())); - - InputStream resourceUpdated = this.getClass().getResourceAsStream("/cwms/cda/api/measurements_updated.json"); - assertNotNull(resourceUpdated); - String jsonUpdated = IOUtils.toString(resourceUpdated, StandardCharsets.UTF_8); - assertNotNull(jsonUpdated); - List measurementsUpdated = Formats.parseContentList(new ContentType(Formats.JSON), jsonUpdated, Measurement.class); - Measurement updatedMeasurement = measurementsUpdated.get(0); - Measurement updatedMeasurement2 = measurementsUpdated.get(1); - - - //Update the Measurement - given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .contentType(Formats.JSON) - .body(jsonUpdated) - .header(AUTH_HEADER, user.toHeaderValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .patch("/measurements/") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); - - // Retrieve the Updated Measurements and assert that they exists with updated values - String locationId = updatedMeasurement.getLocationId(); - given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .queryParam(Controllers.OFFICE_MASK, OFFICE_ID) - .queryParam(Controllers.ID_MASK, locationId) - .queryParam(Controllers.UNIT_SYSTEM, UnitSystem.EN.getValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .get("/measurements/") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)) - .body("[0].height-unit", equalTo(updatedMeasurement.getHeightUnit())) - .body("[0].flow-unit", equalTo(updatedMeasurement.getFlowUnit())) - .body("[0].temp-unit", equalTo(updatedMeasurement.getTempUnit())) - .body("[0].velocity-unit", equalTo(updatedMeasurement.getVelocityUnit())) - .body("[0].area-unit", equalTo(updatedMeasurement.getAreaUnit())) - .body("[0].used", equalTo(updatedMeasurement.isUsed())) - .body("[0].agency", equalTo(updatedMeasurement.getAgency())) - .body("[0].party", equalTo(updatedMeasurement.getParty())) - .body("[0].wm-comments", equalTo(updatedMeasurement.getWmComments())) - .body("[0].instant", equalTo(updatedMeasurement.getInstant().toString())) - .body("[0].number", equalTo(updatedMeasurement.getNumber())) - .body("[0].id.name", equalTo(updatedMeasurement.getLocationId())) - .body("[0].id.office-id", equalTo(updatedMeasurement.getOfficeId())) - .body("[0].streamflow-measurement.gage-height", equalTo(updatedMeasurement.getStreamflowMeasurement().getGageHeight().floatValue())) - .body("[0].streamflow-measurement.flow", equalTo(updatedMeasurement.getStreamflowMeasurement().getFlow().floatValue())) - .body("[0].streamflow-measurement.quality", equalTo(updatedMeasurement.getStreamflowMeasurement().getQuality())) - .body("[0].supplemental-streamflow-measurement.channel-flow", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getChannelFlow().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-flow", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankFlow().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-max-depth", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankMaxDepth().floatValue())) - .body("[0].supplemental-streamflow-measurement.channel-max-depth", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getChannelMaxDepth().floatValue())) - .body("[0].supplemental-streamflow-measurement.avg-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getAvgVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.surface-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getSurfaceVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.max-velocity", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMaxVelocity().floatValue())) - .body("[0].supplemental-streamflow-measurement.effective-flow-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getEffectiveFlowArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.cross-sectional-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getCrossSectionalArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.mean-gage", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMeanGage().floatValue())) - .body("[0].supplemental-streamflow-measurement.top-width", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getTopWidth().floatValue())) - .body("[0].supplemental-streamflow-measurement.main-channel-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getMainChannelArea().floatValue())) - .body("[0].supplemental-streamflow-measurement.overbank-area", equalTo(updatedMeasurement.getSupplementalStreamflowMeasurement().getOverbankArea().floatValue())) - .body("[0].usgs-measurement.remarks", equalTo(updatedMeasurement.getUsgsMeasurement().getRemarks())) - .body("[0].usgs-measurement.current-rating", equalTo(updatedMeasurement.getUsgsMeasurement().getCurrentRating())) - .body("[0].usgs-measurement.control-condition", equalTo(updatedMeasurement.getUsgsMeasurement().getControlCondition())) - .body("[0].usgs-measurement.flow-adjustment", equalTo(updatedMeasurement.getUsgsMeasurement().getFlowAdjustment())) - .body("[0].usgs-measurement.shift-used", equalTo(updatedMeasurement.getUsgsMeasurement().getShiftUsed().floatValue())) - .body("[0].usgs-measurement.percent-difference", equalTo(updatedMeasurement.getUsgsMeasurement().getPercentDifference().floatValue())) - .body("[0].usgs-measurement.delta-height", equalTo(updatedMeasurement.getUsgsMeasurement().getDeltaHeight().floatValue())) - .body("[0].usgs-measurement.delta-time", equalTo(updatedMeasurement.getUsgsMeasurement().getDeltaTime().floatValue())) - .body("[0].usgs-measurement.air-temp", equalTo(updatedMeasurement.getUsgsMeasurement().getAirTemp().floatValue())) - .body("[0].usgs-measurement.water-temp", equalTo(updatedMeasurement.getUsgsMeasurement().getWaterTemp().floatValue())) - .body("[1].height-unit", equalTo(updatedMeasurement2.getHeightUnit())) - .body("[1].flow-unit", equalTo(updatedMeasurement2.getFlowUnit())) - .body("[1].temp-unit", equalTo(updatedMeasurement2.getTempUnit())) - .body("[1].velocity-unit", equalTo(updatedMeasurement2.getVelocityUnit())) - .body("[1].area-unit", equalTo(updatedMeasurement2.getAreaUnit())) - .body("[1].used", equalTo(updatedMeasurement2.isUsed())) - .body("[1].agency", equalTo(updatedMeasurement2.getAgency())) - .body("[1].party", equalTo(updatedMeasurement2.getParty())) - .body("[1].wm-comments", equalTo(updatedMeasurement2.getWmComments())) - .body("[1].instant", equalTo(updatedMeasurement2.getInstant().toString())) - .body("[1].number", equalTo(updatedMeasurement2.getNumber())) - .body("[1].id.name", equalTo(updatedMeasurement2.getLocationId())) - .body("[1].id.office-id", equalTo(updatedMeasurement2.getOfficeId())) - .body("[1].streamflow-measurement.gage-height", equalTo(updatedMeasurement2.getStreamflowMeasurement().getGageHeight().floatValue())) - .body("[1].streamflow-measurement.flow", equalTo(updatedMeasurement2.getStreamflowMeasurement().getFlow().floatValue())) - .body("[1].streamflow-measurement.quality", equalTo(updatedMeasurement2.getStreamflowMeasurement().getQuality())) - .body("[1].supplemental-streamflow-measurement.channel-flow", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getChannelFlow().floatValue())) - .body("[1].supplemental-streamflow-measurement.overbank-flow", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getOverbankFlow().floatValue())) - .body("[1].supplemental-streamflow-measurement.overbank-max-depth", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getOverbankMaxDepth().floatValue())) - .body("[1].supplemental-streamflow-measurement.channel-max-depth", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getChannelMaxDepth().floatValue())) - .body("[1].supplemental-streamflow-measurement.avg-velocity", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getAvgVelocity().floatValue())) - .body("[1].supplemental-streamflow-measurement.surface-velocity", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getSurfaceVelocity().floatValue())) - .body("[1].supplemental-streamflow-measurement.max-velocity", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getMaxVelocity().floatValue())) - .body("[1].supplemental-streamflow-measurement.effective-flow-area", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getEffectiveFlowArea().floatValue())) - .body("[1].supplemental-streamflow-measurement.cross-sectional-area", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getCrossSectionalArea().floatValue())) - .body("[1].supplemental-streamflow-measurement.mean-gage", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getMeanGage().floatValue())) - .body("[1].supplemental-streamflow-measurement.top-width", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getTopWidth().floatValue())) - .body("[1].supplemental-streamflow-measurement.main-channel-area", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getMainChannelArea().floatValue())) - .body("[1].supplemental-streamflow-measurement.overbank-area", equalTo(updatedMeasurement2.getSupplementalStreamflowMeasurement().getOverbankArea().floatValue())) - .body("[1].usgs-measurement.remarks", equalTo(updatedMeasurement2.getUsgsMeasurement().getRemarks())) - .body("[1].usgs-measurement.current-rating", equalTo(updatedMeasurement2.getUsgsMeasurement().getCurrentRating())) - .body("[1].usgs-measurement.control-condition", equalTo(updatedMeasurement2.getUsgsMeasurement().getControlCondition())) - .body("[1].usgs-measurement.flow-adjustment", equalTo(updatedMeasurement2.getUsgsMeasurement().getFlowAdjustment())) - .body("[1].usgs-measurement.shift-used", equalTo(updatedMeasurement2.getUsgsMeasurement().getShiftUsed().floatValue())) - .body("[1].usgs-measurement.percent-difference", equalTo(updatedMeasurement2.getUsgsMeasurement().getPercentDifference().floatValue())) - .body("[1].usgs-measurement.delta-height", equalTo(updatedMeasurement2.getUsgsMeasurement().getDeltaHeight().floatValue())) - .body("[1].usgs-measurement.delta-time", equalTo(updatedMeasurement2.getUsgsMeasurement().getDeltaTime().floatValue())) - .body("[1].usgs-measurement.air-temp", equalTo(updatedMeasurement2.getUsgsMeasurement().getAirTemp().floatValue())) - .body("[1].usgs-measurement.water-temp", equalTo(updatedMeasurement2.getUsgsMeasurement().getWaterTemp().floatValue())); - // Delete the Measurements given() .log().ifValidationFails(LogDetail.ALL, true) @@ -588,7 +384,7 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .when() .redirects().follow(true) .redirects().max(3) - .delete("/measurements/" + locationId) + .delete("/measurements/" + measurement1.getLocationId()) .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() @@ -599,7 +395,7 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .log().ifValidationFails(LogDetail.ALL, true) .accept(Formats.JSON) .queryParam(Controllers.OFFICE, OFFICE_ID) - .queryParam(Controllers.ID_MASK, locationId) + .queryParam(Controllers.ID_MASK, measurement1.getLocationId()) .queryParam(Controllers.UNIT_SYSTEM, UnitSystem.EN.getValue()) .when() .redirects().follow(true) @@ -611,35 +407,6 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .statusCode(is(HttpServletResponse.SC_NOT_FOUND)); } - @Test - @MinimumSchema(MINIMUM_SCHEMA) - void test_update_does_not_exist() throws Exception { - System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY); - TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL; - - InputStream resourceUpdated = this.getClass().getResourceAsStream("/cwms/cda/api/measurements_updated.json"); - assertNotNull(resourceUpdated); - String jsonUpdated = IOUtils.toString(resourceUpdated, StandardCharsets.UTF_8); - assertNotNull(jsonUpdated); - List measurementsUpdated = Formats.parseContentList(new ContentType(Formats.JSON), jsonUpdated, Measurement.class); - - //Update the Measurement(s) that were never stored, and therefore doesn't exist in the db - given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .contentType(Formats.JSON) - .body(jsonUpdated) - .header(AUTH_HEADER, user.toHeaderValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .patch("/measurements/") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_NOT_FOUND)); - } - @Test @MinimumSchema(MINIMUM_SCHEMA) void test_delete_does_not_exist() { diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dao/MeasurementDaoTestIT.java b/cwms-data-api/src/test/java/cwms/cda/data/dao/MeasurementDaoTestIT.java index ce1b66912..6779656fd 100644 --- a/cwms-data-api/src/test/java/cwms/cda/data/dao/MeasurementDaoTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/data/dao/MeasurementDaoTestIT.java @@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -132,17 +131,6 @@ void testRoundTrip() throws Exception { assertNotNull(meas2Found); DTOMatch.assertMatch(meas2, meas2Found); - //test update - meas1 = buildMeasurement1(streamLocId, 200); - measurementDao.updateMeasurement(meas1); - - List retrievedMeasurements = measurementDao.retrieveMeasurements(OFFICE_ID, streamLocId, null, null, UnitSystem.EN.getValue(), - null, null, null, null, meas1.getNumber(), meas1.getNumber(), null, null); - DTOMatch.assertMatch(meas1, retrievedMeasurements.get(0)); - - Measurement doesntExist = buildMeasurementDoesntExist(streamLocId); - assertThrows(NotFoundException.class, () -> measurementDao.updateMeasurement(doesntExist)); - //delete measurements measurementDao.deleteMeasurements(meas1.getId().getOfficeId(), meas1.getId().getName(), null, null, null, null, null, null, null, null, null, null, null); measurementDao.deleteMeasurements(meas2.getId().getOfficeId(), meas2.getId().getName(), null, null, null, null, null, null, null, null, null, null, null); @@ -184,7 +172,6 @@ void testRoundTripMultipleStore() throws Exception { StreamLocation streamLocation2 = StreamLocationDaoTestIT.buildTestStreamLocation("TEST_STREAM_123", streamLocId2, OFFICE_ID,11.0, Bank.RIGHT); try { - System.setProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY, String.valueOf(true)); //store stream locations streamLocationDao.storeStreamLocation(streamLocation, false); streamLocationDao.storeStreamLocation(streamLocation2, false); @@ -224,16 +211,6 @@ void testRoundTripMultipleStore() throws Exception { assertNotNull(meas2Found); DTOMatch.assertMatch(meas2, meas2Found); - //test update - meas1 = buildMeasurement1(streamLocId, 400); - meas1B = buildMeasurement2(streamLocId, 500); - List updatedMeasurements = new ArrayList<>(); - updatedMeasurements.add(meas1); - updatedMeasurements.add(meas1B); - measurementDao.updateMeasurements(updatedMeasurements); - - System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY); - retrievedMeasurements = measurementDao.retrieveMeasurements(OFFICE_ID, streamLocId, null, null, UnitSystem.EN.getValue(), null, null, null, null, null, null, null, null); @@ -252,10 +229,6 @@ void testRoundTripMultipleStore() throws Exception { assertNotNull(retrievedMeas1B); DTOMatch.assertMatch(meas1B, retrievedMeas1B); - Measurement doesntExist = buildMeasurementDoesntExist(streamLocId); - updatedMeasurements.add(doesntExist); - assertThrows(NotFoundException.class, () -> measurementDao.updateMeasurements(updatedMeasurements)); - //delete measurements measurementDao.deleteMeasurements(meas1.getId().getOfficeId(), meas1.getId().getName(), null, null, null, null, null, null, null, null, null, null, null); measurementDao.deleteMeasurements(meas2.getId().getOfficeId(), meas2.getId().getName(), null, null, null, null, null, null, null, null, null, null, null); @@ -267,7 +240,6 @@ void testRoundTripMultipleStore() throws Exception { assertThrows(NotFoundException.class, () -> measurementDao.retrieveMeasurements(meas2F.getId().getOfficeId(), meas2F.getId().getName(), null, null, UnitSystem.EN.getValue(), null, null, null, null, null, null, null, null)); } finally { - System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY); //delete stream locations streamLocationDao.deleteStreamLocation( streamLocation.getStreamLocationNode().getId().getOfficeId(), diff --git a/cwms-data-api/src/test/resources/cwms/cda/api/measurement_updated.json b/cwms-data-api/src/test/resources/cwms/cda/api/measurement_updated.json deleted file mode 100644 index e137289df..000000000 --- a/cwms-data-api/src/test/resources/cwms/cda/api/measurement_updated.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "height-unit": "ft", - "flow-unit": "cfs", - "temp-unit": "F", - "velocity-unit": "fps", - "area-unit": "ft2", - "used": true, - "agency": "USGS", - "party": "SPK", - "wm-comments": "Measurement made during normal flow conditions.", - "instant": "2024-09-16T00:00:00Z", - "number": "123456", - "id": { - "name": "StreamLoc321", - "office-id": "SPK" - }, - "streamflow-measurement": { - "gage-height": 5.8, - "flow": 350.0, - "quality": "G" - }, - "supplemental-streamflow-measurement": { - "channel-flow": 300.0, - "overbank-flow": 50.0, - "overbank-max-depth": 5.0, - "channel-max-depth": 10.0, - "avg-velocity": 1.5, - "surface-velocity": 2.0, - "max-velocity": 3.0, - "effective-flow-area": 200.0, - "cross-sectional-area": 250.0, - "mean-gage": 20.0, - "top-width": 30.0, - "main-channel-area": 150.0, - "overbank-area": 80.0 - }, - "usgs-measurement": { - "remarks": "Remarks", - "current-rating": "1", - "control-condition": "FILL", - "flow-adjustment": "OTHR", - "shift-used": 0.1, - "percent-difference": 5.0, - "delta-height": 0.05, - "delta-time": 10.0, - "air-temp": 20.0, - "water-temp": 15.0 - } -} diff --git a/cwms-data-api/src/test/resources/cwms/cda/api/measurements_updated.json b/cwms-data-api/src/test/resources/cwms/cda/api/measurements_updated.json deleted file mode 100644 index e681d6e73..000000000 --- a/cwms-data-api/src/test/resources/cwms/cda/api/measurements_updated.json +++ /dev/null @@ -1,100 +0,0 @@ -[ - { - "height-unit": "ft", - "flow-unit": "cfs", - "temp-unit": "F", - "velocity-unit": "fps", - "area-unit": "ft2", - "used": true, - "agency": "USGS", - "party": "SPK", - "wm-comments": "Measurement made during normal flow conditions.", - "instant": "2024-09-16T00:00:00Z", - "number": "123456", - "id": { - "name": "StreamLoc321", - "office-id": "SPK" - }, - "streamflow-measurement": { - "gage-height": 5.8, - "flow": 350.0, - "quality": "G" - }, - "supplemental-streamflow-measurement": { - "channel-flow": 300.0, - "overbank-flow": 50.0, - "overbank-max-depth": 5.0, - "channel-max-depth": 10.0, - "avg-velocity": 1.5, - "surface-velocity": 2.0, - "max-velocity": 3.0, - "effective-flow-area": 200.0, - "cross-sectional-area": 250.0, - "mean-gage": 20.0, - "top-width": 30.0, - "main-channel-area": 150.0, - "overbank-area": 80.0 - }, - "usgs-measurement": { - "remarks": "Remarks", - "current-rating": "1", - "control-condition": "FILL", - "flow-adjustment": "OTHR", - "shift-used": 0.1, - "percent-difference": 5.0, - "delta-height": 0.05, - "delta-time": 10.0, - "air-temp": 20.0, - "water-temp": 15.0 - } - }, - { - "height-unit": "ft", - "flow-unit": "cfs", - "temp-unit": "F", - "velocity-unit": "fps", - "area-unit": "ft2", - "used": true, - "agency": "USGS", - "party": "SPK", - "wm-comments": "Measurement made after recent rainfall2.", - "instant": "2024-09-17T12:00:00Z", - "number": "654321", - "id": { - "name": "StreamLoc321", - "office-id": "SPK" - }, - "streamflow-measurement": { - "gage-height": 6.4, - "flow": 279.0, - "quality": "F" - }, - "supplemental-streamflow-measurement": { - "channel-flow": 320.0, - "overbank-flow": 45.0, - "overbank-max-depth": 4.5, - "channel-max-depth": 9.8, - "avg-velocity": 1.8, - "surface-velocity": 2.5, - "max-velocity": 3.5, - "effective-flow-area": 220.0, - "cross-sectional-area": 240.0, - "mean-gage": 21.0, - "top-width": 32.0, - "main-channel-area": 163.0, - "overbank-area": 82.0 - }, - "usgs-measurement": { - "remarks": "Post-rain conditions.", - "current-rating": "2", - "control-condition": "FILL", - "flow-adjustment": "OTHR", - "shift-used": 0.15, - "percent-difference": 4.5, - "delta-height": 0.4, - "delta-time": 15.0, - "air-temp": 19.0, - "water-temp": 16.0 - } - } -]