Search in sources :

Example 56 with UserTaskInstanceDesc

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

the class ESimultaneousProcessInstancesTest method testSimultaneousProcesses.

@Test()
public void testSimultaneousProcesses() {
    ProcessInstance pi1 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
    ProcessInstance pi2 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
    ProcessInstance pi3 = ejb.startAndGetProcess(ProcessDefinitions.HUMAN_TASK);
    // check that all the process instances are running
    Assertions.assertThat(pi1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Assertions.assertThat(pi2.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // start and complete the task for p2
    long taskId = ejb.getTasksByProcessInstanceId(pi2.getId()).get(0);
    Map<String, Object> params = new HashMap<>();
    params.put("userId", userId);
    ejb.start(taskId, userId);
    ejb.complete(taskId, userId, params);
    // check that p2 is completed
    ProcessInstanceDesc instanceDesc = ejb.getProcessInstanceById(pi2.getId());
    Assertions.assertThat(instanceDesc).isNotNull();
    Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    // other processes shouldn't be affected
    pi1 = ejb.getProcessInstance(pi1.getId());
    Assertions.assertThat(pi1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    pi3 = ejb.getProcessInstance(pi3.getId());
    Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // abort p1 to test that the tasks will be removed
    ejb.abortProcessInstance(pi1.getId());
    instanceDesc = ejb.getProcessInstanceById(pi1.getId());
    Assertions.assertThat(instanceDesc).isNotNull();
    Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_ABORTED);
    // p1 was aborted so there shouldn't be any tasks to do
    List<Long> taskIds = ejb.getTasksByProcessInstanceId(pi1.getId());
    Assertions.assertThat(taskIds).hasSize(1);
    UserTaskInstanceDesc taskDesc = ejb.getTaskById(taskIds.get(0));
    Assertions.assertThat(taskDesc.getStatus()).isEqualTo(Status.Exited.name());
    // p3 still shouldn't be affected by any of the previous operations
    pi3 = ejb.getProcessInstance(pi3.getId());
    Assertions.assertThat(pi3.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // start and complete the task for p3
    taskId = ejb.getTasksByProcessInstanceId(pi3.getId()).get(0);
    params = new HashMap<>();
    params.put("userId", userId);
    ejb.start(taskId, userId);
    ejb.complete(taskId, userId, params);
    // check that p3 is completed
    instanceDesc = ejb.getProcessInstanceById(pi3.getId());
    Assertions.assertThat(instanceDesc).isNotNull();
    Assertions.assertThat(instanceDesc.getState().intValue()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    taskIds = ejb.getTasksByProcessInstanceId(pi3.getId());
    Assertions.assertThat(taskIds).hasSize(1);
    taskDesc = ejb.getTaskById(taskIds.get(0));
    Assertions.assertThat(taskDesc.getStatus()).isEqualTo(Status.Completed.name());
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) RemoteEjbTest(org.jbpm.remote.ejb.test.RemoteEjbTest) Test(org.junit.Test)

Example 57 with UserTaskInstanceDesc

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

the class EGetTaskTest method testGetTaskInstanceInfo.

@Test
public void testGetTaskInstanceInfo() {
    Long pid = ejb.startProcess(ProcessDefinitions.HUMAN_TASK);
    long taskId = ejb.getTasksByProcessInstanceId(pid).get(0);
    UserTaskInstanceDesc task = ejb.getTaskById(taskId);
    System.out.println(task.getActualOwner() + "," + task.getTaskId() + "," + task.getStatus());
    Assertions.assertThat(userId).isEqualTo(task.getActualOwner());
    Assertions.assertThat(Status.Reserved.name()).isEqualTo(task.getStatus());
}
Also used : UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) RemoteEjbTest(org.jbpm.remote.ejb.test.RemoteEjbTest) Test(org.junit.Test)

Example 58 with UserTaskInstanceDesc

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

the class QueryServiceImplTest method testGetTaskInstances.

@Test
public void testGetTaskInstances() {
    query = new SqlQueryDefinition("getAllTaskInstances", dataSourceJNDIname);
    query.setExpression("select ti.* from AuditTaskImpl ti ");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 59 with UserTaskInstanceDesc

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

the class QueryServiceImplTest method testGetFilteredTaskInstancesAsPotOwners.

@Test
public void testGetFilteredTaskInstancesAsPotOwners() {
    // let's grant managers role so process can be started
    List<String> roles = new ArrayList<String>();
    roles.add("managers");
    identityProvider.setRoles(roles);
    query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.FILTERED_PO_TASK);
    query.setExpression(PO_TASK_QUERY);
    queryService.registerQuery(query);
    List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
    assertNotNull(queries);
    assertEquals(1, queries.size());
    QueryDefinition registeredQuery = queryService.getQuery(query.getName());
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    identityProvider.setName("salaboy");
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
    assertNotNull(taskSummaries);
    assertEquals(1, taskSummaries.size());
    // let's now change the roles so user should not see instances
    roles.clear();
    roles.add("employees");
    identityProvider.setRoles(roles);
    identityProvider.setName("anotherUser");
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
    assertNotNull(taskSummaries);
    assertEquals(0, taskSummaries.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) TaskSummary(org.kie.api.task.model.TaskSummary) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 60 with UserTaskInstanceDesc

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

the class QueryServiceImplTest method testGetTaskInstancesAsExcludedOwner.

@Test
public void testGetTaskInstancesAsExcludedOwner() {
    final String potentialOwner = "maciej";
    final String excludedOwner = "kris";
    final List<String> roles = Arrays.asList("admins");
    query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK);
    query.setExpression(PO_TASK_QUERY);
    queryService.registerQuery(query);
    List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
    assertNotNull(queries);
    assertEquals(1, queries.size());
    QueryDefinition registeredQuery = queries.get(0);
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    registeredQuery = queryService.getQuery(query.getName());
    assertNotNull(registeredQuery);
    assertEquals(query.getName(), registeredQuery.getName());
    assertEquals(query.getSource(), registeredQuery.getSource());
    assertEquals(query.getExpression(), registeredQuery.getExpression());
    assertEquals(query.getTarget(), registeredQuery.getTarget());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>());
    assertNotNull(processInstanceId);
    identityProvider.setName(potentialOwner);
    identityProvider.setRoles(roles);
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    identityProvider.setName(excludedOwner);
    identityProvider.setRoles(roles);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)118 Test (org.junit.Test)67 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)36 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)35 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)35 InternalTaskService (org.kie.internal.task.api.InternalTaskService)35 UserTaskService (org.jbpm.services.api.UserTaskService)34 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)34 TaskService (org.kie.api.task.TaskService)34 HashMap (java.util.HashMap)23 QueryContext (org.kie.api.runtime.query.QueryContext)22 ArrayList (java.util.ArrayList)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)16 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)16 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)15 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)11 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)6