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