Search in sources :

Example 26 with Wrapped

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

the class BlockingResponseCallback method get.

@Override
public <T> T get(Class<T> type) {
    if (marshaller == null) {
        throw new IllegalStateException("No marshaller given, can't use get(Class) to return response");
    }
    ServiceResponsesList responsesList = get();
    if (responsesList.getResponses() == null || responsesList.getResponses().isEmpty()) {
        logger.debug("No data found in the response, returning null");
        return null;
    }
    ServiceResponse response = responsesList.getResponses().get(0);
    if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) {
        Object result = response.getResult();
        if (result instanceof String) {
            logger.debug("Response '{}' of type string, unmarshalling it...", result);
            result = marshaller.unmarshall((String) result, type);
            logger.debug("Result after unmarshall operation {}", result);
        }
        // handle wrapped objects
        if (result instanceof Wrapped) {
            result = ((Wrapped) result).unwrap();
        }
        return (T) result;
    } else {
        logger.debug("Non successful response '{}', returning null", response.getMsg());
        return null;
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) ServiceResponse(org.kie.server.api.model.ServiceResponse) Wrapped(org.kie.server.api.model.Wrapped)

Example 27 with Wrapped

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

the class CaseServicesClientImpl method startCase.

@Override
public String startCase(String containerId, String caseDefinitionId, CaseFile caseFile) {
    Object result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_DEF_ID, caseDefinitionId);
        result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + START_CASE_POST_URI, valuesMap), caseFile, String.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseService", "startCase", serialize(caseFile), marshaller.getFormat().getType(), new Object[] { containerId, caseDefinitionId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), Object.class);
    }
    if (result instanceof Wrapped) {
        return (String) ((Wrapped) result).unwrap();
    }
    return (String) 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) Wrapped(org.kie.server.api.model.Wrapped) CommandScript(org.kie.server.api.commands.CommandScript)

Example 28 with Wrapped

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

the class CaseServicesClientImpl method getCaseInstanceData.

@Override
public Object getCaseInstanceData(String containerId, String caseId, String name) {
    Object result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        valuesMap.put(CASE_FILE_ITEM, name);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_FILE_BY_NAME_GET_URI, valuesMap), Object.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseService", "getCaseFileDataByName", marshaller.getFormat().getType(), new Object[] { containerId, caseId, name })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = deserialize(response.getResult(), Object.class);
    }
    if (result instanceof Wrapped) {
        return ((Wrapped) result).unwrap();
    }
    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) Wrapped(org.kie.server.api.model.Wrapped) CommandScript(org.kie.server.api.commands.CommandScript)

Example 29 with Wrapped

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

the class ProcessServicesClientImpl method getProcessInstanceVariables.

@Override
public Map<String, Object> getProcessInstanceVariables(String containerId, Long processInstanceId) {
    Object variables = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_INST_ID, processInstanceId);
        variables = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VARS_GET_URI, valuesMap), Object.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "getProcessInstanceVariables", marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        variables = deserialize(response.getResult(), Object.class);
    }
    if (variables instanceof Wrapped) {
        return (Map) ((Wrapped) variables).unwrap();
    }
    return (Map) variables;
}
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) Wrapped(org.kie.server.api.model.Wrapped) CommandScript(org.kie.server.api.commands.CommandScript) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with Wrapped

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

the class ProcessServicesClientImpl method startProcess.

@Override
public Long startProcess(String containerId, String processId, CorrelationKey correlationKey, Map<String, Object> variables) {
    Object result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(PROCESS_ID, processId);
        valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
        result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_WITH_CORRELATION_KEY_POST_URI, valuesMap), variables, Object.class);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "startProcessWithCorrelation", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[] { containerId, processId, correlationKey.toExternalForm() })));
        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(), Object.class);
    }
    if (result instanceof Wrapped) {
        return (Long) ((Wrapped) result).unwrap();
    }
    return ((Number) result).longValue();
}
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) Wrapped(org.kie.server.api.model.Wrapped) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

Wrapped (org.kie.server.api.model.Wrapped)36 ServiceResponse (org.kie.server.api.model.ServiceResponse)32 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)31 KieServerCommand (org.kie.server.api.model.KieServerCommand)31 HashMap (java.util.HashMap)27 CommandScript (org.kie.server.api.commands.CommandScript)27 ArrayList (java.util.ArrayList)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)5 List (java.util.List)4 Map (java.util.Map)4 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)4 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)4 VariableInstanceList (org.kie.server.api.model.instance.VariableInstanceList)4 Marshaller (org.kie.server.api.marshalling.Marshaller)3 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)3 ItemList (org.kie.server.api.model.ItemList)3 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)3 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)3 QueryDefinitionList (org.kie.server.api.model.definition.QueryDefinitionList)3