I am trying to execute different drool rules in java having different business logic but rule 2 needs to be executed after rule 1 gets executed. For this, I have used ruleflow-group. I am able to execute rule 1 properly but rule 2 is return 0 from kieSession.fireAllRules() method.
My 2nd drool rule looks like below now:
import com.drools.A;
import com.drools.B;
import java.util.List;
import java.util.ArrayList;
import com.drools.OutputDTO;
global List<OutputDTO> outputDTOs;
rule "ABC with Approved Status"
ruleflow-group "status"
when
$outputDTO: OutputDTO();
$transaction: A( $b : b != null )
exists( B( group == "ABC" , status == "Approved" ) from $b )
then
$outputDTO.setGroup("ABC");
$outputDTO.setStatus("Approved");
outputDTOs.add($outputDTO);
end;
rule "XYZ with Approved Status"
ruleflow-group "status"
when
$outputDTO: OutputDTO();
$transaction: A( $b : b != null )
exists( B( group == "XYZ" , status == "Approved" ) from $b )
then
$outputDTO.setGroup("XYZ");
$outputDTO.setStatus("Approved");
outputDTOs.add($outputDTO);
end;
The rule execution part is as below:
kieSession.getAgenda().getAgendaGroup("scope").setFocus();
int x = kieSession.fireAllRules(); // rule 1 got executed here successfully
logger.debug("Number of rules matched for getting dynamic scopes - {} ", x); // x=3
//processing from rule 1 data and creating object A and then trying to //execute rule 2 from below
List<OutputDTO> outputDTOs = new ArrayList<>();
kieSession.setGlobal("outputDTOs", outputDTOs);
kieSession.insert(a); // A object
kieSession.getAgenda().getAgendaGroup("status").setFocus();
int y = kieSession.fireAllRules(); // getting y =0 here
kieSession.dispose();
return outputDTOs;
Can anyone please tell me how can I run rule 2 here ?