use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.
the class ReportDetailPanel method initForm.
protected void initForm() {
// Check if a start form is defined
final ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
StartFormData startFormData = processEngine.getFormService().getStartFormData(processDefinition.getId());
if (startFormData != null && ((startFormData.getFormProperties() != null && !startFormData.getFormProperties().isEmpty()) || startFormData.getFormKey() != null)) {
processDefinitionStartForm = new FormPropertiesForm();
detailContainer.addComponent(processDefinitionStartForm);
processDefinitionStartForm.setFormProperties(startFormData.getFormProperties());
processDefinitionStartForm.setSubmitButtonCaption(i18nManager.getMessage(Messages.REPORTING_GENERATE_REPORT));
processDefinitionStartForm.hideCancelButton();
processDefinitionStartForm.addListener(new FormPropertiesEventListener() {
private static final long serialVersionUID = 1L;
protected void handleFormSubmit(FormPropertiesEvent event) {
// Report is generated by running a process and storing the dataset in the history tablkes
savedFormProperties = event.getFormProperties();
ProcessInstance processInstance = startProcessInstanceWithFormProperties(processDefinition.getId(), event.getFormProperties());
generateReport(processInstance);
}
protected void handleFormCancel(FormPropertiesEvent event) {
// Not needed, cancel button not shown in report panels
}
});
} else {
// Just start the process-instance since it has no form.
ProcessInstance processInstance = startProcessInstance(processDefinition.getId());
generateReport(processInstance);
}
}
use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.
the class StartProcessInstanceClickListener method buttonClick.
public void buttonClick(ClickEvent event) {
// Check if process-definition defines a start-form
StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
if (startFormData != null && ((startFormData.getFormProperties() != null && !startFormData.getFormProperties().isEmpty()) || startFormData.getFormKey() != null)) {
parentPage.showStartForm(processDefinition, startFormData);
} else {
// Just start the process-instance since it has no form.
// TODO: Error handling
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
// Show notification of success
notificationManager.showInformationNotification(Messages.PROCESS_STARTED_NOTIFICATION, getProcessDisplayName(processDefinition));
// Switch to inbox page in case a task of this process was created
List<Task> loggedInUsersTasks = taskService.createTaskQuery().taskAssignee(ExplorerApp.get().getLoggedInUser().getId()).processInstanceId(processInstance.getId()).list();
if (!loggedInUsersTasks.isEmpty()) {
ExplorerApp.get().getViewManager().showInboxPage(loggedInUsersTasks.get(0).getId());
}
}
}
use of org.activiti.engine.form.StartFormData in project Activiti by Activiti.
the class FormPropertyDefaultValueTest method testStartFormDefaultValue.
@Deployment
public void testStartFormDefaultValue() throws Exception {
String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("FormPropertyDefaultValueTest.testDefaultValue").latestVersion().singleResult().getId();
StartFormData startForm = formService.getStartFormData(processDefinitionId);
List<FormProperty> formProperties = startForm.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);
}
}
// Override 2 properties. The others should pe posted as the default-value
Map<String, String> formDataUpdate = new HashMap<String, String>();
formDataUpdate.put("longExpressionProperty", "1");
formDataUpdate.put("booleanProperty", "false");
ProcessInstance processInstance = formService.submitStartFormData(processDefinitionId, 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.StartFormData in project Activiti by Activiti.
the class FormServiceTest method testTaskFormPropertyDefaultsAndFormRendering.
@Deployment(resources = { "org/activiti/engine/test/api/form/FormsProcess.bpmn20.xml", "org/activiti/engine/test/api/form/start.form", "org/activiti/engine/test/api/form/task.form" })
public void testTaskFormPropertyDefaultsAndFormRendering() {
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
StartFormData startForm = formService.getStartFormData(procDefId);
assertNotNull(startForm);
assertEquals(deploymentIdFromDeploymentAnnotation, startForm.getDeploymentId());
assertEquals("org/activiti/engine/test/api/form/start.form", startForm.getFormKey());
assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
assertEquals(procDefId, startForm.getProcessDefinition().getId());
Object renderedStartForm = formService.getRenderedStartForm(procDefId);
assertEquals("start form content", renderedStartForm);
Map<String, String> properties = new HashMap<String, String>();
properties.put("room", "5b");
properties.put("speaker", "Mike");
String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
expectedVariables.put("speaker", "Mike");
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
Task task = taskService.createTaskQuery().singleResult();
String taskId = task.getId();
TaskFormData taskForm = formService.getTaskFormData(taskId);
assertEquals(deploymentIdFromDeploymentAnnotation, taskForm.getDeploymentId());
assertEquals("org/activiti/engine/test/api/form/task.form", taskForm.getFormKey());
assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
assertEquals(taskId, taskForm.getTask().getId());
assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId));
properties = new HashMap<String, String>();
properties.put("room", "3f");
formService.submitTaskFormData(taskId, properties);
expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "3f");
expectedVariables.put("speaker", "Mike");
variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
}
use of org.activiti.engine.form.StartFormData 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;
}
Aggregations