Search in sources :

Example 46 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskOnLaneTest method testProcess.

@Test
public void testProcess() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertProcessInstanceActive(processInstance.getId());
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let john execute Task 1
    String taskUser = "john";
    String locale = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
    assertEquals(1, list.size());
    TaskSummary task = list.get(0);
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart once again");
    List<Status> reservedOnly = new ArrayList<Status>();
    reservedOnly.add(Status.Reserved);
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedOnly, locale);
    assertEquals(1, list.size());
    task = list.get(0);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 47 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskOnLaneTest method testProcessWIthDifferentGroups.

@Test
public void testProcessWIthDifferentGroups() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLaneDifferentGroups.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertProcessInstanceActive(processInstance.getId());
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLaneDifferentGroups.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    // let manager execute Task 1
    String taskUser = "manager";
    String locale = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
    assertEquals(1, list.size());
    TaskSummary task = list.get(0);
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart once again");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    List<Status> reservedAndRegistered = new ArrayList<Status>();
    reservedAndRegistered.add(Status.Reserved);
    reservedAndRegistered.add(Status.Ready);
    // manager does not have access to the second task
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedAndRegistered, locale);
    assertEquals(0, list.size());
    // now try john
    taskUser = "john";
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedAndRegistered, locale);
    assertEquals(1, list.size());
    task = list.get(0);
    // task is in ready state so claim is required
    assertEquals(Status.Ready, task.getStatus());
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 48 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class HumanTaskSwimlaneTest method testSwimlaneWithMultipleActorsAssigned.

@Test
public void testSwimlaneWithMultipleActorsAssigned() {
    createRuntimeManager(SWIMLANE_MULTIPLE_ACTORS);
    String user = "john";
    RuntimeEngine runtime = getRuntimeEngine();
    KieSession kSession = runtime.getKieSession();
    TaskService taskservice = runtime.getTaskService();
    kSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("TASK")) {
                Object swimlaneActorId = ((HumanTaskNodeInstance) event.getNodeInstance()).getWorkItem().getParameter("SwimlaneActorId");
                assertNull(swimlaneActorId);
            }
        }
    });
    Map<String, Object> map = new HashMap<String, Object>();
    ProcessInstance instance = kSession.startProcess(SWIMLANE_MULTIPLE_ACTORS_ID, map);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Ready);
    statuses.add(Status.Reserved);
    statuses.add(Status.InProgress);
    List<TaskSummary> tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertEquals(Status.Ready, task.getStatus());
    taskservice.claim(task.getId(), user);
    taskservice.start(task.getId(), user);
    tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertEquals(Status.InProgress, task.getStatus());
    taskservice.complete(task.getId(), user, map);
    assertProcessInstanceCompleted(instance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 49 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class MVELLifeCycleManagerTest method testClaimIsAllowedExcludedOwner.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object is
 * not allowed to execute operations on the given task. We expect to get a {@link PermissionDeniedException}.
 */
@Test(expected = PermissionDeniedException.class)
public void testClaimIsAllowedExcludedOwner() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Created } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    // Test whether we can claim the task. This should not be possible.
    Operation operation = Operation.Claim;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Created);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 50 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class MVELLifeCycleManagerTest method testDelegateIsAllowedExcludedOwnerBusinessAdministrator.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object IS
 * allowed to execute operations on the given task IF the person is also a Business Administrator.
 */
@Test
public void testDelegateIsAllowedExcludedOwnerBusinessAdministrator() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')], businessAdministrators = [new User('BB8')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    /*
		 * Test whether we can delegate the task. Because the user is a BusinessAdministrator, this should be possible, even if the owner is
		 * in the ExcludedOwners list.
		 */
    Operation operation = Operation.Delegate;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    allowed.add(Allowed.BusinessAdministrator);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Ready);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Status (org.kie.api.task.model.Status)60 ArrayList (java.util.ArrayList)50 TaskSummary (org.kie.api.task.model.TaskSummary)49 Test (org.junit.Test)44 Task (org.kie.api.task.model.Task)19 HashMap (java.util.HashMap)16 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 InternalTask (org.kie.internal.task.api.model.InternalTask)16 StringReader (java.io.StringReader)15 KieSession (org.kie.api.runtime.KieSession)14 QueryFilter (org.kie.internal.query.QueryFilter)14 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)10 QueryContext (org.kie.api.runtime.query.QueryContext)10 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 Date (java.util.Date)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)8 TaskService (org.kie.api.task.TaskService)7 List (java.util.List)5 Properties (java.util.Properties)4 JBossUserGroupCallbackImpl (org.jbpm.services.task.identity.JBossUserGroupCallbackImpl)4