Search in sources :

Example 16 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testAddRemovePotOwnersByDifferentUser.

@Test
public void testAddRemovePotOwnersByDifferentUser() throws Exception {
    // Different user cannot be used for JMS as security adapter holds just information about current user
    assumeFalse(configuration.isJms());
    changeUser(USER_ADMINISTRATOR);
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = null;
    try {
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
        Assertions.assertThat(processInstanceId).isNotNull();
        Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
        Assertions.assertThat(tasks).hasSize(1);
        TaskSummary task = tasks.get(0);
        TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        List<String> potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, "PM", "HR");
        OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
        userTaskAdminClient.addPotentialOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(4);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerUsers(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), USER_YODA);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerGroups(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), "PM", "HR");
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(1);
        Assertions.assertThat(potOwners).contains(USER_JOHN);
        add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("PM")).build();
        userTaskAdminClient.addPotentialOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM");
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 17 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testManageTaskInputAndOutput.

@Test
public void testManageTaskInputAndOutput() throws Exception {
    changeUser(USER_ADMINISTRATOR);
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = null;
    try {
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
        Assertions.assertThat(processInstanceId).isNotNull();
        Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
        Assertions.assertThat(tasks).hasSize(1);
        TaskSummary task = tasks.get(0);
        TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), true, false, false);
        Assertions.assertThat(instance).isNotNull();
        Map<String, Object> input = instance.getInputData();
        Assertions.assertThat(input).isNotNull();
        Assertions.assertThat(input).hasSize(4);
        Assertions.assertThat(input).doesNotContainKey("new content");
        Map<String, Object> data = new HashMap<>();
        data.put("new content", "test");
        userTaskAdminClient.addTaskInputs(CONTAINER_ID, task.getId(), data);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), true, false, false);
        Assertions.assertThat(instance).isNotNull();
        input = instance.getInputData();
        Assertions.assertThat(input).isNotNull();
        Assertions.assertThat(input).hasSize(5);
        Assertions.assertThat(input.get("new content")).isEqualTo("test");
        userTaskAdminClient.removeTaskInputs(CONTAINER_ID, task.getId(), "new content");
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), true, false, false);
        Assertions.assertThat(instance).isNotNull();
        input = instance.getInputData();
        Assertions.assertThat(input).isNotNull();
        Assertions.assertThat(input).hasSize(4);
        Assertions.assertThat(input).doesNotContainKey("new content");
        taskClient.saveTaskContent(CONTAINER_ID, task.getId(), data);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, true, false);
        Assertions.assertThat(instance).isNotNull();
        Map<String, Object> output = instance.getOutputData();
        Assertions.assertThat(output).isNotNull();
        Assertions.assertThat(output).hasSize(1);
        Assertions.assertThat(output.get("new content")).isEqualTo("test");
        userTaskAdminClient.removeTaskOutputs(CONTAINER_ID, task.getId(), "new content");
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, true, false);
        Assertions.assertThat(instance).isNotNull();
        output = instance.getOutputData();
        Assertions.assertThat(output).isNotNull();
        Assertions.assertThat(output).hasSize(0);
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 18 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testAddRemovePotOwnersWithContainerAlias.

/*
     * Test to add and remove of potential owners of a task using a container's alias, not the original container id with which it was created. 
     */
