use of org.kie.server.api.model.KieServerCommand 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;
}
use of org.kie.server.api.model.KieServerCommand 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.model.KieServerCommand 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.model.KieServerCommand 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);
}
use of org.kie.server.api.model.KieServerCommand in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testManagementDisabledConfiguredViaCommandService.
@Test
public void testManagementDisabledConfiguredViaCommandService() {
System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
try {
kieServer.destroy();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
kieServer.init();
KieContainerCommandServiceImpl commandService = new KieContainerCommandServiceImpl(kieServer, kieServer.getServerRegistry());
List<KieServerCommand> commands = new ArrayList<>();
commands.add(new CreateContainerCommand());
commands.add(new DisposeContainerCommand());
commands.add(new UpdateScannerCommand());
commands.add(new UpdateReleaseIdCommand());
CommandScript commandScript = new CommandScript(commands);
ServiceResponsesList responseList = commandService.executeScript(commandScript, MarshallingFormat.JAXB, null);
assertNotNull(responseList);
List<ServiceResponse<?>> responses = responseList.getResponses();
assertEquals(4, responses.size());
for (ServiceResponse<?> forbidden : responses) {
assertForbiddenResponse(forbidden);
}
} finally {
System.clearProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED);
}
}
Aggregations