Search in sources :

Example 21 with Wrapped

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

the class ProcessServicesClientImpl method getProcessInstanceVariable.

@Override
public <T> T getProcessInstanceVariable(String containerId, Long processInstanceId, String variableName, Class<T> type) {
    Object 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);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_GET_URI, valuesMap), type);
    } else {
        CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "getProcessInstanceVariable", marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId, variableName })));
        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(), type);
    }
    if (result instanceof Wrapped) {
        return (T) ((Wrapped) result).unwrap();
    }
    return (T) 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 22 with Wrapped

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

the class QueryServicesClientImpl method query.

@Override
public <T> List<T> query(String queryName, String mapper, String orderBy, 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 + "&orderBy=" + orderBy, page, pageSize);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_DEF_URI + "/" + RUN_QUERY_DEF_GET_URI, valuesMap) + queryString, resultTypeList);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryDataService", "query", new Object[] { queryName, mapper, orderBy, 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 null;
}
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 23 with Wrapped

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

the class UserTaskServicesClientImpl method saveTaskContent.

@Override
public Long saveTaskContent(String containerId, Long taskId, String userId, Map<String, Object> values) {
    Object contentId = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        contentId = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_OUTPUT_DATA_PUT_URI, valuesMap) + getUserQueryStr(userId), values, Object.class, getHeaders(null));
    } else {
        Object[] params = null;
        if (userId != null) {
            params = new Object[] { containerId, userId, taskId };
        } else {
            params = new Object[] { containerId, taskId };
        }
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "saveContent", serialize(values), marshaller.getFormat().getType(), params)));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        contentId = deserialize(response.getResult(), Object.class);
    }
    if (contentId instanceof Wrapped) {
        return (Long) ((Wrapped) contentId).unwrap();
    }
    return ((Number) contentId).longValue();
}
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) Wrapped(org.kie.server.api.model.Wrapped)

Example 24 with Wrapped

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

the class UserTaskServicesClientImpl method getTaskInputContentByTaskId.

@Override
public Map<String, Object> getTaskInputContentByTaskId(String containerId, Long taskId) {
    Object variables = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        variables = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_INPUT_DATA_GET_URI, valuesMap), Object.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getTaskInputContentByTaskId", marshaller.getFormat().getType(), new Object[] { containerId, taskId })));
        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 25 with Wrapped

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

the class UserTaskServicesClientImpl method getTaskAttachmentContentById.

@Override
public Object getTaskAttachmentContentById(String containerId, Long taskId, Long attachmentId) {
    Object result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        valuesMap.put(ATTACHMENT_ID, attachmentId);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_ATTACHMENT_CONTENT_GET_URI, valuesMap), Object.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getAttachmentContentById", marshaller.getFormat().getType(), new Object[] { containerId, taskId, attachmentId })));
        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 ((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)

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