Skip to content

Commit

Permalink
Reworked DTO to clarify Structure for JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Jul 29, 2024
1 parent 72dc070 commit 13a2e8a
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@
import cwms.cda.data.dto.LookupType;
import cwms.cda.data.dto.watersupply.PumpType;
import cwms.cda.data.dto.watersupply.WaterSupplyPump;
import cwms.cda.data.dto.watersupply.WaterSupplyPumpAccounting;
import cwms.cda.data.dto.watersupply.PumpAccounting;
import cwms.cda.data.dto.watersupply.WaterUser;
import cwms.cda.data.dto.watersupply.WaterUserContract;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import usace.cwms.db.dao.ifc.loc.LocationRefType;
import usace.cwms.db.dao.ifc.loc.LocationType;
import usace.cwms.db.dao.ifc.watersupply.WaterUserAccountingType;
Expand Down Expand Up @@ -182,17 +179,9 @@ public static WaterUser map(WaterUserContractRefType contract,
.withProjectId(projectLocation).withWaterRight(contractName).build();
}

public static WaterSupplyPumpAccounting map(WAT_USR_CONTRACT_ACCT_OBJ_T watUsrContractAcctObjT) {
public static PumpAccounting map(WAT_USR_CONTRACT_ACCT_OBJ_T watUsrContractAcctObjT) {
WaterUserAccountingType accounting = WaterUserTypeUtil.toWaterUserAccountingType(watUsrContractAcctObjT);
return new WaterSupplyPumpAccounting.Builder().withWaterUser(new WaterUser.Builder()
.withEntityName(accounting.getContractRefTUser()
.getWaterUserType().getEntityName()).withProjectId(new CwmsId.Builder()
.withOfficeId(accounting.getContractRefTUser()
.getWaterUserType().getParentLocationRefType().getOfficeId())
.withName(accounting.getContractRefTUser().getWaterUserType().getEntityName())
.build())
.withWaterRight(accounting.getContractRefTUser().getWaterUserType().getWaterRight()).build())
.withContractName(accounting.getContractRefTUser().getContractName())
return new PumpAccounting.Builder()
.withPumpLocation(new CwmsId.Builder().withOfficeId(accounting.getPumpLocationRefTUser().getOfficeId())
.withName(accounting.getPumpLocationRefTUser().getBaseLocationId()).build())
.withTransferType(new LookupType.Builder().withDisplayValue(accounting.getPhysicalXferTYpe()
Expand All @@ -203,24 +192,4 @@ public static WaterSupplyPumpAccounting map(WAT_USR_CONTRACT_ACCT_OBJ_T watUsrCo
.withTransferDate(accounting.getTransferStartDatetime().toInstant())
.withComment(accounting.getAccountingRemarks()).build();
}

public static List<WaterUserAccountingType> map(List<WaterSupplyPumpAccounting> accountingList) {
List<WaterUserAccountingType> accountingResult = new ArrayList<>();

for (WaterSupplyPumpAccounting accounting : accountingList) {
accountingResult.add(new WaterUserAccountingType(new WaterUserContractRefType(new WaterUserType(accounting
.getWaterUser().getEntityName(),
new LocationRefType(accounting.getWaterUser().getProjectId().getName(), null,
accounting.getWaterUser().getProjectId().getOfficeId()),
accounting.getWaterUser().getWaterRight()), accounting.getContractName()),
new LocationRefType(accounting.getPumpLocation().getName(), null,
accounting.getPumpLocation().getOfficeId()),
new usace.cwms.db.dao.ifc.cat.LookupType(accounting.getTransferType().getOfficeId(),
accounting.getTransferType().getDisplayValue(),
accounting.getTransferType().getTooltip(), accounting.getTransferType().getActive()),
accounting.getFlow(), new Date(accounting.getTransferDate().toEpochMilli()),
accounting.getComment()));
}
return accountingResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,34 @@

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.data.dto.LookupType;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.annotations.FormattableWith;
import cwms.cda.formatters.json.JsonV1;
import java.time.Instant;

@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class,
aliases = {Formats.DEFAULT, Formats.JSON})
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonDeserialize(builder = WaterSupplyPumpAccounting.Builder.class)
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
public class WaterSupplyPumpAccounting extends CwmsDTOBase {
@JsonProperty(required = true)
private final WaterUser waterUser;
@JsonProperty(required = true)
private final String contractName;

@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 Double flow;
private final Double flow;
@JsonProperty(required = true)
private final Instant transferDate;
private final String comment;

private WaterSupplyPumpAccounting(Builder builder) {
this.waterUser = builder.waterUser;
this.contractName = builder.contractName;
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 WaterUser getWaterUser() {
return this.waterUser;
}

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

public CwmsId getPumpLocation() {
return this.pumpLocation;
}
Expand All @@ -97,29 +74,13 @@ public String getComment() {
return this.comment;
}

public void setUndefined() {
this.flow = Double.NEGATIVE_INFINITY;
}

public static final class Builder {
private WaterUser waterUser;
private String contractName;
private CwmsId pumpLocation;
private LookupType transferType;
private Double flow;
private Instant transferDate;
private String comment;

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

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

public Builder withPumpLocation(CwmsId pumpLocation) {
this.pumpLocation = pumpLocation;
return this;
Expand All @@ -145,8 +106,8 @@ public Builder withComment(String comment) {
return this;
}

public WaterSupplyPumpAccounting build() {
return new WaterSupplyPumpAccounting(this);
public PumpAccounting build() {
return new PumpAccounting(this);
}
}
}
Loading

0 comments on commit 13a2e8a

Please sign in to comment.