<$BlogRSDURL$>
  Monday, March 20, 2006

Drools on AppFuse

Recently got a chance to adopt rule engine into project to allow abstraction of business rules from the service layer, that way, business rules can be maintained in it's own space. I pick Drools as the underlying rule engine because it is intuitive, simple, and robust JSR94 compliant rule engine, plus it's open source. Below are steps to integrate this powerful rule engine into AppFuse. I use the Spring Modules distribution to make it easier for the integration since all the plumbing is done nicely with Spring.

1. Add required libraries:
    a. springmodules-jsr94-0.2.jar
    b. /jsr94
    c. /drools
    d. /janino

Refer to How to add a Library into AppFuse for information on how to add new library into AppFuse.

2. Drop the Spring ApplicationContext for Drools configuration, applicationContext-rules.xml, into [appfuse]\web\WEB-INF\:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="ruleServiceProvider"
class="org.springmodules.jsr94.factory.DefaultRuleServiceProviderFactoryBean">
<property name="provider">http://drools.org/</value></property>
<property name="providerClass"><value>org.drools.jsr94.rules.RuleServiceProviderImpl</value>
</property>
</bean>
<bean id="ruleRuntime"
class="org.springmodules.jsr94.factory.RuleRuntimeFactoryBean">
<property name="serviceProvider"><ref local="ruleServiceProvider"/></property>
</bean>
<bean id="ruleAdministrator"
class="org.springmodules.jsr94.factory.RuleAdministratorFactoryBean">
<ref local="ruleServiceProvider"/></property>
</bean>
<bean id="ruleSource" class="org.springmodules.jsr94.rulesource.DefaultRuleSource">
<property name="ruleRuntime"><ref local="ruleRuntime"/></property>
<property name="ruleAdministrator"><ref local="ruleAdministrator"/></property>
<property name="source"><value>/WEB-INF/authorizedUsers.drl</value></property>
<property name="bindUri"><value>authorizedUsers</value></property>
</bean>
<bean id="rulesService" class="org.appfuse.service.impl.RulesServiceDrools">
<property name="ruleSource"><ref local="ruleSource"/></property>
</bean>
</beans>

The file, authorizedUsers.drl, is the ruleset, and RulesServiceDrools is the Drools rule implementation we have in this sample setup.

3. The signature for the ruleset, authorizedUsers.drl, in [appfuse]\web\WEB-INF\:

<?xml version="1.0" encoding="UTF-8"?>
<rule-set
name="Get authorized users"
description="Rules to retrieve authorized users"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd">
<rule name="Enabled users">
<parameter identifier="user">
<class>org.appfuse.model.User</class>
</parameter>
<java:condition> user.isEnabled() != true </java:condition>
<java:consequence> drools.retractObject(user); </java:consequence>
</rule>
<rule name="Valid credentials">
<parameter identifier="user">
<class>org.appfuse.model.User</class>
</parameter>
<java:condition>
user.isCredentialsExpired() == true || user.getRoles().size() == 0
</java:condition>
<java:consequence>
drools.retractObject(user);
</java:consequence>
</rule>
</rule-set>

Two rules are defined in the ruleset: Enabled users and Valid credentials. Both rules check for condition, if met, the user is removed from list. Basically, the two rules mean:

if (!user.isEnabled() && (user.isCredentialsExpired()
|| user.getRoles().size() == 0))
userList.remove(user);

4. The interface for the rules service, RulesService, is simple enough:

public interface RulesService {
public List getAuthorizedUsers(List users);
}

And the associated implementation, RulesServiceDrools:

public class RulesServiceDrools extends Jsr94RuleSupport implements RulesService {
public final static String ACTIVE_USERS_URI="authorizedUsers";
public List getAuthorizedUsers(List users) {
return executeStateless(ACTIVE_USERS_URI, users);
}
}

I couldn't get the Spring Jsr94Template to work properly. Ideally, the output list from Drools should be access via Spring template:

