use of org.kie.server.api.model.instance.NodeInstance in project droolsjbpm-integration by kiegroup.
the class QueryServicesClientImpl method findNodeInstanceByWorkItemId.
@Override
public NodeInstance findNodeInstanceByWorkItemId(Long processInstanceId, Long workItemId) {
NodeInstance result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(PROCESS_INST_ID, processInstanceId);
valuesMap.put(WORK_ITEM_ID, workItemId);
result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + NODE_INSTANCES_BY_WORK_ITEM_ID_GET_URI, valuesMap), NodeInstance.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getNodeInstanceForWorkItem", new Object[] { processInstanceId, workItemId })));
ServiceResponse<NodeInstance> response = (ServiceResponse<NodeInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
return result;
}
use of org.kie.server.api.model.instance.NodeInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method getNodeInstanceForWorkItem.
@ApiOperation(value = "Returns node instances for a specified work item in a specified process instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Node instance id not found"), @ApiResponse(code = 200, response = NodeInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCE_NODE_RESPONSE_JSON) })) })
@GET
@Path(NODE_INSTANCES_BY_WORK_ITEM_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getNodeInstanceForWorkItem(@Context HttpHeaders headers, @ApiParam(value = "process instance id that work item belongs to", required = true) @PathParam(PROCESS_INST_ID) long processInstanceId, @ApiParam(value = "work item id to retrieve node instance for", required = true) @PathParam("workItemId") long workItemId) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
NodeInstance nodeInstanceDesc = null;
try {
nodeInstanceDesc = runtimeDataServiceBase.getNodeInstanceForWorkItem(processInstanceId, workItemId);
} catch (IllegalArgumentException e) {
return notFound(MessageFormat.format(NODE_INSTANCE_NOT_FOUND, workItemId, processInstanceId), v, conversationIdHeader);
}
return createCorrectVariant(nodeInstanceDesc, headers, Response.Status.OK, conversationIdHeader);
}
use of org.kie.server.api.model.instance.NodeInstance in project droolsjbpm-integration by kiegroup.
the class SLAComplianceIntegrationTest method testSLAonProcessViolated.
@Test
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testSLAonProcessViolated() throws Exception {
Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA, new HashMap<>());
assertProcessInstance(pid, STATE_ACTIVE, SLA_PENDING);
// Yoda should have one task available without SLA
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
assertThat(task.getName()).isEqualTo("Hello");
List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
assertThat(activeNodes).hasSize(1);
NodeInstance taskNode = activeNodes.get(0);
assertNodeInstance(taskNode, "Hello", SLA_NA);
// Let's wait for SLA violation
KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, pid, 8_000L);
assertProcessInstance(pid, STATE_ACTIVE, SLA_VIOLATED);
taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 0);
assertThat(tasks).isEmpty();
activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
assertThat(activeNodes).isEmpty();
taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
assertNodeInstance(taskNode, "Hello", SLA_NA);
// Process should be completed, but SLA should still be violated
assertProcessInstance(pid, STATE_COMPLETED, SLA_VIOLATED);
}
use of org.kie.server.api.model.instance.NodeInstance in project droolsjbpm-integration by kiegroup.
the class SLAComplianceIntegrationTest method testSLAonProcessMet.
@Test
public void testSLAonProcessMet() throws Exception {
Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK_WITH_SLA, new HashMap<>());
assertProcessInstance(pid, STATE_ACTIVE, SLA_PENDING);
// Yoda should have one task available without SLA
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
assertThat(task.getName()).isEqualTo("Hello");
List<NodeInstance> activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
assertThat(activeNodes).hasSize(1);
NodeInstance taskNode = activeNodes.get(0);
assertNodeInstance(taskNode, "Hello", SLA_NA);
// Complete task before SLA violation
taskClient.completeAutoProgress(CONTAINER_ID, task.getId(), USER_YODA, null);
tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 0);
assertThat(tasks).isEmpty();
activeNodes = processClient.findActiveNodeInstances(CONTAINER_ID, pid, 0, 10);
assertThat(activeNodes).isEmpty();
taskNode = getNodeInstanceById(queryClient.findCompletedNodeInstances(pid, 0, 10), taskNode.getId());
assertNodeInstance(taskNode, "Hello", SLA_NA);
// Process should be completed and SLA should be met
assertProcessInstance(pid, STATE_COMPLETED, SLA_MET);
}
use of org.kie.server.api.model.instance.NodeInstance in project droolsjbpm-integration by kiegroup.
the class ProcessServiceIntegrationTest method testGetNodeInstances.
@Test
public void testGetNodeInstances() 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<NodeInstance> instances = processClient.findActiveNodeInstances(CONTAINER_ID, processInstanceId, 0, 10);
assertNotNull(instances);
assertEquals(1, instances.size());
NodeInstance expectedFirstTask = NodeInstance.builder().name("First task").containerId(CONTAINER_ID).nodeType("HumanTaskNode").completed(false).processInstanceId(processInstanceId).build();
NodeInstance nodeInstance = instances.get(0);
assertNodeInstance(expectedFirstTask, nodeInstance);
assertNotNull(nodeInstance.getWorkItemId());
assertNotNull(nodeInstance.getDate());
instances = processClient.findCompletedNodeInstances(CONTAINER_ID, processInstanceId, 0, 10);
assertNotNull(instances);
assertEquals(1, instances.size());
NodeInstance expectedStart = NodeInstance.builder().name("start").containerId(CONTAINER_ID).nodeType("StartNode").completed(true).processInstanceId(processInstanceId).build();
nodeInstance = instances.get(0);
assertNodeInstance(expectedStart, nodeInstance);
assertNull(nodeInstance.getWorkItemId());
assertNotNull(nodeInstance.getDate());
instances = processClient.findNodeInstances(CONTAINER_ID, processInstanceId, 0, 10);
assertNotNull(instances);
assertEquals(3, instances.size());
nodeInstance = instances.get(0);
assertNodeInstance(expectedFirstTask, nodeInstance);
assertNotNull(nodeInstance.getWorkItemId());
assertNotNull(nodeInstance.getDate());
nodeInstance = instances.get(1);
assertNodeInstance(expectedStart, nodeInstance);
assertNull(nodeInstance.getWorkItemId());
assertNotNull(nodeInstance.getDate());
nodeInstance = instances.get(2);
expectedStart.setCompleted(false);
assertNodeInstance(expectedStart, nodeInstance);
assertNull(nodeInstance.getWorkItemId());
assertNotNull(nodeInstance.getDate());
} finally {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
Aggregations