use of org.activiti.bpmn.model.FormValue in project Activiti by Activiti.
the class BaseStepDefinitionConverter method convertProperties.
/**
* Converts form properties. Multiple step types can contain forms,
* hence why it it a shared method here.
*/
protected List<FormProperty> convertProperties(FormDefinition formDefinition) {
List<FormProperty> formProperties = new ArrayList<FormProperty>();
for (FormPropertyDefinition propertyDefinition : formDefinition.getFormPropertyDefinitions()) {
FormProperty formProperty = new FormProperty();
formProperties.add(formProperty);
formProperty.setId(propertyDefinition.getName());
formProperty.setName(propertyDefinition.getName());
formProperty.setRequired(propertyDefinition.isMandatory());
String type = null;
if (propertyDefinition instanceof NumberPropertyDefinition) {
type = "long";
} else if (propertyDefinition instanceof DatePropertyDefinition) {
type = "date";
} else if (propertyDefinition instanceof BooleanPropertyDefinition) {
type = "boolean";
} else if (propertyDefinition instanceof ListPropertyDefinition) {
type = "enum";
ListPropertyDefinition listDefinition = (ListPropertyDefinition) propertyDefinition;
if (!listDefinition.getEntries().isEmpty()) {
List<FormValue> formValues = new ArrayList<FormValue>(listDefinition.getEntries().size());
for (ListPropertyEntry entry : listDefinition.getEntries()) {
FormValue formValue = new FormValue();
// We're using same value for id and name for the moment
formValue.setId(entry.getValue());
formValue.setName(entry.getName());
formValues.add(formValue);
}
formProperty.setFormValues(formValues);
}
} else {
// Fallback to simple text
type = "string";
}
formProperty.setType(type);
}
return formProperties;
}
use of org.activiti.bpmn.model.FormValue in project Activiti by Activiti.
the class FormPropertiesConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertEquals("formPropertiesProcess", model.getMainProcess().getId());
assertEquals("User registration", model.getMainProcess().getName());
assertEquals(true, model.getMainProcess().isExecutable());
FlowElement startFlowElement = model.getMainProcess().getFlowElement("startNode");
assertNotNull(startFlowElement);
assertTrue(startFlowElement instanceof StartEvent);
StartEvent startEvent = (StartEvent) startFlowElement;
List<FormProperty> formProperties = startEvent.getFormProperties();
assertNotNull(formProperties);
assertEquals("Invalid form properties list: ", 8, formProperties.size());
for (FormProperty formProperty : formProperties) {
if (formProperty.getId().equals("new_property_1")) {
checkFormProperty(formProperty, "v000", true, false, false);
} else if (formProperty.getId().equals("new_property_2")) {
checkFormProperty(formProperty, "v001", true, false, true);
} else if (formProperty.getId().equals("new_property_3")) {
checkFormProperty(formProperty, "v010", true, true, false);
} else if (formProperty.getId().equals("new_property_4")) {
checkFormProperty(formProperty, "v011", true, true, true);
} else if (formProperty.getId().equals("new_property_5")) {
checkFormProperty(formProperty, "v100", true, false, false);
List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
for (FormValue formValue : formProperty.getFormValues()) {
Map<String, Object> formValueMap = new HashMap<String, Object>();
formValueMap.put("id", formValue.getId());
formValueMap.put("name", formValue.getName());
formValues.add(formValueMap);
}
checkFormPropertyFormValues(formValues);
} else if (formProperty.getId().equals("new_property_6")) {
checkFormProperty(formProperty, "v101", true, false, true);
} else if (formProperty.getId().equals("new_property_7")) {
checkFormProperty(formProperty, "v110", true, true, false);
} else if (formProperty.getId().equals("new_property_8")) {
checkFormProperty(formProperty, "v111", true, true, true);
} else {
fail("unexpected form property id " + formProperty.getId());
}
}
FlowElement userFlowElement = model.getMainProcess().getFlowElement("userTask");
assertNotNull(userFlowElement);
assertTrue(userFlowElement instanceof UserTask);
UserTask userTask = (UserTask) userFlowElement;
formProperties = userTask.getFormProperties();
assertNotNull(formProperties);
assertEquals("Invalid form properties list: ", 8, formProperties.size());
for (FormProperty formProperty : formProperties) {
if (formProperty.getId().equals("new_property_1")) {
checkFormProperty(formProperty, "v000", false, false, false);
} else if (formProperty.getId().equals("new_property_2")) {
checkFormProperty(formProperty, "v001", false, false, true);
} else if (formProperty.getId().equals("new_property_3")) {
checkFormProperty(formProperty, "v010", false, true, false);
} else if (formProperty.getId().equals("new_property_4")) {
checkFormProperty(formProperty, "v011", false, true, true);
} else if (formProperty.getId().equals("new_property_5")) {
checkFormProperty(formProperty, "v100", true, false, false);
List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
for (FormValue formValue : formProperty.getFormValues()) {
Map<String, Object> formValueMap = new HashMap<String, Object>();
formValueMap.put("id", formValue.getId());
formValueMap.put("name", formValue.getName());
formValues.add(formValueMap);
}
checkFormPropertyFormValues(formValues);
} else if (formProperty.getId().equals("new_property_6")) {
checkFormProperty(formProperty, "v101", true, false, true);
} else if (formProperty.getId().equals("new_property_7")) {
checkFormProperty(formProperty, "v110", true, true, false);
} else if (formProperty.getId().equals("new_property_8")) {
checkFormProperty(formProperty, "v111", true, true, true);
} else {
fail("unexpected form property id " + formProperty.getId());
}
}
}
Aggregations