Search in sources :

Example 6 with CommandScript

use of org.kie.server.api.commands.CommandScript in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method findVariablesCurrentState.

@Override
public List<VariableInstance> findVariablesCurrentState(Long processInstanceId) {
    VariableInstanceList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + VAR_INSTANCES_BY_INSTANCE_ID_GET_URI, valuesMap), VariableInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getVariablesCurrentState", new Object[] { processInstanceId })));
        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 7 with CommandScript

use of org.kie.server.api.commands.CommandScript in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method findProcessInstanceByCorrelationKey.

@Override
public ProcessInstance findProcessInstanceByCorrelationKey(CorrelationKey correlationKey) {
    ProcessInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_CORRELATION_KEY_GET_URI, valuesMap), ProcessInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceByCorrelationKey", new Object[] { correlationKey.toExternalForm() })));
        ServiceResponse<ProcessInstance> response = (ServiceResponse<ProcessInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        return 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) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance)

Example 8 with CommandScript

use of org.kie.server.api.commands.CommandScript in project droolsjbpm-integration by kiegroup.

the class QueryServicesClientImpl method query.

@Override
public <T> List<T> query(String queryName, String mapper, QueryFilterSpec filterSpec, Integer page, Integer pageSize, Class<T> resultType) {
    Object result = null;
    Class<?> resultTypeList = getResultTypeList(resultType);
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(QUERY_NAME, queryName);
        String queryString = getPagingQueryString("?mapper=" + mapper, page, pageSize);
        result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_DEF_URI + "/" + RUN_FILTERED_QUERY_DEF_POST_URI, valuesMap) + queryString, filterSpec, resultTypeList);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryDataService", "queryFiltered", serialize(filterSpec), marshaller.getFormat().getType(), new Object[] { queryName, mapper, page, pageSize })));
        ServiceResponse<Object> response = (ServiceResponse<Object>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null) {
        if (result instanceof ItemList) {
            return ((ItemList<T>) result).getItems();
        } else if (result instanceof List) {
            return (List) result;
        } else if (result instanceof Wrapped) {
            return (List) ((Wrapped) result).unwrap();
        }
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) ServiceResponse(org.kie.server.api.model.ServiceResponse) ItemList(org.kie.server.api.model.ItemList) Wrapped(org.kie.server.api.model.Wrapped) ExecutionErrorInstanceList(org.kie.server.api.model.admin.ExecutionErrorInstanceList) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) TaskWithProcessDescriptionList(org.kie.server.api.model.instance.TaskWithProcessDescriptionList) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) List(java.util.List) QueryDefinitionList(org.kie.server.api.model.definition.QueryDefinitionList) ProcessInstanceCustomVarsList(org.kie.server.api.model.instance.ProcessInstanceCustomVarsList) ArrayList(java.util.ArrayList) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) ProcessInstanceUserTaskWithVariablesList(org.kie.server.api.model.instance.ProcessInstanceUserTaskWithVariablesList) TaskInstanceList(org.kie.server.api.model.instance.TaskInstanceList) ItemList(org.kie.server.api.model.ItemList)

Example 9 with CommandScript

use of org.kie.server.api.commands.CommandScript in project droolsjbpm-integration by kiegroup.

the class RuleServicesClientImpl method executeCommandsWithResults.

@Override
public ServiceResponse<ExecutionResults> executeCommandsWithResults(String id, Command<?> cmd, Status status) {
    if (config.isRest()) {
        return makeHttpPostRequestAndCreateServiceResponse(loadBalancer.getUrl() + "/containers/instances/" + id, cmd, (Class) ExecutionResultImpl.class, getHeaders(cmd), status);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CallContainerCommand(id, serialize(cmd))));
        ServiceResponse response = executeJmsCommand(script, cmd.getClass().getName(), null, id).getResponses().get(0);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        if (response.getResult() instanceof String) {
            response.setResult(deserialize((String) response.getResult(), (Class) ExecutionResultImpl.class));
        }
        return response;
    }
}
Also used : CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) CommandScript(org.kie.server.api.commands.CommandScript)

Example 10 with CommandScript

use of org.kie.server.api.commands.CommandScript in project droolsjbpm-integration by kiegroup.

the class SolverServicesClientImpl method addProblemFactChange.

@Override
public void addProblemFactChange(String containerId, String solverId, ProblemFactChange problemFactChange) {
    checkMandatoryParameter("containerId", containerId);
    checkMandatoryParameter("solverId", solverId);
    checkMandatoryParameter("problemFactChange", problemFactChange);
    if (config.isRest()) {
        String uri = getURI(containerId, solverId) + "/" + RestURI.SOLVER_PROBLEM_FACT_CHANGES;
        makeHttpPostRequestAndCreateCustomResponse(uri, problemFactChange, ServiceResponse.class, getHeaders(problemFactChange));
    } else {
        CommandScript script = new CommandScript(Collections.singletonList(new AddProblemFactChangeCommand(containerId, solverId, problemFactChange)));
        ServiceResponse<Void> response = (ServiceResponse<Void>) executeJmsCommand(script, AddProblemFactChangeCommand.class.getName(), KieServerConstants.CAPABILITY_BRP, containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
    }
}
Also used : ServiceResponse(org.kie.server.api.model.ServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) AddProblemFactChangeCommand(org.kie.server.api.commands.optaplanner.AddProblemFactChangeCommand)

Aggregations

CommandScript (org.kie.server.api.commands.CommandScript)275 ServiceResponse (org.kie.server.api.model.ServiceResponse)269 KieServerCommand (org.kie.server.api.model.KieServerCommand)256 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)232 HashMap (java.util.HashMap)218 Wrapped (org.kie.server.api.model.Wrapped)27 ArrayList (java.util.ArrayList)22 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)17 TaskSummaryList (org.kie.server.api.model.instance.TaskSummaryList)16 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)14 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)12 KieContainerResource (org.kie.server.api.model.KieContainerResource)9 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)8 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)8 VariableInstanceList (org.kie.server.api.model.instance.VariableInstanceList)8 RequestInfoInstanceList (org.kie.server.api.model.instance.RequestInfoInstanceList)7 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)6 Map (java.util.Map)5 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)5