Search in sources :

Example 11 with InternalKnowledgeRuntime

use of org.drools.core.common.InternalKnowledgeRuntime 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)

Example 12 with InternalKnowledgeRuntime

use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.

the class TimerNodeInstance method internalTrigger.

public void internalTrigger(NodeInstance from, String type) {
    if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
    }
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    timerInstance = createTimerInstance(kruntime);
    if (getTimerInstances() == null) {
        addTimerListener();
    }
    ((InternalProcessRuntime) kruntime.getProcessRuntime()).getTimerManager().registerTimer(timerInstance, (ProcessInstance) getProcessInstance());
    timerId = timerInstance.getId();
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime)

Example 13 with InternalKnowledgeRuntime

use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.

the class EndNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
    }
    boolean hidden = false;
    if (getNode().getMetaData().get("hidden") != null) {
        hidden = true;
    }
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
    }
    ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
    if (getEndNode().isTerminate()) {
        if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
            if (getEndNode().getScope() == EndNode.PROCESS_SCOPE) {
                getProcessInstance().setState(ProcessInstance.STATE_COMPLETED);
            } else {
                while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
                    ((org.jbpm.workflow.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
                }
                ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
            }
        } else {
            ((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_COMPLETED);
        }
    } else {
        ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
    }
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 14 with InternalKnowledgeRuntime

use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.

the class NodeInstanceImpl method cancel.

public void cancel() {
    nodeInstanceContainer.removeNodeInstance(this);
    boolean hidden = false;
    Node node = getNode();
    if (node != null && node.getMetaData().get("hidden") != null) {
        hidden = true;
    }
    if (!hidden) {
        InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) Node(org.kie.api.definition.process.Node)

Example 15 with InternalKnowledgeRuntime

use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.

the class NodeInstanceImpl method trigger.

public final void trigger(NodeInstance from, String type) {
    boolean hidden = false;
    if (getNode().getMetaData().get("hidden") != null) {
        hidden = true;
    }
    if (from != null) {
        int level = ((org.jbpm.workflow.instance.NodeInstance) from).getLevel();
        ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(level);
        Collection<Connection> incoming = getNode().getIncomingConnections(type);
        for (Connection conn : incoming) {
            if (conn.getFrom().getId() == from.getNodeId()) {
                this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId"));
                break;
            }
        }
    }
    configureSla();
    InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeTriggered(this, kruntime);
    }
    try {
        getExecutionErrorHandler().processing(this);
        internalTrigger(from, type);
    } catch (WorkflowRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new WorkflowRuntimeException(this, getProcessInstance(), e);
    }
    if (!hidden) {
        ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeTriggered(this, kruntime);
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) Connection(org.kie.api.definition.process.Connection) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) ActionNodeInstance(org.jbpm.workflow.instance.node.ActionNodeInstance) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException)

Aggregations

InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)18 ArrayList (java.util.ArrayList)4 Connection (org.kie.api.definition.process.Connection)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 HashMap (java.util.HashMap)3 CompositeNodeInstance (org.jbpm.workflow.instance.node.CompositeNodeInstance)3 Node (org.kie.api.definition.process.Node)3 Map (java.util.Map)2 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)2 RegistryContext (org.drools.core.command.impl.RegistryContext)2 MarshallingConfigurationImpl (org.drools.serialization.protobuf.marshalling.MarshallingConfigurationImpl)2 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 ConstraintEvaluator (org.jbpm.process.instance.impl.ConstraintEvaluator)2 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)2 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)2 ActionNodeInstance (org.jbpm.workflow.instance.node.ActionNodeInstance)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 KieRuntime (org.kie.api.runtime.KieRuntime)2