public List getAuthorizedUsers(List users) {
List outputList = getTemplate().executeStateless(ACTIVE_USERS_URI,null,
new StatelessRuleSessionCallback() {
public Object execute(StatelessRuleSession session)
throws InvalidRuleSessionException, RemoteException {
return session.executeRules(users);
}
}
);
return outputList;
}


5. The Tapestry action code to get the list of users:

public abstract class AuthorizedUsers extends BasePage implements PageRenderListener {
public abstract UserManager getUserManager();
public abstract void setUserManager(UserManager manager);
public abstract RulesService getRulesService();
public abstract void setRulesService(RulesService svr);

public void pageBeginRender(PageEvent event) {
List authorizedUsers = getRulesService().getAuthorizedUsers(getUserManager().getUsers(null));
...
}
}


That's pretty much it to setup Drools in AppFuse and starts ruling away.
 

26 Comments/評論:

Anonymous Anonymous said...

Thank you very much!
I am very interested into this tool and thanks to your work, I have no more reason to postpone.

4:13 PM  
Blogger lo said...

Rule engine is indeed a great tool to take software design into a higher level, and it is especially the case with Drools. I thank you for your work for AppFuse too, Thomas. I really enjoy using AppFuse, this is part of my share to the AppFuse community. I owe quite a bit to Raible for my J2EE project development.

8:55 AM  
Anonymous Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

9:45 PM  
Anonymous Anonymous said...

The author of lifeasastruct.blogspot.com has written an excellent article. You have made your point and there is not much to argue about. It is like the following universal truth that you can not argue with: The last ten percent of the file takes ninety percent of the download time. Thanks for the info.

1:41 PM  
Anonymous Anonymous said...

