Search in sources :

Example 71 with ServiceResponse

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

the class KieClientServicesIntegrationTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    KieServerInfo info = new KieServerInfo("mock", "1.2.3");
    List<String> capabilities = Arrays.asList(KieServerConstants.CAPABILITY_BPM, KieServerConstants.CAPABILITY_BPM_UI, KieServerConstants.CAPABILITY_BRM, KieServerConstants.CAPABILITY_BRP, KieServerConstants.CAPABILITY_CASE, KieServerConstants.CAPABILITY_DMN);
    info.setCapabilities(capabilities);
    ServiceResponse<KieServerInfo> response = new ServiceResponse<KieServerInfo>(ResponseType.SUCCESS, "Kie Server info");
    response.setResult(info);
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(response, KieServerInfo.class, ServiceResponse.class))));
    // case mock response
    ProcessDefinitionList caseResponse = new ProcessDefinitionList();
    caseResponse.setProcesses(new ProcessDefinition[] { new ProcessDefinition() });
    stubFor(get(urlMatching("/queries/cases/processes.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(caseResponse, ProcessDefinitionList.class, ProcessDefinition.class))));
    // document mock response
    DocumentInstance documentResponse = new DocumentInstance();
    documentResponse.setIdentifier("1234");
    stubFor(get(urlMatching("/documents/1234")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(documentResponse, DocumentInstance.class))));
    // job service mock response
    RequestInfoInstanceList jobResponse = new RequestInfoInstanceList();
    stubFor(get(urlMatching("/jobs.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(jobResponse, RequestInfoInstanceList.class))));
    // query service mock response
    NodeInstanceList queryResponse = new NodeInstanceList();
    stubFor(get(urlMatching("/queries/processes/instances/100/nodes/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(queryResponse, NodeInstanceList.class))));
    // solver service mock response
    SolverInstanceList solverResponse = new SolverInstanceList();
    stubFor(get(urlMatching("/containers/my-container/solvers")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(solverResponse, SolverInstanceList.class))));
    // ui service mock response
    stubFor(get(urlMatching("/containers/my-container/forms/processes/my-process.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("my form")));
    // user task mock response
    TaskSummaryList userTaskResponse = new TaskSummaryList();
    stubFor(get(urlMatching("/queries/tasks/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(userTaskResponse, TaskSummaryList.class))));
    return new RouteBuilder() {

        @Override
        public void configure() {
            from("direct:start").to("kie:" + getAuthenticadUrl("admin", "admin")).to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) KieServerInfo(org.kie.server.api.model.KieServerInfo) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) ServiceResponse(org.kie.server.api.model.ServiceResponse) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance)

Example 72 with ServiceResponse

use of org.kie.server.api.model.ServiceResponse 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 73 with ServiceResponse

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

the class ProcessServicesClientImpl method computeProcessOutcome.

@Override
public Map<String, Object> computeProcessOutcome(String containerId, String processId, Map<String, Object> variables) {
    Object result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_ID, processId);
        result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + COMPUTE_PROCESS_OUTCOME_POST_URI, valuesMap), variables, Object.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "computeProcessOutcome", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[] { containerId, processId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), Map.class);
    }
    return (Map<String, Object>) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 74 with ServiceResponse

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

the class ProcessServicesClientImpl method getProcessInstance.

@Override
public ProcessInstance getProcessInstance(String containerId, Long processInstanceId, boolean withVars) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        return makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_GET_URI, valuesMap) + "?withVars=" + withVars, ProcessInstance.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "getProcessInstance", marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId, withVars })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return deserialize(response.getResult(), ProcessInstance.class);
    }
}
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)

Example 75 with ServiceResponse

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

the class ProcessServicesClientImpl method signalProcessInstanceByCorrelationKey.

@Override
public void signalProcessInstanceByCorrelationKey(String containerId, CorrelationKey correlationKey, String signalName, Object event) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
        valuesMap.put(SIGNAL_NAME, signalName);
        Map<String, String> headers = new HashMap<String, String>();
        makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + SIGNAL_PROCESS_BY_CORRELATION_KEY_POST_URI, valuesMap), event, String.class, headers);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "signalProcessInstanceByCorrelationKey", serialize(event), marshaller.getFormat().getType(), new Object[] { containerId, correlationKey.toExternalForm(), signalName })));
        ServiceResponse<?> response = (ServiceResponse<?>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
    }
}
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)

Aggregations

ServiceResponse (org.kie.server.api.model.ServiceResponse)315 CommandScript (org.kie.server.api.commands.CommandScript)269 KieServerCommand (org.kie.server.api.model.KieServerCommand)261 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)234 HashMap (java.util.HashMap)224 ArrayList (java.util.ArrayList)41 Wrapped (org.kie.server.api.model.Wrapped)32 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)23 KieContainerResource (org.kie.server.api.model.KieContainerResource)18 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 TaskSummaryList (org.kie.server.api.model.instance.TaskSummaryList)17 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)15 Map (java.util.Map)13 Message (org.kie.server.api.model.Message)13 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 Test (org.junit.Test)11 List (java.util.List)9 ReleaseId (org.kie.server.api.model.ReleaseId)9 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)9 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)8