use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class UserTaskAdminServicesClientImpl method reassignWhenNotCompleted.
@Override
public Long reassignWhenNotCompleted(String containerId, Long taskId, String expiresAt, OrgEntities orgEntities) {
Object result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(TASK_INSTANCE_ID, taskId);
Map<String, String> headers = new HashMap<String, String>();
String queryString = "?expiresAt=" + expiresAt + "&whenNotCompleted=true";
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_TASK_URI + "/" + TASK_INSTANCE_REASSIGNMENTS_URI, valuesMap) + queryString, orgEntities, Object.class, headers);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskAdminService", "reassignWhenNotCompleted", serialize(orgEntities), marshaller.getFormat().getType(), new Object[] { containerId, taskId, expiresAt })));
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 ControllerUtils method unmarshal.
public static <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) {
if (data == null || data.isEmpty()) {
return null;
}
MarshallingFormat format = getFormat(marshallingFormat);
Marshaller marshaller = null;
switch(format) {
case JAXB:
{
marshaller = jaxbMarshaller;
break;
}
case JSON:
{
marshaller = jsonMarshaller;
break;
}
default:
{
marshaller = jsonMarshaller;
break;
}
}
Object instance = marshaller.unmarshall(data, unmarshalType);
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 DMNKieContainerCommandServiceImpl 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)) {
LOG.warn("Unsupported command '{}' given, will not process it", command.getClass().getName());
continue;
}
try {
ServiceResponse<?> result = null;
Object handler = null;
DescriptorCommand descriptorCommand = (DescriptorCommand) command;
// find out the handler to call to process given command
if ("DMNService".equals(descriptorCommand.getService())) {
handler = modelEvaluatorServiceBase;
} 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()) {
LOG.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg);
if (arg instanceof Wrapped) {
arg = ((Wrapped) arg).unwrap();
}
LOG.debug("After :: Argument with type {} and value {}", arg.getClass(), arg);
arguments.add(arg);
}
if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) {
arguments.add(descriptorCommand.getPayload());
}
if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) {
arguments.add(descriptorCommand.getMarshallerFormat());
}
LOG.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments);
// process command via reflection and handler
result = (ServiceResponse<?>) MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray());
LOG.debug("Handler {} returned response {}", handler, result);
// return successful result
responses.add(result);
} catch (InvocationTargetException e) {
responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage()));
} catch (Throwable e) {
LOG.error("Error while processing {} command", command, e);
// return failure result
responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
}
}
LOG.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 JBPMKieContainerCommandServiceImpl 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;
}
boolean wrapResults = false;
try {
Object result = null;
Object handler = null;
DescriptorCommand descriptorCommand = (DescriptorCommand) command;
// find out the handler to call to process given command
if ("DefinitionService".equals(descriptorCommand.getService())) {
handler = definitionServiceBase;
} else if ("ProcessService".equals(descriptorCommand.getService())) {
handler = processServiceBase;
} else if ("UserTaskService".equals(descriptorCommand.getService())) {
handler = userTaskServiceBase;
} else if ("QueryService".equals(descriptorCommand.getService())) {
handler = runtimeDataServiceBase;
} else if ("JobService".equals(descriptorCommand.getService())) {
handler = executorServiceBase;
} else if ("QueryDataService".equals(descriptorCommand.getService())) {
handler = queryDataServiceBase;
// enable wrapping as in case of embedded objects jaxb does not properly parse it due to possible unknown types (List<?> etc)
if (marshallingFormat.equals(MarshallingFormat.JAXB)) {
wrapResults = true;
}
} else if ("DocumentService".equals(descriptorCommand.getService())) {
handler = documentServiceBase;
} else if ("ProcessAdminService".equals(descriptorCommand.getService())) {
handler = processAdminServiceBase;
} else if ("UserTaskAdminService".equals(descriptorCommand.getService())) {
handler = userTaskAdminServiceBase;
} 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);
}
if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) {
arguments.add(descriptorCommand.getPayload());
}
if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) {
arguments.add(descriptorCommand.getMarshallerFormat());
}
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);
if (wrapResults) {
result = ModelWrapper.wrap(result);
logger.debug("Wrapped response is {}", result);
}
// return successful result
responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result));
} catch (InvocationTargetException e) {
logger.error("Error while processing {} command", command, 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 ProcessServicesClientImpl method startProcessFromNodeIds.
@Override
public Long startProcessFromNodeIds(String containerId, String processId, CorrelationKey correlationKey, Map<String, Object> variables, String... nodes) {
Object result = null;
ProcessStartSpec spec = new ProcessStartSpec();
spec.setVariables(variables);
spec.setNodeIds(Arrays.asList(nodes));
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(PROCESS_ID, processId);
valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_FROM_NODES_WITH_CORRELATION_KEY_POST_URI, valuesMap), spec, Object.class);
} else {
CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "startProcessWithCorrelationKeyFromNodeIds", serialize(spec), marshaller.getFormat().getType(), containerId, processId, correlationKey.toExternalForm())));
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();
}
Aggregations