use of org.kie.kogito.internal.process.event.KogitoProcessEventSupport in project kogito-runtimes by kiegroup.
the class DynamicUtils method executeWorkItem.
private static void executeWorkItem(StatefulKnowledgeSessionImpl ksession, KogitoWorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
KogitoProcessRuntime kruntime = asKogitoProcessRuntime(ksession);
KogitoProcessEventSupport eventSupport = kruntime.getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, ksession);
((InternalKogitoWorkItemManager) kruntime.getKogitoWorkItemManager()).internalExecuteWorkItem(workItem);
workItemNodeInstance.internalSetWorkItemId(workItem.getStringId());
eventSupport.fireAfterNodeTriggered(workItemNodeInstance, ksession);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventSupport in project kogito-runtimes by kiegroup.
the class DynamicUtils method executeSubProcess.
private static String 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 {
KogitoProcessEventSupport eventSupport = ((InternalProcessRuntime) ksession.getProcessRuntime()).getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, ksession);
ProcessInstance subProcessInstance = null;
if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) {
List<String> businessKeys = new ArrayList<>();
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) ksession.createProcessInstance(processId, subProcessCorrelationKey, parameters);
} else {
subProcessInstance = (ProcessInstance) ksession.createProcessInstance(processId, parameters);
}
subProcessInstance.setMetaData("ParentProcessInstanceId", processInstance.getStringId());
subProcessInstance.setParentProcessInstanceId(processInstance.getStringId());
RuleUnitStatefulKnowledgeSessionImpl kogitoSession = (RuleUnitStatefulKnowledgeSessionImpl) ksession;
String subProcessInstanceId = subProcessInstance.getStringId();
subProcessInstance = (ProcessInstance) asKogitoProcessRuntime(kogitoSession).startProcessInstance(subProcessInstanceId);
subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstanceId);
eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, ksession);
if (subProcessInstance.getState() == KogitoProcessInstance.STATE_COMPLETED) {
subProcessNodeInstance.triggerCompleted();
} else {
subProcessNodeInstance.addEventListeners();
}
return subProcessInstanceId;
}
}
Aggregations