use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ProcessInstanceService method updateBinaryVariable.
@PUT
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateBinaryVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName, MultipartBody multipartBody) {
Execution execution = getExecutionInstanceFromRequest(processInstanceId);
RestVariable result;
try {
result = setBinaryVariable(multipartBody, execution, RestResponseFactory.VARIABLE_PROCESS, false);
} catch (IOException | ServletException e) {
throw new BPMNRestException("Exception occured during creating binary execution variable", e);
}
return Response.ok().entity(result).build();
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ProcessInstanceService method updateVariable.
@PUT
@Path("/{processInstanceId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public RestVariable updateVariable(@PathParam("processInstanceId") String processInstanceId, @PathParam("variableName") String variableName, @Context HttpServletRequest httpServletRequest) {
Execution execution = getExecutionInstanceFromRequest(processInstanceId);
RestVariable restVariable = null;
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
try {
restVariable = new ObjectMapper().readValue(httpServletRequest.getInputStream(), RestVariable.class);
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("request body could not be transformed to a RestVariable " + "instance.", e);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext;
try {
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(httpServletRequest.getInputStream()));
jaxbContext = JAXBContext.newInstance(RestVariable.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
restVariable = (RestVariable) jaxbUnmarshaller.unmarshal(xsr);
} catch (JAXBException | IOException | XMLStreamException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable " + "instance.", e);
}
}
if (restVariable == null) {
throw new ActivitiException("Invalid body was supplied");
}
if (!restVariable.getName().equals(variableName)) {
throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
}
return setSimpleVariable(restVariable, execution, false);
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ProcessInstanceService method performCorrelation.
private Response performCorrelation(ProcessInstanceCreateRequest processInstanceCreateRequest) {
CorrelationActionRequest correlationActionRequest = new CorrelationActionRequest();
String requestValue = processInstanceCreateRequest.getProcessDefinitionId();
if (requestValue != null) {
correlationActionRequest.setProcessDefinitionId(processInstanceCreateRequest.getProcessDefinitionId());
}
requestValue = processInstanceCreateRequest.getProcessDefinitionKey();
if (requestValue != null) {
correlationActionRequest.setProcessDefinitionKey(requestValue);
}
if (processInstanceCreateRequest.isCustomTenantSet()) {
correlationActionRequest.setTenantId(processInstanceCreateRequest.getTenantId());
}
requestValue = processInstanceCreateRequest.getMessageName();
if (requestValue != null) {
correlationActionRequest.setMessageName(requestValue);
}
List<RestVariable> variables = processInstanceCreateRequest.getVariables();
if (variables != null) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
List<QueryVariable> correlationVariableList = new ArrayList<>();
for (RestVariable variable : variables) {
QueryVariable correlationVariable = new QueryVariable();
correlationVariable.setName(variable.getName());
correlationVariable.setOperation("equals");
correlationVariable.setType(variable.getType());
correlationVariable.setValue(restResponseFactory.getVariableValue(variable));
correlationVariableList.add(correlationVariable);
}
correlationActionRequest.setCorrelationVariables(correlationVariableList);
}
variables = processInstanceCreateRequest.getAdditionalVariables();
if (variables != null) {
correlationActionRequest.setVariables(variables);
}
correlationActionRequest.setAction(CorrelationActionRequest.ACTION_MESSAGE_EVENT_RECEIVED);
return new CorrelationProcess().getQueryResponse(correlationActionRequest, uriInfo);
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ProcessInstanceService method getVariables.
@GET
@Path("/{processInstanceId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariables(@PathParam("processInstanceId") String processInstanceId) {
String scope = uriInfo.getQueryParameters().getFirst("scope");
Execution execution = getExecutionInstanceFromRequest(processInstanceId);
List<RestVariable> restVariableList = processVariables(execution, scope, RestResponseFactory.VARIABLE_PROCESS);
RestVariableCollection restVariableCollection = new RestVariableCollection();
restVariableCollection.setRestVariables(restVariableList);
return Response.ok().entity(restVariableCollection).build();
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class RestResponseFactory method createRestVariable.
/*public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope,
String id, int variableType, boolean includeBinaryValue, String baseUri){
return createRestVariable(name, value, scope, id, variableType, includeBinaryValue, baseUri);
}*/
public RestVariable createRestVariable(String name, Object value, RestVariable.RestVariableScope scope, String id, int variableType, boolean includeBinaryValue, String baseUri) {
RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
RestVariableConverter converter = null;
RestVariable restVar = new RestVariable();
restVar.setVariableScope(scope);
restVar.setName(name);
if (value != null) {
// Try converting the value
for (RestVariableConverter c : variableConverters) {
if (c.getVariableType().isAssignableFrom(value.getClass())) {
converter = c;
break;
}
}
if (converter != null) {
converter.convertVariableValue(value, restVar);
restVar.setType(converter.getRestTypeName());
} else {
// Revert to default conversion, which is the serializable/byte-array form
if (value instanceof Byte[] || value instanceof byte[]) {
restVar.setType(BYTE_ARRAY_VARIABLE_TYPE);
} else {
restVar.setType(SERIALIZABLE_VARIABLE_TYPE);
}
if (includeBinaryValue) {
restVar.setValue(value);
}
if (variableType == VARIABLE_TASK) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_EXECUTION) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_PROCESS) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_TASK) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_PROCESS) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_VARINSTANCE) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_VARIABLE_INSTANCE_DATA, id));
} else if (variableType == VARIABLE_HISTORY_DETAIL) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_DETAIL_VARIABLE_DATA, id));
}
}
}
return restVar;
}
Aggregations