I have a very simple test case to reward the player if he registers the first time. When I am running my test case getting an error.
Message [id=1, kieBase=defaultKieBase, level=ERROR, path=player.drl, line=10, column=0
text=Unable to Analyse Expression isNew == true:
[Error: no such identifier: isNew]
[Near : {... isNew == true ....}]
^ [Line: 10, Column: 8]]
I checked that the model class has the variable declared correctly and the same is referred to .drl file.
Player.drl
import com.xyz.model.business.objects.Player;
import com.xyz.rules.domain.Points;
import java.util.*;
global com.xyz.rules.domain.Points points;
dialect "mvel"
rule "Reward Point if User registered"
when
playerInstance:Player(isNew == true);
then
points.setPoints(1000);
end
Model Class
package com.xyz.model.business.objects;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder(toBuilder = true)
public class Player {
private String userId;
private String name;
private int age;
private boolean isNew;
}
You should should implement getters for the bean / model properties. As new
is reserved word in Java I would replace it with new_
. Because the property type is boolean
getter name is isNew_
not getNew_
.
Rule
Replace Player(isNew == true)
with Player(new_ == true)
.
Model
Replace
private boolean isNew;
with
private boolean new_;
public boolean isNew_() {
return new_;
}