Search in sources :

Example 1 with FormDataResponse

use of org.activiti.rest.service.api.form.FormDataResponse in project Activiti by Activiti.

the class RestResponseFactory method createFormDataResponse.

public FormDataResponse createFormDataResponse(FormData formData) {
    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();
    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.activiti.rest.service.api.form.RestEnumFormProperty) RestEnumFormProperty(org.activiti.rest.service.api.form.RestEnumFormProperty) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Map(java.util.Map) FormDataResponse(org.activiti.rest.service.api.form.FormDataResponse)

Aggregations

Map (java.util.Map)1 FormProperty (org.activiti.engine.form.FormProperty)1 StartFormData (org.activiti.engine.form.StartFormData)1 TaskFormData (org.activiti.engine.form.TaskFormData)1 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)1 FormDataResponse (org.activiti.rest.service.api.form.FormDataResponse)1 RestEnumFormProperty (org.activiti.rest.service.api.form.RestEnumFormProperty)1 RestFormProperty (org.activiti.rest.service.api.form.RestFormProperty)1