Search in sources :

Example 6 with VariableInstanceList

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

the class ProcessServiceRestOnlyIntegrationTest method testProcessVariablesHistoryWhichBelongsToAContainer.

@Test
public void testProcessVariablesHistoryWhichBelongsToAContainer() {
    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 process instance variable which belongs to a process instance in a deployed container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, pid);
        valuesMap.put(VAR_NAME, "stringData");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCE_BY_VAR_NAME_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        VariableInstanceList variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.getItems()).isEmpty();
        response.close();
        // find process instance variable which belongs to a non-existing process instance
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, "-1");
        valuesMap.put(VAR_NAME, "stringData");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCE_BY_VAR_NAME_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.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) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) WebTarget(javax.ws.rs.client.WebTarget) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 7 with VariableInstanceList

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

the class ProcessServicesClientImpl method findVariableHistory.

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

Example 8 with VariableInstanceList

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

the class RuntimeDataServiceBase method getVariablesCurrentState.

public VariableInstanceList getVariablesCurrentState(long processInstanceId) {
    logger.debug("About to search for variables within process instance  '{}'", processInstanceId);
    Collection<VariableDesc> variableDescs = runtimeDataService.getVariablesCurrentState(processInstanceId);
    logger.debug("Found {} variables within process instance '{}'", variableDescs.size(), processInstanceId);
    VariableInstanceList variableInstanceList = convertToVariablesList(variableDescs);
    logger.debug("Returning result of variables search: {}", variableInstanceList);
    return variableInstanceList;
}
Also used : VariableDesc(org.jbpm.services.api.model.VariableDesc) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList)

Example 9 with VariableInstanceList

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

the class RuntimeDataServiceBase method getVariableHistory.

public VariableInstanceList getVariableHistory(long processInstanceId, String variableName, Integer page, Integer pageSize) {
    logger.debug("About to search for variable '{}; history within process instance '{}' with page {} and page size {}", variableName, processInstanceId, page, pageSize);
    Collection<VariableDesc> variableDescs = runtimeDataService.getVariableHistory(processInstanceId, variableName, buildQueryContext(page, pageSize));
    logger.debug("Found {} variable {} history entries within process instance '{}'", variableDescs.size(), variableName, processInstanceId);
    VariableInstanceList variableInstanceList = convertToVariablesList(variableDescs);
    logger.debug("Returning result of variable '{}; history search: {}", variableName, variableInstanceList);
    return variableInstanceList;
}
Also used : VariableDesc(org.jbpm.services.api.model.VariableDesc) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList)

Example 10 with VariableInstanceList

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

the class ConvertUtils method convertToVariablesList.

public static VariableInstanceList convertToVariablesList(Collection<VariableDesc> variables) {
    if (variables == null) {
        return new VariableInstanceList(new VariableInstance[0]);
    }
    List<VariableInstance> processes = new ArrayList<VariableInstance>(variables.size());
    for (VariableDesc vi : variables) {
        VariableInstance nodeInstance = convertToVariable(vi);
        processes.add(nodeInstance);
    }
    return new VariableInstanceList(processes);
}
Also used : VariableDesc(org.jbpm.services.api.model.VariableDesc) ArrayList(java.util.ArrayList) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) VariableInstance(org.kie.server.api.model.instance.VariableInstance)

Aggregations

VariableInstanceList (org.kie.server.api.model.instance.VariableInstanceList)13 HashMap (java.util.HashMap)6 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 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Header (org.kie.server.remote.rest.common.Header)4 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)4 VariableDesc (org.jbpm.services.api.model.VariableDesc)3 WebTarget (javax.ws.rs.client.WebTarget)2 Response (javax.ws.rs.core.Response)2 Variant (javax.ws.rs.core.Variant)2 DeploymentNotActiveException (org.jbpm.services.api.DeploymentNotActiveException)2 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)2 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)2