Skip to content

Commit

Permalink
Updated transfer type checking, fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Jul 29, 2024
1 parent c1d525b commit 0a7238d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiRequestBody;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
import java.util.List;




public class AccountingCreateController implements Handler {
Expand Down Expand Up @@ -110,31 +111,28 @@ public void handle(@NotNull Context ctx) {
WaterSupplyAccounting.class);
WaterSupplyAccountingDao waterSupplyAccountingDao = getWaterSupplyAccountingDao(dsl);
LookupTypeDao lookupTypeDao = new LookupTypeDao(dsl);
List<LookupType> lookupList = lookupTypeDao.retrieveLookupTypes("AT_PHYSICAL_TRANSFER_TYPE", "PHYS_TRANS_TYPE", office);
List<LookupType> lookupList = lookupTypeDao
.retrieveLookupTypes("AT_PHYSICAL_TRANSFER_TYPE", "PHYS_TRANS_TYPE", office);

if (!searchForTransferType(accounting, lookupList)) {
ctx.status(HttpServletResponse.SC_BAD_REQUEST).json("No such transfer type found.");
return;
for (PumpAccounting pumpAccounting : accounting.getPumpAccounting()) {
if (!searchForTransferType(pumpAccounting, lookupList)) {
ctx.status(HttpServletResponse.SC_BAD_REQUEST).json("No matching transfer type found "
+ "for an accounting entry.");
return;
}
}

waterSupplyAccountingDao.storeAccounting(accounting);
ctx.status(HttpServletResponse.SC_CREATED).json(contractId + " created successfully");
}
}

private boolean searchForTransferType(WaterSupplyAccounting accounting, List<LookupType> lookupTypes) {
Iterator<PumpAccounting> pumpAccountingIterator = accounting.getPumpAccounting().iterator();
Iterator<LookupType> lookupTypeIterator = lookupTypes.iterator();
while (pumpAccountingIterator.hasNext()) {
PumpAccounting pumpAccounting = pumpAccountingIterator.next();
while (lookupTypeIterator.hasNext()) {
LookupType lookupType = lookupTypeIterator.next();
if (pumpAccounting.getTransferType().getActive() == lookupType.getActive()
&& pumpAccounting.getTransferType().getOfficeId().equals(lookupType.getOfficeId())
&& pumpAccounting.getTransferType().getTooltip().equals(lookupType.getTooltip())
&& pumpAccounting.getTransferType().getDisplayValue().equals(lookupType.getDisplayValue())) {
return true;
}
private boolean searchForTransferType(PumpAccounting accounting, List<LookupType> lookupTypes) {
for (LookupType lookupType : lookupTypes) {
if (accounting.getTransferType().getActive() == lookupType.getActive()
&& accounting.getTransferType().getOfficeId().equals(lookupType.getOfficeId())
&& accounting.getTransferType().getTooltip().equals(lookupType.getTooltip())
&& accounting.getTransferType().getDisplayValue().equals(lookupType.getDisplayValue())) {
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void testCreateRetrieveWaterAccounting() throws Exception {
.body("[0].water-user.project-id.office-id", equalTo(WATER_SUPPLY_ACCOUNTING.getWaterUser().getProjectId().getOfficeId()))
.body("[0].water-user.water-right", equalTo(WATER_SUPPLY_ACCOUNTING.getWaterUser().getWaterRight()))
.body("[0].pump-accounting[0].transfer-type.display-value", equalTo(testTransferType.getDisplayValue()))
.body("[0].pump-accounting[0].pump-location.name", equalTo(WATER_SUPPLY_ACCOUNTING.getPumpAccounting().get(0).getPumpLocation().getName()))
.body("[0].pump-accounting[1].pump-location.name", equalTo(WATER_SUPPLY_ACCOUNTING.getPumpAccounting().get(1).getPumpLocation().getName()))
.body("[0].pump-accounting[1].pump-location.name", equalTo(WATER_SUPPLY_ACCOUNTING.getPumpAccounting().get(0).getPumpLocation().getName()))
.body("[0].pump-accounting[0].pump-location.name", equalTo(WATER_SUPPLY_ACCOUNTING.getPumpAccounting().get(1).getPumpLocation().getName()))
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"transfer-type": {
"office-id": "SWT",
"display-value": "Test Transfer Type 2",
"tooltip": "Test Tool Tip 2",
"display-value": "Test Transfer Type",
"tooltip": "Test Tool Tip",
"active": true
},
"flow": 2.0,
Expand Down

0 comments on commit 0a7238d

Please sign in to comment.