Search in sources :

Example 1 with UserTaskServicesClient

use of org.kie.server.client.UserTaskServicesClient in project kiegroup-examples by tkobayas.

the class KieServerRestUtils method getUserTaskServicesClient.

public static UserTaskServicesClient getUserTaskServicesClient(String username, String password) {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, username, password);
    List<String> capabilities = new ArrayList<String>();
    capabilities.add(KieServerConstants.CAPABILITY_BPM);
    config.setCapabilities(capabilities);
    config.setTimeout(600000);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    UserTaskServicesClient userTaskServiceClient = client.getServicesClient(UserTaskServicesClient.class);
    return userTaskServiceClient;
}
Also used : UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient)

Example 2 with UserTaskServicesClient

use of org.kie.server.client.UserTaskServicesClient 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 3 with UserTaskServicesClient

use of org.kie.server.client.UserTaskServicesClient in project kiegroup-examples by tkobayas.

the class StartAndCompleteTaskTest method testRest.

public void testRest() throws Exception {
    UserTaskServicesClient taskClient = KieServerRestUtils.getUserTaskServicesClient(USERNAME, PASSWORD);
    taskClient.startTask(CONTAINER_ID, 3L, USERNAME);
    taskClient.completeTask(CONTAINER_ID, 3L, USERNAME, null);
}
Also used : UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient)

Example 4 with UserTaskServicesClient

use of org.kie.server.client.UserTaskServicesClient 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 5 with UserTaskServicesClient

use of org.kie.server.client.UserTaskServicesClient in project droolsjbpm-integration by kiegroup.

the class KeycloakKieServerTest method testProcessStartAndWorkOnUserTask.

@Test
public void testProcessStartAndWorkOnUserTask() {
    setupClient(JOHN, JOHN_PW);
    // query for all available process definitions
    QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
    List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);
    assertEquals(2, processes.size());
    ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    // get details of process definition
    ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);
    assertNotNull(definition);
    assertEquals(processId, definition.getId());
    // start process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", JOHN);
    params.put("reason", "test on spring boot");
    Long processInstanceId = processClient.startProcess(containerId, processId, params);
    assertNotNull(processInstanceId);
    UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);
    // find available tasks
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(JOHN, 0, 10);
    assertEquals(1, tasks.size());
    // complete task
    Long taskId = tasks.get(0).getId();
    taskClient.startTask(containerId, taskId, JOHN);
    taskClient.completeTask(containerId, taskId, JOHN, null);
    // find active process instances
    List<ProcessInstance> instances = queryClient.findProcessInstances(0, 10);
    assertEquals(1, instances.size());
    tasks = taskClient.findTasksAssignedAsPotentialOwner(JOHN, 0, 10);
    assertEquals(1, tasks.size());
    // at the end abort process instance
    processClient.abortProcessInstance(containerId, processInstanceId);
    ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId);
    assertNotNull(processInstance);
    assertEquals(3, processInstance.getState().intValue());
}
Also used : QueryServicesClient(org.kie.server.client.QueryServicesClient) HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

UserTaskServicesClient (org.kie.server.client.UserTaskServicesClient)8 HashMap (java.util.HashMap)5 TaskSummary (org.kie.server.api.model.instance.TaskSummary)5 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)5 ArrayList (java.util.ArrayList)4 KieServicesClient (org.kie.server.client.KieServicesClient)4 KieServicesConfiguration (org.kie.server.client.KieServicesConfiguration)4 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)3 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)3 QueryServicesClient (org.kie.server.client.QueryServicesClient)3 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)1 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1 InsertObjectCommand (org.drools.core.command.runtime.rule.InsertObjectCommand)1 ExecutableCommand (org.kie.api.command.ExecutableCommand)1 RuleServicesClient (org.kie.server.client.RuleServicesClient)1