use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class ExecutionService method getVariables.
@GET
@Path("/{executionId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariables(@PathParam("executionId") String executionId) {
String scope = uriInfo.getQueryParameters().getFirst("scope");
Execution execution = getExecutionFromRequest(executionId);
List<RestVariable> restVariableList = processVariables(execution, scope, RestResponseFactory.VARIABLE_EXECUTION, uriInfo);
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 SignalService method signalEventReceived.
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response signalEventReceived(SignalEventReceivedRequest signalRequest) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
if (signalRequest.getSignalName() == null) {
throw new ActivitiIllegalArgumentException("signalName is required");
}
Map<String, Object> signalVariables = null;
if (signalRequest.getVariables() != null) {
signalVariables = new HashMap<String, Object>();
for (RestVariable variable : signalRequest.getVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required.");
}
signalVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
if (signalRequest.isAsync()) {
if (signalVariables != null) {
throw new ActivitiIllegalArgumentException("Async signals cannot take variables as payload");
}
if (signalRequest.isCustomTenantSet()) {
runtimeService.signalEventReceivedAsyncWithTenantId(signalRequest.getSignalName(), signalRequest.getTenantId());
} else {
runtimeService.signalEventReceivedAsync(signalRequest.getSignalName());
}
return Response.ok().status(Response.Status.ACCEPTED).build();
} else {
if (signalRequest.isCustomTenantSet()) {
runtimeService.signalEventReceivedWithTenantId(signalRequest.getSignalName(), signalVariables, signalRequest.getTenantId());
} else {
runtimeService.signalEventReceived(signalRequest.getSignalName(), signalVariables);
}
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class WorkflowTaskService method completeTask.
protected void completeTask(Task task, TaskActionRequest actionRequest, TaskService taskService) {
if (actionRequest.getVariables() != null) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
RestResponseFactory restResponseFactory = new RestResponseFactory();
for (RestVariable var : actionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
taskService.complete(task.getId(), variablesToSet);
} else {
taskService.complete(task.getId());
}
}
use of org.wso2.carbon.bpmn.rest.engine.variable.RestVariable in project carbon-business-process by wso2.
the class WorkflowTaskService method updateTaskVariable.
@PUT
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateTaskVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName, @Context HttpServletRequest httpServletRequest) {
Task task = getTaskFromRequest(taskId);
RestVariable restVariable = null;
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
try {
restVariable = new ObjectMapper().readValue(httpServletRequest.getInputStream(), RestVariable.class);
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Error converting request body to RestVariable instance", e);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(RestVariable.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
restVariable = (RestVariable) jaxbUnmarshaller.unmarshal(getXMLReader(httpServletRequest.getInputStream()));
} catch (JAXBException | IOException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "Rest Variable 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.");
}
RestVariable result = setSimpleVariable(restVariable, task, false);
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 WorkflowTaskService method updateBinaryTaskVariable.
@PUT
@Path("/{taskId}/variables/{variableName}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateBinaryTaskVariable(@PathParam("taskId") String taskId, @PathParam("variableName") String variableName, MultipartBody multipartBody) {
Task task = getTaskFromRequest(taskId);
RestVariable result = null;
try {
result = setBinaryVariable(multipartBody, task, false, uriInfo);
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("Error Reading variable attachment", e);
}
if (result != null) {
if (!result.getName().equals(variableName)) {
throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
}
}
return Response.ok().entity(result).build();
}
Aggregations