Search in sources :

Example 46 with DescriptorCommand

use of org.kie.server.api.commands.DescriptorCommand 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 47 with DescriptorCommand

use of org.kie.server.api.commands.DescriptorCommand 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 48 with DescriptorCommand

use of org.kie.server.api.commands.DescriptorCommand in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerControllerClientTest method verifyServiceMethods.

private void verifyServiceMethods(final Class service) throws Exception {
    final String name = service.getName();
    final Method[] methods = service.getMethods();
    for (int i = 0; i < methods.length; i++) {
        final Method m = methods[i];
        MethodUtils.invokeMethod(controllerClient, m.getName(), new Object[m.getParameterCount()]);
        ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(String.class);
        verify(client).sendTextWithInternalHandler(contentCaptor.capture(), any(InternalMessageHandler.class));
        final DescriptorCommand command = WebSocketUtils.unmarshal(contentCaptor.getValue(), DescriptorCommand.class);
        assertNotNull(command);
        assertEquals(name, command.getService());
        assertEquals(m.getName(), command.getMethod());
        reset(client);
    }
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) Method(java.lang.reflect.Method) InternalMessageHandler(org.kie.server.controller.websocket.common.handlers.InternalMessageHandler)

Example 49 with DescriptorCommand

use of org.kie.server.api.commands.DescriptorCommand in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerControllerClientTest method checkUpdateContainerSpec.

private void checkUpdateContainerSpec(boolean expected) throws IOException {
    verify(controllerClient).updateContainerSpec(eq(SERVER_TEMPLATE_ID), eq(CONTAINER_ID), any(ContainerSpec.class), eq(expected));
    ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(String.class);
    verify(client).sendTextWithInternalHandler(contentCaptor.capture(), any(InternalMessageHandler.class));
    final DescriptorCommand command = WebSocketUtils.unmarshal(contentCaptor.getValue(), DescriptorCommand.class);
    assertNotNull(command);
    assertEquals(UPDATE_CONTAINER_SPEC_METHOD, command.getMethod());
    assertEquals(4, command.getArguments().size());
    assertEquals(SERVER_TEMPLATE_ID, command.getArguments().get(0));
    assertEquals(CONTAINER_ID, command.getArguments().get(1));
    assertEquals(expected, command.getArguments().get(3));
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) InternalMessageHandler(org.kie.server.controller.websocket.common.handlers.InternalMessageHandler)

Example 50 with DescriptorCommand

use of org.kie.server.api.commands.DescriptorCommand in project droolsjbpm-integration by kiegroup.

the class JBPMUIKieContainerCommandServiceImpl method executeScript.

@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
    List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
    for (KieServerCommand command : commands.getCommands()) {
        if (!(command instanceof DescriptorCommand)) {
            logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName());
            continue;
        }
        try {
            Object result = null;
            Object handler = null;
            DescriptorCommand descriptorCommand = (DescriptorCommand) command;
            // find out the handler to call to process given command
            if ("FormService".equals(descriptorCommand.getService())) {
                handler = formServiceBase;
            } else if ("ImageService".equals(descriptorCommand.getService())) {
                handler = imageServiceBase;
            } else if ("FormRendererService".equals(descriptorCommand.getService())) {
                handler = formRendererBase;
            } else {
                throw new IllegalStateException("Unable to find handler for " + descriptorCommand.getService() + " service");
            }
            List<Object> arguments = new ArrayList();
            // process and unwrap arguments
            for (Object arg : descriptorCommand.getArguments()) {
                logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg);
                if (arg instanceof Wrapped) {
                    arg = ((Wrapped) arg).unwrap();
                }
                logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg);
                arguments.add(arg);
            }
            logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments);
            // process command via reflection and handler
            result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray());
            logger.debug("Handler {} returned response {}", handler, result);
            // return successful result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result));
        } catch (InvocationTargetException e) {
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage()));
        } catch (Throwable e) {
            logger.error("Error while processing {} command", command, e);
            // return failure result
            responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
        }
    }
    logger.debug("About to return responses '{}'", responses);
    return new ServiceResponsesList(responses);
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) Wrapped(org.kie.server.api.model.Wrapped) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)238 KieServerCommand (org.kie.server.api.model.KieServerCommand)234 ServiceResponse (org.kie.server.api.model.ServiceResponse)234 CommandScript (org.kie.server.api.commands.CommandScript)232 HashMap (java.util.HashMap)218 Wrapped (org.kie.server.api.model.Wrapped)31 ArrayList (java.util.ArrayList)24 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)18 TaskSummaryList (org.kie.server.api.model.instance.TaskSummaryList)16 NodeInstanceList (org.kie.server.api.model.instance.NodeInstanceList)14 ExecutionErrorInstanceList (org.kie.server.api.model.admin.ExecutionErrorInstanceList)8 ProcessDefinitionList (org.kie.server.api.model.definition.ProcessDefinitionList)8 VariableInstanceList (org.kie.server.api.model.instance.VariableInstanceList)8 RequestInfoInstanceList (org.kie.server.api.model.instance.RequestInfoInstanceList)7 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)6 Map (java.util.Map)5 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 List (java.util.List)4 QueryDefinitionList (org.kie.server.api.model.definition.QueryDefinitionList)4