Search in sources :

Example 1 with TaskSummary

use of org.kie.server.api.model.instance.TaskSummary in project kiegroup-examples by tkobayas.

the class DemoTest method testRest.

public void testRest() throws Exception {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
    List<String> capabilities = new ArrayList<String>();
    capabilities.add(KieServerConstants.CAPABILITY_BPM);
    config.setCapabilities(capabilities);
    config.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    ProcessServicesClient processServiceClient = client.getServicesClient(ProcessServicesClient.class);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("processVar1", "AAA1");
    params.put("processVar2", "BBB2");
    long processInstanceId = processServiceClient.startProcess(CONTAINER_ID, "project1.helloProcess", params);
    System.out.println("startProcess() : processInstanceId = " + processInstanceId);
    UserTaskServicesClient userTaskServiceClient = client.getServicesClient(UserTaskServicesClient.class);
    List<TaskSummary> taskList = userTaskServiceClient.findTasksAssignedAsPotentialOwner(USERNAME, 0, 100);
    for (TaskSummary taskSummary : taskList) {
        System.out.println("taskSummary.getId() = " + taskSummary.getId() + ", staus = " + taskSummary.getStatus());
        long taskId = taskSummary.getId();
        if (taskSummary.getStatus().equals("Reserved")) {
            userTaskServiceClient.startTask(CONTAINER_ID, taskId, USERNAME);
        }
        userTaskServiceClient.completeTask(CONTAINER_ID, taskId, USERNAME, null);
    }
}
Also used : HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) TaskSummary(org.kie.server.api.model.instance.TaskSummary)

Example 2 with TaskSummary

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

the class BaseKieServerClientKarafIntegrationTest method testCompleteInteractionWithKieServer.

protected void testCompleteInteractionWithKieServer(MarshallingFormat marshallingFormat) {
    KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, KieServerConstants.user, KieServerConstants.password);
    configuration.setMarshallingFormat(marshallingFormat);
    // configuration.addJaxbClasses(extraClasses);
    // KieServicesClient kieServicesClient =  KieServicesFactory.newKieServicesClient(configuration, kieContainer.getClassLoader());
    KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(configuration, this.getClass().getClassLoader());
    // query for all available process definitions
    QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
    List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
    System.out.println("\t######### Available processes" + processes);
    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    // get details of process definition
    ProcessDefinition definition = processClient.getProcessDefinition(KieServerConstants.containerId, KieServerConstants.processId);
    System.out.println("\t######### Definition details: " + definition);
    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", KieServerConstants.user);
    Long processInstanceId = processClient.startProcess(KieServerConstants.containerId, KieServerConstants.processId, params);
    System.out.println("\t######### Process instance id: " + processInstanceId);
    UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);
    // find available tasks
    List<TaskSummary> tasks = taskClient.findTasks(KieServerConstants.user, 0, 10);
    System.out.println("\t######### Tasks: " + tasks);
    // complete task
    Long taskId = tasks.get(0).getId();
    taskClient.startTask(KieServerConstants.containerId, taskId, KieServerConstants.user);
    taskClient.completeTask(KieServerConstants.containerId, taskId, KieServerConstants.user, null);
    // work with rules
    List<ExecutableCommand<?>> commands = new ArrayList<ExecutableCommand<?>>();
    BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands);
    executionCommand.setLookup("defaultKieSession");
    InsertObjectCommand insertObjectCommand = new InsertObjectCommand();
    insertObjectCommand.setOutIdentifier("person");
    insertObjectCommand.setObject("john");
    FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
    commands.add(insertObjectCommand);
    commands.add(fireAllRulesCommand);
    RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
    ruleClient.executeCommands(KieServerConstants.containerId, executionCommand);
    System.out.println("\t######### Rules executed");
    // at the end abort process instance
    processClient.abortProcessInstance(KieServerConstants.containerId, processInstanceId);
    ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
    System.out.println("\t######### ProcessInstance: " + processInstance);
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) RuleServicesClient(org.kie.server.client.RuleServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ExecutableCommand(org.kie.api.command.ExecutableCommand) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) InsertObjectCommand(org.drools.core.command.runtime.rule.InsertObjectCommand)

Example 3 with TaskSummary

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

