Skip to content

Commit

Permalink
Water Supply Accounting DTO (#800)
Browse files Browse the repository at this point in the history
Implements Water Supply Accounting DTO with tests
  • Loading branch information
zack-rma authored Nov 20, 2024
1 parent be650dc commit a2715b3
Show file tree
Hide file tree
Showing 7 changed files with 756 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
*
* 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.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import cwms.cda.data.dto.CwmsId;

@JsonDeserialize(builder = PumpLocation.Builder.class)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
public final class PumpLocation {
private final CwmsId pumpIn;
private final CwmsId pumpOut;
private final CwmsId pumpBelow;

private PumpLocation(Builder builder) {
this.pumpIn = builder.pumpIn;
this.pumpOut = builder.pumpOut;
this.pumpBelow = builder.pumpBelow;
}

public CwmsId getPumpIn() {
return this.pumpIn;
}

public CwmsId getPumpOut() {
return this.pumpOut;
}

public CwmsId getPumpBelow() {
return this.pumpBelow;
}

public static final class Builder {
private CwmsId pumpIn;
private CwmsId pumpOut;
private CwmsId pumpBelow;

public Builder withPumpIn(CwmsId pumpIn) {
this.pumpIn = pumpIn;
return this;
}

public Builder withPumpOut(CwmsId pumpOut) {
this.pumpOut = pumpOut;
return this;
}

public Builder withPumpBelow(CwmsId pumpBelow) {
this.pumpBelow = pumpBelow;
return this;
}

public PumpLocation build() {
return new PumpLocation(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
*
* 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.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import cwms.cda.data.dto.CwmsDTOBase;

@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
public final class PumpTransfer extends CwmsDTOBase {
@JsonProperty(required = true)
private final PumpType pumpType;
@JsonProperty(required = true)
private final String transferTypeDisplay;
@JsonProperty(required = true)
private final Double flow;
@JsonProperty(required = true)
private final String comment;

@JsonCreator
public PumpTransfer(@JsonProperty("pump-type") PumpType pumpType,
@JsonProperty("transfer-type-display") String transferTypeDisplay,
@JsonProperty("flow") Double flow, @JsonProperty("comment") String comment) {
this.transferTypeDisplay = transferTypeDisplay;
this.flow = flow;
this.comment = comment;
this.pumpType = pumpType;
}

public String getTransferTypeDisplay() {
return this.transferTypeDisplay;
}

public Double getFlow() {
return this.flow;
}

public PumpType getPumpType() {
return this.pumpType;
}

public String getComment() {
return this.comment;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
*
* 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.JsonIgnoreProperties;
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 io.swagger.v3.oas.annotations.media.Schema;
import java.time.Instant;
import java.util.List;
import java.util.Map;

@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class,
aliases = {Formats.DEFAULT, Formats.JSON})
@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;
@JsonProperty(required = true)
private final PumpLocation pumpLocations;
@Schema(name = "data-columns")
private final Map<Instant, List<PumpTransfer>> pumpAccounting;

private WaterSupplyAccounting(Builder builder) {
this.contractName = builder.contractName;
this.waterUser = builder.waterUser;
this.pumpLocations = builder.pumpLocations;
this.pumpAccounting = builder.pumpAccounting;
}

public String getContractName() {
return this.contractName;
}

public WaterUser getWaterUser() {
return this.waterUser;
}

public Map<Instant, List<PumpTransfer>> getPumpAccounting() {
return this.pumpAccounting;
}

public PumpLocation getPumpLocations() {
return this.pumpLocations;
}


@JsonIgnoreProperties("data-columns")
public static final class Builder {
private String contractName;
private WaterUser waterUser;
private Map<Instant, List<PumpTransfer>> pumpAccounting;
private PumpLocation pumpLocations;

public Builder withContractName(String contractName) {
this.contractName = contractName;
return this;
}

public Builder withWaterUser(WaterUser waterUser) {
this.waterUser = waterUser;
return this;
}

public Builder withPumpAccounting(
Map<Instant, List<PumpTransfer>> pumpAccounting) {
this.pumpAccounting = pumpAccounting;
return this;
}

public Builder withPumpLocations(
PumpLocation pumpLocations) {
this.pumpLocations = pumpLocations;
return this;
}

public WaterSupplyAccounting build() {
return new WaterSupplyAccounting(this);
}
}
}
Loading

0 comments on commit a2715b3

Please sign in to comment.