Search in sources :

Example 1 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class StartNodeInstanceTest method testStartNode.

@Test
public void testStartNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), mockNodeFactory);
    RuleFlowProcess process = new RuleFlowProcess();
    StartNode startNode = new StartNode();
    startNode.setId(1);
    startNode.setName("start node");
    mockNode.setId(2);
    new ConnectionImpl(startNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(startNode);
    process.addNode(mockNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    processInstance.start();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
    List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    assertNotNull(triggeredBy);
    assertEquals(1, triggeredBy.size());
    assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class CancelNodeInstanceCommand method execute.

public Void execute(Context context) {
    logger.debug("About to cancel node instance with id {} on process instance {}", nodeInstanceId, processInstanceId);
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
    }
    NodeInstance nodeInstance = wfp.getNodeInstances(true).stream().filter(ni -> ni.getId() == nodeInstanceId).findFirst().orElse(null);
    if (nodeInstance == null) {
        throw new NodeInstanceNotFoundException("Node instance with id " + nodeInstanceId + " not found");
    }
    logger.debug("Found node instance {} to be canceled", nodeInstance);
    ((NodeInstanceImpl) nodeInstance).cancel();
    logger.debug("Node instance {} canceled successfully", nodeInstance);
    return null;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) NodeInstanceNotFoundException(org.jbpm.services.api.NodeInstanceNotFoundException) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 3 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class ListNodesCommand method execute.

public List<ProcessNode> execute(Context context) {
    List<ProcessNode> nodes = null;
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, true);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("No process instance can be found for id " + processInstanceId);
    }
    String processId = wfp.getProcessId();
    nodes = wfp.getRuleFlowProcess().getNodesRecursively().stream().map(n -> new ProcessNodeImpl(n.getName(), n.getId(), n.getClass().getSimpleName(), processId)).collect(Collectors.toList());
    return nodes;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessNodeImpl(org.jbpm.kie.services.impl.admin.ProcessNodeImpl) ProcessNode(org.jbpm.services.api.admin.ProcessNode) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 4 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class GetProcessInstancesTest method createProcessInstanceAndGetStartDate.

@Test
public void createProcessInstanceAndGetStartDate() throws Exception {
    StatefulKnowledgeSession ksession = reloadKnowledgeSession();
    long processId = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId();
    assertEquals(0, ksession.getProcessInstances().size());
    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) ksession.getProcessInstance(processId);
    assertNotNull("Process " + processId + " exist!", processInstance);
    assertNotNull("Process start at " + processInstance.getStartDate(), processInstance.getStartDate());
    ksession.dispose();
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceSubProcess.

@Test
public void testPersistenceSubProcess() {
    setUp();
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    InternalKnowledgeBase ruleBase = KnowledgeBaseFactory.newKnowledgeBase();
    KiePackage pkg = getProcessSubProcess();
    ruleBase.addPackages((Collection) Arrays.asList(pkg));
    PersistableRunner service = new PersistableRunner(ruleBase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    long processInstanceId = processInstance.getId();
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    SubProcessNodeInstance subProcessNodeInstance = (SubProcessNodeInstance) nodeInstances.iterator().next();
    long subProcessInstanceId = subProcessNodeInstance.getProcessInstanceId();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(subProcessInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(subProcessInstance);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
    service.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) SessionConfiguration(org.drools.core.SessionConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)23 KieSession (org.kie.api.runtime.KieSession)14 Test (org.junit.Test)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 RegistryContext (org.drools.core.command.impl.RegistryContext)6 KieBase (org.kie.api.KieBase)6 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)5 StringReader (java.io.StringReader)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 WorkflowProcessImpl (org.jbpm.workflow.core.impl.WorkflowProcessImpl)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)3 ReturnValueConstraintEvaluator (org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator)3 TimerManager (org.jbpm.process.instance.timer.TimerManager)3 ArrayList (java.util.ArrayList)2 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)2