From e548dcbb650088fda6e68bd52f1b5478da2da934 Mon Sep 17 00:00:00 2001 From: zack-rma Date: Fri, 1 Nov 2024 11:05:53 -0700 Subject: [PATCH] Updated DAO to match DTO, fixed storage and retrieval bugs, added pagination support --- .../watersupply/WaterSupplyAccountingDao.java | 108 +++--- .../dao/watersupply/WaterSupplyUtils.java | 340 +++++++----------- .../WaterSupplyAccountingDaoIT.java | 216 +++++++---- .../WaterSupplyAccountingTest.java | 4 +- .../test/java/cwms/cda/helpers/DTOMatch.java | 22 +- 5 files changed, 383 insertions(+), 307 deletions(-) diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDao.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDao.java index 75ae4a565..ac3d2e565 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDao.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDao.java @@ -28,9 +28,9 @@ import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dto.CwmsId; -import cwms.cda.data.dto.watersupply.PumpAccounting; import cwms.cda.data.dto.watersupply.PumpTransfer; import cwms.cda.data.dto.watersupply.WaterSupplyAccounting; +import cwms.cda.data.dto.watersupply.WaterSupplyAccountingList; import cwms.cda.data.dto.watersupply.WaterUser; import hec.lang.Const; import java.math.BigInteger; @@ -39,7 +39,10 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jooq.DSLContext; import org.jooq.impl.DSL; import usace.cwms.db.dao.ifc.loc.LocationRefType; @@ -53,6 +56,8 @@ public class WaterSupplyAccountingDao extends JooqDao { + private static final Logger LOGGER = Logger.getLogger(WaterSupplyAccountingDao.class.getName()); + public WaterSupplyAccountingDao(DSLContext dsl) { super(dsl); } @@ -80,7 +85,7 @@ public void storeAccounting(WaterSupplyAccounting accounting) { }); } - public List retrieveAccounting(String contractName, WaterUser waterUser, + public WaterSupplyAccountingList retrieveAccounting(String contractName, WaterUser waterUser, CwmsId projectLocation, String units, Instant startTime, Instant endTime, boolean startInclusive, boolean endInclusive, boolean ascendingFlag, int rowLimit) { @@ -95,49 +100,70 @@ public List retrieveAccounting(String contractName, Water String ascendingFlagStr = OracleTypeMap.formatBool(ascendingFlag); BigInteger rowLimitBigInt = BigInteger.valueOf(rowLimit); - return connectionResult(dsl, c -> { - setOffice(c, projectLocation.getOfficeId()); - WAT_USR_CONTRACT_ACCT_TAB_T watUsrContractAcctObjTs - = CWMS_WATER_SUPPLY_PACKAGE.call_RETRIEVE_ACCOUNTING_SET(DSL.using(c).configuration(), - contractRefT, units, startTimestamp, endTimestamp, timeZoneId, startInclusiveFlag, - endInclusiveFlag, ascendingFlagStr, rowLimitBigInt, transferType); - if (!watUsrContractAcctObjTs.isEmpty()) { - return WaterSupplyUtils.toWaterSupplyAccountingList(c, watUsrContractAcctObjTs); - } else { - return new ArrayList<>(); - } - }); + return new WaterSupplyAccountingList.Builder() + .withWaterSupplyAccounting( + connectionResult(dsl, c -> { + setOffice(c, projectLocation.getOfficeId()); + WAT_USR_CONTRACT_ACCT_TAB_T watUsrContractAcctObjTs + = CWMS_WATER_SUPPLY_PACKAGE.call_RETRIEVE_ACCOUNTING_SET(DSL.using(c).configuration(), + contractRefT, units, startTimestamp, endTimestamp, timeZoneId, startInclusiveFlag, + endInclusiveFlag, ascendingFlagStr, rowLimitBigInt, transferType); + if (!watUsrContractAcctObjTs.isEmpty()) { + return WaterSupplyUtils.toWaterSupplyAccountingList(c, watUsrContractAcctObjTs); + } else { + return new ArrayList<>(); + } + })) + .withPageSize(rowLimit) + .build(); } private List getTimeWindowTypeList(WaterSupplyAccounting accounting) { List retList = new ArrayList<>(); - if (accounting.getPumpInAccounting() != null) { - for (PumpAccounting pumpIn : accounting.getPumpInAccounting().values()) { - LocationRefType locationRefType = new LocationRefType(pumpIn.getPumpLocation().getName(), - null, pumpIn.getPumpLocation().getOfficeId()); - for (PumpTransfer transfer : pumpIn.getPumpTransfers().values()) { - retList.add(new TimeWindowType(locationRefType, new Date(transfer.getTransferDate().toEpochMilli()), - new Date(transfer.getTransferDate().toEpochMilli()))); - } - } - } - if (accounting.getPumpOutAccounting() != null) { - for (PumpAccounting pumpOut : accounting.getPumpOutAccounting().values()) { - LocationRefType locationRefType = new LocationRefType(pumpOut.getPumpLocation().getName(), - null, pumpOut.getPumpLocation().getOfficeId()); - for (PumpTransfer transfer : pumpOut.getPumpTransfers().values()) { - retList.add(new TimeWindowType(locationRefType, new Date(transfer.getTransferDate().toEpochMilli()), - new Date(transfer.getTransferDate().toEpochMilli()))); - } - } - } - if (accounting.getPumpBelowAccounting() != null) { - for (PumpAccounting pumpBelow : accounting.getPumpBelowAccounting().values()) { - LocationRefType locationRefType = new LocationRefType(pumpBelow.getPumpLocation().getName(), - null, pumpBelow.getPumpLocation().getOfficeId()); - for (PumpTransfer transfer : pumpBelow.getPumpTransfers().values()) { - retList.add(new TimeWindowType(locationRefType, new Date(transfer.getTransferDate().toEpochMilli()), - new Date(transfer.getTransferDate().toEpochMilli()))); + if (accounting.getPumpAccounting() != null) { + for (Map.Entry> transfers : accounting.getPumpAccounting().entrySet()) { + for (PumpTransfer transfer : transfers.getValue()) { + switch (transfer.getPumpType()) { + case IN: + retList.add( + new TimeWindowType( + new LocationRefType( + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpIn().getName(), false), + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpIn().getName(), true), + accounting.getPumpLocations().getPumpIn().getOfficeId()), + Date.from(transfers.getKey()), + Date.from(transfers.getKey()))); + break; + case OUT: + retList.add( + new TimeWindowType( + new LocationRefType( + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpOut().getName(), false), + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpOut().getName(), true), + accounting.getPumpLocations().getPumpIn().getOfficeId()), + Date.from(transfers.getKey()), + Date.from(transfers.getKey()))); + break; + case BELOW: + retList.add( + new TimeWindowType( + new LocationRefType( + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpBelow().getName(), false), + WaterSupplyUtils.parseLocationParts( + accounting.getPumpLocations().getPumpBelow().getName(), true), + accounting.getPumpLocations().getPumpIn().getOfficeId()), + Date.from(transfers.getKey()), + Date.from(transfers.getKey()))); + break; + default: + LOGGER.log(Level.CONFIG, "Unknown pump type: {0}", transfer.getPumpType()); + break; + } } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyUtils.java b/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyUtils.java index 74ade7ac0..8fb9b53bf 100644 --- a/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyUtils.java +++ b/cwms-data-api/src/main/java/cwms/cda/data/dao/watersupply/WaterSupplyUtils.java @@ -31,7 +31,7 @@ import cwms.cda.data.dto.CwmsId; import cwms.cda.data.dto.LookupType; import cwms.cda.data.dto.watersupply.AccountingKey; -import cwms.cda.data.dto.watersupply.PumpAccounting; +import cwms.cda.data.dto.watersupply.PumpLocation; import cwms.cda.data.dto.watersupply.PumpTransfer; import cwms.cda.data.dto.watersupply.PumpType; import cwms.cda.data.dto.watersupply.WaterSupplyAccounting; @@ -42,10 +42,13 @@ import java.sql.Timestamp; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jooq.impl.DSL; import usace.cwms.db.dao.ifc.loc.LocationRefType; import usace.cwms.db.dao.ifc.watersupply.WaterUserAccountingType; @@ -63,6 +66,7 @@ final class WaterSupplyUtils { + private static final Logger LOGGER = Logger.getLogger(WaterSupplyUtils.class.getName()); private WaterSupplyUtils() { throw new IllegalStateException("Utility class"); @@ -171,38 +175,70 @@ public static WATER_USER_CONTRACT_TAB_T toWaterUserContractTs(WaterUserContract public static List toWaterUserAccTypeList(WaterSupplyAccounting accounting, WaterUser waterUser, String contractName) { List retList = new ArrayList<>(); - if (accounting.getPumpInAccounting() != null) { - for (PumpAccounting pumpIn : accounting.getPumpInAccounting().values()) { - retList.addAll(toWaterUserAccType(pumpIn, waterUser, contractName)); - } - } - if (accounting.getPumpOutAccounting() != null) { - for (PumpAccounting pumpOut : accounting.getPumpOutAccounting().values()) { - retList.addAll(toWaterUserAccType(pumpOut, waterUser, contractName)); - } - } - if (accounting.getPumpBelowAccounting() != null) { - for (PumpAccounting pumpBelow : accounting.getPumpBelowAccounting().values()) { - retList.addAll(toWaterUserAccType(pumpBelow, waterUser, contractName)); + if (accounting.getPumpAccounting() != null) { + for (Map.Entry> pumpIn : accounting.getPumpAccounting().entrySet()) { + retList.addAll(toWaterUserAccType(pumpIn.getValue(), waterUser, contractName, + accounting.getPumpLocations(), pumpIn.getKey())); } } return retList; } - public static List toWaterUserAccType(PumpAccounting accounting, WaterUser user, - String contractName) { + public static List toWaterUserAccType(List accounting, WaterUser user, + String contractName, PumpLocation pumpLocation, Instant transferDate) { List retList = new ArrayList<>(); - for (PumpTransfer transfer : accounting.getPumpTransfers().values()) { - retList.add(new WaterUserAccountingType(new WaterUserContractRefType(toWaterUserType(user), - contractName), new LocationRefType(accounting.getPumpLocation().getName(), - null, accounting.getPumpLocation().getOfficeId()), - new usace.cwms.db.dao.ifc.cat.LookupType(accounting.getPumpLocation().getOfficeId(), - transfer.getTransferTypeDisplay(), null, true), transfer.getFlow(), - new Date(transfer.getTransferDate().toEpochMilli()), transfer.getComment())); + for (PumpTransfer transfer : accounting) { + switch (transfer.getPumpType()) { + case IN: + retList.add( + new WaterUserAccountingType(new WaterUserContractRefType(toWaterUserType(user), contractName), + new LocationRefType(parseLocationParts(pumpLocation.getPumpIn().getName(), false), + parseLocationParts(pumpLocation.getPumpIn().getName(), true), + pumpLocation.getPumpIn().getOfficeId()), + new usace.cwms.db.dao.ifc.cat.LookupType(pumpLocation.getPumpIn().getOfficeId(), + transfer.getTransferTypeDisplay(), null, true), transfer.getFlow(), + new Date(transferDate.toEpochMilli()), transfer.getComment())); + break; + case OUT: + retList.add( + new WaterUserAccountingType(new WaterUserContractRefType(toWaterUserType(user), contractName), + new LocationRefType(parseLocationParts(pumpLocation.getPumpOut().getName(), false), + parseLocationParts(pumpLocation.getPumpOut().getName(), true), + pumpLocation.getPumpOut().getOfficeId()), + new usace.cwms.db.dao.ifc.cat.LookupType(pumpLocation.getPumpOut().getOfficeId(), + transfer.getTransferTypeDisplay(), null, true), transfer.getFlow(), + new Date(transferDate.toEpochMilli()), transfer.getComment())); + break; + case BELOW: + retList.add( + new WaterUserAccountingType(new WaterUserContractRefType(toWaterUserType(user), contractName), + new LocationRefType(parseLocationParts(pumpLocation.getPumpBelow().getName(), false), + parseLocationParts(pumpLocation.getPumpBelow().getName(), true), + pumpLocation.getPumpBelow().getOfficeId()), + new usace.cwms.db.dao.ifc.cat.LookupType(pumpLocation.getPumpBelow().getOfficeId(), + transfer.getTransferTypeDisplay(), null, true), transfer.getFlow(), + new Date(transferDate.toEpochMilli()), transfer.getComment())); + break; + default: + LOGGER.log(Level.CONFIG, "Unknown pump type: {0}", transfer.getPumpType()); + break; + } } return retList; } + public static String parseLocationParts(String location, boolean subLocation) { + String[] parts = location.split("-"); + int size = parts.length; + if (subLocation) { + if (size < 2) { + return null; + } + return parts[1]; + } + return parts[0]; + } + public static WaterUserType toWaterUserType(WaterUser waterUser) { return new WaterUserType(waterUser.getEntityName(), toLocationRefType(waterUser.getProjectId()), waterUser.getWaterRight()); @@ -248,224 +284,122 @@ public static List toWaterSupplyAccountingList(Connection for (WAT_USR_CONTRACT_ACCT_OBJ_T watUsrContractAcctObjT : watUsrContractAcctTabT) { WaterUserAccountingType accounting = WaterUserTypeUtil.toWaterUserAccountingType(watUsrContractAcctObjT); WaterContractDao waterContractDao = new WaterContractDao(DSL.using(c)); - WaterUserContract waterUserContract = waterContractDao.getWaterContract(accounting.getContractRefTUser() - .getContractName(), new CwmsId.Builder().withOfficeId(accounting.getContractRefTUser() - .getWaterUserType().getParentLocationRefType().getOfficeId()).withName(accounting.getContractRefTUser() - .getWaterUserType().getParentLocationRefType().getBaseLocationId()).build(), accounting.getContractRefTUser() - .getWaterUserType().getEntityName()); + WaterUserContract waterUserContract = waterContractDao.getWaterContract( + accounting.getContractRefTUser().getContractName(), + new CwmsId.Builder() + .withOfficeId(accounting.getContractRefTUser().getWaterUserType().getParentLocationRefType().getOfficeId()) + .withName(accounting.getContractRefTUser().getWaterUserType().getParentLocationRefType().getBaseLocationId()) + .build(), + accounting.getContractRefTUser().getWaterUserType().getEntityName()); String pumpIn = waterUserContract.getPumpInLocation().getPumpLocation().getName(); String pumpOut = waterUserContract.getPumpOutLocation().getPumpLocation().getName(); String pumpBelow = waterUserContract.getPumpOutBelowLocation().getPumpLocation().getName(); - AccountingKey key = new AccountingKey.Builder().withWaterUser(new WaterUser.Builder() - .withProjectId(new CwmsId.Builder() - .withOfficeId(accounting.getContractRefTUser() - .getWaterUserType().getParentLocationRefType().getOfficeId()) - .withName(accounting.getContractRefTUser().getWaterUserType() - .getParentLocationRefType().getBaseLocationId()).build()) - .withEntityName(accounting.getContractRefTUser().getWaterUserType().getEntityName()) - .withWaterRight(accounting.getContractRefTUser().getWaterUserType() - .getWaterRight()).build()) - .withContractName(accounting.getContractRefTUser().getContractName()).build(); + AccountingKey key = new AccountingKey.Builder() + .withWaterUser(new WaterUser.Builder() + .withProjectId(new CwmsId.Builder() + .withOfficeId(accounting.getContractRefTUser().getWaterUserType().getParentLocationRefType().getOfficeId()) + .withName(accounting.getContractRefTUser().getWaterUserType().getParentLocationRefType().getBaseLocationId()) + .build()) + .withEntityName(accounting.getContractRefTUser().getWaterUserType().getEntityName()) + .withWaterRight(accounting.getContractRefTUser().getWaterUserType().getWaterRight()).build()) + .withContractName(accounting.getContractRefTUser().getContractName()) + .build(); if (cacheMap.containsKey(key)) { if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpIn) : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpIn)) - { - if (cacheMap.get(key).getPumpInAccounting() != null && cacheMap.get(key).getPumpInAccounting().containsKey(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()))) { - cacheMap.get(key).getPumpInAccounting().get(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId())) - .getPumpTransfers().put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); + + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpIn)) { + + if (cacheMap.get(key).getPumpAccounting() != null + && cacheMap.get(key).getPumpAccounting().containsKey(accounting.getTransferStartDatetime().toInstant())) { + + List tempList = cacheMap.get(key).getPumpAccounting() + .get(accounting.getTransferStartDatetime().toInstant()); + List transferList = new ArrayList<>(tempList); + transferList.add(new PumpTransfer(PumpType.IN, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), transferList); } else { - Map timeMap = new TreeMap<>(); - timeMap.put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); - cacheMap.get(key).getPumpInAccounting().put(accounting.getPumpLocationRefTUser() != null && - accounting.getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), - new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder().withOfficeId(accounting - .getPumpLocationRefTUser().getOfficeId()) - .withName(accounting.getPumpLocationRefTUser().getSubLocationId() == null - || accounting.getPumpLocationRefTUser().getSubLocationId().isEmpty() - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).build()) - .withPumpTransfers(timeMap) - .build()); + List transferList = Collections.singletonList(new PumpTransfer(PumpType.IN, + accounting.getPhysicalXferTYpe().getDisplayValue(), accounting.getAccountingFlow(), + accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), + transferList); } } else if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpOut) : (accounting.getPumpLocationRefTUser().getBaseLocationId() + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpOut)) { - if (cacheMap.get(key).getPumpOutAccounting().containsKey(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()))) { - cacheMap.get(key).getPumpOutAccounting().get(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId())) - .getPumpTransfers().put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); + if (cacheMap.get(key).getPumpAccounting().containsKey(accounting.getTransferStartDatetime().toInstant())) { + List tempList = cacheMap.get(key).getPumpAccounting().get(accounting.getTransferStartDatetime().toInstant()); + List transferList = new ArrayList<>(tempList); + transferList.add(new PumpTransfer(PumpType.OUT, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), transferList); } else { - Map timeMap = new TreeMap<>(); - timeMap.put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); - cacheMap.get(key).getPumpOutAccounting().put(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), - new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder().withOfficeId(accounting - .getPumpLocationRefTUser().getOfficeId()) - .withName(accounting.getPumpLocationRefTUser().getSubLocationId() == null - || accounting.getPumpLocationRefTUser().getSubLocationId().isEmpty() - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).build()) - .withPumpTransfers(timeMap) - .build()); + List transferList = Collections.singletonList(new PumpTransfer(PumpType.OUT, + accounting.getPhysicalXferTYpe().getDisplayValue(), accounting.getAccountingFlow(), + accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), + transferList); } } else if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpBelow) : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpBelow)) - { - if (cacheMap.get(key).getPumpBelowAccounting().containsKey(accounting - .getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()))) { - cacheMap.get(key).getPumpBelowAccounting().get(accounting.getPumpLocationRefTUser() - .getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId())) - .getPumpTransfers().put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); + + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpBelow)) { + + if (cacheMap.get(key).getPumpAccounting().containsKey(accounting.getTransferStartDatetime().toInstant())) { + List tempList = cacheMap.get(key).getPumpAccounting().get(accounting.getTransferStartDatetime().toInstant()); + List transferList = new ArrayList<>(tempList); + transferList.add(new PumpTransfer(PumpType.BELOW, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), transferList); } else { - Map timeMap = new TreeMap<>(); - timeMap.put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); - cacheMap.get(key).getPumpBelowAccounting().put(accounting.getPumpLocationRefTUser() - .getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), - new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder().withOfficeId(accounting - .getPumpLocationRefTUser().getOfficeId()) - .withName(accounting.getPumpLocationRefTUser().getSubLocationId() == null - || accounting.getPumpLocationRefTUser().getSubLocationId().isEmpty() - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).build()) - .withPumpTransfers(timeMap) - .build()); + List transferList = Collections.singletonList(new PumpTransfer(PumpType.BELOW, + accounting.getPhysicalXferTYpe().getDisplayValue(), accounting.getAccountingFlow(), + accounting.getAccountingRemarks())); + cacheMap.get(key).getPumpAccounting().put(accounting.getTransferStartDatetime().toInstant(), + transferList); } } } else { - Map inMap = new TreeMap<>(); - Map outMap = new TreeMap<>(); - Map belowMap = new TreeMap<>(); - - Map timeMap = new TreeMap<>(); - timeMap.put(accounting.getTransferStartDatetime().toInstant(), - new PumpTransfer.Builder() - .withTransferTypeDisplay(accounting.getPhysicalXferTYpe() - .getDisplayValue()) - .withTransferDate(accounting.getTransferStartDatetime().toInstant()) - .withComment(accounting.getAccountingRemarks()) - .withFlow(accounting.getAccountingFlow()).build()); - PumpAccounting pumpAccounting = new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder().withOfficeId(accounting - .getPumpLocationRefTUser().getOfficeId()) - .withName(accounting.getPumpLocationRefTUser().getSubLocationId() == null - || accounting.getPumpLocationRefTUser().getSubLocationId().isEmpty() - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).build()) - .withPumpTransfers(timeMap) - .build(); + List transferList = new ArrayList<>(); + Map> timeMap = new TreeMap<>(); if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpIn) : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpIn)) - { - inMap.put(accounting.getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), pumpAccounting); + + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpIn)) { + transferList.add(new PumpTransfer(PumpType.IN, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); } else if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpOut) : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpOut)) - { - outMap.put(accounting.getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), pumpAccounting); + + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpOut)) { + transferList.add(new PumpTransfer(PumpType.OUT, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); } else if (accounting.getPumpLocationRefTUser().getSubLocationId() == null ? accounting.getPumpLocationRefTUser().getBaseLocationId().equals(pumpBelow) : (accounting.getPumpLocationRefTUser().getBaseLocationId() + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()).equals(pumpBelow)) { - belowMap.put(accounting.getPumpLocationRefTUser().getSubLocationId() == null - ? accounting.getPumpLocationRefTUser().getBaseLocationId() - : (accounting.getPumpLocationRefTUser().getBaseLocationId() - + "-" + accounting.getPumpLocationRefTUser().getSubLocationId()), pumpAccounting); + transferList.add(new PumpTransfer(PumpType.BELOW, accounting.getPhysicalXferTYpe().getDisplayValue(), + accounting.getAccountingFlow(), accounting.getAccountingRemarks())); } + timeMap.put(accounting.getTransferStartDatetime().toInstant(), transferList); + WaterSupplyAccounting supplyAccounting = new WaterSupplyAccounting.Builder() - .withPumpBelowAccounting(belowMap) - .withPumpInAccounting(inMap) - .withPumpOutAccounting(outMap) + .withPumpAccounting(timeMap) .withContractName(key.getContractName()) .withWaterUser(key.getWaterUser()) + .withPumpLocations(new PumpLocation.Builder() + .withPumpIn(CwmsId.buildCwmsId(waterUserContract.getPumpInLocation().getPumpLocation().getOfficeId(), + waterUserContract.getPumpInLocation().getPumpLocation().getName())) + .withPumpOut(CwmsId.buildCwmsId(waterUserContract.getPumpOutLocation().getPumpLocation().getOfficeId(), + waterUserContract.getPumpOutLocation().getPumpLocation().getName())) + .withPumpBelow(CwmsId.buildCwmsId(waterUserContract.getPumpOutBelowLocation().getPumpLocation().getOfficeId(), + waterUserContract.getPumpOutBelowLocation().getPumpLocation().getName())) + .build()) .build(); cacheMap.put(key, supplyAccounting); } diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDaoIT.java b/cwms-data-api/src/test/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDaoIT.java index 09661fd83..df318cb6e 100644 --- a/cwms-data-api/src/test/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDaoIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/data/dao/watersupply/WaterSupplyAccountingDaoIT.java @@ -37,10 +37,11 @@ import cwms.cda.data.dto.Location; import cwms.cda.data.dto.LookupType; import cwms.cda.data.dto.project.Project; -import cwms.cda.data.dto.watersupply.PumpAccounting; +import cwms.cda.data.dto.watersupply.PumpLocation; import cwms.cda.data.dto.watersupply.PumpTransfer; import cwms.cda.data.dto.watersupply.PumpType; import cwms.cda.data.dto.watersupply.WaterSupplyAccounting; +import cwms.cda.data.dto.watersupply.WaterSupplyAccountingList; import cwms.cda.data.dto.watersupply.WaterSupplyPump; import cwms.cda.data.dto.watersupply.WaterUser; import cwms.cda.data.dto.watersupply.WaterUserContract; @@ -51,12 +52,14 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; import java.time.ZoneId; +import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Map; @@ -148,7 +151,7 @@ void testStoreAndRetrieveWaterSupplyPumpAccounting(String method) throws Excepti switch (method) { // Months are zero indexed case "default": - instance.set(2025, 9, 1, 0, 0); + instance.set(2025, 8, 30, 0, 0); startTime = instance.getTime().toInstant(); break; case "startInclusiveTrue": @@ -202,6 +205,126 @@ void testStoreAndRetrieveWaterSupplyPumpAccounting(String method) throws Excepti } } + @Test + void testStoreRetrievePaginated() throws Exception { + // Test Structure + // 1) Create and store a Water Supply Contract + // 2) Create and store Water Supply Pump Accounting + // 3) Retrieve Water Supply Pump Accounting and assert it is the same (or not in DB) + WaterSupplyAccounting accounting = buildTestAccounting(); + + Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + instance.clear(); + instance.set(2025, 9, 1, 12, 0); + Instant endTime = instance.getTime().toInstant(); + instance.clear(); + boolean startInclusive = true; + boolean endInclusive = true; + instance.set(2025, 9, 1, 0, 0); + Instant startTime = instance.getTime().toInstant(); + + CwmsDatabaseContainer db = CwmsDataApiSetupCallback.getDatabaseLink(); + db.connection(c -> { + DSLContext ctx = getDslContext(c, OFFICE_ID); + WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); + accountingDao.storeAccounting(accounting); + }, CwmsDataApiSetupCallback.getWebUser()); + + int rowLimit = 2; + boolean headFlag = false; + + Map> firstPageMap = new TreeMap<>(); + List transfers = accounting.getPumpAccounting().get(Instant.parse("2025-10-01T00:00:00Z")); + firstPageMap.put(Instant.parse("2025-10-01T00:00:00Z"), transfers); + + WaterSupplyAccounting accounting2 = new WaterSupplyAccounting.Builder() + .withWaterUser(accounting.getWaterUser()) + .withContractName(accounting.getContractName()) + .withWaterUser(accounting.getWaterUser()) + .withPumpLocations(accounting.getPumpLocations()) + .withPumpAccounting(firstPageMap) + .build(); + + // retrieve and assert in db + // page 1 + final Instant finalStartTime = startTime; + final Instant finalEndTime = endTime; + final boolean finalStartInclusive = startInclusive; + db.connection(c -> { + DSLContext ctx = getDslContext(c, OFFICE_ID); + WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); + WaterSupplyAccountingList pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() + .getName(), contract.getWaterUser(), contract.getWaterUser().getProjectId(), + null, finalStartTime, finalEndTime, finalStartInclusive, endInclusive, headFlag, rowLimit); + assertFalse(pumpAccounting.getWaterSupplyAccounting().isEmpty()); + assertEquals(rowLimit, pumpAccounting.getPageSize()); + for (WaterSupplyAccounting returnedAccounting : pumpAccounting.getWaterSupplyAccounting()) { + assertNotNull(returnedAccounting.getPumpAccounting()); + DTOMatch.assertMatch(accounting2, returnedAccounting); + } + }, CwmsDataApiSetupCallback.getWebUser()); + + Map> secondPageMap = new TreeMap<>(); + List transfers2 = accounting.getPumpAccounting().get(Instant.parse("2025-10-02T00:00:00Z")); + secondPageMap.put(Instant.parse("2025-10-02T00:00:00Z"), transfers2); + + WaterSupplyAccounting accounting3 = new WaterSupplyAccounting.Builder() + .withWaterUser(accounting.getWaterUser()) + .withContractName(accounting.getContractName()) + .withWaterUser(accounting.getWaterUser()) + .withPumpLocations(accounting.getPumpLocations()) + .withPumpAccounting(secondPageMap) + .build(); + + startTime = Instant.parse("2025-10-01T12:00:00Z"); + endTime = Instant.parse("2025-10-03T00:00:00Z"); + startInclusive = false; + final Instant finalStartTime1 = startTime; + final Instant finalEndTime1 = endTime; + final boolean finalStartInclusive1 = startInclusive; + db.connection(c -> { + DSLContext ctx = getDslContext(c, OFFICE_ID); + WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); + WaterSupplyAccountingList pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() + .getName(), contract.getWaterUser(), contract.getWaterUser().getProjectId(), + null, finalStartTime1, finalEndTime1, finalStartInclusive1, endInclusive, headFlag, rowLimit); + assertFalse(pumpAccounting.getWaterSupplyAccounting().isEmpty()); + assertEquals(rowLimit, pumpAccounting.getPageSize()); + for (WaterSupplyAccounting returnedAccounting : pumpAccounting.getWaterSupplyAccounting()) { + assertNotNull(returnedAccounting.getPumpAccounting()); + DTOMatch.assertMatch(accounting3, returnedAccounting); + } + }, CwmsDataApiSetupCallback.getWebUser()); + + + } + + @Test + void testStoreRetrieve() throws Exception { + WaterSupplyAccounting accounting = buildTestAccounting(); + final Instant startTime = Instant.parse("2015-10-01T00:00:00Z"); + final Instant endTime = Instant.parse("2035-10-03T00:00:00Z"); + final boolean startInclusive = false; + final boolean endInclusive = false; + final boolean headFlag = false; + final int rowLimit = 20; + CwmsDatabaseContainer db = CwmsDataApiSetupCallback.getDatabaseLink(); + db.connection(c -> { + DSLContext ctx = getDslContext(c, OFFICE_ID); + WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); + accountingDao.storeAccounting(accounting); + WaterSupplyAccountingList pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() + .getName(), contract.getWaterUser(), contract.getWaterUser().getProjectId(), + null, startTime, endTime, startInclusive, endInclusive, headFlag, rowLimit); + assertFalse(pumpAccounting.getWaterSupplyAccounting().isEmpty()); + assertEquals(rowLimit, pumpAccounting.getPageSize()); + for (WaterSupplyAccounting returnedAccounting : pumpAccounting.getWaterSupplyAccounting()) { + assertNotNull(returnedAccounting.getPumpAccounting()); + DTOMatch.assertMatch(accounting, returnedAccounting); + } + }, CwmsDataApiSetupCallback.getWebUser()); + } + private void assertPumpAccountingInDB(WaterUserContract contract, Instant startTime, Instant endTime, boolean startInclusive, boolean endInclusive, boolean headFlag, int rowLimit) throws Exception { @@ -210,13 +333,13 @@ private void assertPumpAccountingInDB(WaterUserContract contract, Instant startT db.connection(c -> { DSLContext ctx = getDslContext(c, OFFICE_ID); WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); - List pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() - .getName(), contract.getWaterUser(), new CwmsId.Builder().withOfficeId(OFFICE_ID) - .withName(contract.getWaterUser().getProjectId().getName()).build(), + WaterSupplyAccountingList pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() + .getName(), contract.getWaterUser(), contract.getWaterUser().getProjectId(), null, startTime, endTime, startInclusive, endInclusive, headFlag, rowLimit); - assertFalse(pumpAccounting.isEmpty()); - for (WaterSupplyAccounting returnedAccounting : pumpAccounting) { - assertNotNull(returnedAccounting.getPumpInAccounting()); + assertFalse(pumpAccounting.getWaterSupplyAccounting().isEmpty()); + assertEquals(rowLimit, pumpAccounting.getPageSize()); + for (WaterSupplyAccounting returnedAccounting : pumpAccounting.getWaterSupplyAccounting()) { + assertNotNull(returnedAccounting.getPumpAccounting()); DTOMatch.assertMatch(buildTestAccounting(), returnedAccounting); } }, CwmsDataApiSetupCallback.getWebUser()); @@ -229,22 +352,21 @@ private void assertPumpAccountingInDBEmpty(WaterUserContract contract, db.connection(c -> { DSLContext ctx = getDslContext(c, OFFICE_ID); WaterSupplyAccountingDao accountingDao = new WaterSupplyAccountingDao(ctx); - List pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() + WaterSupplyAccountingList pumpAccounting = accountingDao.retrieveAccounting(contract.getContractId() .getName(), contract.getWaterUser(), new CwmsId.Builder().withName(contract.getWaterUser() .getProjectId().getName()).withOfficeId(OFFICE_ID).build(), null, startTime, endTime, startInclusive, endInclusive, headFlag, rowLimit); - for (WaterSupplyAccounting returnedAccounting : pumpAccounting) { - assertAll( - () -> assertTrue(returnedAccounting.getPumpInAccounting().isEmpty()), - () -> assertTrue(returnedAccounting.getPumpOutAccounting().isEmpty()), - () -> assertTrue(returnedAccounting.getPumpBelowAccounting().isEmpty()) - ); + assertEquals(rowLimit, pumpAccounting.getPageSize()); + for (WaterSupplyAccounting returnedAccounting : pumpAccounting.getWaterSupplyAccounting()) { + assertTrue(returnedAccounting.getPumpAccounting().isEmpty()); } }, CwmsDataApiSetupCallback.getWebUser()); } protected static WaterUser buildTestWaterUser(String entityName) { - return new WaterUser.Builder().withEntityName(entityName).withProjectId(new CwmsId.Builder() + return new WaterUser.Builder() + .withEntityName(entityName) + .withProjectId(new CwmsId.Builder() .withName(PROJECT_NAME) .withOfficeId(OFFICE_ID) .build()) @@ -313,7 +435,7 @@ protected static Location buildTestLocation(String locationName, String location protected static Project buildTestProject() { return new Project.Builder().withLocation(buildTestLocation(PROJECT_NAME, - "Test Location Type")) + "PROJECT")) .withFederalCost(new BigDecimal("15980654.55")) .build(); } @@ -321,53 +443,25 @@ protected static Project buildTestProject() { private WaterSupplyAccounting buildTestAccounting() { return new WaterSupplyAccounting.Builder().withWaterUser(testUser) .withContractName(contract.getContractId().getName()) - .withPumpInAccounting(buildTestPumpAccountingList(1)) - .withPumpOutAccounting(buildTestPumpAccountingList(2)) + .withPumpAccounting(buildTestPumpAccountingList()) + .withPumpLocations(new PumpLocation.Builder() + .withPumpIn(CwmsId.buildCwmsId(OFFICE_ID, contract.getPumpInLocation().getPumpLocation().getName())) + .withPumpOut(CwmsId.buildCwmsId(OFFICE_ID, contract.getPumpOutLocation().getPumpLocation().getName())) + .withPumpBelow(CwmsId.buildCwmsId(OFFICE_ID, contract.getPumpOutBelowLocation().getPumpLocation().getName())) + .build()) .build(); } - private Map buildTestPumpAccountingList(int index) { - Map retList = new TreeMap<>(); - Map transfers = new TreeMap<>(); - Map transfers2 = new TreeMap<>(); - if (index == 1) - { - transfers.put(Instant.parse("2025-10-01T00:00:00Z"), new PumpTransfer.Builder() - .withFlow(100.0) - .withTransferDate(Instant.parse("2025-10-01T00:00:00Z")) - .withTransferTypeDisplay("Test Transfer") - .build()); - transfers.put(Instant.parse("2025-10-02T00:00:00Z"), new PumpTransfer.Builder() - .withFlow(200.0) - .withTransferDate(Instant.parse("2025-10-02T00:00:00Z")) - .withTransferTypeDisplay("Test Transfer") - .build()); - retList.put(contract.getContractId().getName() + "-Pump 1", new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder() - .withName(contract.getContractId().getName() + "-Pump 1") - .withOfficeId(OFFICE_ID) - .build()) - .withPumpTransfers(transfers) - .build()); - } else { - transfers2.put(Instant.parse("2025-10-03T00:00:00Z"), new PumpTransfer.Builder() - .withFlow(300.0) - .withTransferDate(Instant.parse("2025-10-03T00:00:00Z")) - .withTransferTypeDisplay("Test Transfer") - .build()); - transfers2.put(Instant.parse("2025-10-04T00:00:00Z"), new PumpTransfer.Builder() - .withFlow(400.0) - .withTransferDate(Instant.parse("2025-10-04T00:00:00Z")) - .withTransferTypeDisplay("Test Transfer") - .build()); - retList.put(contract.getContractId().getName() + "-Pump 2", new PumpAccounting.Builder() - .withPumpLocation(new CwmsId.Builder() - .withName(contract.getContractId().getName() + "-Pump 2") - .withOfficeId(OFFICE_ID) - .build()) - .withPumpTransfers(transfers2) - .build()); - } + private Map> buildTestPumpAccountingList() { + Map> retList = new TreeMap<>(); + List transfers = new ArrayList<>(); + transfers.add(new PumpTransfer(PumpType.IN, "Conduit", 100.0, "Test Transfer")); + transfers.add(new PumpTransfer(PumpType.OUT, "Pipeline", 200.0, "Emergency Transfer")); + retList.put(Instant.parse("2025-10-01T00:00:00Z"), transfers); + transfers.clear(); + transfers.add(new PumpTransfer(PumpType.OUT, "Canal", 300.0, "Test Transfer")); + transfers.add(new PumpTransfer(PumpType.BELOW, "Stream", 400.0, "Emergency Transfer")); + retList.put(Instant.parse("2025-10-02T00:00:00Z"), transfers); return retList; } } diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterSupplyAccountingTest.java b/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterSupplyAccountingTest.java index cd60a500b..b98b875e3 100644 --- a/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterSupplyAccountingTest.java +++ b/cwms-data-api/src/test/java/cwms/cda/data/dto/watersupply/WaterSupplyAccountingTest.java @@ -188,10 +188,12 @@ void testBuildWSA() { .withPumpAccounting(buildTestPumpAccountingList()) .withWaterUser(user) .build(); + List tempList = new ArrayList<>(); + tempList.add(wsa); WaterSupplyAccountingList wsaList = new WaterSupplyAccountingList.Builder() .withPageSize(10) - .withWaterSupplyAccounting(Collections.singletonList(wsa)) + .withWaterSupplyAccounting(tempList) .build(); assertAll( 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 06d2302a8..ac5b9c99a 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 @@ -386,7 +386,7 @@ public static void assertMatch(Map> first, Map first, List second) { + assertAll( + () -> assertEquals(first.size(), second.size(), "Pump transfer sizes do not match"), + () -> { + for (PumpTransfer transfer : first) { + boolean found = false; + for (PumpTransfer secondTransfer : second) { + if (transfer.getPumpType().equals(secondTransfer.getPumpType())) { + found = true; + assertMatch(transfer, secondTransfer); + } + } + if (!found) { + fail("Pump transfer not found: " + transfer.getTransferTypeDisplay()); + } + } + } + ); + } + private static void assertMatch(PumpColumn first, PumpColumn second) { assertAll( () -> assertEquals(first.getName(), second.getName(), "Pump column names do not match"),