use of org.activiti.engine.form.FormProperty 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;
}
use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.
the class FormPropertyDefaultValueTest method testDefaultValue.
@Deployment
public void testDefaultValue() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
TaskFormData formData = formService.getTaskFormData(task.getId());
List<FormProperty> formProperties = formData.getFormProperties();
assertEquals(4, formProperties.size());
for (FormProperty prop : formProperties) {
if ("booleanProperty".equals(prop.getId())) {
assertEquals("true", prop.getValue());
} else if ("stringProperty".equals(prop.getId())) {
assertEquals("someString", prop.getValue());
} else if ("longProperty".equals(prop.getId())) {
assertEquals("42", prop.getValue());
} else if ("longExpressionProperty".equals(prop.getId())) {
assertEquals("23", prop.getValue());
} else {
assertTrue("Invalid form property: " + prop.getId(), false);
}
}
Map<String, String> formDataUpdate = new HashMap<String, String>();
formDataUpdate.put("longExpressionProperty", "1");
formDataUpdate.put("booleanProperty", "false");
formService.submitTaskFormData(task.getId(), formDataUpdate);
assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.
the class FormServiceTest method testFormPropertyExpression.
@Deployment
public void testFormPropertyExpression() {
Map<String, Object> varMap = new HashMap<String, Object>();
// variable name mapping
varMap.put("speaker", "Mike");
Address address = new Address();
varMap.put("address", address);
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, varMap);
String taskId = taskService.createTaskQuery().singleResult().getId();
TaskFormData taskFormData = formService.getTaskFormData(taskId);
List<FormProperty> formProperties = taskFormData.getFormProperties();
FormProperty propertySpeaker = formProperties.get(0);
assertEquals("speaker", propertySpeaker.getId());
assertEquals("Mike", propertySpeaker.getValue());
assertEquals(2, formProperties.size());
Map<String, String> properties = new HashMap<String, String>();
properties.put("street", "Broadway");
formService.submitTaskFormData(taskId, properties);
address = (Address) runtimeService.getVariable(processInstance.getId(), "address");
assertEquals("Broadway", address.getStreet());
}
use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.
the class FormServiceTest method testFormPropertyDetails.
@SuppressWarnings("unchecked")
@Deployment
public void testFormPropertyDetails() {
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
StartFormData startFormData = formService.getStartFormData(procDefId);
FormProperty property = startFormData.getFormProperties().get(0);
assertEquals("speaker", property.getId());
assertNull(property.getValue());
assertTrue(property.isReadable());
assertTrue(property.isWritable());
assertFalse(property.isRequired());
assertEquals("string", property.getType().getName());
property = startFormData.getFormProperties().get(1);
assertEquals("start", property.getId());
assertNull(property.getValue());
assertTrue(property.isReadable());
assertTrue(property.isWritable());
assertFalse(property.isRequired());
assertEquals("date", property.getType().getName());
assertEquals("dd-MMM-yyyy", property.getType().getInformation("datePattern"));
property = startFormData.getFormProperties().get(2);
assertEquals("direction", property.getId());
assertNull(property.getValue());
assertTrue(property.isReadable());
assertTrue(property.isWritable());
assertFalse(property.isRequired());
assertEquals("enum", property.getType().getName());
Map<String, String> values = (Map<String, String>) property.getType().getInformation("values");
Map<String, String> expectedValues = new LinkedHashMap<String, String>();
expectedValues.put("left", "Go Left");
expectedValues.put("right", "Go Right");
expectedValues.put("up", "Go Up");
expectedValues.put("down", "Go Down");
// ACT-1023: check if ordering is retained
Iterator<Entry<String, String>> expectedValuesIterator = expectedValues.entrySet().iterator();
for (Entry<String, String> entry : values.entrySet()) {
Entry<String, String> expectedEntryAtLocation = expectedValuesIterator.next();
assertEquals(expectedEntryAtLocation.getKey(), entry.getKey());
assertEquals(expectedEntryAtLocation.getValue(), entry.getValue());
}
assertEquals(expectedValues, values);
}
use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.
the class FormPropertiesComponent method getFormPropertyValues.
/**
* Returns all values filled in in the writable fields on the form.
*
* @throws InvalidValueException when a validation error occurs.
*/
public Map<String, String> getFormPropertyValues() throws InvalidValueException {
// Commit the form to ensure validation is executed
form.commit();
Map<String, String> formPropertyValues = new HashMap<String, String>();
// Get values from fields defined for each form property
for (FormProperty formProperty : formProperties) {
if (formProperty.isWritable()) {
Field field = form.getField(formProperty.getId());
FormPropertyRenderer renderer = getRenderer(formProperty);
String fieldValue = renderer.getFieldValue(formProperty, field);
formPropertyValues.put(formProperty.getId(), fieldValue);
}
}
return formPropertyValues;
}
Aggregations