<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: drools error [ERR 102] Line 40:43 mismatched input '&&' expecting ')' in rule "Free Fish Food Sample"
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/mschwery">Mike schwery</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/588797#588797">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>full rule</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package org.drools.examples</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import org.drools.WorkingMemory</p><p>import org.drools.examples.PetStore.Order</p><p>import org.drools.examples.PetStore.Purchase</p><p>import org.drools.examples.PetStore.Product</p><p>import java.util.ArrayList</p><p>import javax.swing.JOptionPane; </p><p>import javax.swing.JFrame         </p><p>global JFrame frame </p><p>global javax.swing.JTextArea textArea</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>//dialect "mvel"</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>// insert each item in the shopping cart into the Working Memory </p><p>rule "Explode Cart"</p><p>    agenda-group "init"</p><p>    auto-focus true    </p><p>    salience 10</p><p>    dialect "java"</p><p>    when</p><p>        $order : Order( grossTotal == -1 )</p><p>        $item : Purchase() from $order.items</p><p>    then</p><p>        insert( $item );</p><p>        drools.getKnowledgeRuntime().getAgenda().getAgendaGroup( "show items" ).setFocus();        </p><p>        drools.getKnowledgeRuntime().getAgenda().getAgendaGroup( "evaluate" ).setFocus();        </p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>// Free Fish Food sample when we buy a Gold Fish if we haven't already  bought </p><p>// Fish Food and dont already have a Fish Food Sample</p><p>rule "Free Fish Food Sample"</p><p>    agenda-group "evaluate"</p><p>    dialect "mvel"</p><p>    when</p><p>        $order : Order()</p><p>        not ( $p : Product( name == "Fish Food") && Purchase( product == $p )) </p><p>        not ( $p : Product( name == "Fish Food Sample") && Purchase( product == $p ) )        </p><p>        exists ( $p : Product( name == "Gold Fish") && Purchase( product == $p ) )    </p><p>        $fishFoodSample : Product( name == "Fish Food Sample" );</p><p>    then</p><p>        System.out.println( "Adding free Fish Food Sample to cart" );</p><p>        purchase = new Purchase($order, $fishFoodSample);</p><p>        insert( purchase );</p><p>        $order.addItem( purchase );    </p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>// Suggest a tank if we have bought more than 5 gold fish and dont already have one</p><p>rule "Suggest Tank"</p><p>       agenda-group "evaluate"</p><p>       dialect "java"</p><p>    when</p><p>        $order : Order()</p><p>        not ( $p : Product( name == "Fish Tank") && Purchase( product == $p ) )    </p><p>        ArrayList( $total : size > 5 ) from collect( Purchase( product.name == "Gold Fish" ) )</p><p>        $fishTank : Product( name == "Fish Tank" )        </p><p>    then</p><p>        requireTank(frame, drools.getWorkingMemory(), $order, $fishTank, $total);     </p><p>end    </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>rule "Show Items"</p><p>    agenda-group "show items"</p><p>    dialect "java"</p><p>    when</p><p>        $order : Order( )</p><p>        $p : Purchase( order == $order )</p><p>    then    </p><p>        textArea.append( $p.getProduct() + "\n");</p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>rule "do checkout"</p><p>        dialect "java"</p><p>    when</p><p>    then</p><p>        doCheckout(frame, drools.getWorkingMemory());</p><p>end    </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>rule "Gross Total"</p><p>    agenda-group "checkout"</p><p>    dialect "mvel"</p><p>    when</p><p>        $order : Order( grossTotal == -1)</p><p>        Number( total : doubleValue ) from accumulate( Purchase( $price : product.price ),</p><p>                                                              sum( $price ) )</p><p>    then    </p><p>        modify( $order ) { grossTotal = total }</p><p>        textArea.append( "\ngross total=" + total + "\n" );</p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>rule "Apply 5% Discount"</p><p>    agenda-group "checkout"</p><p>    dialect "mvel"</p><p>    when</p><p>        $order : Order( grossTotal >= 10 && < 20 )</p><p>    then</p><p>        $order.discountedTotal = $order.grossTotal * 0.95;</p><p>        textArea.append( "discountedTotal total=" + $order.discountedTotal + "\n" );        </p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>rule "Apply 10% Discount"</p><p>    agenda-group "checkout"</p><p>    dialect "mvel"</p><p>    when</p><p>        $order : Order( grossTotal >= 20 )</p><p>    then</p><p>        $order.discountedTotal = $order.grossTotal * 0.90;</p><p>        textArea.append( "discountedTotal total=" + $order.discountedTotal + "\n" );    </p><p>end</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>function void doCheckout(JFrame frame, WorkingMemory workingMemory) {</p><p>        Object[] options = {"Yes",</p><p>                            "No"};</p><p>                            </p><p>        int n = JOptionPane.showOptionDialog(frame,</p><p>                                             "Would you like to checkout?",</p><p>                                             "",</p><p>                                             JOptionPane.YES_NO_OPTION,</p><p>                                             JOptionPane.QUESTION_MESSAGE,</p><p>                                             null,</p><p>                                             options,</p><p>                                             options[0]);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>       if (n == 0) {</p><p>            workingMemory.setFocus( "checkout" );</p><p>       }   </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>function boolean requireTank(JFrame frame, WorkingMemory workingMemory, Order order, Product fishTank, int total) {</p><p>        Object[] options = {"Yes",</p><p>                            "No"};</p><p>                            </p><p>        int n = JOptionPane.showOptionDialog(frame,</p><p>                                             "Would you like to buy a tank for your " + total + " fish?",</p><p>                                             "Purchase Suggestion",</p><p>                                             JOptionPane.YES_NO_OPTION,</p><p>                                             JOptionPane.QUESTION_MESSAGE,</p><p>                                             null,</p><p>                                             options,</p><p>                                             options[0]);</p><p>                                             </p><p>       System.out.print( "SUGGESTION: Would you like to buy a tank for your "</p><p>                           + total + " fish? - " );</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>       if (n == 0) {</p><p>             Purchase purchase = new Purchase( order, fishTank );</p><p>             workingMemory.insert( purchase );</p><p>             order.addItem( purchase );</p><p>             System.out.println( "Yes" );</p><p>       } else {</p><p>            System.out.println( "No" );</p><p>       }      </p><p>       return true;</p><p>}</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/588797#588797">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>