Skip to content

Commit

Permalink
PIM-1763: Added fields and VerifiableCommodities. Configured verified…
Browse files Browse the repository at this point in the history
…_yield_amendment_code table.
  • Loading branch information
dpitk2222 committed Nov 26, 2024
1 parent b612c60 commit dca9327
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
import ca.bc.gov.mal.cirras.underwriting.model.v1.DopYieldContractCommodity;
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;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.DeclaredYieldContractCommodityDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.DeclaredYieldContractDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.InventoryFieldDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.InventorySeededGrainDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.PolicyDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldAmendmentDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldContractCommodityDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldContractDao;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ContractedFieldDetailDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.DeclaredYieldContractCommodityDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.DeclaredYieldContractDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventoryFieldDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventorySeededGrainDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.PolicyDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldAmendmentDto;
import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractCommodityDto;
Expand Down Expand Up @@ -57,6 +63,9 @@ public class CirrasVerifiedYieldServiceImpl implements CirrasVerifiedYieldServic

// daos
private PolicyDao policyDao;
private InventoryFieldDao inventoryFieldDao;
private InventorySeededGrainDao inventorySeededGrainDao;
private ContractedFieldDetailDao contractedFieldDetailDao;
private DeclaredYieldContractDao declaredYieldContractDao;
private DeclaredYieldContractCommodityDao declaredYieldContractCommodityDao;
private VerifiedYieldContractDao verifiedYieldContractDao;
Expand All @@ -79,6 +88,18 @@ public void setPolicyDao(PolicyDao policyDao) {
this.policyDao = policyDao;
}

public void setInventoryFieldDao(InventoryFieldDao inventoryFieldDao) {
this.inventoryFieldDao = inventoryFieldDao;
}

public void setInventorySeededGrainDao(InventorySeededGrainDao inventorySeededGrainDao) {
this.inventorySeededGrainDao = inventorySeededGrainDao;
}

public void setContractedFieldDetailDao(ContractedFieldDetailDao contractedFieldDetailDao) {
this.contractedFieldDetailDao = contractedFieldDetailDao;
}

public void setDeclaredYieldContractDao(DeclaredYieldContractDao declaredYieldContractDao) {
this.declaredYieldContractDao = declaredYieldContractDao;
}
Expand Down Expand Up @@ -123,6 +144,7 @@ public VerifiedYieldContract<? extends AnnualField> rolloverVerifiedYieldContrac
}

loadDopYieldContractCommodities(dycDto);
loadFields(dycDto);

result = verifiedYieldContractFactory.getDefaultVerifiedYieldContract(policyDto, dycDto, factoryContext, authentication);

Expand Down Expand Up @@ -176,7 +198,49 @@ private void calculateVerifiedYieldContractCommodities(VerifiedYieldContract<? e
}
}
}

private void loadFields(DeclaredYieldContractDto dto) throws DaoException {

List<ContractedFieldDetailDto> fields = contractedFieldDetailDao.selectForVerifiedYield(dto.getContractId(), dto.getCropYear());
dto.setFields(fields);

for (ContractedFieldDetailDto cfdDto : dto.getFields()) {
loadPlantings(cfdDto);
}
}

private void loadFields(VerifiedYieldContractDto dto) throws DaoException {

List<ContractedFieldDetailDto> fields = contractedFieldDetailDao.selectForVerifiedYield(dto.getContractId(), dto.getCropYear());
dto.setFields(fields);

for (ContractedFieldDetailDto cfdDto : dto.getFields()) {
loadPlantings(cfdDto);
}
}

private void loadPlantings(ContractedFieldDetailDto cfdDto) throws DaoException {

List<InventoryFieldDto> plantings = inventoryFieldDao.select(cfdDto.getFieldId(), cfdDto.getCropYear(), cfdDto.getInsurancePlanId());
cfdDto.setPlantings(plantings);

for (InventoryFieldDto ifDto : plantings) {

if ( InsurancePlans.GRAIN.getInsurancePlanId().equals(cfdDto.getInsurancePlanId()) ) {
loadSeededGrains(ifDto);
} else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(cfdDto.getInsurancePlanId()) ) {

} else {
throw new ServiceException("Insurance Plan must be GRAIN or FORAGE");
}
}
}


private void loadSeededGrains(InventoryFieldDto ifDto) throws DaoException {
List<InventorySeededGrainDto> inventorySeededGrains = inventorySeededGrainDao.selectForVerifiedYield(ifDto.getInventoryFieldGuid());
ifDto.setInventorySeededGrains(inventorySeededGrains);
}

@Override
public VerifiedYieldContract<? extends AnnualField> getVerifiedYieldContract(String verifiedYieldContractGuid,
Expand Down Expand Up @@ -211,6 +275,7 @@ private VerifiedYieldContract<? extends AnnualField> loadVerifiedYieldContract(

loadVerifiedYieldContractCommodities(dto);
loadVerifiedYieldAmendments(dto);
loadFields(dto);

return verifiedYieldContractFactory.getVerifiedYieldContract(dto, factoryContext, authentication);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public List<CodeTableConfig> codeTableConfigs() {
result.add(plantInsurabilityTypeCodeTableConfig());
result.add(landIdentifierTypeCodeTableConfig());
result.add(primaryReferenceTypeCodeTableConfig());
result.add(verifiedYieldAmendmentCodeTableConfig());
result.add(policyCropYearCodeTableConfig());
result.add(insurancePlanTableConfig());
result.add(officeTableConfig());
Expand Down Expand Up @@ -108,7 +109,10 @@ public CodeTableConfig primaryReferenceTypeCodeTableConfig() {
return createCodeTableConfig("primary_reference_type_code", "SORT_ORDER");
}


@Bean
public CodeTableConfig verifiedYieldAmendmentCodeTableConfig() {
return createCodeTableConfig("verified_yield_amendment_code", "DESCRIPTION");
}

@Bean
public CodeTableConfig policyCropYearCodeTableConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ public CirrasVerifiedYieldService cirrasVerifiedYieldService() {
result.setVerifiedYieldContractFactory(verifiedYieldContractFactory);

result.setPolicyDao(persistenceSpringConfig.policyDao());
result.setInventoryFieldDao(persistenceSpringConfig.inventoryFieldDao());
result.setInventorySeededGrainDao(persistenceSpringConfig.inventorySeededGrainDao());
result.setContractedFieldDetailDao(persistenceSpringConfig.contractedFieldDetailDao());
result.setDeclaredYieldContractDao(persistenceSpringConfig.declaredYieldContractDao());
result.setDeclaredYieldContractCommodityDao(persistenceSpringConfig.declaredYieldContractCommodityDao());
result.setVerifiedYieldContractDao(persistenceSpringConfig.verifiedYieldContractDao());
Expand Down

0 comments on commit dca9327

Please sign in to comment.