Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public override void PriceShoppingCart(ShoppingCart sc)
        {
            if (sc != null)
            {
                InitShoppingCartForPricing(sc);

                BatchExecutionCommand batchCommand = BuildBatchExecutionCommand(sc);

                // ServiceResponse<ExecutionResults> executeResponse = rulesClient.executeCommandsWithResults(CONTAINER_ID, batchCommand);

                // if (executeResponse.getType() == ResponseType.SUCCESS) {
                //     ExecutionResults results = executeResponse.getResult();
                //     PsmShoppingCart resultSc = (PsMShoppingCart) results.getValue("shoppingcart");
                //     MapShoppingCartPricingResults(resultSc, sc);
                // } else {
                // TODO: Some proper, micro-service type error handling here.
                string message = "Error calculating prices.";
                log.LogError(message);
                throw new Exception(message);
                // }
            }
        }