the class UserTaskClientIntegrationTest method testTaskWorkflow.

@Test
public void testTaskWorkflow() {
    final Map<String, Object> initialProcessVariables = new HashMap<>();
    initialProcessVariables.put(PROCESS_VARIABLE_NAME, INITIAL_PROCESS_VARIABLE_VALUE);
    final long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_HUMAN_TASK, initialProcessVariables);
    Assertions.assertThat(processInstanceId).isPositive();
    Assertions.assertThat(getProcessVariables(CONTAINER_ID, processInstanceId).get(PROCESS_VARIABLE_NAME)).isEqualTo(INITIAL_PROCESS_VARIABLE_VALUE);
    final List<TaskSummary> taskInstances = listTaskInstancesAsPotentialOwner();
    Assertions.assertThat(taskInstances).hasSize(1);
    final long taskId = taskInstances.get(0).getId();
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("containerId", CONTAINER_ID);
    parameters.put("taskId", taskId);
    parameters.put("userId", DEFAULT_USER);
    final ExecutionServerCommand claimTaskCommand = new ExecutionServerCommand();
    claimTaskCommand.setClient("userTask");
    claimTaskCommand.setOperation("claimTask");
    claimTaskCommand.setParameters(parameters);
    runOnExecutionServer(claimTaskCommand);
    final ExecutionServerCommand startTaskCommand = new ExecutionServerCommand();
    startTaskCommand.setClient("userTask");
    startTaskCommand.setOperation("startTask");
    startTaskCommand.setParameters(parameters);
    runOnExecutionServer(startTaskCommand);
    final Map<String, Object> taskParameters = new HashMap<>();
    taskParameters.put("var1", NEW_PROCESS_VARIABLE_VALUE);
    parameters.put("params", taskParameters);
    final ExecutionServerCommand completeTaskCommand = new ExecutionServerCommand();
    completeTaskCommand.setClient("userTask");
    completeTaskCommand.setOperation("completeTask");
    completeTaskCommand.setParameters(parameters);
    runOnExecutionServer(completeTaskCommand);
    Assertions.assertThat(getProcessVariables(CONTAINER_ID, processInstanceId).get(PROCESS_VARIABLE_NAME)).isEqualTo(NEW_PROCESS_VARIABLE_VALUE);
    sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Test(org.junit.Test)

Example 4 with TaskSummary

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

the class RuntimeDataServiceIntegrationTest method testFindTasksSortedByProcessInstanceId.

