Search in sources :

Example 11 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class ProcessDefinitionPropertiesResource method getStartFormProperties.

@RequestMapping(value = "/process-definition/{processDefinitionId}/properties", method = RequestMethod.GET, produces = "application/json")
public ObjectNode getStartFormProperties(@PathVariable String processDefinitionId) {
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    ObjectNode responseJSON = objectMapper.createObjectNode();
    ArrayNode propertiesJSON = objectMapper.createArrayNode();
    if (startFormData != null) {
        List<FormProperty> properties = startFormData.getFormProperties();
        for (FormProperty property : properties) {
            ObjectNode propertyJSON = objectMapper.createObjectNode();
            propertyJSON.put("id", property.getId());
            propertyJSON.put("name", property.getName());
            if (property.getValue() != null) {
                propertyJSON.put("value", property.getValue());
            } else {
                propertyJSON.putNull("value");
            }
            if (property.getType() != null) {
                propertyJSON.put("type", property.getType().getName());
                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked") Map<String, String> valuesMap = (Map<String, String>) property.getType().getInformation("values");
                    if (valuesMap != null) {
                        ArrayNode valuesArray = objectMapper.createArrayNode();
                        propertyJSON.put("enumValues", valuesArray);
                        for (String key : valuesMap.keySet()) {
                            ObjectNode valueJSON = objectMapper.createObjectNode();
                            valueJSON.put("id", key);
                            valueJSON.put("name", valuesMap.get(key));
                            valuesArray.add(valueJSON);
                        }
                    }
                }
            } else {
                propertyJSON.put("type", "String");
            }
            propertyJSON.put("required", property.isRequired());
            propertyJSON.put("readable", property.isReadable());
            propertyJSON.put("writable", property.isWritable());
            propertiesJSON.add(propertyJSON);
        }
    }
    responseJSON.put("data", propertiesJSON);
    return responseJSON;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) EnumFormType(org.activiti.engine.impl.form.EnumFormType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FormProperty (org.activiti.engine.form.FormProperty)11 HashMap (java.util.HashMap)7 Deployment (org.activiti.engine.test.Deployment)6 StartFormData (org.activiti.engine.form.StartFormData)5 TaskFormData (org.activiti.engine.form.TaskFormData)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 Field (com.vaadin.ui.Field)2 Task (org.activiti.engine.task.Task)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 ActivitiException (org.activiti.engine.ActivitiException)1 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)1 EnumFormType (org.activiti.engine.impl.form.EnumFormType)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