Search in sources :

Example 46 with WorkflowProcessInstanceImpl

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

the class RuntimeDataServiceEJBIntegrationTest method testGetTaskByWorkItemId.

@Test
public void testGetTaskByWorkItemId() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance instance = processService.getProcessInstance(processInstanceId);
    assertNotNull(instance);
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstance node = activeNodes.iterator().next();
    assertNotNull(node);
    assertTrue(node instanceof WorkItemNodeInstance);
    Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
    assertNotNull(workItemId);
    UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
    assertNotNull(userTask);
    assertEquals(processInstanceId, userTask.getProcessInstanceId());
    assertEquals("Write a Document", userTask.getName());
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) Test(org.junit.Test)

Example 47 with WorkflowProcessInstanceImpl

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

the class RuntimeDataServiceEJBIntegrationTest method testGetTaskAudit.

@Test
public void testGetTaskAudit() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance instance = processService.getProcessInstance(processInstanceId);
    assertNotNull(instance);
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstance node = activeNodes.iterator().next();
    assertNotNull(node);
    assertTrue(node instanceof WorkItemNodeInstance);
    Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
    assertNotNull(workItemId);
    List<AuditTask> auditTasks = runtimeDataService.getAllAuditTask("salaboy", new QueryFilter(0, 10));
    assertNotNull(auditTasks);
    assertEquals(1, auditTasks.size());
    assertEquals("Write a Document", auditTasks.get(0).getName());
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) AuditTask(org.kie.internal.task.api.AuditTask) Test(org.junit.Test)

Example 48 with WorkflowProcessInstanceImpl

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

the class RuntimeDataServiceEJBIntegrationTest method testGetTaskEvents.

@Test
public void testGetTaskEvents() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance instance = processService.getProcessInstance(processInstanceId);
    assertNotNull(instance);
    Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstance node = activeNodes.iterator().next();
    assertNotNull(node);
    assertTrue(node instanceof WorkItemNodeInstance);
    Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
    assertNotNull(workItemId);
    UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
    assertNotNull(userTask);
    List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(1, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    userTaskService.start(userTask.getTaskId(), "salaboy");
    auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
    assertNotNull(auditTasks);
    assertEquals(2, auditTasks.size());
    assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
    assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) TaskEvent(org.kie.internal.task.api.model.TaskEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) Test(org.junit.Test)

Example 49 with WorkflowProcessInstanceImpl

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

the class MigrationManager method cancelActiveTimersBeforeMigration.

protected Map<Long, List<TimerInstance>> cancelActiveTimersBeforeMigration(RuntimeManager manager) {
    RuntimeEngine engineBefore = manager.getRuntimeEngine(ProcessInstanceIdContext.get(migrationSpec.getProcessInstanceId()));
    try {
        Map<Long, List<TimerInstance>> timerMigrated = engineBefore.getKieSession().execute(new ExecutableCommand<Map<Long, List<TimerInstance>>>() {

            private static final long serialVersionUID = 7144271692067781976L;

            @Override
            public Map<Long, List<TimerInstance>> execute(Context context) {
                Map<Long, List<TimerInstance>> result = new LinkedHashMap<>();
                KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
                TimerManager timerManager = getTimerManager(kieSession);
                WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId());
                Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true);
                for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) {
                    if (active instanceof TimerNodeInstance) {
                        TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId());
                        timerManager.cancelTimer(timerInstance.getId());
                        result.put(active.getId(), Arrays.asList(timerInstance));
                    } else if (active instanceof StateBasedNodeInstance) {
                        List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances();
                        if (timers != null && !timers.isEmpty()) {
                            List<TimerInstance> collected = new ArrayList<>();
                            for (Long timerId : timers) {
                                TimerInstance timerInstance = timerManager.getTimerMap().get(timerId);
                                timerManager.cancelTimer(timerInstance.getId());
                                collected.add(timerInstance);
                            }
                            result.put(active.getId(), collected);
                        }
                    }
                }
                return result;
            }
        });
        return timerMigrated;
    } finally {
        manager.disposeRuntimeEngine(engineBefore);
    }
}
Also used : TimerInstance(org.jbpm.process.instance.timer.TimerInstance) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) ProcessInstanceIdContext(org.kie.internal.runtime.manager.context.ProcessInstanceIdContext) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) TimerManager(org.jbpm.process.instance.timer.TimerManager) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) StateBasedNodeInstance(org.jbpm.workflow.instance.node.StateBasedNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance)

Example 50 with WorkflowProcessInstanceImpl

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

the class MigrationManager method upgradeProcessInstance.

private void upgradeProcessInstance(KieRuntime oldkruntime, KieRuntime kruntime, long processInstanceId, String processId, Map<String, String> nodeMapping, EntityManager em, String deploymentId) {
    if (nodeMapping == null) {
        nodeMapping = new HashMap<String, String>();
    }
    WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) oldkruntime.getProcessInstance(processInstanceId);
    if (processInstance == null) {
        report.addEntry(Type.ERROR, "Could not find process instance " + processInstanceId);
    }
    if (processId == null) {
        report.addEntry(Type.ERROR, "Null process id");
    }
    WorkflowProcess process = (WorkflowProcess) kruntime.getKieBase().getProcess(processId);
    if (process == null) {
        report.addEntry(Type.ERROR, "Could not find process " + processId);
    }
    if (processInstance.getProcessId().equals(processId)) {
        report.addEntry(Type.WARN, "Source and target process id is exactly the same (" + processId + ") it's recommended to use unique process ids");
    }
    synchronized (processInstance) {
        org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
        processInstance.disconnect();
        processInstance.setProcess(oldProcess);
        updateNodeInstances(processInstance, nodeMapping, (NodeContainer) process, em);
        processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) extractIfNeeded(kruntime));
        processInstance.setDeploymentId(deploymentId);
        processInstance.setProcess(process);
        processInstance.reconnect();
    }
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

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