@Test
public void testFindTasksSortedByProcessInstanceId() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    Long processInstanceId2 = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasks(USER_YODA, 0, 50, "processInstanceId", false);
        assertNotNull(tasks);
        List<TaskSummary> reservedTasks = tasks.stream().filter(n -> Status.Reserved.toString().equals(n.getStatus())).collect(Collectors.toList());
        TaskSummary firstTask = reservedTasks.get(0);
        TaskSummary secondTask = reservedTasks.get(1);
        Assertions.assertThat(firstTask.getProcessInstanceId()).as("First reserved task should have bigger process instance id as results should be sorted in descending order.").isGreaterThan(secondTask.getProcessInstanceId());
        // latest task is from second process
        TaskSummary expectedTaskSummary;
        if (processInstanceId2 > processInstanceId) {
            expectedTaskSummary = createDefaultTaskSummary(processInstanceId2);
        } else {
            expectedTaskSummary = createDefaultTaskSummary(processInstanceId);
        }
        assertTaskSummary(expectedTaskSummary, firstTask);
        expectedTaskSummary = null;
        if (processInstanceId2 > processInstanceId) {
            expectedTaskSummary = createDefaultTaskSummary(processInstanceId);
        } else {
            expectedTaskSummary = createDefaultTaskSummary(processInstanceId2);
        }
        assertTaskSummary(expectedTaskSummary, secondTask);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId2);
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) QueryParamFactory.onlyCompletedTasks(org.kie.server.api.util.QueryParamFactory.onlyCompletedTasks) Arrays(java.util.Arrays) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) Assert.assertThat(org.junit.Assert.assertThat) QueryParamFactory.list(org.kie.server.api.util.QueryParamFactory.list) QueryParamFactory.onlyActiveTasks(org.kie.server.api.util.QueryParamFactory.onlyActiveTasks) Map(java.util.Map) KieInternalServices(org.kie.internal.KieInternalServices) TaskEvent(org.kie.internal.task.api.model.TaskEvent) Assertions(org.assertj.core.api.Assertions) Assert.fail(org.junit.Assert.fail) PROCESS_ATTR_DEFINITION_ID(org.jbpm.services.api.AdvanceRuntimeDataService.PROCESS_ATTR_DEFINITION_ID) QueryParamFactory.equalsTo(org.kie.server.api.util.QueryParamFactory.equalsTo) TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) PROCESS_ATTR_DEPLOYMENT_ID(org.jbpm.services.api.AdvanceRuntimeDataService.PROCESS_ATTR_DEPLOYMENT_ID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) QueryParamFactory.history(org.kie.server.api.util.QueryParamFactory.history) Smoke(org.kie.server.integrationtests.category.Smoke) List(java.util.List) ProcessInstanceUserTaskWithVariables(org.kie.server.api.model.instance.ProcessInstanceUserTaskWithVariables) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) KieServicesException(org.kie.server.api.exception.KieServicesException) BeforeClass(org.junit.BeforeClass) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) Assume.assumeFalse(org.junit.Assume.assumeFalse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KieServerAssert(org.kie.server.integrationtests.shared.KieServerAssert) QueryServicesClient(org.kie.server.client.QueryServicesClient) KieServices(org.kie.api.KieServices) Assume(org.junit.Assume) VariableInstance(org.kie.server.api.model.instance.VariableInstance) CorrelationKey(org.kie.internal.process.CorrelationKey) Assert.assertNotNull(org.junit.Assert.assertNotNull) TaskInstance(org.kie.server.api.model.instance.TaskInstance) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SearchQueryFilterSpec(org.kie.server.api.model.definition.SearchQueryFilterSpec) KieServerDeployer(org.kie.server.integrationtests.shared.KieServerDeployer) ProcessInstanceCustomVars(org.kie.server.api.model.instance.ProcessInstanceCustomVars) TestConfig(org.kie.server.integrationtests.config.TestConfig) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Assert.assertNull(org.junit.Assert.assertNull) KieServicesHttpException(org.kie.server.api.exception.KieServicesHttpException) ReleaseId(org.kie.server.api.model.ReleaseId) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 5 with TaskSummary

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

the class RuntimeDataServiceIntegrationTest method testFindTasksOwned.

@Test
public void testFindTasksOwned() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
    try {
        List<TaskSummary> tasks = taskClient.findTasksOwned(USER_YODA, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary expectedTaskSummary = createDefaultTaskSummary(processInstanceId);
        TaskSummary taskInstance = tasks.get(0);
        assertTaskSummary(expectedTaskSummary, taskInstance);
        List<String> status = new ArrayList<String>();
        status.add(Status.InProgress.toString());
        tasks = taskClient.findTasksOwned(USER_YODA, status, 0, 10);
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        taskClient.startTask(CONTAINER_ID, taskInstance.getId(), USER_YODA);
        tasks = taskClient.findTasksOwned(USER_YODA, status, 0, 10);
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        taskInstance = tasks.get(0);
        expectedTaskSummary.setStatus(Status.InProgress.toString());
        assertTaskSummary(expectedTaskSummary, taskInstance);
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.server.api.model.instance.TaskSummary)142 Test (org.junit.Test)131 HashMap (java.util.HashMap)79 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)39 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)31 TaskInstance (org.kie.server.api.model.instance.TaskInstance)28 ArrayList (java.util.ArrayList)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)21 KieServicesException (org.kie.server.api.exception.KieServicesException)14 Category (org.junit.experimental.categories.Category)7 NodeInstance (org.kie.server.api.model.instance.NodeInstance)7 Date (java.util.Date)6 CaseInstance (org.kie.server.api.model.cases.CaseInstance)6 TaskEventInstance (org.kie.server.api.model.instance.TaskEventInstance)6 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)6 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)5 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)5 UserTaskServicesClient (org.kie.server.client.UserTaskServicesClient)5 Calendar (java.util.Calendar)4 List (java.util.List)3