Search in sources :

Example 1 with RestFormProperty

use of org.wso2.carbon.bpmn.rest.model.form.RestFormProperty 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 2 with RestFormProperty

use of org.wso2.carbon.bpmn.rest.model.form.RestFormProperty in project carbon-business-process by wso2.

the class RestResponseFactory method createFormDataResponse.

public FormDataResponse createFormDataResponse(FormData formData, String baseUri) {
    FormDataResponse result = new FormDataResponse();
    result.setDeploymentId(formData.getDeploymentId());
    result.setFormKey(formData.getFormKey());
    if (formData.getFormProperties() != null) {
        for (FormProperty formProp : formData.getFormProperties()) {
            RestFormProperty restFormProp = new RestFormProperty();
            restFormProp.setId(formProp.getId());
            restFormProp.setName(formProp.getName());
            if (formProp.getType() != null) {
                restFormProp.setType(formProp.getType().getName());
            }
            restFormProp.setValue(formProp.getValue());
            restFormProp.setReadable(formProp.isReadable());
            restFormProp.setRequired(formProp.isRequired());
            restFormProp.setWritable(formProp.isWritable());
            if ("enum".equals(restFormProp.getType())) {
                Object values = formProp.getType().getInformation("values");
                if (values != null) {
                    @SuppressWarnings("unchecked") Map<String, String> enumValues = (Map<String, String>) values;
                    for (String enumId : enumValues.keySet()) {
                        RestEnumFormProperty enumProperty = new RestEnumFormProperty();
                        enumProperty.setId(enumId);
                        enumProperty.setName(enumValues.get(enumId));
                        restFormProp.addEnumValue(enumProperty);
                    }
                }
            } else if ("date".equals(restFormProp.getType())) {
                restFormProp.setDatePattern((String) formProp.getType().getInformation("datePattern"));
            }
            result.addFormProperty(restFormProp);
        }
    }
    RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
    if (formData instanceof StartFormData) {
        StartFormData startFormData = (StartFormData) formData;
        if (startFormData.getProcessDefinition() != null) {
            result.setProcessDefinitionId(startFormData.getProcessDefinition().getId());
            result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, startFormData.getProcessDefinition().getId()));
        }
    } else if (formData instanceof TaskFormData) {
        TaskFormData taskFormData = (TaskFormData) formData;
        if (taskFormData.getTask() != null) {
            result.setTaskId(taskFormData.getTask().getId());
            result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, taskFormData.getTask().getId()));
        }
    }
    return result;
}
Also used : RestEnumFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestEnumFormProperty) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) RestEnumFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestEnumFormProperty) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Map(java.util.Map) FormDataResponse(org.wso2.carbon.bpmn.rest.model.form.FormDataResponse)

Aggregations

RestFormProperty (org.wso2.carbon.bpmn.rest.model.form.RestFormProperty)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 FormService (org.activiti.engine.FormService)1 FormProperty (org.activiti.engine.form.FormProperty)1 StartFormData (org.activiti.engine.form.StartFormData)1 TaskFormData (org.activiti.engine.form.TaskFormData)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)1 FormDataResponse (org.wso2.carbon.bpmn.rest.model.form.FormDataResponse)1 RestEnumFormProperty (org.wso2.carbon.bpmn.rest.model.form.RestEnumFormProperty)1 ProcessInstanceResponse (org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse)1