Search in sources :

Example 41 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class RuntimeDataServiceTest method testGetProcessInstanceHistory.

@Test
public void testGetProcessInstanceHistory() throws IOException {
    // BZ1048741
    assertNotNull(managerFactory);
    String id = "custom-manager";
    AbstractAuditLogger auditLogger = AuditLoggerFactory.newJPAInstance();
    ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder();
    auditEventBuilder.setIdentityProvider(new TestIdentifyProviderCDI());
    auditEventBuilder.setDeploymentUnitId(id);
    auditLogger.setBuilder(auditEventBuilder);
    RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).registerableItemsFactory(InjectableRegisterableItemsFactory.getFactory(beanManager, auditLogger));
    builder.addAsset(ResourceFactory.newClassPathResource("repo/processes/general/hello.bpmn"), ResourceType.BPMN2);
    RuntimeManager manager = managerFactory.newSingletonRuntimeManager(builder.get(), id);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("hello");
    Collection<NodeInstanceDesc> nodeInstanceLogs = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
    // assert if logs are ordered by log.id ASC
    Iterator<NodeInstanceDesc> iterator = nodeInstanceLogs.iterator();
    NodeInstanceDesc log0 = iterator.next();
    assertEquals("End", log0.getName());
    NodeInstanceDesc log1 = iterator.next();
    assertEquals("Hello", log1.getName());
    NodeInstanceDesc log2 = iterator.next();
    assertEquals("Start", log2.getName());
    Collection<NodeInstanceDesc> fullNodeInstanceLogs = runtimeDataService.getProcessInstanceFullHistory(processInstance.getId(), new QueryContext());
    // assert if logs are ordered by log.date DESC, log.id DESC
    Iterator<NodeInstanceDesc> fullIterator = fullNodeInstanceLogs.iterator();
    NodeInstanceDesc fullLog0 = fullIterator.next();
    assertEquals("Start", fullLog0.getName());
    assertEquals(true, fullLog0.isCompleted());
    NodeInstanceDesc fullLog1 = fullIterator.next();
    assertEquals("Hello", fullLog1.getName());
    assertEquals(true, fullLog1.isCompleted());
    NodeInstanceDesc fullLog2 = fullIterator.next();
    assertEquals("End", fullLog2.getName());
    assertEquals(true, fullLog2.isCompleted());
    NodeInstanceDesc fullLog3 = fullIterator.next();
    assertEquals("End", fullLog3.getName());
    assertEquals(false, fullLog3.isCompleted());
    NodeInstanceDesc fullLog4 = fullIterator.next();
    assertEquals("Hello", fullLog4.getName());
    assertEquals(false, fullLog4.isCompleted());
    NodeInstanceDesc fullLog5 = fullIterator.next();
    assertEquals("Start", fullLog5.getName());
    assertEquals(false, fullLog5.isCompleted());
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) QueryContext(org.kie.api.runtime.query.QueryContext) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) ServicesAwareAuditEventBuilder(org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 42 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ProcessServiceImpl method abortWorkItem.

@Override
public void abortWorkItem(Long id) {
    NodeInstanceDesc nodeDesc = dataService.getNodeInstanceForWorkItem(id);
    if (nodeDesc == null) {
        throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
    }
    abortWorkItem(nodeDesc.getDeploymentId(), nodeDesc.getProcessInstanceId(), id);
}
Also used : WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc)

Example 43 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ProcessServiceImpl method getWorkItemByProcessInstance.

@Override
public List<WorkItem> getWorkItemByProcessInstance(String deploymentId, Long processInstanceId) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        List<WorkItem> workItems = new ArrayList<>();
        Collection<NodeInstanceDesc> nodes = dataService.getProcessInstanceHistoryActive(processInstanceId, null);
        for (NodeInstanceDesc node : nodes) {
            if (node.getWorkItemId() != null) {
                workItems.add(((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(node.getWorkItemId()));
            }
        }
        return workItems;
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 44 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ProcessServiceEJBIntegrationTest method testStartProcessAndCompleteWorkItemAfterDeactivation.

@Test
public void testStartProcessAndCompleteWorkItemAfterDeactivation() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    deploymentService.deactivate(deploymentUnit.getIdentifier());
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    Map<String, Object> outcome = new HashMap<String, Object>();
    outcome.put("Result", "here is my first document");
    processService.completeWorkItem(activeNodes.iterator().next().getWorkItemId(), outcome);
    activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(2, activeNodes.size());
    Object variableValue = processService.getProcessInstanceVariable(processInstanceId, "approval_document");
    assertNotNull(variableValue);
    assertTrue(variableValue instanceof String);
    assertEquals("here is my first document", variableValue);
    processService.abortProcessInstance(processInstanceId);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) Test(org.junit.Test)

Example 45 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.

the class ProcessServiceEJBIntegrationTest method testStartProcessAndGetWorkItem.

@Test
public void testStartProcessAndGetWorkItem() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    WorkItem wi = processService.getWorkItem(activeNodes.iterator().next().getWorkItemId());
    assertNotNull(wi);
    assertEquals("Human Task", wi.getName());
    assertEquals("Write a Document", wi.getParameter("NodeName"));
    processService.abortProcessInstance(processInstanceId);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Aggregations

NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)45 Test (org.junit.Test)40 QueryContext (org.kie.api.runtime.query.QueryContext)29 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)20 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)15 HashMap (java.util.HashMap)14 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)12 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)9 TaskSummary (org.kie.api.task.model.TaskSummary)9 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 WorkItem (org.kie.api.runtime.process.WorkItem)8 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)6 QueryFilter (org.kie.internal.query.QueryFilter)6 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)4 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)4 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)4 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)4 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)4