-
Notifications
You must be signed in to change notification settings - Fork 14
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
Water Supply Accounting DTO #800
Open
zack-rma
wants to merge
40
commits into
USACE:develop
Choose a base branch
from
zack-rma:feature/water_supply_accounting_dto
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
b0c875e
Implemented Water Supply DTO and Tests
zack-rma f4130b5
Implemented Water Supply DTO and Tests with updated design
zack-rma d6708f8
Updated Water Supply DTO validators
zack-rma d396307
Removed internal validation, replaced with JSON require; Added format…
zack-rma df3d007
Renamed PUMP enum and some other variables, Removed WaterUserContract…
zack-rma a202cc8
Implemented Water Supply DTO and Tests
zack-rma 8b534c9
Updated validation function
zack-rma e203dc8
Renamed Type files, Removed duplicate LookupType and LocationRefType …
zack-rma ed7290f
Removed duplicate location class
zack-rma 92ea19f
Delete LookupType.java
zack-rma 26e395f
First draft of Water Supply DAO
zack-rma 52ab248
Updated Dao to reflect class renames and removals
zack-rma 335cd3d
DAO Testing in progress
zack-rma ee271fc
First draft of Water supply controllers, tests in progress
zack-rma 68cbcb9
Controllers working, testing still in progress
zack-rma a1de635
Test cases passed, Controllers working
zack-rma e5c0de5
Fixed Water Supply Controller tests to match DTO changes
zack-rma 750fd25
Updated Controllers to match DTO and DAO changes
zack-rma 3f01352
Renamed Project Location Ref to Project ID, Removed deprecated Locati…
zack-rma 5547fb9
Incorporated changed DTOs (changed constructors to builders)
zack-rma d9c0f15
Implemented Water Supply Accounting DTO
zack-rma 8593b6e
Refactored DTO, added Mappable data representation
zack-rma 415f9b4
Changed DTO Location from Location object to CwmsId
zack-rma 4108154
Updated JSON input, renamed Project Location Ref to Project ID
zack-rma 3b11d17
Updated Dates to Instant
zack-rma 376b9ec
Incorporated changed Water Supply DTOs (changed constructors to build…
zack-rma 9cc67e3
Switched DTOs to Builder Constructors
zack-rma 6e21d95
Reworked DTO to clarify Structure for JSON
zack-rma e55e9cd
Removed deprecated water pump controller
zack-rma 3208e5a
Updated Accounting DTO and tests
zack-rma f612350
Added base location to pump names
zack-rma 950e791
Added sublocations to tests
zack-rma 40a3c41
Rewrote Water Pump Accounting DTO for more concise JSON files
zack-rma 1a86b94
Finalized pump transfer dto
zack-rma f834f81
CTO-97 - Water Pump Accounting DTO update with TS-style JSON
zack-rma 49af9c3
Updated format to match TimeSeries format, added tests
zack-rma 6baeaf0
Added test
zack-rma 21f1cd3
Updated DTO paging structure
zack-rma 7d5210b
Updated DTO to initialize list
zack-rma 0b17adb
Merge branch 'develop' into feature/water_supply_accounting_dto
zack-rma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/PumpAccounting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* | ||
* 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.data.dto.watersupply; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import cwms.cda.data.dto.CwmsDTOBase; | ||
import cwms.cda.data.dto.CwmsId; | ||
import cwms.cda.data.dto.LookupType; | ||
import java.time.Instant; | ||
|
||
|
||
@JsonDeserialize(builder = PumpAccounting.Builder.class) | ||
public final class PumpAccounting extends CwmsDTOBase { | ||
@JsonProperty(required = true) | ||
private final CwmsId pumpLocation; | ||
@JsonProperty(required = true) | ||
private final LookupType transferType; | ||
@JsonProperty(required = true) | ||
private final Double flow; | ||
@JsonProperty(required = true) | ||
private final Instant transferDate; | ||
private final String comment; | ||
|
||
private PumpAccounting(Builder builder) { | ||
this.pumpLocation = builder.pumpLocation; | ||
this.transferType = builder.transferType; | ||
this.flow = builder.flow; | ||
this.transferDate = builder.transferDate; | ||
this.comment = builder.comment; | ||
} | ||
|
||
public CwmsId getPumpLocation() { | ||
return this.pumpLocation; | ||
} | ||
|
||
public LookupType getTransferType() { | ||
return this.transferType; | ||
} | ||
|
||
public Double getFlow() { | ||
return this.flow; | ||
} | ||
|
||
public Instant getTransferDate() { | ||
return this.transferDate; | ||
} | ||
|
||
public String getComment() { | ||
return this.comment; | ||
} | ||
|
||
public static final class Builder { | ||
private CwmsId pumpLocation; | ||
private LookupType transferType; | ||
private Double flow; | ||
private Instant transferDate; | ||
private String comment; | ||
|
||
public Builder withPumpLocation(CwmsId pumpLocation) { | ||
this.pumpLocation = pumpLocation; | ||
return this; | ||
} | ||
|
||
public Builder withTransferType(LookupType transferType) { | ||
this.transferType = transferType; | ||
return this; | ||
} | ||
|
||
public Builder withFlow(Double flow) { | ||
this.flow = flow; | ||
return this; | ||
} | ||
|
||
public Builder withTransferDate(Instant transferDate) { | ||
this.transferDate = transferDate; | ||
return this; | ||
} | ||
|
||
public Builder withComment(String comment) { | ||
this.comment = comment; | ||
return this; | ||
} | ||
|
||
public PumpAccounting build() { | ||
return new PumpAccounting(this); | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterSupplyAccounting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* | ||
* 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.data.dto.watersupply; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import cwms.cda.data.dto.CwmsDTOBase; | ||
import cwms.cda.formatters.Formats; | ||
import cwms.cda.formatters.annotations.FormattableWith; | ||
import cwms.cda.formatters.json.JsonV1; | ||
import java.util.List; | ||
|
||
@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class, | ||
aliases = {Formats.DEFAULT, Formats.JSON}) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonDeserialize(builder = WaterSupplyAccounting.Builder.class) | ||
@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class) | ||
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class) | ||
public final class WaterSupplyAccounting extends CwmsDTOBase { | ||
@JsonProperty(required = true) | ||
private final String contractName; | ||
@JsonProperty(required = true) | ||
private final WaterUser waterUser; | ||
private final List<PumpAccounting> pumpAccounting; | ||
|
||
private WaterSupplyAccounting(Builder builder) { | ||
this.contractName = builder.contractName; | ||
this.waterUser = builder.waterUser; | ||
this.pumpAccounting = builder.pumpAccounting; | ||
} | ||
|
||
public String getContractName() { | ||
return this.contractName; | ||
} | ||
|
||
public WaterUser getWaterUser() { | ||
return this.waterUser; | ||
} | ||
|
||
public List<PumpAccounting> getPumpAccounting() { | ||
return this.pumpAccounting; | ||
} | ||
|
||
public static final class Builder { | ||
private String contractName; | ||
private WaterUser waterUser; | ||
private List<PumpAccounting> pumpAccounting; | ||
|
||
public Builder withContractName(String contractName) { | ||
this.contractName = contractName; | ||
return this; | ||
} | ||
|
||
public Builder withWaterUser(WaterUser waterUser) { | ||
this.waterUser = waterUser; | ||
return this; | ||
} | ||
|
||
public Builder withPumpAccounting( | ||
List<PumpAccounting> pumpAccounting) { | ||
this.pumpAccounting = pumpAccounting; | ||
return this; | ||
} | ||
|
||
public WaterSupplyAccounting build() { | ||
return new WaterSupplyAccounting(this); | ||
} | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/PumpAccountingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* | ||
* 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.data.dto.watersupply; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import cwms.cda.api.errors.FieldException; | ||
import cwms.cda.data.dto.CwmsId; | ||
import cwms.cda.data.dto.LookupType; | ||
import cwms.cda.formatters.Formats; | ||
import cwms.cda.helpers.DTOMatch; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.shaded.org.apache.commons.io.IOUtils; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
class PumpAccountingTest { | ||
private static final String OFFICE = "SPK"; | ||
|
||
@Test | ||
void testWaterSupplyPumpAccountingSerializationRoundTrip() { | ||
WaterSupplyAccounting pumpAccounting = buildTestAccounting(); | ||
String serialized = Formats.format(Formats.parseHeader(Formats.JSONV1, WaterSupplyAccounting.class), | ||
pumpAccounting); | ||
WaterSupplyAccounting deserialized = Formats.parseContent(Formats.parseHeader(Formats.JSONV1, | ||
WaterSupplyAccounting.class), serialized, WaterSupplyAccounting.class); | ||
DTOMatch.assertMatch(pumpAccounting, deserialized); | ||
} | ||
|
||
@Test | ||
void testWaterSupplyPumpAccountingSerializationRoundTripFromFile() throws Exception { | ||
WaterSupplyAccounting pumpAccounting = buildTestAccounting(); | ||
InputStream resource = this.getClass().getResourceAsStream( | ||
"/cwms/cda/data/dto/watersupply/water_supply_accounting.json"); | ||
assertNotNull(resource); | ||
String serialized = IOUtils.toString(resource, StandardCharsets.UTF_8); | ||
WaterSupplyAccounting deserialized = Formats.parseContent(Formats.parseHeader(Formats.JSONV1, | ||
WaterSupplyAccounting.class), serialized, WaterSupplyAccounting.class); | ||
DTOMatch.assertMatch(pumpAccounting, deserialized); | ||
} | ||
|
||
@Test | ||
void testValidate() { | ||
assertAll( | ||
() -> { | ||
PumpAccounting pumpAccounting = new PumpAccounting.Builder() | ||
.withPumpLocation(new CwmsId.Builder().withOfficeId(OFFICE).withName("Test Pump").build()) | ||
.withTransferType(new LookupType.Builder().withActive(true).withTooltip("Test Tool Tip").withOfficeId(OFFICE) | ||
.withDisplayValue("Test Transfer Type").build()).withFlow(1.0) | ||
.withTransferDate(Instant.ofEpochSecond(10000012648112L)).withComment("Test Comment").build(); | ||
assertDoesNotThrow(pumpAccounting::validate, "Expected validation to pass"); | ||
}, | ||
() -> { | ||
PumpAccounting pumpAccounting = new PumpAccounting.Builder() | ||
.withPumpLocation(null).withTransferType(new LookupType.Builder().withActive(true) | ||
.withTooltip("Test Tool Tip").withOfficeId(OFFICE) | ||
.withDisplayValue("Test Transfer Type").build()) | ||
.withFlow(1.0).withTransferDate(Instant.ofEpochSecond(10000012648112L)) | ||
.withComment("Test Comment").build(); | ||
assertThrows(FieldException.class, pumpAccounting::validate, "Expected validation to " | ||
+ "fail due to null location"); | ||
}, | ||
() -> { | ||
PumpAccounting pumpAccounting = new PumpAccounting.Builder() | ||
.withPumpLocation(new CwmsId.Builder() | ||
.withOfficeId(OFFICE).withName("Test Pump").build()).withTransferType(null) | ||
.withFlow(1.0).withTransferDate(Instant.ofEpochSecond(10000012648112L)) | ||
.withComment("Test Comment").build(); | ||
assertThrows(FieldException.class, pumpAccounting::validate, "Expected validation to " | ||
+ "fail due to null transfer type"); | ||
}, | ||
() -> { | ||
PumpAccounting pumpAccounting = new PumpAccounting.Builder() | ||
.withPumpLocation(new CwmsId.Builder() | ||
.withOfficeId(OFFICE).withName("Test Pump").build()) | ||
.withTransferType(new LookupType.Builder().withActive(true).withTooltip("Test Tool Tip"). | ||
withOfficeId(OFFICE).withDisplayValue("Test Transfer Type").build()).withFlow(null) | ||
.withTransferDate(Instant.ofEpochSecond(10000012648112L)).withComment("Test Comment").build(); | ||
assertThrows(FieldException.class, pumpAccounting::validate, "Expected validation to " | ||
+ "fail due to null flow value"); | ||
}, | ||
() -> { | ||
PumpAccounting pumpAccounting = new PumpAccounting.Builder() | ||
.withPumpLocation(new CwmsId.Builder().withOfficeId(OFFICE).withName("Test Pump").build()) | ||
.withTransferType(new LookupType.Builder().withActive(true).withTooltip("Test Tool Tip") | ||
.withOfficeId(OFFICE).withDisplayValue("Test Transfer Type").build()) | ||
.withFlow(1.0).withTransferDate(null).withComment("Test Comment").build(); | ||
assertThrows(FieldException.class, pumpAccounting::validate, "Expected validation to " | ||
+ "fail due to null transfer date"); | ||
} | ||
); | ||
} | ||
|
||
private WaterSupplyAccounting buildTestAccounting() { | ||
return new WaterSupplyAccounting.Builder().withWaterUser(new WaterUser.Builder().withEntityName("Test Entity") | ||
.withWaterRight("Test Water Right").withProjectId(new CwmsId.Builder().withOfficeId(OFFICE) | ||
.withName("Test Location").build()).build()) | ||
.withContractName("Test Contract").withPumpAccounting(buildTestPumpAccountingList()) | ||
.build(); | ||
} | ||
|
||
private List<PumpAccounting> buildTestPumpAccountingList() { | ||
List<PumpAccounting> retList = new ArrayList<>(); | ||
retList.add(new PumpAccounting.Builder().withPumpLocation(new CwmsId.Builder().withOfficeId(OFFICE) | ||
.withName("Test Location-Test Pump").build()).withTransferType(new LookupType.Builder().withActive(true) | ||
.withTooltip("Test Tool Tip").withOfficeId(OFFICE).withDisplayValue("Test Transfer Type").build()) | ||
.withFlow(1.0).withTransferDate(Instant.ofEpochMilli(10000012648000L)).withComment("Test Comment").build()); | ||
retList.add(new PumpAccounting.Builder().withPumpLocation(new CwmsId.Builder().withOfficeId(OFFICE) | ||
.withName("Test Location-Test Pump 2").build()).withTransferType(new LookupType.Builder().withActive(true) | ||
.withTooltip("Test Tool Tip 2").withOfficeId(OFFICE).withDisplayValue("Test Transfer Type 2").build()) | ||
.withFlow(2.0).withTransferDate(Instant.ofEpochMilli(10000012648000L)).withComment("Test Comment 2").build()); | ||
return retList; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 data structure should be better defined. It should account for the different pumps and then the accounting times for a given pump. It should be able to easily answer without doing a full list scan whether a given pump has accounting, and what the given pump's start and end times are for the accounting.
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.
Restructured for less repeated data and better scaling