Search in sources :

Example 1 with ProcessEventSupport

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());
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Example 2 with ProcessEventSupport

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);
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Example 3 with ProcessEventSupport

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();
    }
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) CorrelationKey(org.kie.internal.process.CorrelationKey) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ArrayList(java.util.ArrayList) Process(org.kie.api.definition.process.Process) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Example 4 with ProcessEventSupport

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;
}
Also used : CaseContext(org.kie.internal.runtime.manager.context.CaseContext) RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) HashMap(java.util.HashMap) KieRuntime(org.kie.api.runtime.KieRuntime) ArrayList(java.util.ArrayList) ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) Entry(java.util.Map.Entry) ExecutableCommand(org.drools.core.command.impl.ExecutableCommand) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) CorrelationKey(org.kie.internal.process.CorrelationKey) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Aggregations

ProcessEventSupport (org.drools.core.event.ProcessEventSupport)4 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)3 ArrayList (java.util.ArrayList)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 CorrelationKey (org.kie.internal.process.CorrelationKey)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 WorkItemManager (org.drools.core.process.instance.WorkItemManager)1 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 Command (org.kie.api.command.Command)1 Process (org.kie.api.definition.process.Process)1 Context (org.kie.api.runtime.Context)1 KieRuntime (org.kie.api.runtime.KieRuntime)1