This my When condition
$cla : cashliquidassets(
entity == "AU001",
asset_liability_indicator == "A",
product_group.contains('Loans','Bankofindia'),
product.contains("DS"),
counterparty_resident_indicator == "AU",
counterparty_type.contains("DS"),
related_entity == "Y"
)
I am getting an error at
Unable to Analyse Expression product_group.contains("Loans","Bankofindia")
Any Suggestions
Without your class model is hard to tell, but assuming that cashliquidassets.product_group is a String, you are trying to use an unexisting method String.contains(String, String).
One option would be to use an OR or and AND between 2 contains:
...
(product_group.contains('Loans') || product_group.contains('Bankofindia')),
...
or
...
product_group.contains('Loans'),
product_group.contains('Bankofindia'),
...
Another option could be to use the matches operator with a regular expression.
Hope it helps,
Related
i have a fairly simple question, i have this rule
rule 'Rule1'
when
$inMess : MetaMessage()
not(MetaMessage(this after[0, 10000] $inMess, this != $inMess))
then
log.info("Message id:"+ $inMess.getId());
end
It works perfectly (in the after operand, if you use only a number it assumes milliseconds), i have only one other thing to do, parametrize the after operator so it can accept a property of the MetaMessage.
Something like this
rule 'Rule1'
when
$inMess : MetaMessage($delay : delay)
not(MetaMessage(this after[0, $delay] $inMess, this != $inMess))
then
log.info("Message id:"+ $inMess.getId());
end
Is there a way to do this?
I am just curious as to why my Eclipse Drools compiler (6.5.0) requires semi-colons at the end of statements in the For loop, as below:
Map businessRulesRequest = $root.containsKey("BusinessRulesRequest") ? $root.get("BusinessRulesRequest") : null
Map quoteRequest = businessRulesRequest!=null && businessRulesRequest.containsKey("QuoteRequest") ? businessRulesRequest.get("QuoteRequest") : null
List resultsByKey = quoteRequest!=null && quoteRequest.containsKey("resultsByKey") ? quoteRequest.get("resultsByKey") : new ArrayList()
for (Map search : resultsByKey) {
Map searchInfo = (search.containsKey("searchInfo") ? search.get("searchInfo") : null);
String searchName = searchInfo!=null && searchInfo.containsKey("searchName") ? searchInfo.get("searchName").toString() : "";
List results = (searchName=="quotesMotor" && search.containsKey("results") ? search.get("results") : new ArrayList());
}
If I remove the semi-colons from the first or second lines in the For loop, I get an "unexpected token" error, but not if I remove it from the last line in the loop.
Is it due to Drools evaluating RHS lines as a single statement and so they must be separated inside any loops?
Note: I understand it is not best practice to code assuming semi-colons are not required, however I came across this issue while experimenting and am just interested to know the reason for the compiler error. Thanks.
I guess the answer is because of MVEL itself. Drools may be delegating the entire chunk of code to MVEL to evaluate and execute.
According to this guide, in MVEL the use of a semi-colon is not mandatory in cases where you have 1 statement, or in the last statement of a script.
Hope it helps,
The problem I am having is I am trying to use ternary operators over if else for smaller code but when using it in my case it is returning a different result than if I use an if else.
The problem code is below;
If Else
if(string.IsNullOrEmpty(jn["LARM"].Value))
pm.ItemLeftArm = null;
else
pm.ItemLeftArm = jn["LARM"];
Ternary
pm.ItemLeftArm = string.IsNullOrEmpty(jn["LARM"].Value) ? null : jn["LARM"];
The jn["LARM"] is a json node from simpleJSON and it is either a number e.g. "0" or nothing e.g. "".
It returns null form the if else but it returns the jn object which transforms from "" into 0.
Im not sure why Im getting this issue.
The code is ok, the problem must be in the JSON. Have you tried logging the jn["LARM"].Value just before the terniary operator in order to be sure that the value is null/empty or not?
BTW, why are you using simpleJSON instead of the new Unity integrated JsonUtility?
I am working on a drool file with the below code:
rule "test rule"
#RuleNumber(1)
#RuleMessage("data mismatch")
when
$myObj : MyObj($localVal1: val1)
$dataMismatch: Boolean() from ($localVal1 == null)
eval $dataMismatch
then
//do something
end
I keep getting the error mismatched input '$dataMismatch' in rule, Parser returned a null Package
Does anyone know where am I going wrong?
Thanks!
Unless you get paid by lines of code written, you should use:
rule "test rule"
#RuleNumber(1)
#RuleMessage("data mismatch")
when
$myObj : MyObj(val1 == null)
then
//do something
end
(Looking into syntax errors cannot be done reliably without knowing the Drools version, which you haven't provided.)
A SubjectTeacherPeriod has a num_attribute_map, which is a map that maps certain attributes (such as "boringness") with their respective scores. I use the following code to sum attributes (such as "boringness") over each day of the week.
But a certain line causes an error.
rule "insertAttributeDayTotal"
//salience 1 // Do these rules first (optional, for performance)
when
$sum_regression_constraint : SumRegressionConstraint(
$class : class_,
$attribute : attribute//,
//$weight : weight;
)
$day_of_week : DayOfWeek()
$attribute_day_total : Number() from accumulate(
SubjectTeacherPeriod(
//period != null,
period.class_ == $class,
period.dayOfWeek == $day_of_week,
$total : num_attribute_map[$attribute] //PROBLEM LINE
),
sum($total)
)
then
//System.out.println("BUCKET TOTAL "+$id+" "+$bucket_total.intValue());
insertLogical(new AttributeDaySum($class, $attribute, $day_of_week, $attribute_day_total.intValue()));
end
The error is:
jesvin#Jesvin-Technovia:~/dev/drools/timetabler$ java -server in.co.technovia.timetabler.TimeTableApp
Exception in thread "main" java.lang.IllegalStateException: There are errors in the scoreDrl's:
Variables can not be used inside bindings. Variable [$attribute] is being used in binding 'num_attribute_map[$attribute]' : [Rule name='insertAttributeDayTotal']
Rule Compilation error : [Rule name='insertAttributeDayTotal']
in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (7:905) : Syntax error on token "null", invalid Type
in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_bb39fd28b3c8457cb8d86fc15b34a0e7.java (9:1050) : $total cannot be resolved
SubjectTeacherPeriod has the curious num_attribute_map so that I can define attributes at runtime. If I wanted a boringness (int) attribute for SubjectTeacherPeriod, I can do num_attribute_map.put("boringness",1) instead of adding a new attribute to SubjectTeacherPeriod.
A SumRegressionConstraint cares about a particular $attribute. That attribute's value is stored in num_attribute_map of SubjectTeacherPeriod. I want to access num_attribute_map[$attribute] but this problem shows up.
What am I doing wrong?
Is there any other way to get dynamic attributes to work?
At the moment, you can't bind a variable to expressions, only to field names. So instead of binding it to:
$total : num_attribute_map[$attribute]
Bind it to:
$total : num_attribute_map
Then, you can use the expression on the function. If you are using the MVEL dialect:
sum( $total[$attribute] )
Or if you are using the java dialect:
sum( $total.get($attribute) )