validate MeterValue timestamps against transaction time window and chronological order#1988
Conversation
Review Summary by QodoValidate MeterValue timestamps against transaction window and order
WalkthroughsDescription• Validate MeterValue timestamps fall within transaction time window • Enforce chronological ordering of MeterValue timestamps • Add comprehensive test coverage for new validations • Refactor timestamp extraction to support multiple validation checks Diagramflowchart LR
MV["MeterValue List"]
Extract["Extract Timestamps"]
FutureCheck["Check Future Timestamps"]
WindowCheck["Check Time Window<br/>start ≤ ts ≤ stop"]
OrderCheck["Check Chronological<br/>Order"]
Result["Validation Result"]
MV --> Extract
Extract --> FutureCheck
FutureCheck --> WindowCheck
WindowCheck --> OrderCheck
OrderCheck --> Result
File Changes1. src/main/java/de/rwth/idsg/steve/service/CentralSystemService16_ServiceValidator.java
|
Code Review by Qodo
1.
|
src/main/java/de/rwth/idsg/steve/service/CentralSystemService16_ServiceValidator.java
Outdated
Show resolved
Hide resolved
Filter null elements from the meterValues list before calling MeterValue::getTimestamp to prevent NPE. Add tests for lists containing null elements. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
hey @rishabhvaish, thanks for your contribution. the code makes, in worst-case scenario, 4 passes over the MeterValues. this can be inefficient with long-running transactions and therefore a long list of MeterValues entries. i think, this number can be reduced to 2 without sacrificing anything. or even 1 (but maybe in this case it will harm the readability and compactness). can you explore an improvement in this area? |
Track earliest, latest timestamps and chronological order in a single loop instead of separate stream operations. Removes the intermediate list allocation and redundant Comparator import. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@goekay — Good catch. Refactored Before: stream → list of timestamps, stream → max, stream → min, loop → order check All existing tests are unchanged — they exercise the same public API and error messages. |
- early exit when not in chronological order. no need to track another variable - init earliest/latest/previous with sensible values such that null-checks are not needed
|
@rishabhvaish i will revert this PR partially, because of #1992 |
The existing
validateMeterValuesInternalchecked that timestamps aren't in the future and don't exceed the stop timestamp, but it didn't verify that they fall within the transaction's time window or arrive in order.I've added two checks:
validateStop, the method now receivesstartTimestampand rejects any MeterValue whose timestamp is before the transaction started. This catches late-arriving meter data from a previous session or clock-drift replays.Both checks follow the existing pattern of returning a
SteveExceptionwithout throwing, so the caller decides how to handle it.Tests cover: before-start rejection, at-start acceptance, out-of-order rejection, in-order acceptance, and equal-timestamp acceptance.
Partial fix for #1962.