Search in sources :

Example 1 with ProcessNode

use of org.jbpm.services.api.admin.ProcessNode in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImpl method getProcessNodes.

@Override
public Collection<ProcessNode> getProcessNodes(long processInstanceId) throws ProcessInstanceNotFoundException {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    if (pi == null) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
    }
    Collection<ProcessNode> nodes = processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(processInstanceId), new ListNodesCommand(processInstanceId));
    return nodes;
}
Also used : ListNodesCommand(org.jbpm.kie.services.impl.admin.commands.ListNodesCommand) ProcessNode(org.jbpm.services.api.admin.ProcessNode) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 2 with ProcessNode

use of org.jbpm.services.api.admin.ProcessNode 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 3 with ProcessNode

use of org.jbpm.services.api.admin.ProcessNode in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testTrigerLastActionNode.

@Test
public void testTrigerLastActionNode() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("Write a Document", active.getName());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(1, tasks.size());
    Collection<ProcessNode> processNodes = processAdminService.getProcessNodes(processInstanceId);
    ProcessNode writeDocNode = processNodes.stream().filter(pn -> pn.getNodeName().equals("Report")).findFirst().orElse(null);
    processAdminService.triggerNode(processInstanceId, writeDocNode.getNodeId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(0, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(0, tasks.size());
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessNode(org.jbpm.services.api.admin.ProcessNode) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 4 with ProcessNode

use of org.jbpm.services.api.admin.ProcessNode in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testCancelAndTriger.

@Test
public void testCancelAndTriger() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("Write a Document", active.getName());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(1, tasks.size());
    processAdminService.cancelNodeInstance(processInstanceId, active.getId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(0, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(0, tasks.size());
    Collection<ProcessNode> processNodes = processAdminService.getProcessNodes(processInstanceId);
    ProcessNode writeDocNode = processNodes.stream().filter(pn -> pn.getNodeName().equals(active.getName())).findFirst().orElse(null);
    processAdminService.triggerNode(processInstanceId, writeDocNode.getNodeId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(1, tasks.size());
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessNode(org.jbpm.services.api.admin.ProcessNode) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 5 with ProcessNode

use of org.jbpm.services.api.admin.ProcessNode in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testCancelAndTrigerAnotherNode.

@Test
public void testCancelAndTrigerAnotherNode() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("Write a Document", active.getName());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(1, tasks.size());
    processAdminService.cancelNodeInstance(processInstanceId, active.getId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(0, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(0, tasks.size());
    Collection<ProcessNode> processNodes = processAdminService.getProcessNodes(processInstanceId);
    ProcessNode writeDocNode = processNodes.stream().filter(pn -> pn.getNodeName().equals("Report")).findFirst().orElse(null);
    processAdminService.triggerNode(processInstanceId, writeDocNode.getNodeId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(0, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(0, tasks.size());
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessNode(org.jbpm.services.api.admin.ProcessNode) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

ProcessNode (org.jbpm.services.api.admin.ProcessNode)5 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)3 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)3 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)3 Test (org.junit.Test)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 QueryFilter (org.kie.internal.query.QueryFilter)3 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 RegistryContext (org.drools.core.command.impl.RegistryContext)1 ProcessNodeImpl (org.jbpm.kie.services.impl.admin.ProcessNodeImpl)1 ListNodesCommand (org.jbpm.kie.services.impl.admin.commands.ListNodesCommand)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 KieSession (org.kie.api.runtime.KieSession)1