use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class FormDataService method getFormData.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFormData() {
String taskId = uriInfo.getQueryParameters().getFirst("taskId");
String processDefinitionId = uriInfo.getQueryParameters().getFirst("processDefinitionId");
if (taskId == null && processDefinitionId == null) {
throw new ActivitiIllegalArgumentException("The taskId or processDefinitionId parameter has to be provided");
}
if (taskId != null && processDefinitionId != null) {
throw new ActivitiIllegalArgumentException("Not both a taskId and a processDefinitionId parameter can be provided");
}
FormData formData = null;
String id = null;
FormService formService = BPMNOSGIService.getFormService();
if (taskId != null) {
formData = formService.getTaskFormData(taskId);
id = taskId;
} else {
formData = formService.getStartFormData(processDefinitionId);
id = processDefinitionId;
}
if (formData == null) {
throw new ActivitiObjectNotFoundException("Could not find a form data with id '" + id + "'.", FormData.class);
}
return Response.ok().entity(new RestResponseFactory().createFormDataResponse(formData, uriInfo.getBaseUri().toString())).build();
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class FormDataService method submitForm.
@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response submitForm(SubmitFormRequest submitRequest) {
if (submitRequest == null) {
throw new ActivitiException("A request body was expected when executing the form submit.");
}
if (submitRequest.getTaskId() == null && submitRequest.getProcessDefinitionId() == null) {
throw new ActivitiIllegalArgumentException("The taskId or processDefinitionId property has to be provided");
}
Map<String, String> propertyMap = new HashMap<String, String>();
if (submitRequest.getProperties() != null) {
for (RestFormProperty formProperty : submitRequest.getProperties()) {
propertyMap.put(formProperty.getId(), formProperty.getValue());
}
}
FormService formService = BPMNOSGIService.getFormService();
Response.ResponseBuilder response = Response.ok();
if (submitRequest.getTaskId() != null) {
formService.submitTaskFormData(submitRequest.getTaskId(), propertyMap);
response.status(Response.Status.NO_CONTENT);
return response.build();
} else {
ProcessInstance processInstance = null;
if (submitRequest.getBusinessKey() != null) {
processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), submitRequest.getBusinessKey(), propertyMap);
} else {
processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), propertyMap);
}
ProcessInstanceResponse processInstanceResponse = new RestResponseFactory().createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
return response.entity(processInstanceResponse).build();
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class ProcessInstanceCreateRequest method cloneInstanceCreationRequest.
public ProcessInstanceQueryRequest cloneInstanceCreationRequest() {
ProcessInstanceQueryRequest processInstanceQueryRequest = new ProcessInstanceQueryRequest();
if (processDefinitionId != null) {
processInstanceQueryRequest.setProcessDefinitionId(processDefinitionId);
}
if (businessKey != null) {
processInstanceQueryRequest.setProcessBusinessKey(businessKey);
}
if (tenantId != null) {
processInstanceQueryRequest.setTenantId(tenantId);
}
if (variables != null) {
RestResponseFactory restResponseFactory = new RestResponseFactory();
List<QueryVariable> queryVariableList = new ArrayList<>();
for (RestVariable restVariable : variables) {
QueryVariable queryVariable = new QueryVariable();
queryVariable.setName(restVariable.getName());
queryVariable.setOperation("equals");
queryVariable.setType(restVariable.getType());
queryVariable.setValue(restResponseFactory.getVariableValue(restVariable));
queryVariableList.add(queryVariable);
}
processInstanceQueryRequest.setVariables(queryVariableList);
}
processInstanceQueryRequest.setIncludeProcessVariables(true);
return processInstanceQueryRequest;
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class HistoricDetailService method getVariableFromRequest.
public RestVariable getVariableFromRequest(boolean includeBinary, String detailId) {
Object value = null;
HistoricVariableUpdate variableUpdate = null;
HistoryService historyService = BPMNOSGIService.getHistoryService();
HistoricDetail detailObject = historyService.createHistoricDetailQuery().id(detailId).singleResult();
if (detailObject instanceof HistoricVariableUpdate) {
variableUpdate = (HistoricVariableUpdate) detailObject;
value = variableUpdate.getValue();
}
if (value == null) {
throw new ActivitiObjectNotFoundException("Historic detail '" + detailId + "' doesn't have a variable value.", VariableInstanceEntity.class);
} else {
return new RestResponseFactory().createRestVariable(variableUpdate.getVariableName(), value, null, detailId, RestResponseFactory.VARIABLE_HISTORY_DETAIL, includeBinary, uriInfo.getBaseUri().toString());
}
}
use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.
the class HistoricProcessInstanceService method addVariables.
protected void addVariables(HistoricProcessInstanceQuery processInstanceQuery, List<QueryVariable> variables) {
for (QueryVariable variable : variables) {
if (variable.getVariableOperation() == null) {
throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
}
if (variable.getValue() == null) {
throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
}
boolean nameLess = variable.getName() == null;
RestResponseFactory restResponseFactory = new RestResponseFactory();
Object actualValue = restResponseFactory.getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
processInstanceQuery.variableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case NOT_EQUALS:
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
break;
case LIKE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
Aggregations