Search in sources :

Example 1 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, 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 2 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 builder, Map<String, Object> parameters, 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 + "&builder=" + builder, page, pageSize);
        result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_DEF_URI + "/" + RUN_FILTERED_QUERY_DEF_POST_URI, valuesMap) + queryString, parameters, resultTypeList);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryDataService", "queryFilteredWithBuilder", serialize(safeMap(parameters)), marshaller.getFormat().getType(), new Object[] { queryName, mapper, builder, 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 3 with Wrapped

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

the class UserTaskServicesClientImpl method getTaskOutputContentByTaskId.

@Override
public Map<String, Object> getTaskOutputContentByTaskId(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_OUTPUT_DATA_GET_URI, valuesMap), Object.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getTaskOutputContentByTaskId", 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 4 with Wrapped

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

the class UserTaskServicesClientImpl method addTaskComment.

@Override
public Long addTaskComment(String containerId, Long taskId, String text, String addedBy, Date addedOn) {
    Object commentId = null;
    TaskComment taskComment = TaskComment.builder().text(text).addedBy(addedBy).addedAt(addedOn).build();
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        commentId = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_COMMENT_ADD_POST_URI, valuesMap), taskComment, Object.class, getHeaders(taskComment));
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "addComment", serialize(taskComment), 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;
        }
        commentId = deserialize(response.getResult(), Object.class);
    }
    if (commentId instanceof Wrapped) {
        return (Long) ((Wrapped) commentId).unwrap();
    }
    return ((Number) commentId).longValue();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskComment(org.kie.server.api.model.instance.TaskComment) 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 5 with Wrapped

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

the class UserTaskServicesClientImpl method addTaskAttachment.

@Override
public Long addTaskAttachment(String containerId, Long taskId, String userId, String name, Object attachment) {
    Object attachmentId = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        attachmentId = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_ATTACHMENT_ADD_POST_URI, valuesMap) + getUserAndAdditionalParam(userId, "name", name), attachment, Object.class, getHeaders(null));
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "addAttachment", serialize(attachment), marshaller.getFormat().getType(), new Object[] { containerId, taskId, userId, name })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        attachmentId = deserialize(response.getResult(), Object.class);
    }
    if (attachmentId instanceof Wrapped) {
        return (Long) ((Wrapped) attachmentId).unwrap();
    }
    return ((Number) attachmentId).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