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;
}
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);
}
}
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);
}
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);
}
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());
}
Aggregations