Search in sources :

Example 1 with RulesAgendaFilter

use of org.activiti.engine.impl.rules.RulesAgendaFilter in project Activiti by Activiti.

the class BusinessRuleTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) execution.getEngineServices().getProcessEngineConfiguration();
    ProcessDefinition processDefinition = processEngineConfiguration.getDeploymentManager().findDeployedProcessDefinitionById(execution.getProcessDefinitionId());
    String deploymentId = processDefinition.getDeploymentId();
    KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
    StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
    if (variablesInputExpressions != null) {
        Iterator<Expression> itVariable = variablesInputExpressions.iterator();
        while (itVariable.hasNext()) {
            Expression variable = itVariable.next();
            ksession.insert(variable.getValue(execution));
        }
    }
    if (!rulesExpressions.isEmpty()) {
        RulesAgendaFilter filter = new RulesAgendaFilter();
        Iterator<Expression> itRuleNames = rulesExpressions.iterator();
        while (itRuleNames.hasNext()) {
            Expression ruleName = itRuleNames.next();
            filter.addSuffic(ruleName.getValue(execution).toString());
        }
        filter.setAccept(!exclude);
        ksession.fireAllRules(filter);
    } else {
        ksession.fireAllRules();
    }
    Collection<Object> ruleOutputObjects = ksession.getObjects();
    if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
        Collection<Object> outputVariables = new ArrayList<Object>();
        for (Object object : ruleOutputObjects) {
            outputVariables.add(object);
        }
        execution.setVariable(resultVariable, outputVariables);
    }
    ksession.dispose();
    leave(execution);
}
Also used : KnowledgeBase(org.drools.KnowledgeBase) Expression(org.activiti.engine.delegate.Expression) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RulesAgendaFilter(org.activiti.engine.impl.rules.RulesAgendaFilter) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Aggregations

ArrayList (java.util.ArrayList)1 Expression (org.activiti.engine.delegate.Expression)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 RulesAgendaFilter (org.activiti.engine.impl.rules.RulesAgendaFilter)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 KnowledgeBase (org.drools.KnowledgeBase)1 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)1