diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/PumpType.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/PumpType.java new file mode 100644 index 000000000..d7c25a270 --- /dev/null +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/PumpType.java @@ -0,0 +1,43 @@ +/* + * + * 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; + +public enum PumpType { + IN("IN"), + OUT("OUT"), + BELOW("BELOW"); + + private final String pumpName; + + PumpType(String name) { + this.pumpName = name; + } + + public String getName() { + return pumpName; + } +} diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterSupplyPump.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterSupplyPump.java new file mode 100644 index 000000000..4f534d018 --- /dev/null +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterSupplyPump.java @@ -0,0 +1,74 @@ +/* + * + * 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.annotation.JsonRootName; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import cwms.cda.data.dto.CwmsDTOBase; +import cwms.cda.data.dto.Location; + +@JsonRootName("water_supply_pump") +@JsonDeserialize(builder = WaterSupplyPump.Builder.class) +public final class WaterSupplyPump extends CwmsDTOBase { + @JsonProperty(required = true) + private final Location pumpLocation; + @JsonProperty(required = true) + private final PumpType pumpType; + + private WaterSupplyPump(Builder builder) { + this.pumpLocation = builder.pumpLocation; + this.pumpType = builder.pumpType; + } + + public Location getPumpLocation() { + return this.pumpLocation; + } + + public PumpType getPumpType() { + return this.pumpType; + } + + public static class Builder { + private Location pumpLocation; + private PumpType pumpType; + + public Builder withPumpLocation(@JsonProperty("pump-location") Location pumpLocation) { + this.pumpLocation = pumpLocation; + return this; + } + + public Builder withPumpType(@JsonProperty("pump-type") PumpType pumpType) { + this.pumpType = pumpType; + return this; + } + + public WaterSupplyPump build() { + return new WaterSupplyPump(this); + } + } +} diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUser.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUser.java new file mode 100644 index 000000000..9330e4614 --- /dev/null +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUser.java @@ -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.data.dto.CwmsId; +import cwms.cda.formatters.Formats; +import cwms.cda.formatters.annotations.FormattableWith; +import cwms.cda.formatters.json.JsonV1; + + +@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class, + aliases = {Formats.DEFAULT, Formats.JSON}) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class) +@JsonDeserialize(builder = WaterUser.Builder.class) +public final class WaterUser extends CwmsDTOBase { + @JsonProperty(required = true) + private final String entityName; + @JsonProperty(required = true) + private final CwmsId projectId; + @JsonProperty(required = true) + private final String waterRight; + + private WaterUser(Builder builder) { + this.entityName = builder.entityName; + this.projectId = builder.projectId; + this.waterRight = builder.waterRight; + } + + public CwmsId getProjectId() { + return this.projectId; + } + + public String getEntityName() { + return this.entityName; + } + + public String getWaterRight() { + return this.waterRight; + } + + public static class Builder { + private String entityName; + private CwmsId projectId; + private String waterRight; + + public Builder withEntityName(@JsonProperty("entity-name") String entityName) { + this.entityName = entityName; + return this; + } + + public Builder withProjectId(@JsonProperty("project-id") CwmsId projectId) { + this.projectId = projectId; + return this; + } + + public Builder withWaterRight(@JsonProperty("water-right") String waterRight) { + this.waterRight = waterRight; + return this; + } + + public WaterUser build() { + return new WaterUser(this); + } + } +} diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUserContract.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUserContract.java new file mode 100644 index 000000000..30ef2aec2 --- /dev/null +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/watersupply/WaterUserContract.java @@ -0,0 +1,241 @@ +/* + * + * 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.CwmsDTO; +import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.LookupType; +import cwms.cda.formatters.Formats; +import cwms.cda.formatters.annotations.FormattableWith; +import cwms.cda.formatters.json.JsonV1; +import java.util.Date; + +@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class) +@JsonDeserialize(builder = WaterUserContract.Builder.class) +public final class WaterUserContract extends CwmsDTO { + + @JsonProperty(required = true) + private final WaterUser waterUser; + @JsonProperty(required = true) + private final CwmsId contractId; + @JsonProperty(required = true) + private final LookupType contractType; + @JsonProperty(required = true) + private final Date contractEffectiveDate; + @JsonProperty(required = true) + private final Date contractExpirationDate; + @JsonProperty(required = true) + private final Double contractedStorage; + @JsonProperty(required = true) + private final Double initialUseAllocation; + @JsonProperty(required = true) + private final Double futureUseAllocation; + @JsonProperty(required = true) + private final String storageUnitsId; + @JsonProperty(required = true) + private final Double futureUsePercentActivated; + @JsonProperty(required = true) + private final Double totalAllocPercentActivated; + private final WaterSupplyPump pumpOutLocation; + private final WaterSupplyPump pumpOutBelowLocation; + private final WaterSupplyPump pumpInLocation; + + private WaterUserContract(Builder builder) { + super(builder.officeId); + this.waterUser = builder.waterUser; + this.contractId = builder.contractId; + this.contractType = builder.contractType; + this.contractEffectiveDate = builder.contractEffectiveDate; + this.contractExpirationDate = builder.contractExpirationDate; + this.contractedStorage = builder.contractedStorage; + this.initialUseAllocation = builder.initialUseAllocation; + this.futureUseAllocation = builder.futureUseAllocation; + this.storageUnitsId = builder.storageUnitsId; + this.futureUsePercentActivated = builder.futureUsePercentActivated; + this.totalAllocPercentActivated = builder.totalAllocPercentActivated; + this.pumpOutLocation = builder.pumpOutLocation; + this.pumpOutBelowLocation = builder.pumpOutBelowLocation; + this.pumpInLocation = builder.pumpInLocation; + } + + public LookupType getContractType() { + return this.contractType; + } + + public Date getContractEffectiveDate() { + return this.contractEffectiveDate; + } + + public Date getContractExpirationDate() { + return this.contractExpirationDate; + } + + public Double getContractedStorage() { + return this.contractedStorage; + } + + public Double getInitialUseAllocation() { + return this.initialUseAllocation; + } + + public Double getFutureUseAllocation() { + return this.futureUseAllocation; + } + + public String getStorageUnitsId() { + return this.storageUnitsId; + } + + public Double getFutureUsePercentActivated() { + return this.futureUsePercentActivated; + } + + public Double getTotalAllocPercentActivated() { + return this.totalAllocPercentActivated; + } + + public WaterSupplyPump getPumpOutLocation() { + return this.pumpOutLocation; + } + + public WaterSupplyPump getPumpOutBelowLocation() { + return this.pumpOutBelowLocation; + } + + public WaterSupplyPump getPumpInLocation() { + return this.pumpInLocation; + } + + public WaterUser getWaterUser() { + return this.waterUser; + } + + public CwmsId getContractId() { + return this.contractId; + } + + public static class Builder { + private String officeId; + private WaterUser waterUser; + private CwmsId contractId; + private LookupType contractType; + private Date contractEffectiveDate; + private Date contractExpirationDate; + private Double contractedStorage; + private Double initialUseAllocation; + private Double futureUseAllocation; + private String storageUnitsId; + private Double futureUsePercentActivated; + private Double totalAllocPercentActivated; + private WaterSupplyPump pumpOutLocation; + private WaterSupplyPump pumpOutBelowLocation; + private WaterSupplyPump pumpInLocation; + + public Builder withOfficeId(String officeId) { + this.officeId = officeId; + return this; + } + + public Builder withWaterUser(WaterUser waterUser) { + this.waterUser = waterUser; + return this; + } + + public Builder withContractId(CwmsId contractId) { + this.contractId = contractId; + return this; + } + + public Builder withContractType(LookupType contractType) { + this.contractType = contractType; + return this; + } + + public Builder withContractEffectiveDate(Date contractEffectiveDate) { + this.contractEffectiveDate = contractEffectiveDate; + return this; + } + + public Builder withContractExpirationDate(Date contractExpirationDate) { + this.contractExpirationDate = contractExpirationDate; + return this; + } + + public Builder withContractedStorage(Double contractedStorage) { + this.contractedStorage = contractedStorage; + return this; + } + + public Builder withInitialUseAllocation(Double initialUseAllocation) { + this.initialUseAllocation = initialUseAllocation; + return this; + } + + public Builder withFutureUseAllocation(Double futureUseAllocation) { + this.futureUseAllocation = futureUseAllocation; + return this; + } + + public Builder withStorageUnitsId(String storageUnitsId) { + this.storageUnitsId = storageUnitsId; + return this; + } + + public Builder withFutureUsePercentActivated(Double futureUsePercentActivated) { + this.futureUsePercentActivated = futureUsePercentActivated; + return this; + } + + public Builder withTotalAllocPercentActivated(Double totalAllocPercentActivated) { + this.totalAllocPercentActivated = totalAllocPercentActivated; + return this; + } + + public Builder withPumpOutLocation(WaterSupplyPump pumpOutLocation) { + this.pumpOutLocation = pumpOutLocation; + return this; + } + + public Builder withPumpOutBelowLocation(WaterSupplyPump pumpOutBelowLocation) { + this.pumpOutBelowLocation = pumpOutBelowLocation; + return this; + } + + public Builder withPumpInLocation(WaterSupplyPump pumpInLocation) { + this.pumpInLocation = pumpInLocation; + return this; + } + + public WaterUserContract build() { + return new WaterUserContract(this); + } + } + + +} diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterUserContractTest.java b/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterUserContractTest.java new file mode 100644 index 000000000..a682e617d --- /dev/null +++ b/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterUserContractTest.java @@ -0,0 +1,255 @@ +/* + * + * 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 cwms.cda.api.enums.Nation; +import cwms.cda.api.errors.FieldException; +import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.Location; +import cwms.cda.data.dto.LookupType; +import cwms.cda.formatters.Formats; +import cwms.cda.helpers.DTOMatch; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Test; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.time.ZoneId; +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.*; + +final class WaterUserContractTest { + private static final String OFFICE_ID = "MVR"; + + @Test + void testWaterUserContractSerializationRoundTrip() { + WaterUserContract waterUserContract = buildTestWaterUserContract(); + String serialized = Formats.format(Formats.parseHeader(Formats.JSONV1, WaterUserContract.class), + waterUserContract); + WaterUserContract deserialized = Formats.parseContent(Formats.parseHeader(Formats.JSONV1, + WaterUserContract.class), serialized, WaterUserContract.class); + DTOMatch.assertMatch(waterUserContract, deserialized); + } + + @Test + void testWaterUserContractSerializationRoundTripFromFile() throws Exception { + WaterUserContract waterUserContract = buildTestWaterUserContract(); + InputStream resource = this.getClass() + .getResourceAsStream("/cwms/cda/data/dto/watersupply/waterusercontract.json"); + assertNotNull(resource); + String serialized = IOUtils.toString(resource, StandardCharsets.UTF_8); + WaterUserContract deserialized = Formats.parseContent(Formats.parseHeader(Formats.JSONV1, + WaterUserContract.class), serialized, WaterUserContract.class); + DTOMatch.assertMatch(waterUserContract, deserialized); + } + + @Test + void testValidate() { + assertAll( + () -> { + WaterUserContract waterUserContract = buildTestWaterUserContract(); + assertDoesNotThrow(waterUserContract::validate, + "Expected validation to pass without errors"); + }, + () -> { + WaterUserContract waterUserContract = new WaterUserContract.Builder() + .withContractType(new LookupType.Builder() + .withOfficeId(OFFICE_ID) + .withActive(true) + .withTooltip("TEST TOOLTIP") + .withDisplayValue("Test Display Value") + .build()) + .withContractId(new CwmsId.Builder().withOfficeId(OFFICE_ID).withName("TEST_CONTRACT").build()) + .withWaterUser(new WaterUser.Builder().withEntityName("Test User").withProjectId( + new CwmsId.Builder().withName("TEST_LOCATION1").withOfficeId(OFFICE_ID).build()) + .withWaterRight("Test Water Right").build()) + .withContractEffectiveDate(new Date(158000)) + .withContractExpirationDate(new Date(167000)) + .withFutureUseAllocation(27800.5) + .withStorageUnitsId("%") + .withContractedStorage(200000.5) + .withFutureUsePercentActivated(15.6) + .withTotalAllocPercentActivated(65.2) + .build(); + assertThrows(FieldException.class, waterUserContract::validate, + "Expected validation to fail with null Initial Use Allocation"); + }, + () -> { + WaterUserContract waterUserContract = new WaterUserContract.Builder() + .withContractId(new CwmsId.Builder().withOfficeId(OFFICE_ID).withName("TEST_CONTRACT").build()) + .withWaterUser(new WaterUser.Builder().withEntityName("Test User") + .withProjectId(new CwmsId.Builder().withName("TEST_LOCATION1") + .withOfficeId(OFFICE_ID).build()) + .withWaterRight("Test Water Right").build()) + .withContractType(new LookupType.Builder() + .withOfficeId(OFFICE_ID) + .withActive(true) + .withTooltip("TEST TOOLTIP") + .withDisplayValue("Test Display Value") + .build()) + .withContractEffectiveDate(new Date(158000)) + .withContractExpirationDate(new Date(167000)) + .withFutureUseAllocation(27800.5) + .withStorageUnitsId("%") + .withContractedStorage(200000.5) + .withInitialUseAllocation(15600.0) + .withFutureUsePercentActivated(15.6) + .build(); + assertThrows(FieldException.class, waterUserContract::validate, + "Expected validation to fail with null Total Activated Allocation Percentage"); + }, + () -> { + WaterUserContract waterUserContract = new WaterUserContract.Builder() + .withContractId(new CwmsId.Builder().withOfficeId(OFFICE_ID).withName("TEST_CONTRACT").build()) + .withWaterUser(new WaterUser.Builder().withEntityName("Test User") + .withProjectId(new CwmsId.Builder().withName("TEST_LOCATION1") + .withOfficeId(OFFICE_ID).build()) + .withWaterRight("Test Water Right").build()) + .withContractType(new LookupType.Builder() + .withOfficeId(OFFICE_ID) + .withActive(true) + .withTooltip("TEST TOOLTIP") + .withDisplayValue("Test Display Value") + .build()) + .withContractEffectiveDate(new Date(158000)) + .withFutureUseAllocation(27800.5) + .withStorageUnitsId("%") + .withContractedStorage(200000.5) + .withInitialUseAllocation(15600.0) + .withFutureUsePercentActivated(15.6) + .withTotalAllocPercentActivated(65.2) + .build(); + assertThrows(FieldException.class, waterUserContract::validate, + "Expected validation to fail with null Contract Expiration date"); + }, + () -> { + WaterUserContract waterUserContract = new WaterUserContract.Builder() + .withContractId(new CwmsId.Builder().withOfficeId(OFFICE_ID).withName("TEST_CONTRACT").build()) + .withWaterUser(new WaterUser.Builder().withEntityName("Test User") + .withProjectId(new CwmsId.Builder().withName("TEST_LOCATION1") + .withOfficeId(OFFICE_ID).build()) + .withWaterRight("Test Water Right").build()) + .withContractType(new LookupType.Builder() + .withOfficeId(OFFICE_ID) + .withActive(true) + .withTooltip("TEST TOOLTIP") + .withDisplayValue("Test Display Value") + .build()) + .withContractEffectiveDate(new Date(158000)) + .withContractExpirationDate(new Date(167000)) + .withFutureUseAllocation(27800.5) + .withContractedStorage(200000.5) + .withInitialUseAllocation(15600.0) + .withFutureUsePercentActivated(15.6) + .withTotalAllocPercentActivated(65.2) + .build(); + assertThrows(FieldException.class, waterUserContract::validate, + "Expected validation to fail with null Storage Units"); + }, + () -> { + WaterUserContract waterUserContract = new WaterUserContract.Builder() + .withContractType(new LookupType.Builder() + .withOfficeId(OFFICE_ID) + .withActive(true) + .withTooltip("TEST TOOLTIP") + .withDisplayValue("Test Display Value") + .build()) + .withContractEffectiveDate(new Date(158000)) + .withContractExpirationDate(new Date(167000)) + .withFutureUseAllocation(27800.5) + .withStorageUnitsId("%") + .withContractedStorage(200000.5) + .withInitialUseAllocation(15600.0) + .withFutureUsePercentActivated(15.6) + .withTotalAllocPercentActivated(65.2) + .build(); + assertThrows(FieldException.class, waterUserContract::validate, + "Expected validation to fail with null User Contract Reference"); + } + ); + + } + + private static WaterUserContract buildTestWaterUserContract() { + return new WaterUserContract.Builder() + .withContractId(new CwmsId.Builder().withOfficeId(OFFICE_ID).withName("TEST_CONTRACT").build()) + .withWaterUser(new WaterUser.Builder().withEntityName("Test User") + .withProjectId(new CwmsId.Builder().withName("TEST_LOCATION1") + .withOfficeId(OFFICE_ID).build()) + .withWaterRight("Test Water Right").build()) + .withContractType(new LookupType.Builder() + .withActive(true) + .withDisplayValue("Test Display Value") + .withOfficeId(OFFICE_ID) + .withTooltip("Test Tooltip") + .build()) + .withOfficeId(OFFICE_ID) + .withContractEffectiveDate(new Date(158000)) + .withContractExpirationDate(new Date(167000)) + .withInitialUseAllocation(15600.0) + .withFutureUseAllocation(27800.5) + .withStorageUnitsId("m3") + .withContractedStorage(200000.5) + .withFutureUsePercentActivated(15.6) + .withTotalAllocPercentActivated(65.2) + .withPumpOutLocation(new WaterSupplyPump.Builder() + .withPumpLocation(buildTestLocation( 1)).withPumpType(PumpType.OUT).build()) + .withPumpOutBelowLocation(new WaterSupplyPump.Builder() + .withPumpLocation(buildTestLocation(2)).withPumpType(PumpType.BELOW).build()) + .withPumpInLocation(new WaterSupplyPump.Builder() + .withPumpLocation(buildTestLocation(3)).withPumpType(PumpType.IN).build()) + .build(); + } + + private static Location buildTestLocation(int num) { + return new Location.Builder(OFFICE_ID, "PUMP" + num) + .withDescription("Test Description") + .withLocationType("Test Location Type") + .withLatitude(0.0) + .withLongName("Test Long Name") + .withLongitude(0.0) + .withHorizontalDatum("WGS84") + .withLocationKind("PUMP") + .withLocationType("Test Location Type") + .withVerticalDatum("WGS84") + .withTimeZoneName(ZoneId.of("UTC")) + .withActive(true) + .withPublicName("Test Public Pump Name") + .withNation(Nation.US) + .withStateInitial("NV") + .withCountyName("Clark") + .withNearestCity("Sparks") + .withPublishedLongitude(0.0) + .withPublishedLatitude(0.0) + .withElevation(150.0) + .withElevationUnits("m") + .withMapLabel("Test Map Label") + .withBoundingOfficeId(OFFICE_ID) + .build(); + } +} \ No newline at end of file diff --git a/cwms-data-api/src/test/java/cwms/cda/helpers/DTOMatch.java b/cwms-data-api/src/test/java/cwms/cda/helpers/DTOMatch.java index 0eaf5a797..28f2b1dbf 100644 --- a/cwms-data-api/src/test/java/cwms/cda/helpers/DTOMatch.java +++ b/cwms-data-api/src/test/java/cwms/cda/helpers/DTOMatch.java @@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.fail; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.Location; import cwms.cda.data.dto.LookupType; import cwms.cda.data.dto.location.kind.VirtualOutletRecord; import cwms.cda.data.dto.location.kind.Embankment; @@ -42,6 +43,9 @@ import cwms.cda.data.dto.stream.StreamLocation; import cwms.cda.data.dto.stream.StreamNode; import cwms.cda.data.dto.stream.StreamReach; +import cwms.cda.data.dto.watersupply.WaterSupplyPump; +import cwms.cda.data.dto.watersupply.WaterUser; +import cwms.cda.data.dto.watersupply.WaterUserContract; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -49,6 +53,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.function.Executable; + @SuppressWarnings({"LongLine", "checkstyle:LineLength"}) public final class DTOMatch { @@ -221,6 +226,73 @@ public static void assertMatch(List first, List second, AssertMatchMet .mapToObj(i -> () -> matcher.assertMatch(first.get(i), second.get(i))))); } + public static void assertMatch(WaterSupplyPump firstPump, WaterSupplyPump secondPump) { + assertAll( + () -> assertMatch(firstPump.getPumpLocation(), secondPump.getPumpLocation()), + () -> assertEquals(firstPump.getPumpType(), secondPump.getPumpType()) + ); + } + + public static void assertMatch(WaterUser firstUser, WaterUser secondUser) { + assertAll( + () -> assertEquals(firstUser.getEntityName(), secondUser.getEntityName()), + () -> DTOMatch.assertMatch(firstUser.getProjectId(), secondUser.getProjectId()), + () -> assertEquals(firstUser.getWaterRight(), secondUser.getWaterRight()) + ); + } + + public static void assertMatch(Location first, Location second) { + assertAll( + () -> assertEquals(first.getName(), second.getName()), + () -> assertEquals(first.getLatitude(), second.getLatitude()), + () -> assertEquals(first.getLongitude(), second.getLongitude()), + () -> assertEquals(first.getHorizontalDatum(), second.getHorizontalDatum()), + () -> assertEquals(first.getElevation(), second.getElevation()), + () -> assertEquals(first.getElevationUnits(), second.getElevationUnits()), + () -> assertEquals(first.getVerticalDatum(), second.getVerticalDatum()), + () -> assertEquals(first.getPublicName(), second.getPublicName()), + () -> assertEquals(first.getLongName(), second.getLongName()), + () -> assertEquals(first.getDescription(), second.getDescription()), + () -> assertEquals(first.getActive(), second.getActive()), + () -> assertEquals(first.getLocationKind(), second.getLocationKind()), + () -> assertEquals(first.getMapLabel(), second.getMapLabel()), + () -> assertEquals(first.getPublishedLatitude(), second.getPublishedLatitude()), + () -> assertEquals(first.getPublishedLongitude(), second.getPublishedLongitude()), + () -> assertEquals(first.getBoundingOfficeId(), second.getBoundingOfficeId()), + () -> assertEquals(first.getNation(), second.getNation()), + () -> assertEquals(first.getNearestCity(), second.getNearestCity()), + () -> assertEquals(first.getStateInitial(), second.getStateInitial()), + () -> assertEquals(first.getCountyName(), second.getCountyName()), + () -> assertEquals(first.getTimezoneName(), second.getTimezoneName()), + () -> assertEquals(first.getOfficeId(), second.getOfficeId()), + () -> assertEquals(first.getLocationType(), second.getLocationType()) + ); + } + + public static void assertMatch(WaterUserContract firstContract, WaterUserContract secondContract) { + assertAll( + () -> assertMatch(firstContract.getWaterUser(), secondContract.getWaterUser()), + () -> DTOMatch.assertMatch(firstContract.getContractId(), secondContract.getContractId()), + () -> DTOMatch.assertMatch(firstContract.getContractType(), secondContract.getContractType()), + () -> assertEquals(firstContract.getContractEffectiveDate().toString(), + secondContract.getContractEffectiveDate().toString()), + () -> assertEquals(firstContract.getContractExpirationDate().toString(), + secondContract.getContractExpirationDate().toString()), + () -> assertEquals(firstContract.getContractedStorage(), secondContract.getContractedStorage()), + () -> assertEquals(firstContract.getInitialUseAllocation(), secondContract.getInitialUseAllocation()), + () -> assertEquals(firstContract.getFutureUseAllocation(), secondContract.getFutureUseAllocation()), + () -> assertEquals(firstContract.getStorageUnitsId(), secondContract.getStorageUnitsId()), + () -> assertEquals(firstContract.getFutureUsePercentActivated(), + secondContract.getFutureUsePercentActivated()), + () -> assertEquals(firstContract.getTotalAllocPercentActivated(), + secondContract.getTotalAllocPercentActivated()), + () -> assertMatch(firstContract.getPumpOutLocation(), secondContract.getPumpOutLocation()), + () -> assertMatch(firstContract.getPumpOutBelowLocation(), secondContract.getPumpOutBelowLocation()), + () -> assertMatch(firstContract.getPumpInLocation(), secondContract.getPumpInLocation()) + ); + } + + @FunctionalInterface public interface AssertMatchMethod{ void assertMatch(T first, T second); diff --git a/cwms-data-api/src/test/resources/cwms/cda/data/dto/watersupply/waterusercontract.json b/cwms-data-api/src/test/resources/cwms/cda/data/dto/watersupply/waterusercontract.json new file mode 100644 index 000000000..b26d6b9e1 --- /dev/null +++ b/cwms-data-api/src/test/resources/cwms/cda/data/dto/watersupply/waterusercontract.json @@ -0,0 +1,113 @@ +{ + "office-id": "MVR", + "water-user": { + "entity-name": "Test User", + "project-id": { + "office-id": "MVR", + "name": "TEST_LOCATION1" + }, + "water-right": "Test Water Right" + }, + "contract-id": { + "office-id": "MVR", + "name": "TEST_CONTRACT" + }, + "contract-type": { + "office-id": "MVR", + "display-value": "Test Display Value", + "tooltip": "Test Tooltip", + "active": true + }, + "contract-effective-date": 158000, + "contract-expiration-date": 167000, + "contracted-storage": 200000.5, + "initial-use-allocation": 15600, + "future-use-allocation": 27800.5, + "storage-units-id": "m3", + "future-use-percent-activated": 15.6, + "total-alloc-percent-activated": 65.2, + "pump-out-location": { + "pump-location": { + "office-id": "MVR", + "name": "PUMP1", + "latitude": 0, + "longitude": 0, + "active": true, + "public-name": "Test Public Pump Name", + "long-name": "Test Long Name", + "description": "Test Description", + "timezone-name": "UTC", + "location-type": "Test Location Type", + "location-kind": "PUMP", + "nation": "US", + "state-initial": "NV", + "county-name": "Clark", + "nearest-city": "Sparks", + "horizontal-datum": "WGS84", + "published-longitude": 0, + "published-latitude": 0, + "vertical-datum": "WGS84", + "elevation": 150, + "map-label": "Test Map Label", + "bounding-office-id": "MVR", + "elevation-units": "m" + }, + "pump-type": "OUT" + }, + "pump-out-below-location": { + "pump-location": { + "office-id": "MVR", + "name": "PUMP2", + "latitude": 0, + "longitude": 0, + "active": true, + "public-name": "Test Public Pump Name", + "long-name": "Test Long Name", + "description": "Test Description", + "timezone-name": "UTC", + "location-type": "Test Location Type", + "location-kind": "PUMP", + "nation": "US", + "state-initial": "NV", + "county-name": "Clark", + "nearest-city": "Sparks", + "horizontal-datum": "WGS84", + "published-longitude": 0, + "published-latitude": 0, + "vertical-datum": "WGS84", + "elevation": 150, + "map-label": "Test Map Label", + "bounding-office-id": "MVR", + "elevation-units": "m" + }, + "pump-type": "BELOW" + }, + "pump-in-location": { + "pump-location": { + "office-id": "MVR", + "name": "PUMP3", + "latitude": 0, + "longitude": 0, + "active": true, + "public-name": "Test Public Pump Name", + "long-name": "Test Long Name", + "description": "Test Description", + "timezone-name": "UTC", + "location-type": "Test Location Type", + "location-kind": "PUMP", + "nation": "US", + "state-initial": "NV", + "county-name": "Clark", + "nearest-city": "Sparks", + "horizontal-datum": "WGS84", + "published-longitude": 0, + "published-latitude": 0, + "vertical-datum": "WGS84", + "elevation": 150, + "map-label": "Test Map Label", + "bounding-office-id": "MVR", + "elevation-units": "m" + }, + "pump-type": "IN" + } +} \ No newline at end of file