[rules-users] (no subject)

Garner, Shawn Garner.Shawn at principal.com
Wed Sep 9 18:02:17 EDT 2009


Functions on the LHS are not advised and says so in the drools user guide.

I can think of two ways to do this (forgive me if my syntax is slightly off).

Way number 1

rule "ProductDescription validation"
    when
        $listing : Listing( $description:productDescription != null, description.title != null )
     then
	ListingScrubber listingScrubber = new ListingScrubber(listing);
	insert(listingScrubber);
end

rule "ProductDescription validation Part 2"
    when
        $listingScrubber : ListingScrubber(forbiddenWordInTitle == true , $title: productDescription.title)
    then
	String word = $listingScrubber.getWord();
        System.out.println("ERROR: " + word); 
end


Way number2

rule "ProductDescription validation"
    when
        $listing : Listing( $description:productDescription != null, $title : productDescription.title != null)              
    then
 	List<ListingWord> listingWordList =  listing.getListingWords();
 	Iterator<ListingWord> listingWordListIter = listingWordList.iterator();
 	while(listingWordListIter.hasNext())
 	{
 		ListingWord listingWord = listingWordListIter.next();
 		assert(listingWord);
 	}
 end
 
 $word : hasForbiddenWordsSet( wordsSet, $description.getTitle() )


rule "ProductDescription validation Part 2"
    when
    	$badWordList : BadWordList($wordList : list)
        $listingWord : ListingWord($word : word memberof $wordList, $listing : listing)
    then
        System.out.println($listing.productDescription + " has naughty word:" + $word); 
End





>>> Original Message>>

Hi! I'm new here and a have a doubt about rules and functions in Drools.

I have this rule:

rule "ProductDescription validation"
    when
        $listing : Listing( $description:productDescription != null )
        eval( $description.getTitle() != null )
        eval( hasForbiddenWordsSet( wordsSet, $description.getTitle() ) )
    then
        System.out.println("ERROR!");
end

And this function:

function boolean hasForbiddenWordsSet(Set wordsSet, String value) { #do something useful here }


And everything works fine. But now I want that function "hasForbiddenWordsSet" return a String. For example to print at "then".
I tried something like this:

rule "ProductDescription validation"
    when
        $listing : Listing( $description:productDescription != null )
        eval( $description.getTitle() != null )
        $word : hasForbiddenWordsSet( wordsSet, $description.getTitle() )
    then
        System.out.println("ERROR: " + word); end

function String hasForbiddenWordsSet(Set wordsSet, String value) { #do something useful here }

But it doesn't work, tried some other things and still no success.

Could someone help me?

Thanks in advance.

--
Leandro Carvalho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090909/41bb3455/attachment-0001.html



-----Message Disclaimer-----

This e-mail message is intended only for the use of the individual or
entity to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately by
reply email to Connect at principal.com and delete or destroy all copies of
the original message and attachments thereto. Email sent to or from the
Principal Financial Group or any of its member companies may be retained
as required by law or regulation.

Nothing in this message is intended to constitute an Electronic signature
for purposes of the Uniform Electronic Transactions Act (UETA) or the
Electronic Signatures in Global and National Commerce Act ("E-Sign")
unless a specific statement to the contrary is included in this message.

While this communication may be used to promote or market a transaction
or an idea that is discussed in the publication, it is intended to provide
general information about the subject matter covered and is provided with
the understanding that The Principal is not rendering legal, accounting,
or tax advice. It is not a marketed opinion and may not be used to avoid
penalties under the Internal Revenue Code. You should consult with
appropriate counsel or other advisors on all matters pertaining to legal,
tax, or accounting obligations and requirements.





More information about the rules-users mailing list