From 0406b74a34595255aa1950a2e445f4208eae7e7d Mon Sep 17 00:00:00 2001 From: Michael Hostettler Date: Tue, 10 Dec 2024 12:51:23 -0800 Subject: [PATCH 1/6] PIM-1811: Implemented new product fields --- .../api/rest/v1/resource/ProductRsrc.java | 18 +++++++++++ .../factory/CirrasDataSyncRsrcFactory.java | 6 +++- .../v1/endpoints/ProductEndpointTest.java | 31 ++++++++++++++++--- ...erifiedYieldContractEndpointGrainTest.java | 15 ++++++--- .../cirras/underwriting/model/v1/Product.java | 6 ++++ .../persistence/v1/dto/ProductDto.java | 22 +++++++++++++ .../v1/dao/mybatis/mapper/ProductMapper.xml | 12 ++++++- .../persistence/v1/dao/ProductDaoTest.java | 9 ++++++ 8 files changed, 107 insertions(+), 12 deletions(-) diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/ProductRsrc.java b/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/ProductRsrc.java index 323ac070..5bdb1894 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/ProductRsrc.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/ProductRsrc.java @@ -28,6 +28,8 @@ public class ProductRsrc extends BaseResource implements Product { private Double productionGuarantee; private Double probableYield; private String insuredByMeasType; + private Double insurableValueHundredPercent; + private Double coverageDollars; private Date dataSyncTransDate; private String transactionType; @@ -109,4 +111,20 @@ public String getTransactionType() { public void setTransactionType(String transactionType) { this.transactionType = transactionType; } + + public Double getInsurableValueHundredPercent() { + return insurableValueHundredPercent; + } + + public void setInsurableValueHundredPercent(Double insurableValueHundredPercent) { + this.insurableValueHundredPercent = insurableValueHundredPercent; + } + + public Double getCoverageDollars() { + return coverageDollars; + } + + public void setCoverageDollars(Double coverageDollars) { + this.coverageDollars = coverageDollars; + } } diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/CirrasDataSyncRsrcFactory.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/CirrasDataSyncRsrcFactory.java index eb57f4ee..a8796f2c 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/CirrasDataSyncRsrcFactory.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/CirrasDataSyncRsrcFactory.java @@ -196,6 +196,8 @@ public void updateProduct(ProductDto dto, Product model) { dto.setProductId(model.getProductId()); dto.setProductionGuarantee(model.getProductionGuarantee()); dto.setProductStatusCode(model.getProductStatusCode()); + dto.setInsurableValueHundredPercent(model.getInsurableValueHundredPercent()); + dto.setCoverageDollars(model.getCoverageDollars()); dto.setDataSyncTransDate(model.getDataSyncTransDate()); } @@ -213,8 +215,10 @@ public Product getProduct(ProductDto dto) { resource.setProductId(dto.getProductId()); resource.setProductionGuarantee(dto.getProductionGuarantee()); resource.setProductStatusCode(dto.getProductStatusCode()); + resource.setInsurableValueHundredPercent(dto.getInsurableValueHundredPercent()); + resource.setCoverageDollars(dto.getCoverageDollars()); resource.setDataSyncTransDate(dto.getDataSyncTransDate()); - + return resource; } diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/ProductEndpointTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/ProductEndpointTest.java index 2d4f1cdc..e917b0f5 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/ProductEndpointTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/ProductEndpointTest.java @@ -166,6 +166,9 @@ public void testCreateUpdateDeleteProduct() throws CirrasUnderwritingServiceExce resource.setProductId(productId); resource.setProductionGuarantee(56.78); resource.setProductStatusCode("OFFER"); + resource.setInsurableValueHundredPercent(150.5); + resource.setCoverageDollars(1155.7); + resource.setDataSyncTransDate(createTransactionDate); resource.setTransactionType(PoliciesSyncEventTypes.ProductCreated); @@ -183,7 +186,9 @@ public void testCreateUpdateDeleteProduct() throws CirrasUnderwritingServiceExce Assert.assertEquals(resource.getProductId(), fetchedResource.getProductId()); Assert.assertEquals(resource.getProductionGuarantee(), fetchedResource.getProductionGuarantee()); Assert.assertEquals(resource.getProductStatusCode(), fetchedResource.getProductStatusCode()); - + Assert.assertEquals(resource.getInsurableValueHundredPercent(), fetchedResource.getInsurableValueHundredPercent()); + Assert.assertEquals(resource.getCoverageDollars(), fetchedResource.getCoverageDollars()); + Assert.assertTrue(resource.getDataSyncTransDate().compareTo(fetchedResource.getDataSyncTransDate()) == 0); @@ -196,6 +201,9 @@ public void testCreateUpdateDeleteProduct() throws CirrasUnderwritingServiceExce fetchedResource.setProbableYield(11.22); fetchedResource.setProductionGuarantee(33.44); fetchedResource.setProductStatusCode("FINAL"); + fetchedResource.setInsurableValueHundredPercent(234.5); + fetchedResource.setCoverageDollars(2233.5); + fetchedResource.setDataSyncTransDate(addSeconds(transactionDate, +1)); fetchedResource.setTransactionType(PoliciesSyncEventTypes.ProductUpdated); @@ -213,7 +221,9 @@ public void testCreateUpdateDeleteProduct() throws CirrasUnderwritingServiceExce Assert.assertEquals(fetchedResource.getProductId(), updatedResource.getProductId()); Assert.assertEquals(fetchedResource.getProductionGuarantee(), updatedResource.getProductionGuarantee()); Assert.assertEquals(fetchedResource.getProductStatusCode(), updatedResource.getProductStatusCode()); - + Assert.assertEquals(fetchedResource.getInsurableValueHundredPercent(), updatedResource.getInsurableValueHundredPercent()); + Assert.assertEquals(fetchedResource.getCoverageDollars(), updatedResource.getCoverageDollars()); + Assert.assertTrue(fetchedResource.getDataSyncTransDate().compareTo(updatedResource.getDataSyncTransDate()) == 0); //DELETE PRODUCT @@ -237,6 +247,8 @@ public void testCreateUpdateDeleteProduct() throws CirrasUnderwritingServiceExce resource2.setProductId(productId); resource2.setProductionGuarantee(56.78); resource2.setProductStatusCode("OFFER"); + resource2.setInsurableValueHundredPercent(188.3); + resource2.setCoverageDollars(8945.4); resource2.setDataSyncTransDate(createTransactionDate); resource2.setTransactionType(PoliciesSyncEventTypes.ProductCreated); @@ -290,6 +302,9 @@ public void testUpdateProductWithoutRecordNoUpdate() throws CirrasUnderwritingSe resource.setProductId(productId); resource.setProductionGuarantee(56.78); resource.setProductStatusCode("OFFER"); + resource.setInsurableValueHundredPercent(150.5); + resource.setCoverageDollars(1155.7); + resource.setDataSyncTransDate(createTransactionDate); @@ -314,7 +329,9 @@ public void testUpdateProductWithoutRecordNoUpdate() throws CirrasUnderwritingSe Assert.assertEquals(resource.getProductId(), fetchedResource.getProductId()); Assert.assertEquals(resource.getProductionGuarantee(), fetchedResource.getProductionGuarantee()); Assert.assertEquals(resource.getProductStatusCode(), fetchedResource.getProductStatusCode()); - + Assert.assertEquals(resource.getInsurableValueHundredPercent(), fetchedResource.getInsurableValueHundredPercent()); + Assert.assertEquals(resource.getCoverageDollars(), fetchedResource.getCoverageDollars()); + Assert.assertTrue(resource.getDataSyncTransDate().compareTo(fetchedResource.getDataSyncTransDate()) == 0); //NO UPDATE EXPECTED BECAUSE TRANSACTION DATE IS EARLIER THAN STORED ONE @@ -336,7 +353,9 @@ public void testUpdateProductWithoutRecordNoUpdate() throws CirrasUnderwritingSe notUpdatedResource.setProbableYield(11.22); notUpdatedResource.setProductionGuarantee(33.44); notUpdatedResource.setProductStatusCode("FINAL"); - + notUpdatedResource.setInsurableValueHundredPercent(222.5); + notUpdatedResource.setCoverageDollars(1235.7); + //UPDATE EXPECTED BECAUSE RECORD EXISTS IT WILL UPDATE IT notUpdatedResource.setTransactionType(PoliciesSyncEventTypes.ProductCreated); @@ -354,7 +373,9 @@ public void testUpdateProductWithoutRecordNoUpdate() throws CirrasUnderwritingSe Assert.assertEquals(notUpdatedResource.getProductId(), updatedResource.getProductId()); Assert.assertEquals(notUpdatedResource.getProductionGuarantee(), updatedResource.getProductionGuarantee()); Assert.assertEquals(notUpdatedResource.getProductStatusCode(), updatedResource.getProductStatusCode()); - + Assert.assertEquals(notUpdatedResource.getInsurableValueHundredPercent(), updatedResource.getInsurableValueHundredPercent()); + Assert.assertEquals(notUpdatedResource.getCoverageDollars(), updatedResource.getCoverageDollars()); + Assert.assertTrue(notUpdatedResource.getDataSyncTransDate().compareTo(updatedResource.getDataSyncTransDate()) == 0); logger.debug(">testUpdateProductWithoutRecordNoUpdate"); diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java index 59cb9bec..780e86bf 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java @@ -257,9 +257,9 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting createDopYieldContract(policyNumber1, 4); //Barley - NON Pedigree - Product - createUpdateProduct(policyId1, productId1, 16, 20, 15.5, barleyNonPediProductionGuarantee, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + createUpdateProduct(policyId1, productId1, 16, 20, 15.5, barleyNonPediProductionGuarantee, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); //Barley - Pedigree - createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedigreeProductionGuarantee, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedigreeProductionGuarantee, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); Integer pageNumber = 1; Integer pageRowCount = 20; @@ -337,7 +337,7 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting barleyCommodity.setHarvestedYieldOverride(120.0); //Create product for Canola - Pedigree - createUpdateProduct(policyId1, productId2, 19, 10, 50.5, canolaPedigreeProductionGuarantee, "Open"); + createUpdateProduct(policyId1, productId2, 19, 10, 50.5, null, null, canolaPedigreeProductionGuarantee, "Open"); List expectedCommodities = newContract.getVerifiedYieldContractCommodities(); @@ -369,7 +369,7 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting service.deleteProduct(topLevelEndpoints, productId1.toString()); //Update Barley Pedigree Product Guarantee - Expect warning Double barleyPedProdGuaranteeNew = barleyPedigreeProductionGuarantee + 20; - createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedProdGuaranteeNew, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedProdGuaranteeNew, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); //Get contract again to prevent precondition fails createdContract = getVerifiedYieldContract(policyNumber1); @@ -429,7 +429,7 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedProdGuaranteeNew, null); //Update Barley Pedigree Product Guarantee to NULL - Expect warning - createUpdateProduct(policyId1, productId3, 17, 50, 20.5, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, null, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); //Get contract VerifiedYieldContractRsrc vyContract = getVerifiedYieldContract(policyNumber1); @@ -787,6 +787,8 @@ private void createUpdateProduct( Integer deductibleLevel, Double probableYield, Double productionGuarantee, + Double insurableValueHundredPercent, + Double coverageDollars, String productStatusCode ) throws CirrasUnderwritingServiceException, ValidationException { @@ -809,6 +811,9 @@ private void createUpdateProduct( product.setProductId(productId); product.setProductionGuarantee(productionGuarantee); product.setProductStatusCode(productStatusCode); + product.setInsurableValueHundredPercent(insurableValueHundredPercent); + product.setCoverageDollars(coverageDollars); + product.setDataSyncTransDate(createTransactionDate); product.setTransactionType(PoliciesSyncEventTypes.ProductCreated); diff --git a/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/Product.java b/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/Product.java index 83d5286c..6954eb57 100644 --- a/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/Product.java +++ b/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/Product.java @@ -31,6 +31,12 @@ public interface Product extends Serializable { public String getInsuredByMeasType(); public void setInsuredByMeasType(String insuredByMeasType); + + public Double getInsurableValueHundredPercent(); + public void setInsurableValueHundredPercent(Double insurableValueHundredPercent); + + public Double getCoverageDollars(); + public void setCoverageDollars(Double coverageDollars); public Date getDataSyncTransDate(); public void setDataSyncTransDate(Date dataSyncTransDate); diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java index 60ae3da9..f39cee9c 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java @@ -27,6 +27,8 @@ public class ProductDto extends BaseDto { private Double productionGuarantee; private Double probableYield; private String insuredByMeasType; + private Double insurableValueHundredPercent; + private Double coverageDollars; private Date dataSyncTransDate; private Integer nonPedigreeCropCommodityId; @@ -52,6 +54,8 @@ public ProductDto(ProductDto dto) { this.productionGuarantee = dto.productionGuarantee; this.probableYield = dto.probableYield; this.insuredByMeasType = dto.insuredByMeasType; + this.insurableValueHundredPercent = dto.insurableValueHundredPercent; + this.coverageDollars = dto.coverageDollars; this.dataSyncTransDate = dto.dataSyncTransDate; this.nonPedigreeCropCommodityId = dto.nonPedigreeCropCommodityId; @@ -86,6 +90,8 @@ public boolean equalsAll(ProductDto other) { result = result&&dtoUtils.equals("productionGuarantee", productionGuarantee, other.productionGuarantee, 4); result = result&&dtoUtils.equals("probableYield", probableYield, other.probableYield, 4); result = result&&dtoUtils.equals("insuredByMeasType", insuredByMeasType, other.insuredByMeasType); + result = result&&dtoUtils.equals("insurableValueHundredPercent", insurableValueHundredPercent, other.insurableValueHundredPercent, 4); + result = result&&dtoUtils.equals("coverageDollars", coverageDollars, other.coverageDollars, 4); result = result&&dtoUtils.equals("dataSyncTransDate", LocalDateTime.ofInstant(dataSyncTransDate.toInstant(), ZoneId.systemDefault()), @@ -167,6 +173,22 @@ public String getInsuredByMeasType() { public void setInsuredByMeasType(String insuredByMeasType) { this.insuredByMeasType = insuredByMeasType; } + + public Double getInsurableValueHundredPercent() { + return insurableValueHundredPercent; + } + + public void setInsurableValueHundredPercent(Double insurableValueHundredPercent) { + this.insurableValueHundredPercent = insurableValueHundredPercent; + } + + public Double getCoverageDollars() { + return coverageDollars; + } + + public void setCoverageDollars(Double coverageDollars) { + this.coverageDollars = coverageDollars; + } public Integer getNonPedigreeCropCommodityId() { return nonPedigreeCropCommodityId; diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml index a1553eb9..e8648de2 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml @@ -15,6 +15,8 @@ + + @@ -36,6 +38,8 @@ t.production_guarantee, t.probable_yield, t.insured_by_meas_type, + t.insurable_value_hundred_percent, + t.coverage_dollars, t.data_sync_trans_date, t.create_user, t.create_date, @@ -79,6 +83,8 @@ production_guarantee, probable_yield, insured_by_meas_type, + insurable_value_hundred_percent, + coverage_dollars, data_sync_trans_date, create_user, create_date, @@ -94,6 +100,8 @@ #{dto.productionGuarantee, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, #{dto.probableYield, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, #{dto.insuredByMeasType, javaType=java.lang.String , jdbcType=VARCHAR, mode=IN}, + #{dto.insurableValueHundredPercent, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, + #{dto.coverageDollars, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, #{dto.dataSyncTransDate, javaType=java.util.Date , jdbcType=TIMESTAMP, mode=IN}, #{userId, javaType=java.lang.String, jdbcType=VARCHAR, mode=IN}, now(), @@ -112,7 +120,9 @@ production_guarantee = #{dto.productionGuarantee, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, probable_yield = #{dto.probableYield, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, insured_by_meas_type = #{dto.insuredByMeasType, javaType=java.lang.String , jdbcType=VARCHAR, mode=IN}, - data_sync_trans_date = #{dto.dataSyncTransDate, javaType=java.util.Date , jdbcType=TIMESTAMP, mode=IN}, + insurable_value_hundred_percent = #{dto.insurableValueHundredPercent, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, + coverage_dollars = #{dto.coverageDollars, javaType=java.lang.Double , jdbcType=NUMERIC, mode=IN}, + data_sync_trans_date = #{dto.dataSyncTransDate, javaType=java.util.Date , jdbcType=TIMESTAMP, mode=IN}, update_user = #{userId, javaType=java.lang.String, jdbcType=VARCHAR, mode=IN}, update_date = now() WHERE product_id = #{dto.productId, javaType=java.lang.Integer , jdbcType=NUMERIC, mode=IN} diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java index 3ae8a69e..28453f3a 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java @@ -185,6 +185,9 @@ public void testInsertUpdateDeleteProduct() throws Exception { newDto.setProductId(productId); newDto.setProductionGuarantee(56.78); newDto.setProductStatusCode("OFFER"); + newDto.setInsurableValueHundredPercent(150.5); + newDto.setCoverageDollars(1155.7); + newDto.setDataSyncTransDate(dataSyncTransDate); @@ -207,6 +210,8 @@ public void testInsertUpdateDeleteProduct() throws Exception { fetchedDto.setProbableYield(11.22); fetchedDto.setProductionGuarantee(33.44); fetchedDto.setProductStatusCode("FINAL"); + fetchedDto.setInsurableValueHundredPercent(210.5); + fetchedDto.setCoverageDollars(8899.7); fetchedDto.setDataSyncTransDate(dataSyncTransDate); dao.update(fetchedDto, userId); @@ -245,6 +250,8 @@ public void testInsertUpdateDeleteProduct() throws Exception { newDto.setProbableYield(22.2); newDto.setProductId(productId2); newDto.setProductionGuarantee(99.0); + newDto.setInsurableValueHundredPercent(180.5); + newDto.setCoverageDollars(3322.7); newDto.setProductStatusCode("FINAL"); newDto.setNonPedigreeCropCommodityId(24); newDto.setIsPedigreeProduct(true); @@ -287,6 +294,8 @@ private void checkProduct(ProductDto expected, ProductDto actual) { Assert.assertEquals("ProductId", expected.getProductId(), actual.getProductId()); Assert.assertEquals("ProductionGuarantee", expected.getProductionGuarantee(), actual.getProductionGuarantee()); Assert.assertEquals("ProductStatusCode", expected.getProductStatusCode(), actual.getProductStatusCode()); + Assert.assertEquals("InsurableValueHundredPercent", expected.getInsurableValueHundredPercent(), actual.getInsurableValueHundredPercent()); + Assert.assertEquals("CoverageDollars", expected.getCoverageDollars(), actual.getCoverageDollars()); Assert.assertEquals("DataSyncTransDate", expected.getDataSyncTransDate(), actual.getDataSyncTransDate()); Assert.assertEquals("NonPedigreeCropCommodityId", expected.getNonPedigreeCropCommodityId(), actual.getNonPedigreeCropCommodityId()); From f9b3820760568feabf440e96902c189a3be65a64 Mon Sep 17 00:00:00 2001 From: Michael Hostettler Date: Tue, 10 Dec 2024 16:20:22 -0800 Subject: [PATCH 2/6] PIM-1811: Implemented PIM-1785 changes to unit test --- ...erifiedYieldContractEndpointGrainTest.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java index 780e86bf..61855e4d 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java @@ -424,27 +424,38 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting //Barley - NON Pedigree checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, false, null, 23.45); //Canola - Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 18, true, canolaPedigreeProductionGuarantee, null); + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 18, true, null, null); //Barley - Pedigree checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedProdGuaranteeNew, null); //Update Barley Pedigree Product Guarantee to NULL - Expect warning createUpdateProduct(policyId1, productId3, 17, 50, 20.5, null, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); - + //Update Canola Pedigree to status final + createUpdateProduct(policyId1, productId2, 19, 10, 50.5, canolaPedigreeProductionGuarantee, null, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + //Get contract VerifiedYieldContractRsrc vyContract = getVerifiedYieldContract(policyNumber1); Assert.assertNotNull(vyContract); - //1 warning expected - Assert.assertEquals(1, vyContract.getProductWarningMessages().size()); + //2 warnings expected + Assert.assertEquals(2, vyContract.getProductWarningMessages().size()); + + //UPDATE product values + vyContract.setUpdateProductValuesInd(true); + vyContract = service.updateVerifiedYieldContract(vyContract); + Assert.assertNotNull(vyContract); + + //0 warnings expected + Assert.assertEquals(0, updatedContract.getProductWarningMessages().size()); + // Check Contract Commodities //Barley - NON Pedigree checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 16, false, null, 23.45); //Canola - Pedigree checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 18, true, canolaPedigreeProductionGuarantee, null); //Barley - Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedProdGuaranteeNew, null); + checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 16, true, null, null); //Delete verified contract ****************************************************************************** From 8d6fde1bb33bc2d9ce46592b5516e08a93d3059f Mon Sep 17 00:00:00 2001 From: Michael Hostettler Date: Tue, 10 Dec 2024 16:41:23 -0800 Subject: [PATCH 3/6] PIM-1811: Implemented release scripts for new columns and data import --- .../03_00_xx/03_06_00/00/ddl/tables/cuws.create.product.sql | 6 ++++++ .../01/cirras.cuws.03_06_00_01.import_cirras_data.dml.sql | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.product.sql b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.product.sql index 0f9eb570..220dfe61 100644 --- a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.product.sql +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.product.sql @@ -10,6 +10,8 @@ CREATE TABLE cuws.product( production_guarantee numeric(14, 4), probable_yield numeric(14, 4), insured_by_meas_type varchar(10) NOT NULL, + insurable_value_hundred_percent numeric(14, 4), + coverage_dollars numeric(14, 4), data_sync_trans_date timestamp(0) NOT NULL, create_user varchar(64) NOT NULL, create_date timestamp(0) NOT NULL, @@ -38,6 +40,10 @@ COMMENT ON COLUMN cuws.product.probable_yield IS 'Probable Yield is the calculat ; COMMENT ON COLUMN cuws.product.insured_by_meas_type IS 'Insured By Meas Type determines how the coverage is calculated (ACRES, UNITS, UNKNOWN), based on cirr_crop_coverage_annual.crop_meas_method_code' ; +COMMENT ON COLUMN cuws.product.insurable_value_hundred_percent IS 'Insurable Value Hundred Percent is the 100% IV of the product' +; +COMMENT ON COLUMN cuws.product.coverage_dollars IS 'Coverage Dollars is the total coverage from the product purchase' +; COMMENT ON COLUMN cuws.product.data_sync_trans_date IS 'Data Sync Trans Date is the date and time when the data has been updated in the source system. This prevents out of date updates' ; COMMENT ON COLUMN cuws.product.create_user IS 'Create User is the user id of the user that created the record' diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/01/cirras.cuws.03_06_00_01.import_cirras_data.dml.sql b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/01/cirras.cuws.03_06_00_01.import_cirras_data.dml.sql index 3ee010a3..45b512dd 100644 --- a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/01/cirras.cuws.03_06_00_01.import_cirras_data.dml.sql +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/01/cirras.cuws.03_06_00_01.import_cirras_data.dml.sql @@ -1,6 +1,6 @@ \o cirras.cuws.03_06_00_01.import_cirras_data.dml.log \qecho Import product -\copy cuws.product(product_id, policy_id, crop_commodity_id, commodity_coverage_code, product_status_code, deductible_level, production_guarantee, probable_yield, insured_by_meas_type, data_sync_trans_date, create_user, create_date, update_user, update_date) FROM data_export_import/product.csv WITH DELIMITER '|' NULL AS 'NULL' +\copy cuws.product(product_id, policy_id, crop_commodity_id, commodity_coverage_code, product_status_code, deductible_level, production_guarantee, probable_yield, insured_by_meas_type, insurable_value_hundred_percent, coverage_dollars, data_sync_trans_date, create_user, create_date, update_user, update_date) FROM data_export_import/product.csv WITH DELIMITER '|' NULL AS 'NULL' \o From 6f604665d79e5051ed383a6f4130a370fa417207 Mon Sep 17 00:00:00 2001 From: vivid-cpreston <97257824+vivid-cpreston@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:05:02 -0800 Subject: [PATCH 4/6] Seperate URLs for check/get token in UI vs API (#121) * Seperate URLs for check/get token in UI vs API * Update variable names --------- Co-authored-by: dpitk2222 <168222245+dpitk2222@users.noreply.github.com> Co-authored-by: mhostett <135278857+mhostett@users.noreply.github.com> --- .github/workflows/openshift-deploy.yml | 6 ++++-- openshift/cirras-underwriting-api-configmap.yaml | 4 ++-- openshift/cirras-underwriting-ui-configmap.yaml | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/openshift-deploy.yml b/.github/workflows/openshift-deploy.yml index ce6c8fee..2fe29671 100644 --- a/.github/workflows/openshift-deploy.yml +++ b/.github/workflows/openshift-deploy.yml @@ -101,8 +101,10 @@ jobs: LOG_LEVEL: ${{ vars.LOG_LEVEL }} CONNECTION_TIMEOUT: ${{ vars.CONNECTION_TIMEOUT }} - WEBADE_CHECK_TOKEN_URL: ${{ vars.WEBADE_CHECK_TOKEN_URL }} - WEBADE_GET_TOKEN_URL: ${{ vars.WEBADE_GET_TOKEN_URL }} + WEBADE_CHECK_CLIENT_TOKEN_URL: ${{ vars.WEBADE_CHECK_CLIENT_TOKEN_URL }} + WEBADE_CHECK_API_TOKEN_URL: ${{ vars.WEBADE_CHECK_API_TOKEN_URL }} + WEBADE_GET_API_TOKEN_URL: ${{ vars.WEBADE_GET_API_TOKEN_URL }} + WEBADE_GET_CLIENT_TOKEN_URL: ${{ vars.WEBADE_GET_CLIENT_TOKEN_URL }} POSTGRES_USERNAME: ${{ vars.POSTGRES_USERNAME}} diff --git a/openshift/cirras-underwriting-api-configmap.yaml b/openshift/cirras-underwriting-api-configmap.yaml index 3577309f..12a9758c 100644 --- a/openshift/cirras-underwriting-api-configmap.yaml +++ b/openshift/cirras-underwriting-api-configmap.yaml @@ -9,13 +9,13 @@ data: TOMCAT_MAX_THREADS: '#{TOMCAT_MAX_THREADS}#' CONNECTION_TIMEOUT: '#{CONNECTION_TIMEOUT}#' WEBADE_CHECK_TOKEN_URL: >- - #{WEBADE_CHECK_TOKEN_URL}# + #{WEBADE_CHECK_API_TOKEN_URL}# CIRRAS_POLICIES_API_URL: '#{CIRRAS_POLICIES_API_URL}#' POSTGRES_MAXACTIVE: '#{POSTGRES_MAXACTIVE}#' WEBADE_USERNAME: '#{WEBADE_USERNAME}#' POSTGRES_URL: >- jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/pituw#{ENV}# - WEBADE_GET_TOKEN_URL: '#{WEBADE_GET_TOKEN_URL}#' + WEBADE_GET_TOKEN_URL: '#{WEBADE_GET_API_TOKEN_URL}#' WEBADE_OAUTH2_AUTHORIZE_URL: '#{WEBADE_OAUTH2_AUTHORIZE_URL}#' JASPER_URL: 'https://#{JASPER_URL}#/jasperserver/' JASPER_USERNAME: '#{JASPER_USERNAME}#' diff --git a/openshift/cirras-underwriting-ui-configmap.yaml b/openshift/cirras-underwriting-ui-configmap.yaml index a725efc9..f684420d 100644 --- a/openshift/cirras-underwriting-ui-configmap.yaml +++ b/openshift/cirras-underwriting-ui-configmap.yaml @@ -22,9 +22,9 @@ data: WEBADE_OAUTH2_AUTHORIZE_URL: '#{WEBADE_OAUTH2_AUTHORIZE_URL}#' WEBADE_OAUTH2_ENABLE_CHECKTOKEN: '#{WEBADE_OAUTH2_ENABLE_CHECKTOKEN}#' LOCAL_CHECKTOKEN_ENDPOINT: '#{LOCAL_CHECKTOKEN_ENDPOINT}#' - WEBADE_CHECK_TOKEN_URL: '#{WEBADE_CHECK_TOKEN_URL}#' + WEBADE_CHECK_TOKEN_URL: '#{WEBADE_CHECK_CLIENT_TOKEN_URL}#' WEBADE_OAUTH2_SITEMINDER_URL: '#{WEBADE_OAUTH2_SITEMINDER_URL}#' - WEBADE_GET_TOKEN_URL: '#{WEBADE_GET_TOKEN_URL}#' + WEBADE_GET_TOKEN_URL: '#{WEBADE_GET_CLIENT_TOKEN_URL}#' WEBADE_OAUTH2_SCOPES: '#{WEBADE_OAUTH2_SCOPES}#' ACTIVE_PORT: '#{ACTIVE_PORT}#' WEB_PATH: '#{WEB_PATH}#' From 1775929f7151bcd0a60063eeb5d3f7960c65ae38 Mon Sep 17 00:00:00 2001 From: David Pitkin Date: Thu, 12 Dec 2024 16:33:49 -0800 Subject: [PATCH 5/6] PIM-1764: Added save VerifiedYieldAmendment. --- .../VerifiedYieldContractRsrcFactory.java | 15 ++++ .../impl/CirrasVerifiedYieldServiceImpl.java | 86 ++++++++++++++++++- .../factory/VerifiedYieldContractFactory.java | 7 ++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java index 90b6852d..eccfebcb 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java @@ -467,6 +467,21 @@ public void updateDto( } + @Override + public void updateDto(VerifiedYieldAmendmentDto dto, VerifiedYieldAmendment model) { + dto.setAcres(model.getAcres()); + dto.setCropCommodityId(model.getCropCommodityId()); + dto.setCropCommodityName(model.getCropCommodityName()); + dto.setFieldId(model.getFieldId()); + dto.setFieldLabel(model.getFieldLabel()); + dto.setIsPedigreeInd(model.getIsPedigreeInd()); + dto.setRationale(model.getRationale()); + dto.setVerifiedYieldAmendmentCode(model.getVerifiedYieldAmendmentCode()); + dto.setVerifiedYieldAmendmentGuid(model.getVerifiedYieldAmendmentGuid()); + dto.setVerifiedYieldContractGuid(model.getVerifiedYieldContractGuid()); + dto.setYieldPerAcre(model.getYieldPerAcre()); + } + private Double notNull(Double value, Double defaultValue) { return (value == null) ? defaultValue : value; } diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java index 1fadea9f..06eb5ec4 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import ca.bc.gov.mal.cirras.underwriting.model.v1.AnnualField; +import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldAmendment; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.ContractedFieldDetailDao; @@ -333,6 +334,19 @@ private void loadVerifiedYieldAmendments(VerifiedYieldContractDto dto) throws Da updateVerifiedYieldContractCommodity(verifiedYieldContractGuid, verifiedContractCommodity, null, false, userId); } } + + // Verified Yield Amendment + List verifiedAmendments = verifiedYieldContract.getVerifiedYieldAmendments(); + if (verifiedAmendments != null && !verifiedAmendments.isEmpty()) { + for (VerifiedYieldAmendment verifiedAmendment : verifiedAmendments) { + + // Double check that it wasn't added then deleted. + if ( !Boolean.TRUE.equals(verifiedAmendment.getDeletedByUserInd()) ) { + updateVerifiedYieldAmendment(verifiedYieldContractGuid, verifiedAmendment, userId); + } + } + } + } else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(verifiedYieldContract.getInsurancePlanId()) ) { } else { @@ -403,8 +417,65 @@ private void insertVerifiedYieldContractCommodity(String verifiedYieldContractGu logger.debug(">insertVerifiedYieldContractCommodity"); - } + } + + private void updateVerifiedYieldAmendment( + String verifiedYieldContractGuid, + VerifiedYieldAmendment verifiedAmendment, + String userId) throws DaoException { + + logger.debug("updateVerifiedYieldAmendment"); + } + + + private void insertVerifiedYieldAmendment(String verifiedYieldContractGuid, + VerifiedYieldAmendment verifiedAmendment, String userId) throws DaoException { + + logger.debug("insertVerifiedYieldAmendment"); + + } + private void deleteVerifiedYieldAmendment(VerifiedYieldAmendment verifiedAmendment) throws DaoException { + + logger.debug("deleteVerifiedYieldAmendment"); + + } + + @Override public VerifiedYieldContract updateVerifiedYieldContract( String verifiedYieldContractGuid, @@ -448,6 +519,18 @@ private void insertVerifiedYieldContractCommodity(String verifiedYieldContractGu } } + // Verified Yield Amendment + List verifiedAmendments = verifiedYieldContract.getVerifiedYieldAmendments(); + if (verifiedAmendments != null && !verifiedAmendments.isEmpty()) { + for (VerifiedYieldAmendment verifiedAmendment : verifiedAmendments) { + if ( Boolean.TRUE.equals(verifiedAmendment.getDeletedByUserInd())) { + deleteVerifiedYieldAmendment(verifiedAmendment); + } else { + updateVerifiedYieldAmendment(verifiedYieldContractGuid, verifiedAmendment, userId); + } + } + } + } else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(verifiedYieldContract.getInsurancePlanId()) ) { } else { @@ -506,6 +589,7 @@ private void deleteVerifiedYieldContract(String verifiedYieldContractGuid) throw if ( InsurancePlans.GRAIN.getInsurancePlanId().equals(dto.getInsurancePlanId()) ) { verifiedYieldContractCommodityDao.deleteForVerifiedYieldContract(verifiedYieldContractGuid); + verifiedYieldAmendmentDao.deleteForVerifiedYieldContract(verifiedYieldContractGuid); } else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(dto.getInsurancePlanId()) ) { diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java index 0573ba05..19fc6af3 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java @@ -8,11 +8,13 @@ import java.util.List; import ca.bc.gov.mal.cirras.underwriting.model.v1.AnnualField; +import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldAmendment; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.DeclaredYieldContractDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.PolicyDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; +import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldAmendmentDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractCommodityDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractDto; @@ -43,4 +45,9 @@ void updateDto( VerifiedYieldContractCommodity model, List productDtos, Boolean updateProductValues); + + void updateDto( + VerifiedYieldAmendmentDto dto, + VerifiedYieldAmendment model); + } From 8dc4a8f1cef0748bc37bddac20b756fa4a64f7f9 Mon Sep 17 00:00:00 2001 From: David Pitkin Date: Thu, 12 Dec 2024 16:49:18 -0800 Subject: [PATCH 6/6] PIM-1764: Unit tests. --- ...erifiedYieldContractEndpointGrainTest.java | 241 +++++++++++++++++- 1 file changed, 240 insertions(+), 1 deletion(-) diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java index 61855e4d..17385423 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java @@ -45,6 +45,7 @@ import ca.bc.gov.mal.cirras.underwriting.model.v1.InventorySeededGrain; import ca.bc.gov.mal.cirras.underwriting.model.v1.InventoryUnseeded; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiableCommodity; +import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldAmendment; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.LandManagementEventTypes; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InsurancePlans; @@ -484,6 +485,179 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting logger.debug(">testInsertUpdateDeleteGrainVerifiedYield"); } + + @Test + public void testInsertUpdateDeleteGrainVerifiedYieldAmendments() throws CirrasUnderwritingServiceException, Oauth2ClientException, ValidationException, DaoException { + logger.debug(" expectedAmendments = new ArrayList(); + + vya = createdContract.getVerifiedYieldAmendments().get(0); + vya.setAcres(55.66); + vya.setCropCommodityId(16); + vya.setCropCommodityName("BARLEY"); + vya.setFieldId(fieldId); + vya.setFieldLabel("LOT 3"); + vya.setIsPedigreeInd(true); + vya.setRationale("rationale A"); + vya.setVerifiedYieldAmendmentCode("Assessment"); + vya.setYieldPerAcre(77.88); + + expectedAmendments.add(vya); + + vya = createdContract.getVerifiedYieldAmendments().get(1); + vya.setAcres(98.76); + vya.setCropCommodityId(18); + vya.setCropCommodityName("CANOLA"); + vya.setFieldId(null); + vya.setFieldLabel(null); + vya.setIsPedigreeInd(false); + vya.setRationale("rationale B"); + vya.setVerifiedYieldAmendmentCode("Appraisal"); + vya.setYieldPerAcre(54.32); + + // The order in which amendments will be returned is reversed by these updates. + expectedAmendments.add(0, vya); + + vya = createdContract.getVerifiedYieldAmendments().get(2); + vya.setDeletedByUserInd(true); + + VerifiedYieldContractRsrc updatedContract = service.updateVerifiedYieldContract(createdContract); + Assert.assertNotNull(updatedContract); + + Assert.assertEquals(createdContract.getContractId(), updatedContract.getContractId()); + Assert.assertEquals(createdContract.getCropYear(), updatedContract.getCropYear()); + Assert.assertEquals(createdContract.getDeclaredYieldContractGuid(), updatedContract.getDeclaredYieldContractGuid()); + Assert.assertEquals(createdContract.getDefaultYieldMeasUnitTypeCode(), updatedContract.getDefaultYieldMeasUnitTypeCode()); + Assert.assertEquals(createdContract.getGrowerContractYearId(), updatedContract.getGrowerContractYearId()); + Assert.assertEquals(createdContract.getInsurancePlanId(), updatedContract.getInsurancePlanId()); + Assert.assertEquals(createdContract.getVerifiedYieldContractGuid(), updatedContract.getVerifiedYieldContractGuid()); + Assert.assertEquals(createdContract.getVerifiedYieldUpdateUser(), updatedContract.getVerifiedYieldUpdateUser()); + Assert.assertNotNull(updatedContract.getVerifiedYieldUpdateTimestamp()); + + checkVerifiedYieldAmendments(expectedAmendments, updatedContract.getVerifiedYieldAmendments()); + + //Delete verified contract ****************************************************************************** + service.deleteVerifiedYieldContract(updatedContract); + + searchResults = service.getUwContractList( + topLevelEndpoints, + null, + null, + null, + null, + policyNumber1, + null, + null, + null, + null, + pageNumber, pageRowCount); + + Assert.assertNotNull(searchResults); + Assert.assertEquals(1, searchResults.getCollection().size()); + + referrer = searchResults.getCollection().get(0); + Assert.assertNotNull(referrer.getInventoryContractGuid()); + Assert.assertNotNull(referrer.getDeclaredYieldContractGuid()); + Assert.assertNull(referrer.getVerifiedYieldContractGuid()); + + logger.debug(">testInsertUpdateDeleteGrainVerifiedYieldAmendments"); + } private void checkVerifiedContractCommodityTotals( List expectedCommodities, @@ -575,6 +749,44 @@ private void checkVerifiedContractCommodityRollover( Assert.assertEquals(null, verifiedCommodity.getVerifiedYieldContractGuid()); Assert.assertEquals(yieldPerAcre, verifiedCommodity.getYieldPerAcre(), 0.00005); } + + private void checkVerifiedYieldAmendments(List expected, List actual) { + if ( expected == null && actual != null || expected != null && actual == null ) { + Assert.fail(); + } else if ( expected != null && actual != null ) { + Assert.assertEquals(expected.size(), actual.size()); + + for ( int i = 0; i < expected.size(); i++ ) { + checkVerifiedYieldAmendment(expected.get(i), actual.get(i)); + } + } + + } + + private void checkVerifiedYieldAmendment(VerifiedYieldAmendment expected, VerifiedYieldAmendment actual) { + if ( expected.getVerifiedYieldAmendmentGuid() != null ) { + Assert.assertEquals(expected.getVerifiedYieldAmendmentGuid(), actual.getVerifiedYieldAmendmentGuid()); + } else { + Assert.assertNotNull(actual.getVerifiedYieldAmendmentGuid()); + } + + if ( expected.getVerifiedYieldContractGuid() != null ) { + Assert.assertEquals(expected.getVerifiedYieldContractGuid(), actual.getVerifiedYieldContractGuid()); + } else { + Assert.assertNotNull(actual.getVerifiedYieldContractGuid()); + } + + Assert.assertEquals(expected.getVerifiedYieldAmendmentCode(), actual.getVerifiedYieldAmendmentCode()); + Assert.assertEquals(expected.getCropCommodityId(), actual.getCropCommodityId()); + Assert.assertEquals(expected.getIsPedigreeInd(), actual.getIsPedigreeInd()); + Assert.assertEquals(expected.getFieldId(), actual.getFieldId()); + Assert.assertEquals(expected.getYieldPerAcre(), actual.getYieldPerAcre()); + Assert.assertEquals(expected.getAcres(), actual.getAcres()); + Assert.assertEquals(expected.getRationale(), actual.getRationale()); + Assert.assertEquals(expected.getCropCommodityName(), actual.getCropCommodityName()); + Assert.assertEquals(expected.getFieldLabel(), actual.getFieldLabel()); + Assert.assertEquals(expected.getDeletedByUserInd(), actual.getDeletedByUserInd()); + } private DopYieldContractCommodity getDopYieldContractCommodity(Integer cropCommodityId, Boolean isPedigree, List dyccList) { @@ -1119,7 +1331,34 @@ DopYieldContractCommodity createDopYieldContractCommodity(Integer cropCommodityI return dycc; } - + + VerifiedYieldAmendment createVerifiedYieldAmendment( + String verifiedYieldAmendmentCode, + Integer cropCommodityId, + String cropCommodityName, + Boolean isPedigreeInd, + Integer fieldId, + String fieldLabel, + Double acres, + Double yieldPerAcre, + String rationale) + { + + VerifiedYieldAmendment vya = new VerifiedYieldAmendment(); + vya.setAcres(acres); + vya.setCropCommodityId(cropCommodityId); + vya.setCropCommodityName(cropCommodityName); + vya.setFieldId(fieldId); + vya.setFieldLabel(fieldLabel); + vya.setIsPedigreeInd(isPedigreeInd); + vya.setRationale(rationale); + vya.setVerifiedYieldAmendmentCode(verifiedYieldAmendmentCode); + vya.setVerifiedYieldAmendmentGuid(null); + vya.setVerifiedYieldContractGuid(null); + vya.setYieldPerAcre(yieldPerAcre); + + return vya; + } private static Date addSeconds(Date date, Integer seconds) { Calendar cal = Calendar.getInstance();