Re: [rules-users] Driving License application
Can you share with us the Applicant class? because if you have something like: boolean valid; it will be automatically initialized to false, so the rule will not do anything just leave the Applicant as it is On Tue, Dec 24, 2013 at 10:05 AM, seyfullah seyfullahti...@outlook.comwrote: Hello, I am trying to implement Driving License example application in Drools Documentation Versio 6.0.0.0 Final. My main method is as below. KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); StatelessKieSession kSession = kContainer.newStatelessKieSession(); Applicant applicant = new Applicant(Mr John Smith, 16); assertTrue( applicant.isValid() ); kSession.execute( applicant ) ; assertFalse ( applicant.isValid() ); My licenseApplication.drl file is as below: package MyPackage import MyPackage.Applicant; rule Is of valid age when $a : Applicant( age 18 ) then $a.setValid ( false ); end Thanks to assertTrue and asserFalse methods, its output is It is false as not expected It is false as expected Bu when I change age parameter from 16 to 22 its output is same again. I expected that it is true. I think there is something wrong. Do you have any idea about this problem? Regards -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- - MyJourney @ http://salaboy.com http://salaboy.wordpress.com - Co-Founder @ http://www.jugargentina.org - Co-Founder @ http://www.jbug.com.ar - Salatino Salaboy Mauricio - ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Driving License application
package MyPackage; public class Applicant { public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isValid() { return valid; } public void setValid(boolean valid) { this.valid = valid; } private String name; private int age; private boolean valid; public Applicant(String nameP, int ageP) { // TODO Auto-generated constructor stub this.name = nameP; this.age = ageP; } } -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403p4027405.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Driving License application
So, if you don't touch in some way the boolean valid, value in your rules or in your java code it will be false not true. On Tue, Dec 24, 2013 at 10:15 AM, seyfullah seyfullahti...@outlook.comwrote: package MyPackage; public class Applicant { public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isValid() { return valid; } public void setValid(boolean valid) { this.valid = valid; } private String name; private int age; private boolean valid; public Applicant(String nameP, int ageP) { // TODO Auto-generated constructor stub this.name = nameP; this.age = ageP; } } -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403p4027405.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- - MyJourney @ http://salaboy.com http://salaboy.wordpress.com - Co-Founder @ http://www.jugargentina.org - Co-Founder @ http://www.jbug.com.ar - Salatino Salaboy Mauricio - ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Driving License application
Ok, I changed my drl file and main method as follows, and it works. Thank you. package MyPackage import MyPackage.Applicant; rule Is of not valid age when $a : Applicant( age 18 ) then $a.setValid ( false ); end rule Is of valid age when $a : Applicant( age 17 ) then $a.setValid ( true ); end KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); StatelessKieSession kSession = kContainer.newStatelessKieSession(); Applicant applicant = new Applicant(Mr John Smith, 16); assertFalse( applicant.isValid() ); kSession.execute( applicant ) ; assertFalse ( applicant.isValid() ); Applicant applicant2 = new Applicant(Mr Bill Wayne, 22); assertFalse( applicant2.isValid() ); kSession.execute( applicant2 ) ; assertTrue ( applicant2.isValid() ); -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403p4027407.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Driving License application
Yeah, that will do the work. On Tue, Dec 24, 2013 at 10:34 AM, seyfullah seyfullahti...@outlook.comwrote: Ok, I changed my drl file and main method as follows, and it works. Thank you. package MyPackage import MyPackage.Applicant; rule Is of not valid age when $a : Applicant( age 18 ) then $a.setValid ( false ); end rule Is of valid age when $a : Applicant( age 17 ) then $a.setValid ( true ); end KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); StatelessKieSession kSession = kContainer.newStatelessKieSession(); Applicant applicant = new Applicant(Mr John Smith, 16); assertFalse( applicant.isValid() ); kSession.execute( applicant ) ; assertFalse ( applicant.isValid() ); Applicant applicant2 = new Applicant(Mr Bill Wayne, 22); assertFalse( applicant2.isValid() ); kSession.execute( applicant2 ) ; assertTrue ( applicant2.isValid() ); -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403p4027407.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- - MyJourney @ http://salaboy.com http://salaboy.wordpress.com - Co-Founder @ http://www.jugargentina.org - Co-Founder @ http://www.jbug.com.ar - Salatino Salaboy Mauricio - ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Driving License application
If you have a property (such as valid) that has N possible values (2 in this case) you should have at least N-1 rules, setting values 1 to N-1 (as you have) and a default by initialisation equal to the N-th value (which is missing from your code). Alternatively, consider using N rules, one for each possible value, and then you don't have to worry about initialisation. -W On 24/12/2013, seyfullah seyfullahti...@outlook.com wrote: package MyPackage; public class Applicant { public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isValid() { return valid; } public void setValid(boolean valid) { this.valid = valid; } private String name; private int age; private boolean valid; public Applicant(String nameP, int ageP) { // TODO Auto-generated constructor stub this.name = nameP; this.age = ageP; } } -- View this message in context: http://drools.46999.n3.nabble.com/Driving-License-application-tp4027403p4027405.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users