Search in sources :

Example 1 with NodeInstance

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;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) NodeInstance(org.kie.server.api.model.instance.NodeInstance)

Example 2 with NodeInstance

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);
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with NodeInstance

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);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 4 with NodeInstance

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);
}
Also used : TaskSummary(org.kie.server.api.model.instance.TaskSummary) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Example 5 with NodeInstance

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);
    }
}
Also used : HashMap(java.util.HashMap) NodeInstance(org.kie.server.api.model.instance.NodeInstance) Test(org.junit.Test)

Aggregations

NodeInstance (org.kie.server.api.model.instance.NodeInstance)23 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 TaskSummary (org.kie.server.api.model.instance.TaskSummary)6 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)4 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)4 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)3 ArrayList (java.util.ArrayList)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 Category (org.junit.experimental.categories.Category)2 CorrelationKey (org.kie.internal.process.CorrelationKey)2 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1