Skip to content

CWMS-2024: New LRTS identifier support #1126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

zack-rma
Copy link
Collaborator

@zack-rma zack-rma commented Jun 9, 2025

CWMS-2024: New LRTS identifier support through header and integration testing

@@ -267,6 +265,7 @@ public class ApiServlet extends HttpServlet {
public static final String DATA_SOURCE = "data_source";
public static final String RAW_DATA_SOURCE = "data_source";
public static final String DATABASE = "database";
public static final String IS_NEW_LRTS = "X-NEW_LRTS";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X-CWMS-LRTS-Formatting

or something like that, but at a minimum: X-CWMS-...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that we don't want LRTS as we're talking about the interval, so something like X-CWMS-Use-LocalRegularInterval. But then again maybe client usage will only be thinking in context of time series so LRTS is clearer. Thoughts?

.when()
.redirects().follow(true)
.redirects().max(3)
.delete("/timeseries/identifier-descriptor/" + tsId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.delete("/timeseries/identifier-descriptor/" + tsId)
.delete("/timeseries/identifier-descriptor/{tsID}", tsId)

There's a minor improvement in the log output when using this form. Also makes it easier to look at when there's more than one parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted path format as suggested.

@@ -68,7 +68,7 @@ static void beforeAll() throws Exception
String ratingXml = readResourceFile("cwms/cda/api/Zanesville_Stage_Flow_COE_Production.xml");
ratingXml = ratingXml.replaceAll("Zanesville", EXISTING_LOC);
String ratingXml2 = ratingXml.replaceAll("2002-04-09T13:53:01Z", "2016-06-06T00:00:00Z");
String ratingXml3 = ratingXml.replaceAll("2002-04-09T13:53:01Z", "2025-06-06T00:00:00Z");
String ratingXml3 = ratingXml.replaceAll("2002-04-09T13:53:01Z", "2065-06-06T00:00:00Z");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this in a separate PR. You're already going to have to update several otherwise complete branches.... and I have one that needs it as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1149 Created a PR here

@zack-rma
Copy link
Collaborator Author

zack-rma commented Jun 12, 2025

The current endpoints that return the legacy LRTS interval identifier despite the database being set to use the new format are:

  • BinaryTimeSeries - GET
  • Levels - GET
  • TimeSeriesGroups - GET

This will be updated if more problematic endpoints are discovered.

An issue has been created for cwms-database, and is visible here: HydrologicEngineeringCenter/cwms-database#24

Copy link
Collaborator

@adamkorynta adamkorynta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration tests should test both new and old format and assert that the returned identifier/name matches the request old/new format.

If the client passes in the new identifier without the requisite header, that should be a client error 400, not an internal server error 500.

.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a client error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added error checking and regex matching, now throws CONFLICT client error.


// Structure of test:
//
// 1)Try to create the binary time series without LRTS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 1)Try to create the binary time series without LRTS
// 1)Try to create the binary time series using new LRTS format without the new LRTS format header

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comment as suggested

.queryParam(Controllers.NAME, tsIdentifier)
.queryParam(Controllers.BEGIN, "2004-05-01T12:00:00Z")
.queryParam(Controllers.END, "2007-05-19T16:00:00Z")
.header(ApiServlet.IS_NEW_LRTS, true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test right after this that tests without the new header to assert that the old interval id is returned

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test to confirm old interval ID is returned

.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.body("binary-values.size()", equalTo(3))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test that the new identifier is returned to the client as part of the name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for name value

org.jooq.Configuration configuration = DSL.using(c).configuration();
CWMS_UTIL_PACKAGE.call_SET_SESSION_INFO(configuration,
SESSION_USE_LRTS_ID_FORMAT, requireBool, requireIntValue);
try(PreparedStatement stmt = c.prepareStatement(createTimeseriesQuery)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query does not distinguish between PRTS and LRTS using the old identifier

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored method to only be used for new interval identifier. Should an alternative query specifying LRTS vs PRTS be used here?

@zack-rma zack-rma marked this pull request as ready for review June 19, 2025 21:03
@zack-rma zack-rma requested a review from adamkorynta June 19, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants