Search in sources :

Example 6 with NodeInstanceList

use of org.kie.server.api.model.instance.NodeInstanceList in project droolsjbpm-integration by kiegroup.

the class ProcessServicesClientImpl method findNodeInstances.

@Override
public List<NodeInstance> findNodeInstances(String containerId, Long processInstanceId, Integer page, Integer pageSize) {
    NodeInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        String queryString = getPagingQueryString("", page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_NODE_INSTANCES_GET_URI, valuesMap) + queryString, NodeInstanceList.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceHistory", new Object[] { processInstanceId, true, true, page, pageSize })));
        ServiceResponse<NodeInstanceList> response = (ServiceResponse<NodeInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getNodeInstances() != null) {
        return Arrays.asList(result.getNodeInstances());
    }
    return Collections.emptyList();
}
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) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 7 with NodeInstanceList

use of org.kie.server.api.model.instance.NodeInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCompletedNodes.

@Override
public List<NodeInstance> getCompletedNodes(String containerId, String caseId, Integer page, Integer pageSize) {
    NodeInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        String queryString = getPagingQueryString("?completed=true", page, pageSize);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_NODE_INSTANCES_GET_URI, valuesMap) + queryString, NodeInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCompletedNodes", new Object[] { containerId, caseId, page, pageSize })));
        ServiceResponse<NodeInstanceList> response = (ServiceResponse<NodeInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
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) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 8 with NodeInstanceList

use of org.kie.server.api.model.instance.NodeInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getActiveNodes.

@Override
public List<NodeInstance> getActiveNodes(String containerId, String caseId, Integer page, Integer pageSize) {
    NodeInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        String queryString = getPagingQueryString("", page, pageSize);
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_NODE_INSTANCES_GET_URI, valuesMap) + queryString, NodeInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getActiveNodes", new Object[] { containerId, caseId, page, pageSize })));
        ServiceResponse<NodeInstanceList> response = (ServiceResponse<NodeInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
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) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList)

Example 9 with NodeInstanceList

use of org.kie.server.api.model.instance.NodeInstanceList in project droolsjbpm-integration by kiegroup.

the class ConvertUtils method convertToNodeInstanceList.

public static NodeInstanceList convertToNodeInstanceList(Collection<NodeInstanceDesc> definitions) {
    if (definitions == null) {
        return new NodeInstanceList(new NodeInstance[0]);
    }
    List<NodeInstance> processes = new ArrayList<NodeInstance>(definitions.size());
    for (NodeInstanceDesc ni : definitions) {
        NodeInstance nodeInstance = convertToNodeInstance(ni);
        processes.add(nodeInstance);
    }
    return new NodeInstanceList(processes);
}
Also used : ArrayList(java.util.ArrayList) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) NodeInstance(org.kie.server.api.model.instance.NodeInstance) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc)

Example 10 with NodeInstanceList

use of org.kie.server.api.model.instance.NodeInstanceList in project droolsjbpm-integration by kiegroup.

the class ProcessServiceRestOnlyIntegrationTest method testNodeInstancesWhichBelongsToAProcess.

@Test
public void testNodeInstancesWhichBelongsToAProcess() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find node instances of process instance which is deployed in the given container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, pid);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_NODE_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        NodeInstanceList nodeInstanceList = marshaller.unmarshall(response.readEntity(String.class), NodeInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(nodeInstanceList.getItems()).hasSize(3);
        response.close();
        // find node instances of non-existing process instance
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, "-1");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_NODE_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        nodeInstanceList = marshaller.unmarshall(response.readEntity(String.class), NodeInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(nodeInstanceList.getItems()).isEmpty();
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) WebTarget(javax.ws.rs.client.WebTarget) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Aggregations

NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)20 HashMap (java.util.HashMap)11 ServiceResponse (org.kie.server.api.model.ServiceResponse)11 CommandScript (org.kie.server.api.commands.CommandScript)10 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)10 KieServerCommand (org.kie.server.api.model.KieServerCommand)10 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)4 Header (org.kie.server.remote.rest.common.Header)4 Variant (javax.ws.rs.core.Variant)3 NodeInstance (org.kie.server.api.model.instance.NodeInstance)3 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)3 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)2