Skip to content
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
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jul 1, 2024
f4130b5
Implemented Water Supply DTO and Tests with updated design
zack-rma Jul 3, 2024
d6708f8
Updated Water Supply DTO validators
zack-rma Jul 16, 2024
d396307
Removed internal validation, replaced with JSON require; Added format…
zack-rma Jul 16, 2024
df3d007
Renamed PUMP enum and some other variables, Removed WaterUserContract…
zack-rma Jul 17, 2024
a202cc8
Implemented Water Supply DTO and Tests
zack-rma Jul 1, 2024
8b534c9
Updated validation function
zack-rma Jul 1, 2024
e203dc8
Renamed Type files, Removed duplicate LookupType and LocationRefType …
zack-rma Jul 2, 2024
ed7290f
Removed duplicate location class
zack-rma Jul 2, 2024
92ea19f
Delete LookupType.java
zack-rma Jul 2, 2024
26e395f
First draft of Water Supply DAO
zack-rma Jul 1, 2024
52ab248
Updated Dao to reflect class renames and removals
zack-rma Jul 2, 2024
335cd3d
DAO Testing in progress
zack-rma Jul 4, 2024
ee271fc
First draft of Water supply controllers, tests in progress
zack-rma Jul 10, 2024
68cbcb9
Controllers working, testing still in progress
zack-rma Jul 12, 2024
a1de635
Test cases passed, Controllers working
zack-rma Jul 16, 2024
e5c0de5
Fixed Water Supply Controller tests to match DTO changes
zack-rma Jul 16, 2024
750fd25
Updated Controllers to match DTO and DAO changes
zack-rma Jul 18, 2024
3f01352
Renamed Project Location Ref to Project ID, Removed deprecated Locati…
zack-rma Jul 22, 2024
5547fb9
Incorporated changed DTOs (changed constructors to builders)
zack-rma Jul 24, 2024
d9c0f15
Implemented Water Supply Accounting DTO
zack-rma Jul 18, 2024
8593b6e
Refactored DTO, added Mappable data representation
zack-rma Jul 19, 2024
415f9b4
Changed DTO Location from Location object to CwmsId
zack-rma Jul 19, 2024
4108154
Updated JSON input, renamed Project Location Ref to Project ID
zack-rma Jul 22, 2024
3b11d17
Updated Dates to Instant
zack-rma Jul 22, 2024
376b9ec
Incorporated changed Water Supply DTOs (changed constructors to build…
zack-rma Jul 24, 2024
9cc67e3
Switched DTOs to Builder Constructors
zack-rma Jul 24, 2024
6e21d95
Reworked DTO to clarify Structure for JSON
zack-rma Jul 25, 2024
e55e9cd
Removed deprecated water pump controller
zack-rma Aug 12, 2024
3208e5a
Updated Accounting DTO and tests
zack-rma Aug 12, 2024
f612350
Added base location to pump names
zack-rma Aug 14, 2024
950e791
Added sublocations to tests
zack-rma Aug 14, 2024
40a3c41
Rewrote Water Pump Accounting DTO for more concise JSON files
zack-rma Aug 26, 2024
1a86b94
Finalized pump transfer dto
zack-rma Aug 27, 2024
f834f81
CTO-97 - Water Pump Accounting DTO update with TS-style JSON
zack-rma Oct 14, 2024
49af9c3
Updated format to match TimeSeries format, added tests
zack-rma Oct 29, 2024
6baeaf0
Added test
zack-rma Oct 29, 2024
21f1cd3
Updated DTO paging structure
zack-rma Oct 31, 2024
7d5210b
Updated DTO to initialize list
zack-rma Nov 1, 2024
0b17adb
Merge branch 'develop' into feature/water_supply_accounting_dto
zack-rma Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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


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);
}
}
}
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;
}
}
Loading