Search in sources :

Example 51 with KieServerCommand

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

the class KieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    if (commands != null) {
        for (KieServerCommand command : commands.getCommands()) {
            if (command instanceof CreateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.createContainer(((CreateContainerCommand) command).getContainer().getContainerId(), ((CreateContainerCommand) command).getContainer()));
            } else if (command instanceof GetServerInfoCommand) {
                responses.add(this.kieServer.getInfo());
            } else if (command instanceof ListContainersCommand) {
                responses.add(this.kieServer.listContainers(((ListContainersCommand) command).getKieContainerResourceFilter()));
            } else if (command instanceof CallContainerCommand) {
                ServiceResponse response = callContainer(((CallContainerCommand) command).getContainerId(), ((CallContainerCommand) command).getPayload(), marshallingFormat, classType, true);
                responses.add(response);
            } else if (command instanceof DisposeContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.disposeContainer(((DisposeContainerCommand) command).getContainerId()));
            } else if (command instanceof GetContainerInfoCommand) {
                responses.add(this.kieServer.getContainerInfo(((GetContainerInfoCommand) command).getContainerId()));
            } else if (command instanceof GetScannerInfoCommand) {
                responses.add(this.kieServer.getScannerInfo(((GetScannerInfoCommand) command).getContainerId()));
            } else if (command instanceof UpdateScannerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateScanner(((UpdateScannerCommand) command).getContainerId(), ((UpdateScannerCommand) command).getScanner()));
            } else if (command instanceof GetReleaseIdCommand) {
                responses.add(this.kieServer.getContainerReleaseId(((GetReleaseIdCommand) command).getContainerId()));
            } else if (command instanceof UpdateReleaseIdCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.updateContainerReleaseId(((UpdateReleaseIdCommand) command).getContainerId(), ((UpdateReleaseIdCommand) command).getReleaseId(), ((UpdateReleaseIdCommand) command).isResetBeforeUpdate()));
            } else if (command instanceof GetServerStateCommand) {
                responses.add(this.kieServer.getServerState());
            } else if (command instanceof ActivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.activateContainer(((ActivateContainerCommand) command).getContainerId()));
            } else if (command instanceof DeactivateContainerCommand) {
                ServiceResponse<?> forbidden = this.kieServer.checkAccessability();
                if (forbidden != null) {
                    logger.warn("Kie Server management api is disabled, skiping command execution {}", command);
                    responses.add(forbidden);
                    continue;
                }
                responses.add(this.kieServer.deactivateContainer(((DeactivateContainerCommand) command).getContainerId()));
            }
        }
    }
    return new ServiceResponsesList(responses);
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) KieServerCommand(org.kie.server.api.model.KieServerCommand) ActivateContainerCommand(org.kie.server.api.commands.ActivateContainerCommand) ArrayList(java.util.ArrayList) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) DeactivateContainerCommand(org.kie.server.api.commands.DeactivateContainerCommand) GetContainerInfoCommand(org.kie.server.api.commands.GetContainerInfoCommand) GetReleaseIdCommand(org.kie.server.api.commands.GetReleaseIdCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) ListContainersCommand(org.kie.server.api.commands.ListContainersCommand) GetServerStateCommand(org.kie.server.api.commands.GetServerStateCommand) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) GetServerInfoCommand(org.kie.server.api.commands.GetServerInfoCommand) GetScannerInfoCommand(org.kie.server.api.commands.GetScannerInfoCommand)

Example 52 with KieServerCommand

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

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

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

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

KieServerCommand (org.kie.server.api.model.KieServerCommand)262 ServiceResponse (org.kie.server.api.model.ServiceResponse)260 CommandScript (org.kie.server.api.commands.CommandScript)256 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)234 HashMap (java.util.HashMap)217 Wrapped (org.kie.server.api.model.Wrapped)31 ArrayList (java.util.ArrayList)27 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)18 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 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)10 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 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)6 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)6 Map (java.util.Map)5