use of org.kie.server.api.model.Wrapped 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.Wrapped in project droolsjbpm-integration by kiegroup.
the class MarshallerHelper method unmarshal.
public <T> T unmarshal(String containerId, String data, String marshallingFormat, Class<T> unmarshalType, ContainerLocator locator) {
if (data == null || data.isEmpty()) {
return null;
}
MarshallingFormat format = getFormat(marshallingFormat);
KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
if (containerInstance == null || format == null) {
throw new IllegalArgumentException("No container found for id " + containerId + " or unknown marshalling format " + marshallingFormat);
}
Marshaller marshaller = containerInstance.getMarshaller(format);
if (marshaller == null) {
throw new IllegalArgumentException("No marshaller found for format " + format);
}
Object instance = marshaller.unmarshall(data, unmarshalType, MarshallingFormat.buildParameters(marshallingFormat));
if (instance instanceof Wrapped) {
return (T) ((Wrapped) instance).unwrap();
}
return (T) instance;
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class ProcessServicesClientImpl method startProcess.
@Override
public Long startProcess(String containerId, String processId, Map<String, Object> variables) {
Object result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(PROCESS_ID, processId);
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap), variables, Object.class);
} else {
CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "startProcess", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[] { containerId, processId })));
ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = deserialize(response.getResult(), Object.class);
}
if (result instanceof Wrapped) {
return (Long) ((Wrapped) result).unwrap();
}
return ((Number) result).longValue();
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class ProcessServicesClientImpl method getAvailableSignals.
@Override
public List<String> getAvailableSignals(String containerId, Long processInstanceId) {
Object signals = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(PROCESS_INST_ID, processInstanceId);
signals = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_SIGNALS_GET_URI, valuesMap), Object.class);
} else {
CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "getAvailableSignals", marshaller.getFormat().getType(), new Object[] { containerId, processInstanceId })));
ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
signals = deserialize(response.getResult(), Object.class);
}
if (signals instanceof Wrapped) {
return (List<String>) ((Wrapped) signals).unwrap();
}
return (List<String>) signals;
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class DocumentServicesClientImpl method createDocument.
@Override
public String createDocument(DocumentInstance documentInstance) {
Object result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), DOCUMENT_URI, valuesMap), documentInstance, Object.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("DocumentService", "storeDocument", serialize(documentInstance), marshaller.getFormat().getType(), new Object[] {})));
ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
if (result instanceof Wrapped) {
return (String) ((Wrapped) result).unwrap();
}
return (String) result;
}
Aggregations