@Test
public void testAddRemovePotOwnersWithContainerAlias() throws Exception {
    changeUser(USER_ADMINISTRATOR);
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = null;
    try {
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
        Assertions.assertThat(processInstanceId).isNotNull();
        Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
        Assertions.assertThat(tasks).hasSize(1);
        TaskSummary task = tasks.get(0);
        TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        List<String> potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, "PM", "HR");
        OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
        userTaskAdminClient.addPotentialOwners(CONTAINER_ID_ALIAS, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID_ALIAS, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(4);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerUsers(CONTAINER_ID_ALIAS, task.getId(), USER_YODA);
        instance = taskClient.getTaskInstance(CONTAINER_ID_ALIAS, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerGroups(CONTAINER_ID_ALIAS, task.getId(), "PM", "HR");
        instance = taskClient.getTaskInstance(CONTAINER_ID_ALIAS, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(1);
        Assertions.assertThat(potOwners).contains(USER_JOHN);
        add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("PM")).build();
        userTaskAdminClient.addPotentialOwners(CONTAINER_ID_ALIAS, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID_ALIAS, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM");
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID_ALIAS, processInstanceId);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 19 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testAddRemoveBusinessAdmins.

@Test
public void testAddRemoveBusinessAdmins() throws Exception {
    changeUser(USER_ADMINISTRATOR);
    Map<String, Object> parameters = new HashMap<String, Object>();
    Long processInstanceId = null;
    try {
        processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
        Assertions.assertThat(processInstanceId).isNotNull();
        Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
        Assertions.assertThat(tasks).hasSize(1);
        TaskSummary task = tasks.get(0);
        TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        List<String> businessAdmins = instance.getBusinessAdmins();
        Assertions.assertThat(businessAdmins).hasSize(2);
        Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators");
        OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
        userTaskAdminClient.addBusinessAdmins(CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        businessAdmins = instance.getBusinessAdmins();
        Assertions.assertThat(businessAdmins).hasSize(3);
        Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators", USER_JOHN);
        userTaskAdminClient.removeBusinessAdminUsers(CONTAINER_ID, task.getId(), USER_JOHN);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        businessAdmins = instance.getBusinessAdmins();
        Assertions.assertThat(businessAdmins).hasSize(2);
        Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators");
        add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("Administrators2")).build();
        userTaskAdminClient.addBusinessAdmins(CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        businessAdmins = instance.getBusinessAdmins();
        Assertions.assertThat(businessAdmins).hasSize(4);
        Assertions.assertThat(businessAdmins).contains(USER_YODA, USER_ADMINISTRATOR, "Administrators", "Administrators2");
        userTaskAdminClient.removeBusinessAdminGroups(CONTAINER_ID, task.getId(), "Administrators2");
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        businessAdmins = instance.getBusinessAdmins();
        Assertions.assertThat(businessAdmins).hasSize(3);
        Assertions.assertThat(businessAdmins).contains(USER_YODA, USER_ADMINISTRATOR, "Administrators");
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 20 with TaskInstance

use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.

the class UserTaskServiceIntegrationTest method testUserTaskSetTaskProperties.

@Test
public void testUserTaskSetTaskProperties() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        // verify current task properties
        assertEquals(0, taskSummary.getPriority().intValue());
        assertNull(taskSummary.getExpirationTime());
        assertTrue(taskSummary.getSkipable().booleanValue());
        assertEquals("First task", taskSummary.getName());
        KieServerAssert.assertNullOrEmpty(taskSummary.getDescription());
        // set task properties
        Calendar currentTime = Calendar.getInstance();
        currentTime.add(Calendar.DAY_OF_YEAR, 1);
        Date expirationDate = currentTime.getTime();
        taskClient.setTaskDescription(CONTAINER_ID, taskSummary.getId(), "Simple user task.");
        taskClient.setTaskExpirationDate(CONTAINER_ID, taskSummary.getId(), expirationDate);
        taskClient.setTaskName(CONTAINER_ID, taskSummary.getId(), "Modified name");
        taskClient.setTaskPriority(CONTAINER_ID, taskSummary.getId(), 10);
        taskClient.setTaskSkipable(CONTAINER_ID, taskSummary.getId(), false);
        // start task
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        // retrieve started task
        TaskInstance taskInstance = taskClient.getTaskInstance(CONTAINER_ID, taskSummary.getId());
        // verify modified task properties
        assertEquals(10, taskInstance.getPriority().intValue());
        assertNotNull(taskInstance.getExpirationDate());
        assertFalse(taskInstance.getSkipable().booleanValue());
        assertEquals("Modified name", taskInstance.getName());
        assertEquals("Simple user task.", taskInstance.getDescription());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) Calendar(java.util.Calendar) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TaskInstance (org.kie.server.api.model.instance.TaskInstance)44 Test (org.junit.Test)29 TaskSummary (org.kie.server.api.model.instance.TaskSummary)27 HashMap (java.util.HashMap)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)8 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)6 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)5 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)5 ArrayList (java.util.ArrayList)4 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)3 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)3 ApiOperation (io.swagger.annotations.ApiOperation)2