use of org.drools.core.event.ProcessEventSupport in project jbpm by kiegroup.
the class VariableScopeInstance method setVariable.
public void setVariable(String name, Object value) {
if (name == null) {
throw new IllegalArgumentException("The name of a variable may not be null!");
}
Object oldValue = variables.get(name);
if (oldValue == null) {
if (value == null) {
return;
}
}
ProcessEventSupport processEventSupport = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getProcessEventSupport();
processEventSupport.fireBeforeVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime());
internalSetVariable(name, value);
processEventSupport.fireAfterVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime());
}
use of org.drools.core.event.ProcessEventSupport in project jbpm by kiegroup.
the class DynamicUtils method executeWorkItem.
private static void executeWorkItem(StatefulKnowledgeSessionImpl ksession, WorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
ProcessEventSupport eventSupport = ((InternalProcessRuntime) ksession.getProcessRuntime()).getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, ksession);
((WorkItemManager) ksession.getWorkItemManager()).internalExecuteWorkItem(workItem);
workItemNodeInstance.internalSetWorkItemId(workItem.getId());
eventSupport.fireAfterNodeTriggered(workItemNodeInstance, ksession);
}
use of org.drools.core.event.ProcessEventSupport in project jbpm by kiegroup.
the class DynamicUtils method executeSubProcess.
private static long executeSubProcess(StatefulKnowledgeSessionImpl ksession, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) {
Process process = ksession.getKieBase().getProcess(processId);
if (process == null) {
logger.error("Could not find process {}", processId);
throw new IllegalArgumentException("No process definition found with id: " + processId);
} else {
ProcessEventSupport eventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, ksession);
ProcessInstance subProcessInstance = null;
if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) {
List<String> businessKeys = new ArrayList<String>();
businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey());
businessKeys.add(processId);
businessKeys.add(String.valueOf(System.currentTimeMillis()));
CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
CorrelationKey subProcessCorrelationKey = correlationKeyFactory.newCorrelationKey(businessKeys);
subProcessInstance = (ProcessInstance) ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, subProcessCorrelationKey, parameters);
} else {
subProcessInstance = (ProcessInstance) ksession.createProcessInstance(processId, parameters);
}
((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId());
((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId());
subProcessInstance = (ProcessInstance) ksession.startProcessInstance(subProcessInstance.getId());
subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId());
eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, ksession);
if (subProcessInstance.getState() == ProcessInstance.STATE_COMPLETED) {
subProcessNodeInstance.triggerCompleted();
} else {
subProcessNodeInstance.addEventListeners();
}
return subProcessInstance.getId();
}
}
use of org.drools.core.event.ProcessEventSupport in project jbpm by kiegroup.
the class StartCaseCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context context) {
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile);
logger.debug("Inserting case file into working memory");
List<Command<?>> commands = new ArrayList<>();
commands.add(commandsFactory.newInsert(caseFile));
commands.add(commandsFactory.newFireAllRules());
BatchExecutionCommand batch = commandsFactory.newBatchExecution(commands);
processService.execute(deploymentId, CaseContext.get(caseId), batch);
logger.debug("Starting process instance for case {} and case definition {}", caseId, caseDefinitionId);
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Map<String, Object> params = new HashMap<>();
// set case id to allow it to use CaseContext when creating runtime engine
params.put(EnvironmentName.CASE_ID, caseId);
final long processInstanceId = processService.startProcess(deploymentId, caseDefinitionId, correlationKey, params);
logger.debug("Case {} successfully started (process instance id {})", caseId, processInstanceId);
final Map<String, Object> caseData = caseFile.getData();
if (caseData != null && !caseData.isEmpty()) {
processService.execute(deploymentId, CaseContext.get(caseId), new ExecutableCommand<Void>() {
private static final long serialVersionUID = -7093369406457484236L;
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance pi = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
if (pi != null) {
ProcessEventSupport processEventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport();
for (Entry<String, Object> entry : caseData.entrySet()) {
String name = "caseFile_" + entry.getKey();
processEventSupport.fireAfterVariableChanged(name, name, null, entry.getValue(), pi, (KieRuntime) ksession);
}
}
return null;
}
});
}
caseEventSupport.fireAfterCaseStarted(caseId, deploymentId, caseDefinitionId, caseFile, processInstanceId);
return null;
}
Aggregations