Search in sources :

Example 46 with RestResponseFactory

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();
}
Also used : FormData(org.activiti.engine.form.FormData) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) FormService(org.activiti.engine.FormService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 47 with RestResponseFactory

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();
    }
}
Also used : ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) Response(javax.ws.rs.core.Response) ActivitiException(org.activiti.engine.ActivitiException) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) FormService(org.activiti.engine.FormService) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 48 with RestResponseFactory

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;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable) ArrayList(java.util.ArrayList)

Example 49 with RestResponseFactory

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());
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 50 with RestResponseFactory

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());
        }
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)

Aggregations

RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)90 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)28 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)26 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 RuntimeService (org.activiti.engine.RuntimeService)16 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)16 GET (javax.ws.rs.GET)14 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)14 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)14 HistoryService (org.activiti.engine.HistoryService)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 RepositoryService (org.activiti.engine.RepositoryService)8 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)7 ArrayList (java.util.ArrayList)6 JAXBContext (javax.xml.bind.JAXBContext)6