-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for virtual location levels #1086
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
base: develop
Are you sure you want to change the base?
Conversation
@zack-rma merge develop in for the nicer test report. |
c4b372b
to
09fb5be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks reasonable. Only issue is with the level of duplication within the test code.
assertThat(response.path("constituents[1].name"), equalTo(existingSpec)); | ||
assertThat(response.path("constituents[1].type"), equalTo("RATING")); | ||
|
||
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These won't get called on failure which can hinder repeatability of tests.
If the location is registered with create location the cascade delete should take care of the ratings so these shouldn't be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed ratings cleanup methods
String specXml = RatingSpecXmlFactory.toXml(specContainer, "", 0, true); | ||
String setXml = RatingContainerXmlFactory.toXml(container, "", 0, true, false); | ||
|
||
CwmsDataApiSetupCallback.getDatabaseLink().connection(c -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This large block is repeated in a near identical way. Some sort of helper function (similar to createLocation) should be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added helper methods to reduce code duplication
@@ -808,4 +1266,63 @@ enum GetAllTestNewAliases | |||
_expectedContentType = expectedContentType; | |||
} | |||
} | |||
|
|||
private String createRatingSpec(String locationName) throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably these would've gone in the DataApiTest class, but this at least makes it easier for the next person to yank up and make more generic.
cwms-data-api/src/main/java/cwms/cda/data/dto/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/SeasonalLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/TimeSeriesLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/ConstantLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/test/resources/cwms/cda/api/virtuallevels/virtual_level_3.json
Outdated
Show resolved
Hide resolved
cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some issues resolved, more fixes to come
cwms-data-api/src/test/resources/cwms/cda/api/virtuallevels/virtual_level_3.json
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/TimeSeriesLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/TimeSeriesLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dao/LocationLevelsDaoImpl.java
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/ConstantLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class) | ||
@FormattableWith(contentType = Formats.XMLV2, formatter = XMLv2.class, aliases = {Formats.XML}) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class LocationLevel extends CwmsDTO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamkorynta considering this new class hierarchy can we ever meaningfully have a plain "LocationLevel"? if not seems like this should be marked abstract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made abstract
@@ -15,7 +42,8 @@ | |||
|
|||
@JsonRootName("location-levels") | |||
@FormattableWith(contentType = Formats.JSONV2, formatter = JsonV2.class, aliases = {Formats.DEFAULT, Formats.JSON}) | |||
public class LocationLevels extends CwmsDTOPaginated { | |||
public class LocationLevels extends CwmsDTOPaginated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do keep the curly on the same line in this project.
} | ||
} catch (NullPointerException e) { | ||
//gets thrown if required field is null | ||
throw new IllegalArgumentException(e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should include the exception so that the stacktrace can hit the log and people can trace issues, should they happen.
also what is throwing null that we can't check for directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated throw to include the exception.
Looking into the NPE catch now.
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/ConstantLocationLevel.java
Outdated
Show resolved
Hide resolved
|
||
ContentType contentType = Formats.parseHeader(Formats.JSONV2, LocationLevel.class); | ||
String jsonStr = Formats.format(contentType, level); | ||
|
||
// If JSONv2 isn't setup correctly it will serialize the level like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though these comments are duplicate, they should be retained, and probably even added to the one above.
anyone of these tests should be reasonable in isolation so it is reasonable to see duplication we would otherwise avoid in normal code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments to other similar methods.
…ng, removed VirtualLocationLevel XML support
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/ConstantLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/VirtualLocationLevel.java
Outdated
Show resolved
Hide resolved
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks, and an change to the builder pattern.
int newPageSize = pageSize - builderMap.size(); | ||
int newOffset = offset - builderMap.size(); // TODO: check if this is correct, this may cause issues with paging | ||
int virtualPageSize = pageSize - builderMap.size(); | ||
int virtualOffset = offset - builderMap.size(); // TODO: check if this is correct, this may cause issues with paging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this todo seems fairly important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated query to combine tables for consistent paging results. In order to get the VirtualLocationLevel constituents list a subquery would be needed, along with some more logic that is currently in a PL/SQL method for a single retrieval. Retrieving a single VirtualLocationLevel would include the constituent data, currently.
@@ -574,49 +569,44 @@ private VirtualLocationLevel buildVirtualLocationLevel(LOCATION_LEVEL_T level, S | |||
|
|||
private ConstantLocationLevel buildConstantLocationLevel(LOCATION_LEVEL_T level, String officeId, String units, | |||
String locationLevelName, ZonedDateTime realEffectiveDate, Double constantValue) { | |||
return new ConstantLocationLevel.Builder(locationLevelName, realEffectiveDate) | |||
return ((ConstantLocationLevel.Builder) new ConstantLocationLevel.Builder(locationLevelName, realEffectiveDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary casts.
} else { | ||
throw new RequiredFieldException("Either interval-minutes or interval-months must be set, but not both"); | ||
} | ||
validator.mutuallyExclusive("Only one of the following can be defined at once for a seasonal location level: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this duplicates the login of the above if/else if/else section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed duplicate logic above
@@ -155,10 +155,10 @@ void test_retrieve_effective_date() throws Exception { | |||
String levelId = "level_with_effect.Flow.Ave.1Day.Regulating"; | |||
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) | |||
LocationLevel level = ((ConstantLocationLevel.Builder) new ConstantLocationLevel.Builder(levelId, time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the amount of casting you're doing really shouldn't be required.
Was it the compiler or the IDE complaining about this? Because somehow this behaves right for the things we do in testcontainers-cwms.. I'll go back and look at the root location level builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unnecessary casts
cwms-data-api/src/main/java/cwms/cda/data/dto/locationlevel/LocationLevel.java
Outdated
Show resolved
Hide resolved
@MikeNeilson It seems this PR and #1109 are failing from the StreamDAOTestIT failing in the same way. It seems to be inconsistent, as it hasn't been failing on all PRs... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concerns have been address.
} | ||
} | ||
|
||
public static <T extends LocationLevel> T castLocationLevel(LocationLevel level, ZonedDateTime unmarshalledDateTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not doing what you think it is doing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed method and refactored logic
attributeUnitsId = null; | ||
} | ||
|
||
if (existingLevel instanceof VirtualLocationLevel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the common builder attributes should get extracted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted common builder attributes
Fixes #469
Adds support for virtual location levels to the levels endpoint. Integration testing included.