Skip to content

Commit

Permalink
CWDB-225 - Updated some descriptions for clarity. Added deletion of m…
Browse files Browse the repository at this point in the history
…easurements to cleanup routine in IT. Code format refactors.
  • Loading branch information
rma-bryson committed Oct 11, 2024
1 parent c1dd10e commit cf63abe
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
20 changes: 10 additions & 10 deletions cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,11 +60,13 @@ final class MeasurementControllerTestIT extends DataApiTestIT {

private static final String OFFICE_ID = TestAccounts.KeyUser.SPK_NORMAL.getOperatingOffice();
private static final List<Stream> STREAMS_CREATED = new ArrayList<>();
private static final List<String> 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");
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit cf63abe

Please sign in to comment.