Search in sources :

Example 1 with KogitoProcessEventSupport

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);
}
Also used : KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) InternalProcessRuntime.asKogitoProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime.asKogitoProcessRuntime) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)

Example 2 with KogitoProcessEventSupport

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;
    }
}
Also used : KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) RuleUnitStatefulKnowledgeSessionImpl(org.drools.ruleunits.impl.sessions.RuleUnitStatefulKnowledgeSessionImpl) CorrelationKey(org.kie.internal.process.CorrelationKey) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ArrayList(java.util.ArrayList) Process(org.kie.api.definition.process.Process) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Aggregations

KogitoProcessEventSupport (org.kie.kogito.internal.process.event.KogitoProcessEventSupport)2 ArrayList (java.util.ArrayList)1 RuleUnitStatefulKnowledgeSessionImpl (org.drools.ruleunits.impl.sessions.RuleUnitStatefulKnowledgeSessionImpl)1 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)1 InternalProcessRuntime.asKogitoProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime.asKogitoProcessRuntime)1 ProcessInstance (org.jbpm.process.instance.ProcessInstance)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 Process (org.kie.api.definition.process.Process)1 CorrelationKey (org.kie.internal.process.CorrelationKey)1 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)1 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)1 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)1 InternalKogitoWorkItemManager (org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)1