<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:drools="http://drools.org/schema/drools-spring"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd">

    <!-- Setup Drools -->
    <drools:grid-node id="node1"/>

    <drools:kbase id="kbase1" node="node1">
        <drools:configuration>
            <drools:mbeans enabled="true"/>
        </drools:configuration>
        <drools:resources>
            <drools:resource type="DRL" source="classpath:testSpring.drl"/>
        </drools:resources>
    </drools:kbase>

    <drools:ksession id="ksession1" type="stateless" name="ksession1" kbase="kbase1" node="node1">
        <!-- Adding a configuration forces drools to use the current classloader (see issue SM-2316) -->
        <drools:configuration />
    </drools:ksession>

    <bean id="droolsHelper" class="org.apache.servicemix.examples.camel.DroolsCommandHelper"/>

    <bean id="personHelper" class="org.apache.servicemix.examples.camel.PersonHelper"/>

    <!-- declare the drools bean here to avoid OSGi classpath issues -->
    <bean id="drools" class="org.drools.camel.component.DroolsComponent"/>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route trace="false" id="testRoute">
            <description>
                Example route that will regularly create a random Person and choose an appropriate drink based on the
                drools rules file. After processing, it divides the people into VIPs and regular clients based on the
                drools result.
            </description>
            <from uri="timer:testRoute"/>
            <bean method="createTestPerson" ref="personHelper"/>
            <to uri="drools:node1/ksession1?action=insertBody" id="DrinkChooser">
                <description>valid 'action' values are:
                    'execute' that takes a 'Command' object (default)
                    'insertBody' that inserts the Exchange.in.body, and executes rules
                    'insertMessage' that inserts the Exchange.in (type org.apache.camel.Message), and executes rules
                    'insertExchange' that inserts the Exchange (type org.apache.camel.Exchange), and executes rules
                </description>
            </to>
            <choice>
                <when id="Vip">
                    <simple>${body.isVip}</simple>
                    <log logName="ServeDrink VIP" message="This ${body.name} is a VIP! Give a ${body.getDrink.getDescription} from the house"/>
                </when>
                <otherwise>
                    <log logName="ServeDrink" message="Serve this ${body.name} a ${body.getDrink.getDescription}"/>
                </otherwise>
            </choice>
        </route>
        <route trace="false" id="ruleOnBody">
            <description>This route shows an example of passing (inserting) the Body of the message as a POJO to Drools
                for execution
            </description>
            <from uri="direct://ruleOnBody"/>
            <to uri="drools:node1/ksession1?action=insertBody">
                <description>valid 'action' values are:
                    'execute' that takes a 'Command' object (default)
                    'insertBody' that inserts the Exchange.in.body, and executes rules
                    'insertMessage' that inserts the Exchange.in (type org.apache.camel.Message), and executes rules
                    'insertExchange' that inserts the Exchange (type org.apache.camel.Exchange), and executes rules
                </description>
            </to>
        </route>
        <route trace="false" id="ruleOnCommand">
            <description>This route shows an example of creating a Drools Command wrapping the Body of the message with
                the help of the custom DroolsCommandHelperBean (included in this project), and passing this Drools
                Command to the ruleset for execution.
            </description>
            <from uri="direct://ruleOnCommand"/>
            <bean method="insertAndFireAll" ref="droolsHelper"/>
            <to uri="drools:node1/ksession1?action=execute">
                <description>valid 'action' values are:
                    'execute' that takes a 'Command' object (default)
                    'insertBody' that inserts the Exchange.in.body, and executes rules
                    'insertMessage' that inserts the Exchange.in (type org.apache.camel.Message), and executes rules
                    'insertExchange' that inserts the Exchange (type org.apache.camel.Exchange), and executes rules
                </description>
            </to>
        </route>
    </camelContext>

</beans>
