Search in sources :

Example 41 with WorkflowProcessInstanceImpl

use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.

the class JbpmJUnitBaseTestCase method assertNumOfIncommingConnections.

public void assertNumOfIncommingConnections(ProcessInstance process, String nodeName, int num) {
    assertNodeExists(process, nodeName);
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
    for (Node node : instance.getNodeContainer().getNodes()) {
        if (node.getName().equals(nodeName)) {
            if (node.getIncomingConnections().size() != num) {
                fail("Expected incomming connections: " + num + " - found " + node.getIncomingConnections().size());
            } else {
                break;
            }
        }
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)

Example 42 with WorkflowProcessInstanceImpl

use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.

the class JbpmJUnitBaseTestCase method assertNodeExists.

public void assertNodeExists(ProcessInstance process, String... nodeNames) {
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
    List<String> names = new ArrayList<String>();
    for (String nodeName : nodeNames) {
        names.add(nodeName);
    }
    for (Node node : instance.getNodeContainer().getNodes()) {
        if (names.contains(node.getName())) {
            names.remove(node.getName());
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) do not exist: " + s);
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Example 43 with WorkflowProcessInstanceImpl

use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.

the class JbpmJUnitBaseTestCase method assertProcessVarExists.

public void assertProcessVarExists(ProcessInstance process, String... processVarNames) {
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
    List<String> names = new ArrayList<String>();
    for (String nodeName : processVarNames) {
        names.add(nodeName);
    }
    for (String pvar : instance.getVariables().keySet()) {
        if (names.contains(pvar)) {
            names.remove(pvar);
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Process Variable(s) do not exist: " + s);
    }
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Example 44 with WorkflowProcessInstanceImpl

use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.

the class JbpmJUnitTestCase method assertNodeExists.

public void assertNodeExists(ProcessInstance process, String... nodeNames) {
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
    List<String> names = new ArrayList<String>();
    for (String nodeName : nodeNames) {
        names.add(nodeName);
    }
    for (Node node : instance.getNodeContainer().getNodes()) {
        if (names.contains(node.getName())) {
            names.remove(node.getName());
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) do not exist: " + s);
    }
}
Also used : Node(org.kie.api.definition.process.Node) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList)

Example 45 with WorkflowProcessInstanceImpl

use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.

the class JPAProcessInstanceManager method getProcessInstance.

public ProcessInstance getProcessInstance(long id, boolean readOnly) {
    InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
    if (manager != null) {
        manager.validate((KieSession) kruntime, ProcessInstanceIdContext.get(id));
    }
    TransactionManager txm = (TransactionManager) this.kruntime.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER);
    org.jbpm.process.instance.ProcessInstance processInstance = null;
    processInstance = (org.jbpm.process.instance.ProcessInstance) this.processInstances.get(id);
    if (processInstance != null) {
        if (((WorkflowProcessInstanceImpl) processInstance).isPersisted() && !readOnly) {
            ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ppcm.beginCommandScopedEntityManager();
            ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
            ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
            if (processInstanceInfo == null) {
                return null;
            }
            TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
            processInstanceInfo.updateLastReadDate();
            EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
        }
        return processInstance;
    }
    // Make sure that the cmd scoped entity manager has started
    ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
    ppcm.beginCommandScopedEntityManager();
    ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
    ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
    if (processInstanceInfo == null) {
        return null;
    }
    processInstance = (org.jbpm.process.instance.ProcessInstance) processInstanceInfo.getProcessInstance(kruntime, this.kruntime.getEnvironment(), readOnly);
    if (!readOnly) {
        processInstanceInfo.updateLastReadDate();
        TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
        EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
    }
    if (((ProcessInstanceImpl) processInstance).getProcessXml() == null) {
        Process process = kruntime.getKieBase().getProcess(processInstance.getProcessId());
        if (process == null) {
            throw new IllegalArgumentException("Could not find process " + processInstance.getProcessId());
        }
        processInstance.setProcess(process);
    }
    if (processInstance.getKnowledgeRuntime() == null) {
        Long parentProcessInstanceId = (Long) ((ProcessInstanceImpl) processInstance).getMetaData().get("ParentProcessInstanceId");
        if (parentProcessInstanceId != null) {
            kruntime.getProcessInstance(parentProcessInstanceId);
        }
        processInstance.setKnowledgeRuntime(kruntime);
        ((ProcessInstanceImpl) processInstance).reconnect();
        if (readOnly) {
            internalRemoveProcessInstance(processInstance);
        }
    }
    return processInstance;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Process(org.kie.api.definition.process.Process) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView) TransactionManager(org.drools.persistence.api.TransactionManager) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager)

Aggregations

WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)53 NodeInstance (org.kie.api.runtime.process.NodeInstance)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)11 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)11 Test (org.junit.Test)10 Node (org.kie.api.definition.process.Node)10 KieSession (org.kie.api.runtime.KieSession)9 Map (java.util.Map)7 RegistryContext (org.drools.core.command.impl.RegistryContext)6 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)6 Process (org.kie.api.definition.process.Process)6 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)5 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)5 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)5 Person (com.salaboy.model.Person)4 KnowledgeBase (org.drools.KnowledgeBase)4 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)4 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)4