use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class ProcessInstanceService method addLocalVariables.
protected void addLocalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
Map<String, Object> rawLocalvariables = runtimeService.getVariablesLocal(execution.getId());
List<RestVariable> localVariables = new RestResponseFactory().createRestVariables(rawLocalvariables, execution.getId(), variableType, RestVariable.RestVariableScope.LOCAL, uriInfo.getBaseUri().toString());
for (RestVariable var : localVariables) {
variableMap.put(var.getName(), var);
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class ProcessInstanceService method setSimpleVariable.
protected RestVariable setSimpleVariable(RestVariable restVariable, Execution execution, boolean isNew) {
if (restVariable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
// Figure out scope, revert to local is omitted
RestVariable.RestVariableScope scope = restVariable.getVariableScope();
if (scope == null) {
scope = RestVariable.RestVariableScope.LOCAL;
}
Object actualVariableValue = new RestResponseFactory().getVariableValue(restVariable);
setVariable(execution, restVariable.getName(), actualVariableValue, scope, isNew);
return constructRestVariable(restVariable.getName(), actualVariableValue, scope, execution.getId(), false);
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class ProcessInstanceService method getIdentityLinK.
@GET
@Path("/{processInstanceId}/identitylinks/users/{identityId}/{type}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLinK(@PathParam("processInstanceId") String processInstanceId, @PathParam("identityId") String identityId, @PathParam("type") String type) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
validateIdentityLinkArguments(identityId, type);
IdentityLink link = getIdentityLink(identityId, type, processInstance.getId());
return Response.ok().entity(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString())).build();
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class ModelService method getModels.
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
// Apply filters
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
ModelQuery modelQuery = repositoryService.createModelQuery();
String id = uriInfo.getQueryParameters().getFirst("id");
if (id != null) {
modelQuery.modelId(id);
}
String category = uriInfo.getQueryParameters().getFirst("category");
if (category != null) {
modelQuery.modelCategory(category);
}
String categoryLike = uriInfo.getQueryParameters().getFirst("categoryLike");
if (categoryLike != null) {
modelQuery.modelCategoryLike(categoryLike);
}
String categoryNotEquals = uriInfo.getQueryParameters().getFirst("categoryNotEquals");
if (categoryNotEquals != null) {
modelQuery.modelCategoryNotEquals(categoryNotEquals);
}
String name = uriInfo.getQueryParameters().getFirst("name");
if (name != null) {
modelQuery.modelName(name);
}
String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
if (nameLike != null) {
modelQuery.modelNameLike(nameLike);
}
String key = uriInfo.getQueryParameters().getFirst("key");
if (key != null) {
modelQuery.modelKey(key);
}
String version = uriInfo.getQueryParameters().getFirst("version");
if (version != null) {
modelQuery.modelVersion(Integer.valueOf(version));
}
String latestVersion = uriInfo.getQueryParameters().getFirst("latestVersion");
if (latestVersion != null) {
boolean isLatestVersion = Boolean.valueOf(latestVersion);
if (isLatestVersion) {
modelQuery.latestVersion();
}
}
String deploymentId = uriInfo.getQueryParameters().getFirst("deploymentId");
if (deploymentId != null) {
modelQuery.deploymentId(deploymentId);
}
String deployed = uriInfo.getQueryParameters().getFirst("deployed");
if (deployed != null) {
boolean isDeployed = Boolean.valueOf(deployed);
if (isDeployed) {
modelQuery.deployed();
} else {
modelQuery.notDeployed();
}
}
String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
if (tenantId != null) {
modelQuery.modelTenantId(tenantId);
}
String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
if (tenantIdLike != null) {
modelQuery.modelTenantIdLike(tenantIdLike);
}
String sWithoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
if (sWithoutTenantId != null) {
boolean withoutTenantId = Boolean.valueOf(sWithoutTenantId);
if (withoutTenantId) {
modelQuery.modelWithoutTenantId();
}
}
DataResponse response = new ModelsPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, modelQuery, "id", allowedSortProperties);
List<ModelResponse> modelResponseList = (List<ModelResponse>) response.getData();
if (log.isDebugEnabled()) {
log.debug("modelResponseList: " + modelResponseList.size());
}
return Response.ok().entity(response).build();
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class WorkflowTaskService method createTaskVariable.
@POST
@Path("/{taskId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createTaskVariable(@PathParam("taskId") String taskId, @Context HttpServletRequest httpServletRequest) {
Task task = getTaskFromRequest(taskId);
List<RestVariable> inputVariables = new ArrayList<>();
List<RestVariable> resultVariables = new ArrayList<>();
Response.ResponseBuilder responseBuilder = Response.ok();
try {
if (Utils.isApplicationJsonRequest(httpServletRequest)) {
try {
@SuppressWarnings("unchecked") List<Object> variableObjects = (List<Object>) new ObjectMapper().readValue(httpServletRequest.getInputStream(), List.class);
for (Object restObject : variableObjects) {
RestVariable restVariable = new ObjectMapper().convertValue(restObject, RestVariable.class);
inputVariables.add(restVariable);
}
} catch (IOException e) {
throw new ActivitiIllegalArgumentException("request body could not be transformed to a RestVariable " + "instance.", e);
}
} else if (Utils.isApplicationXmlRequest(httpServletRequest)) {
JAXBContext jaxbContext = null;
try {
jaxbContext = JAXBContext.newInstance(RestVariableCollection.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
RestVariableCollection restVariableCollection = (RestVariableCollection) jaxbUnmarshaller.unmarshal(getXMLReader(httpServletRequest.getInputStream()));
if (restVariableCollection == null) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable Collection instance.");
}
List<RestVariable> restVariableList = restVariableCollection.getRestVariables();
if (restVariableList.size() == 0) {
throw new ActivitiIllegalArgumentException("xml request body could not identify any rest " + "variables to be updated");
}
for (RestVariable restVariable : restVariableList) {
inputVariables.add(restVariable);
}
} catch (JAXBException | IOException e) {
throw new ActivitiIllegalArgumentException("xml request body could not be transformed to a " + "RestVariable instance.", e);
}
}
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
}
if (inputVariables.size() == 0) {
throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
}
RestVariable.RestVariableScope sharedScope = null;
RestVariable.RestVariableScope varScope = null;
Map<String, Object> variablesToSet = new HashMap<>();
RestResponseFactory restResponseFactory = new RestResponseFactory();
for (RestVariable var : inputVariables) {
// Validate if scopes match
varScope = var.getVariableScope();
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
if (varScope == null) {
varScope = RestVariable.RestVariableScope.LOCAL;
}
if (sharedScope == null) {
sharedScope = varScope;
}
if (varScope != sharedScope) {
throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
}
if (hasVariableOnScope(task, var.getName(), varScope)) {
throw new BPMNConflictException("Variable '" + var.getName() + "' is already present on task '" + task.getId() + "'.");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, task.getId(), RestResponseFactory.VARIABLE_TASK, false, uriInfo.getBaseUri().toString()));
}
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
TaskService taskService = BPMNOSGIService.getTaskService();
if (!variablesToSet.isEmpty()) {
if (sharedScope == RestVariable.RestVariableScope.LOCAL) {
taskService.setVariablesLocal(task.getId(), variablesToSet);
} else {
if (task.getExecutionId() != null) {
// Explicitly set on execution, setting non-local variables on task will override local-variables if exists
runtimeService.setVariables(task.getExecutionId(), variablesToSet);
} else {
// Standalone task, no global variables possible
throw new ActivitiIllegalArgumentException("Cannot set global variables on task '" + task.getId() + "', task is not part of process.");
}
}
}
RestVariableCollection restVariableCollection = new RestVariableCollection();
restVariableCollection.setRestVariables(resultVariables);
responseBuilder.entity(restVariableCollection);
return responseBuilder.status(Response.Status.CREATED).build();
}
Aggregations