Search in sources :

Example 1 with TraceCollector

use of eu.ggnet.dwoss.price.engine.support.TraceCollector in project dwoss by gg-net.

the class PriceEngine method estimate.

/**
 * Executes the Estimation for one SopoUnit.
 * This Method never fails an always returns a usable not null PriceEngineResult
 *
 * @param uu   the UniqueUnit
 * @param spec the ProductSpec
 * @param stock the Stock
 * @return a estimated PriceEngineResult.
 */
public PriceEngineResult estimate(UniqueUnit uu, ProductSpec spec, String stock) {
    Objects.requireNonNull(uu, "UniqueUnit is null");
    Product p = Objects.requireNonNull(uu.getProduct(), "Product of " + uu + " is null");
    Objects.requireNonNull(spec, "ProductSpec is null");
    PriceEngineResult per = new PriceEngineResult(uu, stock);
    TraceCollector log = new TraceCollector();
    per.setTax(GlobalConfig.DEFAULT_TAX.getTax());
    per.setWarrantyId(uu.getWarranty().ordinal());
    if (uu.getWarranty().equals(Warranty.WARRANTY_TILL_DATE)) {
        per.setWarrentyValid(uu.getWarrentyValid());
    }
    L.debug("Starting estimation for refuribisId:{}", uu.getRefurbishId());
    if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED) || p.getFlags().contains(Product.Flag.PRICE_FIXED)) {
        EngineTracer et = new EngineTracer(PriceEngine.class.getSimpleName(), "estimate");
        if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED)) {
            L.debug("refurbishId:{} has UnitPriceFixed", uu.getRefurbishId());
            per.setCustomerPrice(uu.getPrice(PriceType.CUSTOMER));
            per.setRetailerPrice(uu.getPrice(PriceType.RETAILER));
            per.setUnitPriceFixed(SET);
            per.setSpecial("FIX UNIT");
            et.info("UnitFixPrice");
        } else {
            L.debug("refurbishId:{} has PartPriceFixed", uu.getRefurbishId());
            per.setCustomerPrice(p.getPrice(PriceType.CUSTOMER));
            per.setRetailerPrice(p.getPrice(PriceType.RETAILER));
            per.setManufacturerPartPriceFixed(SET);
            per.setSpecial("FIX PRODUCT");
            et.info("ProductFixPrice");
        }
        log.add(et);
    } else if (!estimator.isUnsatisfied()) {
        Result result = estimator.get().estimate(spec, uu);
        L.debug("{}", result);
        log.add(result.getTracer());
        per.setSpecial(result.getTag());
        per.setRetailerPrice(result.getRetailerPrice());
        per.setCustomerPrice(result.getCustomerPrice());
        per.setRetailerToCustomerPricePercentage(result.getRetailerToCustomerPricePercentage());
    } else {
        L.debug("No Estimator found for {},{}", uu, spec);
        per.setSpecial("NO ESTIMATION");
    }
    per.consumeLog(log);
    return per;
}
Also used : TraceCollector(eu.ggnet.dwoss.price.engine.support.TraceCollector) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) EngineTracer(eu.ggnet.dwoss.price.api.EngineTracer) Result(eu.ggnet.dwoss.price.api.Estimator.Result)

Aggregations

EngineTracer (eu.ggnet.dwoss.price.api.EngineTracer)1 Result (eu.ggnet.dwoss.price.api.Estimator.Result)1 TraceCollector (eu.ggnet.dwoss.price.engine.support.TraceCollector)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1