use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class BlockingResponseCallback method get.
@Override
public <T> T get(Class<T> type) {
if (marshaller == null) {
throw new IllegalStateException("No marshaller given, can't use get(Class) to return response");
}
ServiceResponsesList responsesList = get();
if (responsesList.getResponses() == null || responsesList.getResponses().isEmpty()) {
logger.debug("No data found in the response, returning null");
return null;
}
ServiceResponse response = responsesList.getResponses().get(0);
if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) {
Object result = response.getResult();
if (result instanceof String) {
logger.debug("Response '{}' of type string, unmarshalling it...", result);
result = marshaller.unmarshall((String) result, type);
logger.debug("Result after unmarshall operation {}", result);
}
// handle wrapped objects
if (result instanceof Wrapped) {
result = ((Wrapped) result).unwrap();
}
return (T) result;
} else {
logger.debug("Non successful response '{}', returning null", response.getMsg());
return null;
}
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class CaseServicesClientImpl method startCase.
@Override
public String startCase(String containerId, String caseDefinitionId, CaseFile caseFile) {
Object result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(CASE_DEF_ID, caseDefinitionId);
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + START_CASE_POST_URI, valuesMap), caseFile, String.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseService", "startCase", serialize(caseFile), marshaller.getFormat().getType(), new Object[] { containerId, caseDefinitionId })));
ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = deserialize(response.getResult(), Object.class);
}
if (result instanceof Wrapped) {
return (String) ((Wrapped) result).unwrap();
}
return (String) result;
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class CaseServicesClientImpl method getCaseInstanceData.
@Override
public Object getCaseInstanceData(String containerId, String caseId, String name) {
Object result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(CASE_ID, caseId);
valuesMap.put(CASE_FILE_ITEM, name);
result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_FILE_BY_NAME_GET_URI, valuesMap), Object.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseService", "getCaseFileDataByName", marshaller.getFormat().getType(), new Object[] { containerId, caseId, name })));
ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = deserialize(response.getResult(), Object.class);
}
if (result instanceof Wrapped) {
return ((Wrapped) result).unwrap();
}
return result;
}
use of org.kie.server.api.model.Wrapped in project droolsjbpm-integration by kiegroup.
the class ProcessServicesClientImpl method getProcessInstanceVariables.
@Override
public Map<String, Object> getProcessInstanceVariables(String containerId, Long processInstanceId) {
Object variables = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(CONTAINER_ID, containerId);
valuesMap.put(PROCESS_INST_ID, processInstanceId);
variables = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VARS_GET_URI, valuesMap), Object.class);
} else {
CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "getProcessInstanceVariables", 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;
}
variables = deserialize(response.getResult(), Object.class);
}
if (variables instanceof Wrapped) {
return (Map) ((Wrapped) variables).unwrap();
}
return (Map) variables;
}
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, CorrelationKey correlationKey, 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);
valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm());
result = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_WITH_CORRELATION_KEY_POST_URI, valuesMap), variables, Object.class);
} else {
CommandScript script = new CommandScript(singletonList((KieServerCommand) new DescriptorCommand("ProcessService", "startProcessWithCorrelation", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[] { 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