Ejemplo n.º 1
0
        /**
         * Builds a {@link PricingServiceModel.ShoppingCartItem} fact from the given {@link ShoppingCartItem}.
         *
         * @param sci the {@link ShoppingCartItem} from which to build the fact.
         * @return the {@link PricingServiceModel.ShoppingCartItem} fact.
         */
        private PsmShoppingCartItem BuildShoppingCartItem(ShoppingCartItem sci)
        {
            PsmShoppingCartItem factSci = new PsmShoppingCartItem();

            factSci.ItemId   = sci.Product.ItemId;
            factSci.Name     = sci.Product.Name;
            factSci.Price    = sci.Product.Price;
            factSci.Quantity = sci.Quantity;
            return(factSci);
        }
Ejemplo n.º 2
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);
        }