Exception executing consequence for rule (Drools, Guvnor, JBPM5) - drools

am new to BPM, using JBPM5.4 installer.
below is the my drl source code taken from Guvnor..
when firing the rules am getting the error.
rule "TestRule"
dialect "java"
when
exists (Person( name == "estaban" ))
then
Person.setName( "ESTABAN" );
end
StackTrace:
Exception in thread "main" Exception executing consequence for rule "TestRule" in com.tcs: java.lang.NullPointerExceptio
n
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.j
ava:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at com.sample.ProcessMain.main(ProcessMain.java:41)
Caused by: java.lang.NullPointerException
at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8.defaultConsequence(Rule_TestRule_063717b0a0b841d3ae5b0d9fa148
79f8.java:7)
at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
at com.tcs.Rule_TestRule_063717b0a0b841d3ae5b0d9fa14879f8DefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 6 more

You need to bind the fact found in the left-hand-side to a variable. Re-write like so:
rule "TestRule"
dialect "java"
when
$person: Person( name == "estaban" )
then
$person.setName( "ESTABAN" );
update( $person );
end
To do this in Guvnor, when you add/modify the constraint, you will see a "Modify constraints for Person" dialog box. You need to type a variable name such as "$person" in the "Variable name" text box.
This will cause it to change the generated DRL from :
Person( name == "estaban" )
to:
$person: Person( name == "estaban" )
Once you have bound the variable on the LHS then you need to modify the RHS. Select the option "Modify a field of an existing fact". You then need to select your variable name from the list provided and provide the details of which property to modify.

Related

drools I added the break keyword after the from xxx keyword and reported an error

exception: mismatched input '[' in rule "checkTicketExpired"]
why????
rule "checkTicketExpired"
when
$r: RuleResult(holder instanceof Ticket)
$ticket: Ticket() from $r.holder
Ticket(LocalDateTime.now() > expireAt) from $ticket break[expire]
then
then[noting]
.....
then[expire]
.....
then[unAffect]
....
end

KIE workbench integration with Java: mismatched input '<' expecting one of the following tokens: '[package, import, global, declare,..]'

I'm trying to integrate drools kie workbench with java application. I'm Using jboss-as-7.1.1.Final as my workbench. Here is the rule definition:
package com.sample;
rule "set isEligible"
ruleflow-group "sample"
lock-on-active true
when
$p : Student(gpa > 2.0)
then
System.out.println("GPA is greater than 2..");
$p.setEligible(true);
end
From the java application i'm passing the student POJO object to the kieSession object and firing up the rules.
Here is the code:
Student s = new Student();
s.setName("Virat");
s.setGpa(5.0f);
URL u = new URL("http://localhost:8080/kie-wb-distribution-wars-6.2.0.Final-jboss-as7/kie-wb.html#%5Bnull%5D?path_uri=default://master#com/sample/src/main/resources/com/sample/sampleDRL.drl&file_name=sampleDRL.drl&has_version_support=true");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newUrlResource(u), ResourceType.DRL );
kbuilder.hasErrors();
if (kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors() );
}
kbuilder.getKnowledgePackages();
KieBase kieBase = kieContainer.getKieBase();
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(s);
kieSession.fireAllRules();
I'm able to connect to the workbench repository (com:sample:1.0) from the java app. But the problem is, i'm getting the following exception while executing the rule:
[8,0]: [ERR 107] Line 8:0 mismatched input '<' expecting one of the following tokens: '[package, import, global, declare, function, rule, query]'.
[0,0]: Parser returned a null Package
I don't know where i went wrong (because no where i have used '<' symbol).
Ask me for any missing detail. Any help on this would be greatly appreciated. Thank you.

Yeoman Generator in CoffeeScript - HookFor Warning

I'm trying to develop a custom generator for Yeoman using CoffeeScript but I'm facing a problem. When I use the hookFor method in the constructor of my class Generator, I get a warning hookFor must be used within the constructor when I try to init my project with Yeoman and my custom generator. Here is the code of my generator in index.coffee :
path = require 'path'
util = require 'util'
yeoman = require '../../../../'
module.exports = class Generator extends yeoman.generators.Base
constructor: ->
super()
#directories = ['controllers', 'helpers', 'models', 'templates', 'views']
#hookFor 'artefact:controller', args: ['App']
deploy: ->
#directory '.', '.'
#mkdir path.join 'dev', directory for directory in #directories
Any help will be appreciated. Thanks.
Apparently, the error comes from Yeoman Generators code in the yeoman-generators/lib/base.js file.
Here is how I led to that conclusion :
The warning is caused by the variable _running set to true in hookFor function (line 296)
This variable is set to true in run function (line 78) and just after that, methods of the class Generator are iterated (line 81-137)
the constructor defined in CoffeeScript for the class Generator is called during the iteration, so #hookFor is called whereas _running is true : warning!
But, the constructor should not be called because a test is done during the iteration to prevent it (line 92) :
if ( method.constructor === '-' )
However, this test, in my opinion, should be :
if ( method === 'constructor' )
The hack does the trick. Feel free to add comment if I'm wrong.

Drools Expert and Workflow: Unable to resolve ObjectType

I have these validation rule in Drools Expert which I have tested and works fine:
package com.myapp.validationPackage
import com.myapp.model.*;
declare Message
type : String
text : String
end
function Message error(String text) {
Message message = new Message();
message.setType("ERROR");
message.setText(text);
return message;
}
rule "First Validation"
ruleflow-group "Entity Validation"
when
Entity( $h : history )
not ( exists EntityHistory(closeDate == null) from $h
)
then
insert( error("Entity must be open") );
end
Now I want to use this rule in a workflow but give me this error when I try to build the .rf file on Eclipse:
Unable to resolve ObjectType 'Message' : [Rule name='RuleFlow-Split-XX'] ..
How should I use the delcared type to avoid the error?
Thanks.

How to set a nillable attribute for SOAP::Lite object in Perl?

I'm receiving the following error:
Exception: Error code: , messge: com.sun.istack.XMLStreamException2: org.xml.sax.SAXParseException: cvc-elt.3.1: Attribute 'http://www.w3.org/2001/XMLSchema-instance,nil' must not appear on element 'v1:get_list', because the {nillable} property of 'v1:get_list' is false. at ./soap.pl line 42.
This is my Perl code:
my $client = SOAP::Lite
->on_fault( \&faultHandler )
->uri('http://api.domain.net/')
->proxy('https://api.domain.net/MyAPI');
# Execute
$client->get_list();
How do I change/add the nillable attribute and how ?
How do I change/add the nillable attribute and how ?
You use SOAP::Data to create argument for get_list, or for call
Switch to SOAP::Simple , it has better WSDL support cpan BERLE/SOAP-Simple-0.00_03.tar.gz