<?xml version="1.0" encoding="UTF-8"?> 
<process xmlns="http://drools.org/drools-5.0/process"
         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
         xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
         type="RuleFlow" name="Adjust Position" id="adjust position" package-name="org.drools.examples.broker.model" >

  <header>
    <imports>
      <import name="org.drools.examples.broker.model.Action" />
      <import name="org.drools.examples.broker.model.PortfolioAction" />
    </imports>
    <globals>
      <global identifier="services" type="org.drools.examples.broker.BrokerServices" />
    </globals>
    <variables>
      <variable name="symbol" >
        <type name="org.drools.core.process.core.datatype.impl.type.StringDataType" />
      </variable>
      <variable name="quant" >
        <type name="org.drools.core.process.core.datatype.impl.type.UndefinedDataType" />
      </variable>
    </variables>
  </header>

  <nodes>
    <start id="1" name="Start" x="16" y="101" width="80" height="48" />
    <end id="3" name="End" x="1113" y="100" width="76" height="48" />
    <ruleSet id="4" name="Evaluate Position" x="129" y="102" width="157" height="48" ruleFlowGroup="evaluate position" />
    <actionNode id="6" name="Buy Shares" x="533" y="22" width="124" height="48" >
        <action type="expression" dialect="mvel" >services.log( "Buying "+symbol+" shares" ) ;</action>
    </actionNode>
    <actionNode id="7" name="Sell Shares" x="533" y="204" width="124" height="48" >
        <action type="expression" dialect="mvel" >services.log( "Selling "+symbol+" shares" );</action>
    </actionNode>
    <split id="11" name="Take Action" x="340" y="99" width="108" height="49" type="2" >
      <constraints>
        <constraint toNodeId="7" toType="DROOLS_DEFAULT" name="Sell" priority="1" type="rule" dialect="mvel" >PortfolioAction( action == Action.SELL ) </constraint>
        <constraint toNodeId="13" toType="DROOLS_DEFAULT" name="No action" priority="1" type="rule" dialect="mvel" >PortfolioAction( action == Action.NOACTION )  </constraint>
        <constraint toNodeId="6" toType="DROOLS_DEFAULT" name="Buy" priority="1" type="rule" dialect="mvel" >PortfolioAction( action == Action.BUY )  </constraint>
      </constraints>
    </split>
    <join id="12" name="Action taken" x="709" y="99" width="141" height="49" type="2" />
    <actionNode id="13" name="No Action" x="540" y="105" width="111" height="40" >
        <action type="expression" dialect="mvel" >services.log( "Doing no changes to current position" );</action>
    </actionNode>
    <ruleSet id="14" name="Notify" x="939" y="104" width="80" height="40" ruleFlowGroup="notify" />
  </nodes>

  <connections>
    <connection from="14" to="3" />
    <connection from="1" to="4" />
    <connection from="11" to="6" />
    <connection from="11" to="7" />
    <connection from="4" to="11" />
    <connection from="6" to="12" />
    <connection from="7" to="12" />
    <connection from="13" to="12" />
    <connection from="11" to="13" />
    <connection from="12" to="14" />
  </connections>

</process>
