I have a simple that checks whether a user id is present in db
rule "check if user is already present"
agenda-group "dbcheck"
when
$blackListUserDto : BlackListUserDto( )
eval( BlackListServiceImpl.isUserBlacklisted($blackListUserDto) )
then
System.out.println("to be executed first");
System.out.println($blackListUserDto.isUserAlreadyBlacklisted());
end
The method isUserBlacklisted is as follows
public static boolean isUserBlacklisted(BlackListUserDto blackListUserDto)
{
try {
BlackListEntity blackListEntity = blackListRepository.findByUserId(blackListUserDto.getUserId());
if(blackListEntity!=null)
{
blackListUserDto.setUserAlreadyBlacklisted(true);
}
else
//do something else
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
As it can be seen that I am modifying the fact(dto) blackListUserDto by setUserAlreadyBlacklisted(true).
But in the "then" part of rule when I am printing the value
System.out.println($blackListUserDto.isUserAlreadyBlacklisted()); The output is still false.
also I need to share this data in another rule which is as follows
rule "blacklist user"
agenda-group "blacklist"
when
(BlackListUserDto( userAlreadyBlacklisted == false ))
then
//do something else
end
so far my understanding is that when I edit facts then do we need to re insert them again? if yes then how do I insert it in the same session as there is another method in which I am creating this session as follows :-
public void blacklistUser(String userId) throws IOException
{
BlackListUserDto blackListUserDto=new BlackListUserDto();
blackListUserDto.setUserId(userId);
KieSession kieSession = kContainer.newKieSession();
Agenda agenda = kieSession.getAgenda();
agenda.getAgendaGroup( "blacklist" ).setFocus();
agenda.getAgendaGroup( "dbcheck" ).setFocus();
kieSession.insert(blackListUserDto);
kieSession.insert(queryTypeDto);
kieSession.fireAllRules();
kieSession.dispose();
}
what all changes to be done to make sure that the fact gets updated and the updated value gets reflected in the next rule.