Search in sources :

Example 1 with EnumFormType

use of org.activiti.engine.impl.form.EnumFormType 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)

Example 2 with EnumFormType

use of org.activiti.engine.impl.form.EnumFormType in project carbon-business-process by wso2.

the class ProcessDefinitionFormPropertyService method getStartFormProperties.

@GET
@Path("/{processDefinitionId}/properties")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getStartFormProperties(@PathParam("processDefinitionId") String processDefinitionId) {
    FormService formService = BPMNOSGIService.getFormService();
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    FormPropertyResponseCollection formPropertyResponseCollection = new FormPropertyResponseCollection();
    if (startFormData != null) {
        List<FormProperty> properties = startFormData.getFormProperties();
        List<FormPropertyResponse> formPropertyResponseList = new ArrayList<>();
        for (FormProperty property : properties) {
            // ObjectNode propertyJSON = objectMapper.createObjectNode();
            FormPropertyResponse formPropertyResponse = new FormPropertyResponse();
            formPropertyResponse.setId(property.getId());
            formPropertyResponse.setName(property.getName());
            if (property.getValue() != null) {
                formPropertyResponse.setValue(property.getValue());
            } else {
                formPropertyResponse.setValue(null);
            }
            if (property.getType() != null) {
                formPropertyResponse.setType(property.getType().getName());
                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked") Map<String, String> valuesMap = (Map<String, String>) property.getType().getInformation("values");
                    if (valuesMap != null) {
                        List<FormPropertyEnumDataHolder> formPropertyEnumDataHoldersList = new ArrayList<>();
                        for (String key : valuesMap.keySet()) {
                            FormPropertyEnumDataHolder formPropertyEnumDataHolder = new FormPropertyEnumDataHolder();
                            formPropertyEnumDataHolder.setId(key);
                            formPropertyEnumDataHolder.setName(valuesMap.get(key));
                            formPropertyEnumDataHoldersList.add(formPropertyEnumDataHolder);
                        }
                        formPropertyResponse.setEnumValues(formPropertyEnumDataHoldersList);
                    }
                }
            } else {
                formPropertyResponse.setType("String");
            }
            formPropertyResponse.setRequired(property.isRequired());
            formPropertyResponse.setReadable(property.isReadable());
            formPropertyResponse.setWritable(property.isWritable());
            formPropertyResponseList.add(formPropertyResponse);
        }
        formPropertyResponseCollection.setData(formPropertyResponseList);
    }
    return Response.ok().entity(formPropertyResponseCollection).build();
}
Also used : FormPropertyEnumDataHolder(org.wso2.carbon.bpmn.rest.model.form.FormPropertyEnumDataHolder) FormProperty(org.activiti.engine.form.FormProperty) FormService(org.activiti.engine.FormService) FormPropertyResponse(org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponse) ArrayList(java.util.ArrayList) EnumFormType(org.activiti.engine.impl.form.EnumFormType) FormPropertyResponseCollection(org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponseCollection) StartFormData(org.activiti.engine.form.StartFormData) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Map (java.util.Map)2 FormProperty (org.activiti.engine.form.FormProperty)2 StartFormData (org.activiti.engine.form.StartFormData)2 EnumFormType (org.activiti.engine.impl.form.EnumFormType)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FormService (org.activiti.engine.FormService)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 FormPropertyEnumDataHolder (org.wso2.carbon.bpmn.rest.model.form.FormPropertyEnumDataHolder)1 FormPropertyResponse (org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponse)1 FormPropertyResponseCollection (org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponseCollection)1