use of org.drools.runtime.StatefulKnowledgeSession in project jBPM5-Developer-Guide by Salaboy.
the class CompleteWorkItemCallback method onCommandDone.
public void onCommandDone(CommandContext ctx, ExecutionResults results) {
Map<String, Object> output = new HashMap<String, Object>();
if (results != null) {
for (Map.Entry<String, Object> entry : results.getData().entrySet()) {
output.put(entry.getKey(), entry.getValue());
}
}
String sWorkItemId = (String) ctx.getData("_workItemId");
String businessKey = (String) ctx.getData("businessKey");
String[] key = businessKey.split("@");
StatefulKnowledgeSession session = null;
synchronized (SessionStoreUtil.sessionCache) {
session = SessionStoreUtil.sessionCache.get(key[1]);
}
session.getWorkItemManager().completeWorkItem(Long.valueOf(sWorkItemId), output);
}
use of org.drools.runtime.StatefulKnowledgeSession 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);
}
Aggregations