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();
}
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();
}
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);
}
}
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));
}
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);
}
Aggregations