Business Logic Validation Using Rules
by Shazin Sadakath
Hi
I am currently writing a set of Rules to Validate Some Business Logic and
if The Criteria in When clause is met throw an Exception.
Currently I have two rules. I use a StatelessKnowledgeSession and
CommandExecutor.execute method to fire the rules.
But while testing I created a scenario to fire one of the rules and throw
an exception then created another scenario to not to throw an Exception
(Valid Domain Object). But in this case also it is throwing an Exception
with info related to Failed Domain Object.
Regards,
Shazin Sadakath
11 years, 4 months
Unable to get LastModified for ClasspathResource
by sottostee
Hi everyone,
I have got a problem that me go mad.
Clarify I'm working with a Maven project using Eclipse.
I'm trying to add at my KnowledgeBuilder, after i have correctly created a
new instance of it, a drl file.
In order of this, i call a method: void
org.drools.builder.KnowledgeBuilder.add(Resource arg0, ResourceType arg1),
give it like a Resource "ResourceFactory.newClassPathResource(String: name
of my drl)" and like ResourceType: "ResourceType.DRL".
As long as i run my project into Eclipse, all works well.
But, if i create a jar file of my project, when i run this, i have this
exception:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:192)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.io.FileNotFoundException: 'General_multivalue.drl' cannot be
opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 20 more
line 192 is properly:
'builder.add(ResourceFactory.newClassPathResource("General.drl"),
ResourceType.DRL);'
Well....given that in my project I've got some classes which make use of
images, and given that, in this classes I call this method:
getClass().getResource(String of image).getFile() in order to load the
images, and all seems work very well; therefore I'm doing the same thing
with drl file:
I change the old method with:
builder.add(ResourceFactory.newClassPathResource(getClass().getResource("General.drl").getFile()),
ResourceType.DRL);
Now:
1) when i run jar file, the exception is:
java.lang.NullPointerException
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
2) and when i run the project into Eclipse, the exception is:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
Caused by: java.io.FileNotFoundException:
'/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/General_multivalue.drl'
cannot be opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 15 more
but in '/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/' the file
'General_multivalue.drl' EXISTS!!!!
Are there anyone who help me please?
Thanks in advance.
sotto
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-get-LastModified-for-Classpat...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 4 months
Drools in Hawaii
by Mark Proctor
I'm going to be in Hawaii for 3 weeks in september, visiting honolulu, kauaui and maui.
Is there a Drools community on any of those islands, I could be tempted to attend a user group and do a Drools 6 talk :)
Mark
11 years, 4 months
Drools Fusion in JEE environment
by IK81
Hi all,
i am planning to use the Drools engine in the stream mode within an JEE
application server. I have to process events of different users which can
define their own rules. So I plan to instantiate a stateful session for each
user and populate them with the user's rules. However, I am concerned how to
manage the firing of the rules - which might be delayed by some time because
of some rule statements (fire rule after having event A and no event B
within 3 minutes). Spawning a thread for each session and calling
fireUntilHalt is not an option in my opinion.
I've found a solution where somebody uses a scheduler within the container
to call fireAllRules at certain domain-specific intervals (e.g., every 10
seconds). I am wondering if there is a more clever approach. I am thinking
of providing a callback that can be used by Drools to notify when it has to
be "waked-up" again to fire the delayed rule.
Best regards,
Ingo
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Fusion-in-JEE-environment-tp4025...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 4 months
Iterating string objects inside Arraylist
by Ganesh R.
I am a novice in Drools, sorry if this question is trivial and has already been discussed. I couldn't find the direct method for implementing the below behavior.
I have a class like this.
public class Account {
public int balance;
public String id;
public List<String> types;
// getter setters
}
I am trying to check the following:
Accounts having balance greater than $100 and types containing both Savings and Checking.
// Creating sample Facts in Java main
Account account = new Account();
account.setBalance(100);
account.setId("A1");
List<String> temp = new ArrayList<String>();
temp.add("Savings");
temp.add("Checking");
account.setTypes(temp);
// Creating rules
rule "Sample"
when
bat : Account(balance == 100)
then
if (bat.getTypes().contains("Savings") && bat.getTypes().contains("Checking")){
System.out.println("I got this");
}
end
Is there more proficient ways to do this?? like checking the contents of the arraylist (types as per the above example) in rule i.e. in "when" instead of doing it in "then" ??
Much appreciate your answers.
Thank you!
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are not
to copy, disclose, or distribute this e-mail or its contents to any other person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
every reasonable precaution to minimize this risk, but is not liable for any damage
you may sustain as a result of any virus in this e-mail. You should carry out your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
11 years, 4 months
VRP with multi-stream and heterogeneous fleet?
by Colin Sheppard
Hello all, I'm totally new to optaplanner / drools and would like to know
if the following is possible within the framework (I'd mostly likely use
version 6).
I have a VRP where we'd like to consider multiple waste streams
simultaneously (i.e. trash, recycling, food waste, and yard waste). We'd
also like to consider a fleet of split bin trucks (capable of collecting 2
streams at a time but with reduced capacity), single bin trucks, or a
mixture of split and single bin.
So the model would need to allow for a mixture of vehicle types, for nodes
to be visited more than once, and for simultaneous collection to occur in
the case of split bin trucks.
Does this sound like a feasible problem to implement? Would you anticipate
any major or intractable challenges?
Thanks for your advice, I hope I get the chance to start using optaplanner!
Colin Sheppard
--
Colin Sheppard
Research Engineer,
Schatz Energy Research Center
colin(a)humboldt.edu
707.633.8633
11 years, 4 months
Internet Explorer Compatibility
by rjr201
Hi,
I'm working for a client who wishes to use Guvnor with Internet Explorer.
I've tried Guvnor 5.5.0.Final with IE8 and IE9. However, I get an error when
trying to access a rule in the guided editor.
I read in another post
(http://drools.46999.n3.nabble.com/guvnor-5-5-problems-on-Internet-Explore...)
that there are problems with 5.5.0 in IE, that may have been fixed in the
current 5.5.x branch.
I have built the latest code on the branch, but seem to have even more
problems (it doesn't even let me get to the initial Guvnor landing page).
Does anyone have any experience/insight in getting Guvnor working in IE? Or
at least know what version of Guvnor does work in IE? Or just any advice on
this issue at all I would be grateful..
Thanks in advance,
Rich.
--
View this message in context: http://drools.46999.n3.nabble.com/Internet-Explorer-Compatibility-tp40249...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 4 months
Re: [rules-users] rules-users Digest, Vol 80, Issue 34
by pritha.ghosh@wipro.com
I have only one rule employeemaprule
________________________________________
From: rules-users-bounces(a)lists.jboss.org [rules-users-bounces(a)lists.jboss.org] on behalf of rules-users-request(a)lists.jboss.org [rules-users-request(a)lists.jboss.org]
Sent: Wednesday, July 17, 2013 8:13 PM
To: rules-users(a)lists.jboss.org
Subject: rules-users Digest, Vol 80, Issue 34
Send rules-users mailing list submissions to
rules-users(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
rules-users-request(a)lists.jboss.org
You can reach the person managing the list at
rules-users-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of rules-users digest..."
Today's Topics:
1. Re: help on drools guvnor (rjr201)
2. Re: DRL always posting the format as txt instead of model.drl
(learnbrms)
3. Re: rules-users Digest, Vol 80, Issue 33 - help on drools
guvnor (pritha.ghosh(a)wipro.com)
4. Re: rules-users Digest, Vol 80, Issue 33 - help on drools
guvnor (rjr201)
5. Re: Problems with the Mrs Manners Benchmark (Mark Proctor)
----------------------------------------------------------------------
Message: 1
Date: Wed, 17 Jul 2013 06:28:45 -0700 (PDT)
From: rjr201 <rich.j.riley(a)gmail.com>
Subject: Re: [rules-users] help on drools guvnor
To: rules-users(a)lists.jboss.org
Message-ID: <1374067725846-4024977.post(a)n3.nabble.com>
Content-Type: text/plain; charset=us-ascii
What are your rules?
--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-help-on-drools-guvnor-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
------------------------------
Message: 2
Date: Wed, 17 Jul 2013 06:32:18 -0700 (PDT)
From: learnbrms <srivats.rayaprolu(a)gmail.com>
Subject: Re: [rules-users] DRL always posting the format as txt
instead of model.drl
To: rules-users(a)lists.jboss.org
Message-ID: <1374067938811-4024978.post(a)n3.nabble.com>
Content-Type: text/plain; charset=us-ascii
Can anyone please advise to my above problem ?
Thanks,
Sri
--
View this message in context: http://drools.46999.n3.nabble.com/DRL-always-posting-the-format-as-txt-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
------------------------------
Message: 3
Date: Wed, 17 Jul 2013 13:34:10 +0000
From: <pritha.ghosh(a)wipro.com>
Subject: Re: [rules-users] rules-users Digest, Vol 80, Issue 33 - help
on drools guvnor
To: <rules-users(a)lists.jboss.org>
Message-ID:
<6374181C9192E7459C135FEE70E5E16509F1E31F(a)CHN-SNR-MBX-8.wipro.com>
Content-Type: text/plain; charset="us-ascii"
The same code runs fine with
urlResource = (org.drools.io.impl.UrlResource) org.drools.io.ResourceFactory
.newUrlResource(new java.net.URL("http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/OBSP..."));
And resourse type "DRL"
Please find below the source code of the rule
rule "EmployeeMapRule"
no-loop true
enabled true
dialect "mvel"
when
EmployeeMap : EmployeeMap( employeeID : EmployeeID != null , employeeName : EmployeeName != null , employeeCountry : EmployeeCountry in ( "INDIA", "Australia", "USA" ) )
then
EmployeeMap.setEmployeeName( employeeName+" Success" );
EmployeeMap.setEmployeeCountry( employeeCountry );
EmployeeMap.setEmployeeID( employeeID );
update( EmployeeMap );
end
I have written the rule in guvnor.
Drools version 5.5
Please find below the source code for my model employeemap
declare EmployeeMap
EmployeeName: String
EmployeeCountry: String
EmployeeID: Integer
end
I have attached the pojo class I am using to fire the rule
Thanks,
Pritha
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of rules-users-request(a)lists.jboss.org
Sent: Wednesday, July 17, 2013 6:50 PM
To: rules-users(a)lists.jboss.org
Subject: rules-users Digest, Vol 80, Issue 33
Send rules-users mailing list submissions to
rules-users(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
rules-users-request(a)lists.jboss.org
You can reach the person managing the list at
rules-users-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of rules-users digest..."
Today's Topics:
1. Re: help on drools guvnor (Stephen Masters)
----------------------------------------------------------------------
Message: 1
Date: Wed, 17 Jul 2013 14:19:21 +0100
From: Stephen Masters <stephen.masters(a)me.com>
Subject: Re: [rules-users] help on drools guvnor
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID: <93FD4B72-09E1-4AEB-8ACD-CFC3B4BD36A9(a)me.com>
Content-Type: text/plain; charset="us-ascii"
Have you tested that the rules fire when you load them as DRL?
It would probably be worth showing us what EmployeeMap looks like and the rule which you expect to fire if there is an EmployeeMap in working memory.
The Drools version would also be useful.
Steve
On 17 Jul 2013, at 14:04, pritha.ghosh(a)wipro.com wrote:
> Hi,
>
> I am not able to run rules from .pkg resources.
>
> Knowledgesession is getting populated with package and rules inside the packages but when I am firing ksession.fireAllRules(); no rules are getting executed.
>
> Below is my program
>
> final KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>
> // Use this line if calling rule defined using guvnor package
> org.drools.io.impl.UrlResource urlResource;
> try {
> urlResource = (org.drools.io.impl.UrlResource) org.drools.io.ResourceFactory
> .newUrlResource(new
> java.net.URL("http://localhost:8080/drools-guvnor/org.drools.guvnor.Gu
> vnor/package/OBSPOC/OBSSNAP/OBSPOC_OBSSNAP.pkg"));
>
>
> urlResource.setBasicAuthentication("enabled");
> urlResource.setUsername("admin");
> urlResource.setPassword("admin");
> kbuilder.add(urlResource,ResourceType.PKG);
> }
> catch (MalformedURLException e) {
> System.out.println("malformed URL");
> e.printStackTrace();
> }
> catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> // create the knowledge base
> KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase();
>
>
>
>
> // Check the builder for errors
> if (kbuilder.hasErrors()) {
> System.out.println(kbuilder.getErrors().toString() + "********");
> throw new RuntimeException("Unable to compile the rule file.");
> }else{
> System.out.println(".....Rule File is Read Successfully....");
> }
>
> // get the compiled packages (which are serializable)
> final Collection pkgs = kbuilder
> .getKnowledgePackages();
>
> // add the packages to a knowledgebase (deploy the knowledge packages).
> // final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
> kbase.addKnowledgePackages(pkgs);
>
>
> final StatefulKnowledgeSession ksession = kbase
>
> .newStatefulKnowledgeSession();
>
> ksession.addEventListener(new DebugAgendaEventListener());
> ksession.addEventListener(new
> DebugWorkingMemoryEventListener());
>
> EmployeeMap employeeMap = new EmployeeMap();
> employeeMap.setEmployeeCountry("INDIA");
> employeeMap.setEmployeeID(1);
> employeeMap.setEmployeeName("USERP");
>
> ksession.insert(employeeMap);
> ksession.fireAllRules();
>
>
> ksession.dispose();
>
>
> Thanks,
> Pritha
> Please do not print this email unless it is absolutely necessary.
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
11 years, 4 months
Problems with the Mrs Manners Benchmark
by Sven Böcherer
Hello,
I am writing my dissertation on BRMS. I want to analyze the performance of
different systems. Drools is one of them.
I installed Drools 6 and wanted to start the Mrs Manners Benchmark for a
first analysis.
Unfortunately if I chose anything else but 5 guests, I get an infinite loop
where the program is never able to find the seating arrangement.
Attached you find a screenshot of what the console looks like.
I really hope you can help me with this problem.
Best regards,
Sven Böcherer
Sven Böcherer
Bachelorthesis
EXXETA AG
Albert-Nestler-Str. 11
76131 Karlsruhe
fon +49 721 6105-1500
fax +49 721 6105-1599
mail <mailto:Sven.Boecherer@EXXETA.com> Sven.Boecherer(a)EXXETA.com
web <http://www.exxeta.de/> www.EXXETA.com
Sitz der Gesellschaft:
EXXETA AG
Albert-Nestler-Str. 11, 76131 Karlsruhe
Vorstände: Achim Kirchgässner, Andreas Ritter
Aufsichtsratsvorsitzender: Ulrich A. Götz
Ust-IdNr. DE813026499
Eingetragen beim Amtsgericht Mannheim HRB 702566
Diese E-Mail enthaelt vertrauliche oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der beabsichtigte Empfaenger sind,
informieren Sie bitte sofort den Absender und loeschen Sie diese E-Mail.
Das unbefugte Kopieren dieser E-Mail oder die unbefugte Weitergabe der
enthaltenen Informationen ist nicht gestattet.
The information contained in this message is confidential or protected by
law.
If you are not the intended recipient, please contact the sender and
delete this message. Any unauthorized copying of this message or
unauthorized distribution of the information contained herein is prohibited.
11 years, 4 months