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

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

Related

Triggerhandler class and trigger issue - showing nullpoint exception error

trigger AssignedResourceTrigger on AssignedResource (after insert,after update){
if(trigger.isAfter & AssignedResourceTriggerHandler.isRecursive){
if(trigger.isInsert || trigger.isUpdate){
AssignedResourceTriggerHandler.assignedResourceOnServiceAppointment(trigger.new);
AssignedResourceTriggerHandler.isRecursive = false;
}
}
}
This is the error:
AssignedResourceTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.AssignedResourceTriggerHandler: line 9, column 1 Trigger.AssignedResourceTrigger: line 3, column 1

drools doesn't recognize ! with custom operators

I am getting issue when i use ! along with drools string operations like matches, str[startsWith] .
Any idea why drools doesn't allow ! with operators like matches , not matches, str[startsWith], str[endsWith], length
The ! works for other operators like == , < ,> .
Drl with exception :
package example
import com.Customer
rule "sample rule"
no-loop true
dialect "mvel"
when
$customer:Customer!(state == "CA" && city str[startsWith] "TOP")
then
System.out.println("Do something" );
end
Error Message :
[ERR 102] Line 11:19 mismatched input '!' in rule "sample rule" in pattern]
Drl without exception:
package example
import com.Customer
rule "sample rule"
no-loop true
dialect "mvel"
when
$customer:Customer!(state != "CA" && city != "TOP")
then
System.out.println("Do something" );
end
Drools should be able to validate the below drl without any issues,
package example
import com.Customer
rule "sample rule"
no-loop true
dialect "mvel"
when
$customer:Customer!(state == "CA" && city str[startsWith] "TOP")
then
System.out.println("Do something" );
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.

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

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.

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.