Search in sources :

Example 51 with ServiceResponse

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

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

the class UserTaskServicesClientImpl method getTaskAttachmentById.

@Override
public TaskAttachment getTaskAttachmentById(String containerId, Long taskId, Long attachmentId) {
    TaskAttachment attachment = 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);
        attachment = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_ATTACHMENT_GET_URI, valuesMap), TaskAttachment.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getAttachmentById", 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;
        }
        attachment = deserialize(response.getResult(), TaskAttachment.class);
    }
    return attachment;
}
Also used : TaskAttachment(org.kie.server.api.model.instance.TaskAttachment) 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 53 with ServiceResponse

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

the class UserTaskServicesClientImpl method findTasks.

@Override
public List<TaskSummary> findTasks(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_GET_URI, valuesMap) + queryString, TaskSummaryList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getAllAuditTask", new Object[] { 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) CommandScript(org.kie.server.api.commands.CommandScript) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList)

Example 54 with ServiceResponse

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

Example 55 with ServiceResponse

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

the class DecisionMarshallingTest method testMarshalling.

@Test
public void testMarshalling() {
    KieSession kieSession = new KieHelper().addFromClassPath("/FunctionDefinition.dmn").build().newKieSession();
    DMNRuntime dmnRuntime = kieSession.getKieRuntime(DMNRuntime.class);
    DMNModel model = dmnRuntime.getModels().get(0);
    DMNContext realCtx = dmnRuntime.newContext();
    realCtx.set("a", 10);
    realCtx.set("b", 5);
    DMNContextKS dmnClientRequest = new DMNContextKS(realCtx.getAll());
    DMNContextKS mu_dmnClientRequest = marshallUnmarshall(dmnClientRequest);
    assertEquals(dmnClientRequest.getNamespace(), mu_dmnClientRequest.getNamespace());
    assertEquals(dmnClientRequest.getModelName(), mu_dmnClientRequest.getModelName());
    assertThat(dmnClientRequest.getDecisionNames(), is(mu_dmnClientRequest.getDecisionNames()));
    assertEquals(dmnClientRequest.getDmnContext().size(), mu_dmnClientRequest.getDmnContext().size());
    assertEquals(dmnClientRequest.getDmnContext().keySet(), mu_dmnClientRequest.getDmnContext().keySet());
    DMNResult evaluateAll = dmnRuntime.evaluateAll(model, realCtx);
    ServiceResponse<DMNResultKS> dmnClientResponse = new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.SUCCESS, "Test case", new DMNResultKS(model.getNamespace(), model.getName(), dmnClientRequest.getDecisionNames(), evaluateAll));
    ServiceResponse<DMNResultKS> mu_dmnClientResponse = marshallUnmarshall(dmnClientResponse);
    assertEquals(dmnClientResponse.getResult().getNamespace(), mu_dmnClientResponse.getResult().getNamespace());
    assertEquals(dmnClientResponse.getResult().getModelName(), mu_dmnClientResponse.getResult().getModelName());
    assertThat(dmnClientResponse.getResult().getDecisionNames(), is(mu_dmnClientResponse.getResult().getDecisionNames()));
    assertEquals(dmnClientResponse.getResult().getDmnContext().size(), mu_dmnClientResponse.getResult().getDmnContext().size());
    assertEquals(dmnClientResponse.getResult().getDmnContext().keySet(), mu_dmnClientResponse.getResult().getDmnContext().keySet());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) ServiceResponse(org.kie.server.api.model.ServiceResponse) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) DMNResultKS(org.kie.server.api.model.dmn.DMNResultKS) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS) Test(org.junit.Test)

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