Search in sources :

Example 16 with ServiceResponse

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

the class UserTaskServicesClientImpl method completeTask.

@Override
public void completeTask(String containerId, Long taskId, String userId, Map<String, Object> params) {
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_COMPLETE_PUT_URI, valuesMap) + getUserQueryStr(userId), params, String.class, getHeaders(null));
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "complete", serialize(safeMap(params)), marshaller.getFormat().getType(), new Object[] { containerId, taskId, userId })));
        ServiceResponse<Object> response = (ServiceResponse<Object>) 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)

Example 17 with ServiceResponse

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

the class UserTaskServicesClientImpl method findTasksByVariable.

@Override
public List<TaskSummary> findTasksByVariable(String userId, String variableName, List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    TaskSummaryList result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(VAR_NAME, variableName);
        String userQuery = getUserQueryStr(userId);
        String statusQuery = getAdditionalParams(userQuery, "status", status);
        String queryString = getPagingQueryString(statusQuery, page, pageSize) + "&sort=" + sort + "&sortOrder=" + sortOrder;
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + TASKS_BY_VAR_NAME_GET_URI, valuesMap) + queryString, TaskSummaryList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getTasksByVariables", new Object[] { userId, variableName, "", safeList(status), page, pageSize, sort, sortOrder })));
        ServiceResponse<TaskSummaryList> response = (ServiceResponse<TaskSummaryList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    if (result != null && result.getTasks() != null) {
        return Arrays.asList(result.getTasks());
    }
    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) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList)

Example 18 with ServiceResponse

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

the class UserTaskServicesClientImpl method getTaskCommentsByTaskId.

@Override
public List<TaskComment> getTaskCommentsByTaskId(String containerId, Long taskId) {
    TaskCommentList commentList = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        commentList = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_COMMENTS_GET_URI, valuesMap), TaskCommentList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getCommentsByTaskId", 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;
        }
        commentList = deserialize(response.getResult(), TaskCommentList.class);
    }
    if (commentList.getTasks() != null) {
        return Arrays.asList(commentList.getTasks());
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) TaskCommentList(org.kie.server.api.model.instance.TaskCommentList) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 19 with ServiceResponse

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

the class UserTaskServicesClientImpl method findTasksAssignedAsBusinessAdministrator.

@Override
public List<TaskSummary> findTasksAssignedAsBusinessAdministrator(String userId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    TaskSummaryList taskSummaryList = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        String queryString = getUserAndPagingQueryString(userId, page, pageSize) + "&sort=" + sort + "&sortOrder=" + sortOrder;
        taskSummaryList = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + TASKS_ASSIGN_BUSINESS_ADMINS_GET_URI, valuesMap) + queryString, TaskSummaryList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getTasksAssignedAsBusinessAdministratorByStatus", new Object[] { new ArrayList(), userId, page, pageSize, sort, sortOrder })));
        ServiceResponse<TaskSummaryList> response = (ServiceResponse<TaskSummaryList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        taskSummaryList = response.getResult();
    }
    if (taskSummaryList != null && taskSummaryList.getTasks() != null) {
        return Arrays.asList(taskSummaryList.getTasks());
    }
    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) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList)

Example 20 with ServiceResponse

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

the class RemoteBusinessRuleTaskHandler method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> parameters = new HashMap<>(workItem.getParameters());
    String containerId = (String) parameters.remove("ContainerId");
    if (containerId == null || containerId.isEmpty()) {
        throw new IllegalArgumentException("Container ID is required for remote BusinessRuleTask");
    }
    String language = (String) parameters.remove("Language");
    if (language == null) {
        language = DRL_LANG;
    }
    String kieSessionName = (String) parameters.remove("KieSessionName");
    // remove engine specific parameters
    parameters.remove("TaskName");
    parameters.remove("KieSessionType");
    Map<String, Object> results = new HashMap<>();
    logger.debug("Facts to be inserted into working memory {}", parameters);
    if (DRL_LANG.equalsIgnoreCase(language)) {
        RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
        List<Command<?>> commands = new ArrayList<Command<?>>();
        BatchExecutionCommand executionCommand = commandsFactory.newBatchExecution(commands, kieSessionName);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            String inputKey = workItem.getId() + "_" + entry.getKey();
            commands.add(commandsFactory.newInsert(entry.getValue(), inputKey, true, null));
        }
        commands.add(commandsFactory.newFireAllRules("Fired"));
        ServiceResponse<ExecutionResults> reply = ruleClient.executeCommandsWithResults(containerId, executionCommand);
        if (ServiceResponse.ResponseType.FAILURE.equals(reply.getType())) {
            throw new KieServicesException(reply.getMsg());
        }
        ExecutionResults executionResults = reply.getResult();
        logger.debug("{} rules fired", executionResults.getValue("Fired"));
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            String inputKey = workItem.getId() + "_" + entry.getKey();
            String key = entry.getKey().replaceAll(workItem.getId() + "_", "");
            results.put(key, executionResults.getValue(inputKey));
        }
    } else if (DMN_LANG.equalsIgnoreCase(language)) {
        String namespace = (String) parameters.remove("Namespace");
        String model = (String) parameters.remove("Model");
        String decision = (String) parameters.remove("Decision");
        DMNServicesClient dmnClient = client.getServicesClient(DMNServicesClient.class);
        DMNContext dmnContext = dmnClient.newContext();
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            dmnContext.set(entry.getKey(), entry.getValue());
        }
        ServiceResponse<DMNResult> evaluationResult = null;
        if (decision != null) {
            evaluationResult = dmnClient.evaluateDecisionByName(containerId, namespace, model, decision, dmnContext);
        } else {
            evaluationResult = dmnClient.evaluateAll(containerId, namespace, model, dmnContext);
        }
        DMNResult dmnResult = evaluationResult.getResult();
        results.putAll(dmnResult.getContext().getAll());
    } else {
        throw new IllegalArgumentException("Not supported language type " + language);
    }
    logger.debug("Facts retrieved from working memory {}", results);
    workItemManager.completeWorkItem(workItem.getId(), results);
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNServicesClient(org.kie.server.client.DMNServicesClient) HashMap(java.util.HashMap) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) DMNContext(org.kie.dmn.api.core.DMNContext) RuleServicesClient(org.kie.server.client.RuleServicesClient) ServiceResponse(org.kie.server.api.model.ServiceResponse) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException)

Aggregations

ServiceResponse (org.kie.server.api.model.ServiceResponse)315 CommandScript (org.kie.server.api.commands.CommandScript)269 KieServerCommand (org.kie.server.api.model.KieServerCommand)261 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)234 HashMap (java.util.HashMap)224 ArrayList (java.util.ArrayList)41 Wrapped (org.kie.server.api.model.Wrapped)32 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)23 KieContainerResource (org.kie.server.api.model.KieContainerResource)18 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 TaskSummaryList (org.kie.server.api.model.instance.TaskSummaryList)17 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)15 Map (java.util.Map)13 Message (org.kie.server.api.model.Message)13 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 Test (org.junit.Test)11 List (java.util.List)9 ReleaseId (org.kie.server.api.model.ReleaseId)9 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)9 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)8