Ejemplo n.º 1
0
 /**
  * Maps the {@link PricingServiceModel.ShoppingCart} pricing results to the given {@link ShoppingCart}.
  *
  * @param resultSc the {@link PricingServiceModel.ShoppingCart} containing the pricing defined by the rules engine.
  * @param sc       the {@link ShoppingCart} onto which we need to map the results.
  */
 private void MapShoppingCartPricingResults(PsmShoppingCart resultSc, ShoppingCart sc)
 {
     sc.CartItemPromoSavings = resultSc.CartItemPromoSavings;
     sc.CartItemTotal        = resultSc.CartItemTotal;
     sc.ShippingPromoSavings = resultSc.ShippingPromoSavings;
     sc.ShippingTotal        = resultSc.ShippingTotal;
     sc.CartTotal            = resultSc.CartTotal;
 }
Ejemplo n.º 2
0
        /**
         * Builds a {@link PricingServiceModel.ShoppingCart} fact from the given {@link ShoppingCart}.
         *
         * @param sc the {@link ShoppingCart} from which to build the fact.
         * @return the {@link PricingServiceModel.ShoppingCart} fact
         */
        private PsmShoppingCart BuildShoppingCartFact(ShoppingCart sc)
        {
            PsmShoppingCart factSc = new PsmShoppingCart();

            factSc.CartItemPromoSavings = sc.CartItemPromoSavings;
            factSc.CartItemTotal        = sc.CartItemTotal;
            factSc.CartTotal            = sc.CartTotal;
            factSc.ShippingPromoSavings = sc.ShippingPromoSavings;
            factSc.ShippingTotal        = sc.ShippingTotal;
            return(factSc);
        }
Ejemplo n.º 3
0
        /**
         * Builds the KIE {@link BatchExecutionCommand}, which contains all the KIE logic like insertion of facts, starting of ruleflow
         * processes and firing of rules, from the given {@link ShoppingCart}.
         *
         * @param sc the {@link ShoppingCart} from which the build the {@link BatchExecutionCommand}.
         * @return the {@link BatchExecutionCommand}
         */
        private BatchExecutionCommand BuildBatchExecutionCommand(ShoppingCart sc)
        {
            // KieCommands commandsFactory = KieServices.Factory.get().getCommands();
            // List of BRMS commands that will be send to the rules-engine (e.g. inserts, fireAllRules, etc).
            // IList<Command<object>> commands = new List<object>();

            // Insert the promo first. Promotions are retrieved from the PromoService.
            foreach (var promo in ps.Promotions)
            {
                PsmPromoEvent promoEvent = new PsmPromoEvent(promo.ItemId, promo.PercentOff);
                // Note that we insert the fact into the "Promo Stream".
                // Command<type> insertPromoEventCommand = commandsFactory.newInsert(promoEvent, "outPromo", false, "Promo Stream");
                // commands.add(insertPromoEventCommand);
            }

            /*
             * Build the ShoppingCart fact from the given ShoppingCart.
             */
            PsmShoppingCart factSc = BuildShoppingCartFact(sc);

            // commands.add(commandsFactory.newInsert(factSc, "shoppingcart", true, "DEFAULT"));

            // Insert the ShoppingCartItems.
            IList <ShoppingCartItem> scItems = sc.ShoppingCartItemList;

            foreach (ShoppingCartItem nextSci in scItems)
            {
                // Build the ShoppingCartItem fact from the given ShoppingCartItem.
                PsmShoppingCartItem factSci = BuildShoppingCartItem(nextSci);
                factSci.ShoppingCart = factSc;
                // commands.add(commandsFactory.newInsert(factSci));
            }

            // Add extra fireAllRules command. Workaround for: https://issues.jboss.org/browse/DROOLS-1593
            // TODO: Remove workaround when bug has been fixed.
            // commands.add(commandsFactory.newFireAllRules());

            // Start the process (ruleflow).
            // commands.add(commandsFactory.newStartProcess(RULEFLOW_PROCESS_NAME));

            // Fire the rules
            // commands.add(commandsFactory.newFireAllRules());

            BatchExecutionCommand batchCommand = new BatchExecutionCommand(); // = commandsFactory.newBatchExecution(commands, KIE_SESSION_NAME);

            return(batchCommand);
        }