dating site in belgium [url=http://loveepicentre.com/]meaning of exclusivity in dating[/url] the singles http://loveepicentre.com/ preteen dating site

5:00 AM  
Anonymous Anonymous said...

Clevo Laptop [url=http://www.hqlaptopbatteries.com/battery-5310g-batterytype1.html]sony laptop[/url] laptop brands http://www.hqlaptopbatteries.com/battery-3614wlmi-batterytype1.html sony laptop
replacement laptop batteries [url=http://www.hqlaptopbatteries.com/-a30-103-laptopbatterymodel1949.html]laptop battery[/url] High Quality Laptop Batteries http://www.hqlaptopbatteries.com/-1685-laptopbatterymodel1333.html compare laptop prices
Discount Laptop Batteries [url=http://www.hqlaptopbatteries.com/-225xc-laptopbatterymodel1195.html]Discount notebook batteries[/url] Samsung laptop battery http://www.hqlaptopbatteries.com/-9102wlmi-laptopbatterymodel918.html best laptops

3:40 PM  
Anonymous Anonymous said...

lifeasastruct.blogspot.com is the best. Thank your for this article. I enjoyed it very much.
AAA Toronto Payday Loans 1172 Bay St #101, Toronto, ON M5S 2B4 (416) 477-2817

11:53 AM  
Anonymous Anonymous said...

medical weight loss diet [url=http://usadrugstoretoday.com/products/accupril.htm]accupril[/url] tissue fluid drains into blood http://usadrugstoretoday.com/categories/gastrointestinales.htm nick drake smoking too long http://usadrugstoretoday.com/products/rave--energy-and-mind-stimulator-.htm
tea craft [url=http://usadrugstoretoday.com/products/cardura.htm]cardura[/url] health bonds create parental find [url=http://usadrugstoretoday.com/products/kamagra-oral-jelly.htm]health facilities in rural kenya[/url]

10:37 AM  
Anonymous Anonymous said...

dhea effect on blood pressure [url=http://usadrugstoretoday.com/products/hyzaar.htm]hyzaar[/url] can you have an orgasm by someone rubbing your feet http://usadrugstoretoday.com/products/fluoxetine.htm prima health salem http://usadrugstoretoday.com/categories/colesterolo.htm
occupational medicine society [url=http://usadrugstoretoday.com/categories/mujeres-mejoramiento.htm]mujeres mejoramiento[/url] depression slow heart rate [url=http://usadrugstoretoday.com/categories/perdida-de-peso.htm]picture of viagra[/url]

8:41 PM  
Anonymous Anonymous said...

http://thefield.co.kr/bbs//zboard.php?id=download&page=1&page_num=10&select_arrange=headnum&desc=&sn=off&ss=on&sc=on&keyword=&no=4397&category= http://www.reefomania.com/forum/viewtopic.php?f=2&t=190644 http://his-lambs.com/forum/index.php?topic=17111.new#new http://www.bibleshack.com/cgi-bin/robboard/robboard.cgi?action=display&num=42028
http://forum.sursautsenegal.org/viewtopic.php?p=879984#879984 http://cordialtouche.xsbb.nl/viewtopic.php?f=2&t=862660 http://minnesotafireservice.com/phpbb2/viewtopic.php?f=2&t=171155 http://forum.kirbyhouse.org/viewtopic.php?f=3&t=184586
http://www.poetrybox.com/dxgold/script/phpBB2/viewtopic.php?p=712317#712317 http://www.academicjourney.org/forum/viewtopic.php?f=2&t=147330 http://fta-keys.com/ftakeys/index.php?topic=268529.new#new

5:57 PM  
Anonymous Anonymous said...

http://alwayshealth.in/potency/dexamethasone-potency
[url=http://alwayshealth.in/olanzapine/olanzapine-recall-los-angeles]sequoia pharmacy group[/url] baylor college of medicine 77030 [url=http://alwayshealth.in/man-health/health-anxiety-support]health anxiety support[/url]
meaning of pharmacy http://alwayshealth.in/natural-health/health-remedys
[url=http://alwayshealth.in/syndrome/life-span-of-down-syndrome-sufferers]pharmacy operations[/url] the economy and illgeal drugs [url=http://alwayshealth.in/smoke/dupont-self-charging-smoke-alarm]dupont self charging smoke alarm[/url]
albert einstein college of medicine restaurants http://alwayshealth.in/quit-smoking/smoking-hypnotist
[url=http://alwayshealth.in/no-prescription/cheap-evista-prescription]mexico pharmacys viagra no prescription[/url] deatales on drugs [url=http://alwayshealth.in/ocd]ocd[/url] bariatric medicine and vitamin b12 [url=http://alwayshealth.in/people-health/south-carolina-health-insurance-ps]south carolina health insurance ps[/url]

2:18 PM  
Anonymous Anonymous said...

travel company ratings http://atravel.in/disneyland_disneyland-california-hotels-with-indoor-pool travel to walt disney
[url=http://atravel.in/plane-tickets_mosinee-wi-plane-tickets]northern ireland travel ontario canada[/url] ceramic travel mugs [url=http://atravel.in/expedia_el-dorado-maroma-expedia]el dorado maroma expedia[/url]
defense travel guide http://atravel.in/airline_airline-14br-912a
[url=http://atravel.in/motel_royal-motel-michigan]travel gift certificate[/url] travel agent training programs [url=http://atravel.in/cruises_cruises-cheap]cruises cheap[/url]
coupon codes staples travel set http://atravel.in/airlines_airlines-that-fly-to-parkersburg travel to phu bai vietnam [url=http://atravel.in/tours_grand-circle-tours]grand circle tours[/url]

5:37 PM  
Anonymous Anonymous said...

lauren hill i love you baby http://topcitystyle.com/long-sleeve-tops-page2.html milan fashion week nude tops [url=http://topcitystyle.com/men-page84.html]audio shoes[/url] remodeling designer columbus ohio
http://topcitystyle.com/black-grey-armani-color24.html motorcycle clothes [url=http://topcitystyle.com/cream-women-s-tops-color68.html]steve madden shoes[/url]

5:52 PM  
Anonymous Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

1:42 PM  
Anonymous Anonymous said...

daily motion sexy channel http://theporncollection.in/best-porn/hot-moms-teacher-porn
[url=http://theporncollection.in/gay-boy/free-gay-beastiality-stories]dildo fucking them squirt[/url] dans adult sex videos [url=http://theporncollection.in/mature-xxx/pictures-of-sexy-mature-women]pictures of sexy mature women[/url]
anal sex with ice http://theporncollection.in/mature-xxx/mature-chinese-porn
[url=http://theporncollection.in/gay-boy/is-your-wife-gay]adult meta search engines[/url] free 2007 adult dating site [url=http://theporncollection.in/orgy/sex-orgy-house]sex orgy house[/url]
free bleach hentai gallery http://theporncollection.in/mature-woman/vanessa-mature
[url=http://theporncollection.in/lesbian-xxx/free-celebrity-lesbian-clips]adult shop retailer birmingham[/url] adult entertainment and acmp and 800 679 7110 [url=http://theporncollection.in/gay-xxx/gay-male-porn-and-free]gay male porn and free[/url]
free dildo video http://theporncollection.in/gay-male/gay-drill-sargent-mean-murtha-audio-clip
[url=http://theporncollection.in/orgy/freeamateur-asian-orgy-video]boca chica adult[/url] hot porn vidoes [url=http://theporncollection.in/gay-sex/sensual-gay-clips-trailers]sensual gay clips trailers[/url]

10:01 AM  
Anonymous Anonymous said...

hotel travel flights http://xwa.in/map/map-point visa requirements for travel to india
[url=http://xwa.in/disneyland/attractions-near-disneyland]mexico city gay travel[/url] mexico travel insurance air cheap europe travel [url=http://xwa.in/inn/tahitian-inn-new-port-richey]tahitian inn new port richey[/url]
travel plug for powerbook http://xwa.in/inn/westchester-inn-westchester-il
[url=http://xwa.in/motel/super-8-motel-garland-tx]irs foreign travel reimbursement policy[/url] travel trailers for sale in fl [url=http://xwa.in/tourism/singapore-ir-impact-tourism]singapore ir impact tourism[/url]
travel insurance sydney http://xwa.in/motel/mirco-fridge-combo-for-motel fargo travel agencies [url=http://xwa.in/hotel/hilton-hotel-quebec-city]hilton hotel quebec city[/url]

4:23 PM  
Anonymous Anonymous said...

finnland movie producer [url=http://worldmovs.co.cc/full_version-from-hell-jack-the-ripper/14415database/]From Hell Jack The Ripper[/url] sound of music movie lyrics [url=http://worldmovs.co.cc/full_version-adios-pequena-adios/19991database/]Adios Pequena Adios[/url]
pirates adult movie [url=http://full-length-movies.com/dvd-quality-movie-resident-evil/12005database/]Resident Evil[/url] ben10 movie [url=http://worldmovs.co.cc/full_version-national-treasure---book-of-secrets/4155database/]National Treasure - Book Of Secrets[/url]
movie props new york california [url=http://worldmovs.co.cc/full_version-pecker/29857database/]Pecker[/url] right through to you movie lyrics [url=http://full-length-movies.com/dvd-quality-movie-grace-is-gone/2591database/]Grace Is Gone[/url]
dawg movie [url=http://full-length-movies.com/dvd-quality-movie-new-world-disorder-8/17802database/]New World Disorder 8[/url] movie music man [url=http://worldmovs.co.cc/full_version-viaje-a-dajerling/25401database/]Viaje A Dajerling[/url]

5:31 AM  
Anonymous Anonymous said...

yokkaichi asthma [url=http://usadrugstoretoday.com/products/kamagra-oral-jelly.htm]kamagra oral jelly[/url] berkeley springs internal medicine http://usadrugstoretoday.com/products/parlodel.htm
on site dental [url=http://usadrugstoretoday.com/products/amitriptyline.htm]amitriptyline[/url] immunity in bacteria infection [url=http://usadrugstoretoday.com/products/lotrisone.htm ]disney kid at heart [/url] patterson dental chlor
new york times fda report [url=http://usadrugstoretoday.com/products/seroquel.htm]seroquel[/url] anillo vaginal http://usadrugstoretoday.com/products/reminyl.htm
allergy diabetes diet [url=http://usadrugstoretoday.com/products/cozaar.htm]cozaar[/url] down syndrome turner syndrome klinefelter syndrome [url=http://usadrugstoretoday.com/products/grifulvin-v.htm ]histrionic personality disorder and parenting [/url] john mayer dreaming with a broken heart

12:43 PM  
Anonymous Anonymous said...

joey lauren adams nude http://www.thefashionhouse.us/richmond-club-wear-brand18.html etnies skate shoes at zappos [url=http://www.thefashionhouse.us/leapord-print-evening-cocktail-color40.html]gucci deigns[/url] elderly active fashion advertisement
http://www.thefashionhouse.us/prada-women-leather-bag-vitello-shine-bowler--item2097.html corporate interior designers [url=http://www.thefashionhouse.us/tunic-page2.html]work shoes[/url]

1:37 PM  
Anonymous Anonymous said...

http://xwv.in/lipitor/is/there/fluoride/in/lipitor
[url=http://xwv.in/ketorolac/mechanism/of/action/of/ketorolac]drug overdose student jackson county nc[/url] antibiotic medicine for sinuses [url=http://xwv.in/osteoporosis/new/treatments/for/osteoporosis]new treatments for osteoporosis[/url]
omeprazole drug test http://xwv.in/isotretinoin
[url=http://xwv.in/ketoconazole/ketoconazole/canine]drug restistant staph infection[/url] erectile dysfunction help [url=http://xwv.in/ketorolac/what/is/ketorolac]what is ketorolac[/url]
formaldihide mixed with drugs http://xwv.in/lopressor/lopressor/peak
[url=http://xwv.in/osteoporosis/reclast/infusion/osteoporosis]multi vitamins drug information[/url] drug use of the opium war [url=http://xwv.in/tramadol/tramadol/with/sertraline]tramadol with sertraline[/url] prescription drugs prostate cancer treatment [url=http://xwv.in/ketoconazole/ketoconazole/cream/available/without/a/prescription]ketoconazole cream available without a prescription[/url]

4:59 PM  
Anonymous Anonymous said...

lauren rose lewis http://www.thefashionhouse.us/green-on-sale-color53.html ferragamo shoes women [url=http://www.thefashionhouse.us/versace-women-s-tops-brand1.html]opinion on best shoes for plantar fashiitis[/url] las vegas comedy shoes
http://www.thefashionhouse.us/gray-color99.html fubu slam anodized perf shoes [url=http://www.thefashionhouse.us/purple-round-neck-color37.html]ski clothes[/url]

5:01 AM  
Anonymous Anonymous said...

fashion illustration http://luxefashion.us/denim-blue-stretch-jeans-color7.html klein adept geometry [url=http://luxefashion.us/coralline-gucci-color112.html]insole shoes[/url] shoes boots western childrens
http://luxefashion.us/blue-casual-color32.html kleiner perkins [url=http://luxefashion.us/accessories-men-underwear-type5.html]most comfortable womens shoes[/url]

5:18 AM  
Anonymous Anonymous said...

the invention of the first automobile http://xwm.in/cadillac/cadillac-allentie gnassi mercedes
[url=http://xwm.in/buick/buick-navigation-system]aftermarket auto accessories[/url] resume for auto detailer [url=http://xwm.in/oldsmobile/restored-classics-oldsmobile]restored classics oldsmobile[/url]
sig rogich mercedes images http://xwm.in/fuel/types-of-hydrogen-fuel-cells
[url=http://xwm.in/buell/buell-blast-service-manual-download]automobile tire wear rating[/url] automobile salesman career [url=http://xwm.in/aprilia/aprilia-caponord]aprilia caponord[/url]
replacement seat for 2005 dodge 1500 http://xwm.in/geo
[url=http://xwm.in/daewoo/replace-daewoo-hard-drive]auto parts store aurora illinois[/url] automobile plants in china provinces [url=http://xwm.in/honda/honda-powered-water-pump]honda powered water pump[/url]

5:56 PM  
Anonymous Anonymous said...

hollywood casino grantville http://lwv.in/blackjack/online-strip-blackjack jackpot casino appereanes
[url=http://lwv.in/lottery/the-uk-international-lottery]casinos blackjack games[/url] footy gambling broker [url=http://lwv.in/casino-online/sofitel-reef-casino-cairns]sofitel reef casino cairns[/url]
casinos burlington iowa http://lwv.in/jackpot/jackpot-for-california-super-lotto-saturday-may-7
[url=http://lwv.in/online-casinos/how-do-casinos-cheat-at-blackjack]island casino bingo[/url] az lottery results [url=http://lwv.in/poker-online/online-striping-poker-games]online striping poker games[/url]
pete rose gambling http://lwv.in/jackpot/blog-trivia-jackpot-questions aztec casinos [url=http://lwv.in/joker/dragon-warrior-monsters-joker-faq]dragon warrior monsters joker faq[/url]

9:19 AM  
Anonymous Anonymous said...

mob rules movie [url=http://moviestrawberry.com/films/film_pride_prejudice/]pride prejudice[/url] anime movie sites http://moviestrawberry.com/films/film_abbott_and_costello_meet_the_mummy/ new movie review
full movie nurse sex [url=http://moviestrawberry.com/films/film_the_forbidden_dance/]the forbidden dance[/url] movie dog benji breed http://moviestrawberry.com/films/film_camille_70/ she creature movie
the mummy movie [url=http://moviestrawberry.com/films/film_saturday_night_live_the_best_of_jimmy_fallon/]saturday night live the best of jimmy fallon[/url] wallace movie theater
movie the messenger [url=http://moviestrawberry.com/films/film_lock_stock_and_two_smoking_barrels/]lock stock and two smoking barrels[/url] apocalypto movie http://moviestrawberry.com/hqmoviesbygenres/download-genre_music-movies/?page=2 movie foreign blue nazi jew post war relatinship
the kingdom movie [url=http://moviestrawberry.com/films/film_american_pie_presents_beta_house/]american pie presents beta house[/url] songs featured in the grease movie http://moviestrawberry.com/films/film_how_she_move/ he said she said movie soundtrack

6:06 PM  
Anonymous Anonymous said...

Helo ! Forex - Outwork чашку кофе успешной имеют свободные деньги, пройти регистрацию forex [url=http://foxfox.ifxworld.com/]forex[/url]

3:07 AM  

Post a Comment /投評論

<< Home

Software Culture
  03/01/2004 - 04/01/2004
  04/01/2004 - 05/01/2004
  05/01/2004 - 06/01/2004
  06/01/2004 - 07/01/2004
  08/01/2004 - 09/01/2004
  11/01/2004 - 12/01/2004
  07/01/2005 - 08/01/2005
  09/01/2005 - 10/01/2005
  10/01/2005 - 11/01/2005
  01/01/2006 - 02/01/2006
  03/01/2006 - 04/01/2006
ColdFusion
日常毒藥與養料
  Smart talk always right?
  Drools on AppFuse
  Braille, braille
  可愛提示
  The Dynamic SRC of IMG
  Preferred Locale on AppFuse
  告訴你為什麼程式不 work
  絲綢之路 2000:致命病毒
  AJAX on AppFuse
  1918
  Meet Mr. Writely
  網際網路的最後一頁
  小螞蟻最短篇
  健檢, e檢
  Open source ColdFusion
  八月半個
  自行其是
  Rich DHTML client
  cfspring, seriously
  三百萬民主補給站
  敏督利小插曲
  迷上喬治亞
  說故事
  Where are they?
  宿夢
  An Architect's View
  Martin Fowler
  Loud Thinking
  Raible Designs   fullasagoog
Home


Powered by Blogger