Skip to content

Commit

Permalink
Merge pull request #136 from bcgov/feature/3.6.0
Browse files Browse the repository at this point in the history
Feature/3.6.0
  • Loading branch information
vivid-esnauffer authored Dec 12, 2024
2 parents f071bec + 6815d9b commit f0c9dde
Show file tree
Hide file tree
Showing 49 changed files with 2,784 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ byte[] generateInventoryReport(
String policyNumber,
String growerInfo,
String sortColumn,
String policyIds
String policyIds,
String reportType
) throws CirrasUnderwritingServiceException;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ public byte[] generateInventoryReport(
String policyNumber,
String growerInfo,
String sortColumn,
String policyIds) throws CirrasUnderwritingServiceException {
String policyIds,
String reportType) throws CirrasUnderwritingServiceException {

GenericRestDAO<byte[]> dao = this.getRestDAOFactory().getGenericRestDAO(byte[].class);

Expand All @@ -474,6 +475,7 @@ public byte[] generateInventoryReport(
putQueryParam(queryParams, "growerInfo", growerInfo);
putQueryParam(queryParams, "sortColumn", sortColumn);
putQueryParam(queryParams, "policyIds", policyIds);
putQueryParam(queryParams, "reportType", reportType);

Response<byte[]> response = dao.Process(ResourceTypes.BYTES, new NullTransformer("application/octet-stream", "bytes"), parent, queryParams, getWebClient());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract;
import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity;
import ca.bc.gov.nrs.common.wfone.rest.resource.BaseResource;
import ca.bc.gov.nrs.common.wfone.rest.resource.MessageRsrc;

@XmlRootElement(namespace = ResourceTypes.NAMESPACE, name = ResourceTypes.VERIFIED_YIELD_CONTRACT_NAME)
@XmlSeeAlso({ VerifiedYieldContractRsrc.class })
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type")
public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedYieldContract<AnnualFieldRsrc> {
public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedYieldContract<AnnualFieldRsrc, MessageRsrc> {

private static final long serialVersionUID = 1L;

Expand All @@ -32,10 +33,12 @@ public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedY

private Integer insurancePlanId;
private Integer growerContractYearId;
private Boolean updateProductValuesInd;

private List<AnnualFieldRsrc> fields = new ArrayList<AnnualFieldRsrc>();
private List<VerifiedYieldContractCommodity> verifiedYieldContractCommodities = new ArrayList<VerifiedYieldContractCommodity>();
private List<VerifiedYieldAmendment> verifiedYieldAmendments = new ArrayList<VerifiedYieldAmendment>();
private List<MessageRsrc> productWarningMessages = new ArrayList<MessageRsrc>();

public String getVerifiedYieldContractGuid() {
return verifiedYieldContractGuid;
Expand Down Expand Up @@ -100,6 +103,14 @@ public void setGrowerContractYearId(Integer growerContractYearId) {
this.growerContractYearId = growerContractYearId;
}

public Boolean getUpdateProductValuesInd() {
return updateProductValuesInd;
}

public void setUpdateProductValuesInd(Boolean updateProductValuesInd) {
this.updateProductValuesInd = updateProductValuesInd;
}

public List<AnnualFieldRsrc> getFields() {
return fields;
}
Expand All @@ -121,4 +132,11 @@ public void setVerifiedYieldAmendments(List<VerifiedYieldAmendment> verifiedYiel
this.verifiedYieldAmendments = verifiedYieldAmendments;
}

public List<MessageRsrc> getProductWarningMessages() {
return productWarningMessages;
}
public void setProductWarningMessages(List<MessageRsrc> productWarningMessages) {
this.productWarningMessages = productWarningMessages;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Response generateInventoryReport(
@Parameter(description = "Filter the results by the policy number") @QueryParam("policyNumber") String policyNumber,
@Parameter(description = "Filter the results by the grower info (Name, Number, Phone, Email") @QueryParam("growerInfo") String growerInfo,
@Parameter(description = "Sort by column") @QueryParam("sortColumn") String sortColumn,
@Parameter(description = "IDs of policies to be included") @QueryParam("policyIds") String policyIds
@Parameter(description = "IDs of policies to be included") @QueryParam("policyIds") String policyIds,
@Parameter(description = "Type of report: unseeded or seeded (GRAIN only)") @QueryParam("reportType") String reportType
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public Response generateInventoryReport(
String policyNumber,
String growerInfo,
String sortColumn,
String policyIds) {
String policyIds,
String reportType) {

Response response = null;

Expand Down Expand Up @@ -69,6 +70,7 @@ public Response generateInventoryReport(
toString(growerInfo),
toString(sortColumn),
toString(policyIds),
toString(reportType),
getFactoryContext(),
getWebAdeAuthentication());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.factory;

import ca.bc.gov.nrs.common.wfone.rest.resource.MessageRsrc;
import ca.bc.gov.nrs.common.wfone.rest.resource.RelLink;
import ca.bc.gov.nrs.wfone.common.model.Message;
import ca.bc.gov.nrs.wfone.common.rest.endpoints.resource.factory.BaseResourceFactory;
import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryContext;
import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryException;
import ca.bc.gov.nrs.wfone.common.webade.authentication.WebAdeAuthentication;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.ws.rs.core.UriBuilder;

Expand All @@ -32,18 +38,21 @@
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.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;
import ca.bc.gov.mal.cirras.underwriting.service.api.v1.model.factory.VerifiedYieldContractFactory;
import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.CommodityCoverageCode;
import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InsurancePlans;

public class VerifiedYieldContractRsrcFactory extends BaseResourceFactory implements VerifiedYieldContractFactory {

@Override
public VerifiedYieldContract<? extends AnnualField> getDefaultVerifiedYieldContract(
public VerifiedYieldContract<? extends AnnualField, ? extends Message> getDefaultVerifiedYieldContract(
PolicyDto policyDto,
DeclaredYieldContractDto dycDto,
List<ProductDto> productDtos,
FactoryContext context,
WebAdeAuthentication authentication
) throws FactoryException {
Expand All @@ -69,7 +78,7 @@ public VerifiedYieldContract<? extends AnnualField> getDefaultVerifiedYieldContr
List<VerifiedYieldContractCommodity> vyContractCommodities = new ArrayList<VerifiedYieldContractCommodity>();

for (DeclaredYieldContractCommodityDto dyccDto : dycDto.getDeclaredYieldContractCommodities()) {
VerifiedYieldContractCommodity vyccModel = createDefaultVerifiedYieldContractCommodity(dyccDto);
VerifiedYieldContractCommodity vyccModel = createDefaultVerifiedYieldContractCommodity(dyccDto, productDtos);
vyContractCommodities.add(vyccModel);
}

Expand All @@ -93,11 +102,19 @@ private void populateDefaultResource(VerifiedYieldContractRsrc resource, PolicyD
resource.setVerifiedYieldContractGuid(null);
resource.setVerifiedYieldUpdateTimestamp(null);
resource.setVerifiedYieldUpdateUser(null);
resource.setProductWarningMessages(new ArrayList<MessageRsrc>());
}


private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodity(DeclaredYieldContractCommodityDto dto) {
private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodity(DeclaredYieldContractCommodityDto dto, List<ProductDto> productDtos) {
VerifiedYieldContractCommodity model = new VerifiedYieldContractCommodity();

//Get production guarantee
Double productionGuarantee = null;
ProductDto product = getProductDto(dto.getCropCommodityId(), dto.getIsPedigreeInd(), productDtos);
if(product != null && product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) {
productionGuarantee = product.getProductionGuarantee();
}

model.setCropCommodityId(dto.getCropCommodityId());
model.setCropCommodityName(dto.getCropCommodityName());
Expand All @@ -106,7 +123,7 @@ private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodi
model.setHarvestedYield(null); // Calculated later
model.setHarvestedYieldOverride(null);
model.setIsPedigreeInd(dto.getIsPedigreeInd());
model.setProductionGuarantee(null); // TODO: Will be implemented later.
model.setProductionGuarantee(productionGuarantee);
model.setSoldYieldDefaultUnit(dto.getSoldYieldDefaultUnit());
model.setStoredYieldDefaultUnit(dto.getStoredYieldDefaultUnit());
model.setTotalInsuredAcres(dto.getTotalInsuredAcres());
Expand All @@ -118,7 +135,7 @@ private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodi
}

@Override
public VerifiedYieldContract<? extends AnnualField> getVerifiedYieldContract(VerifiedYieldContractDto dto,
public VerifiedYieldContract<? extends AnnualField, ? extends Message> getVerifiedYieldContract(VerifiedYieldContractDto dto, List<ProductDto> productDtos,
FactoryContext context, WebAdeAuthentication authentication) throws FactoryException {

VerifiedYieldContractRsrc resource = new VerifiedYieldContractRsrc();
Expand All @@ -137,13 +154,21 @@ public VerifiedYieldContract<? extends AnnualField> getVerifiedYieldContract(Ver
resource.setFields(fields);
}

List<MessageRsrc> productWarnings = new ArrayList<MessageRsrc>();

// Verified Yield Contract Commodity
if (!dto.getVerifiedYieldContractCommodities().isEmpty()) {
List<VerifiedYieldContractCommodity> verifiedContractCommodities = new ArrayList<VerifiedYieldContractCommodity>();

for (VerifiedYieldContractCommodityDto vyccDto : dto.getVerifiedYieldContractCommodities()) {
VerifiedYieldContractCommodity vyccModel = createVerifiedYieldContractCommodity(vyccDto);
verifiedContractCommodities.add(vyccModel);

//Check product guarantee
MessageRsrc warning = getProductWarning(vyccDto, productDtos);
if(warning != null) {
productWarnings.add(warning);
}
}

resource.setVerifiedYieldContractCommodities(verifiedContractCommodities);
Expand All @@ -161,6 +186,8 @@ public VerifiedYieldContract<? extends AnnualField> getVerifiedYieldContract(Ver
resource.setVerifiedYieldAmendments(verifiedYieldAmendments);
}

resource.setProductWarningMessages(productWarnings);

String eTag = getEtag(resource);
resource.setETag(eTag);

Expand All @@ -182,8 +209,87 @@ private void populateResource(VerifiedYieldContractRsrc resource, VerifiedYieldC
resource.setVerifiedYieldContractGuid(dto.getVerifiedYieldContractGuid());
resource.setVerifiedYieldUpdateTimestamp(dto.getVerifiedYieldUpdateTimestamp());
resource.setVerifiedYieldUpdateUser(dto.getVerifiedYieldUpdateUser());
resource.setUpdateProductValuesInd(false);

}

public static final String PRODUCT_STATUS_FINAL = "FINAL";
public static final String PRODUCTION_GUARANTEE_DIFFERENCE_MSG = "Production guarantee for %s is different in the product: %.2f";
public static final String PRODUCTION_GUARANTEE_NONE_MSG = "There is no production guarantee for %s";
public static final String PRODUCTION_GUARANTEE_NO_PRODUCT_MSG = "There is no product for %s in CIRRAS. The shown Production guarantee is not valid anymore.";

private MessageRsrc getProductWarning(VerifiedYieldContractCommodityDto vyccDto, List<ProductDto> productDtos) {

MessageRsrc messageRsrc = null;

//Find product
ProductDto product = getProductDto(vyccDto.getCropCommodityId(), vyccDto.getIsPedigreeInd(), productDtos);

if(product != null) {
if(product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) {
if (Double.compare(notNull(product.getProductionGuarantee(), (double)-1), notNull(vyccDto.getProductionGuarantee(), (double)-1)) != 0) {
//Add warning if values are different -> Only if product is in status FINAL
String commodity = vyccDto.getCropCommodityName();
if(vyccDto.getIsPedigreeInd()) {
commodity = commodity + " Pedigreed";
}

String msg = "";
if(product.getProductionGuarantee() == null) {
msg = String.format(PRODUCTION_GUARANTEE_NONE_MSG, commodity, product.getProductionGuarantee());
} else {
msg = String.format(PRODUCTION_GUARANTEE_DIFFERENCE_MSG, commodity, product.getProductionGuarantee());
}

messageRsrc = new MessageRsrc(msg);
}
}
} else {
//No product: Check if the production guarantee in commodity totals is null
if(vyccDto.getProductionGuarantee() != null) {
//Add warning if there is no product but a saved production guarantee
String commodity = vyccDto.getCropCommodityName();
if(vyccDto.getIsPedigreeInd()) {
commodity = commodity + " Pedigreed";
}

String msg = String.format(PRODUCTION_GUARANTEE_NO_PRODUCT_MSG, commodity);
messageRsrc = new MessageRsrc(msg);
}
}


return messageRsrc;
}

private static final Set<String> coverageCodes = new HashSet<String>(Arrays.asList(
new String[] {
CommodityCoverageCode.QUANTITY_GRAIN,
CommodityCoverageCode.QUANTITY_FORAGE,
CommodityCoverageCode.QUANTITY_SILAGE_CORN
}));

private ProductDto getProductDto(Integer cropCommodityId, Boolean isPedigree, List<ProductDto> productDtos) {

ProductDto product = null;

if(productDtos != null && productDtos.size() > 0) {
//Products in CIRRAS use a different commodity id for pedigreed than in this app. A table maps the correct commodity ids and
//are returned to the NonPedigreeCropCommodityId property
List<ProductDto> products = productDtos.stream()
.filter(x -> x.getNonPedigreeCropCommodityId().equals(cropCommodityId)
&& x.getIsPedigreeProduct().equals(isPedigree)
&& coverageCodes.contains(x.getCommodityCoverageCode()))
.collect(Collectors.toList());

if (products != null && products.size() > 0) {
product = products.get(0);
}
}


return product;
}

private VerifiedYieldContractCommodity createVerifiedYieldContractCommodity(VerifiedYieldContractCommodityDto dto) {
VerifiedYieldContractCommodity model = new VerifiedYieldContractCommodity();
Expand Down Expand Up @@ -314,7 +420,7 @@ private static void setLinks(String verifiedYieldContractGuid, VerifiedYieldCont
}

@Override
public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract<? extends AnnualField> model, String userId) {
public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract<? extends AnnualField, ? extends Message> model, String userId) {

dto.setVerifiedYieldContractGuid(model.getVerifiedYieldContractGuid());
dto.setContractId(model.getContractId());
Expand All @@ -329,7 +435,22 @@ public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract<? exte
}

@Override
public void updateDto(VerifiedYieldContractCommodityDto dto, VerifiedYieldContractCommodity model) {
public void updateDto(
VerifiedYieldContractCommodityDto dto,
VerifiedYieldContractCommodity model,
List<ProductDto> productDtos,
Boolean updateProductValues) {

Double productionGuarantee = model.getProductionGuarantee();
//Get production guarantee if user wants to update the values
if(Boolean.TRUE.equals(updateProductValues)) {
ProductDto product = getProductDto(dto.getCropCommodityId(), dto.getIsPedigreeInd(), productDtos);
if(product != null && product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) {
productionGuarantee = product.getProductionGuarantee();
} else {
productionGuarantee = null;
}
}

dto.setVerifiedYieldContractCommodityGuid(model.getVerifiedYieldContractCommodityGuid());
dto.setVerifiedYieldContractGuid(model.getVerifiedYieldContractGuid());
Expand All @@ -339,11 +460,14 @@ public void updateDto(VerifiedYieldContractCommodityDto dto, VerifiedYieldContra
dto.setHarvestedAcresOverride(model.getHarvestedAcresOverride());
dto.setStoredYieldDefaultUnit(model.getStoredYieldDefaultUnit());
dto.setSoldYieldDefaultUnit(model.getSoldYieldDefaultUnit());
dto.setProductionGuarantee(model.getProductionGuarantee());
dto.setProductionGuarantee(productionGuarantee);
dto.setHarvestedYield(model.getHarvestedYield());
dto.setHarvestedYieldOverride(model.getHarvestedYieldOverride());
dto.setYieldPerAcre(model.getYieldPerAcre());

}


private Double notNull(Double value, Double defaultValue) {
return (value == null) ? defaultValue : value;
}
}
Loading

0 comments on commit f0c9dde

Please sign in to comment.