use of org.activiti.engine.form.TaskFormData in project Activiti by Activiti.
the class TaskDetailPanel method initTaskForm.
protected void initTaskForm() {
// Check if task requires a form
TaskFormData formData = formService.getTaskFormData(task.getId());
if (formData != null && formData.getFormProperties() != null && !formData.getFormProperties().isEmpty()) {
taskForm = new FormPropertiesForm();
taskForm.setSubmitButtonCaption(i18nManager.getMessage(Messages.TASK_COMPLETE));
taskForm.setCancelButtonCaption(i18nManager.getMessage(Messages.TASK_RESET_FORM));
taskForm.setFormHelp(i18nManager.getMessage(Messages.TASK_FORM_HELP));
taskForm.setFormProperties(formData.getFormProperties());
taskForm.addListener(new FormPropertiesEventListener() {
private static final long serialVersionUID = -3893467157397686736L;
@Override
protected void handleFormSubmit(FormPropertiesEvent event) {
Map<String, String> properties = event.getFormProperties();
formService.submitTaskFormData(task.getId(), properties);
notificationManager.showInformationNotification(Messages.TASK_COMPLETED, task.getName());
taskPage.refreshSelectNext();
}
@Override
protected void handleFormCancel(FormPropertiesEvent event) {
// Clear the form values
taskForm.clear();
}
});
// Only if current user is task's assignee
taskForm.setEnabled(isCurrentUserAssignee());
// Add component to page
centralLayout.addComponent(taskForm);
} else {
// Just add a button to complete the task
// TODO: perhaps move to a better place
CssLayout buttonLayout = new CssLayout();
buttonLayout.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
buttonLayout.setWidth(100, UNITS_PERCENTAGE);
centralLayout.addComponent(buttonLayout);
completeButton = new Button(i18nManager.getMessage(Messages.TASK_COMPLETE));
completeButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
// If no owner, make assignee owner (will go into archived then)
if (task.getOwner() == null) {
task.setOwner(task.getAssignee());
taskService.setOwner(task.getId(), task.getAssignee());
}
taskService.complete(task.getId());
notificationManager.showInformationNotification(Messages.TASK_COMPLETED, task.getName());
taskPage.refreshSelectNext();
}
});
completeButton.setEnabled(isCurrentUserAssignee() || isCurrentUserOwner());
buttonLayout.addComponent(completeButton);
}
}
use of org.activiti.engine.form.TaskFormData 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.TaskFormData 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.TaskFormData 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.TaskFormData in project Activiti by Activiti.
the class GetRenderedTaskFormCmd method execute.
public Object execute(CommandContext commandContext) {
TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
}
if (task.getTaskDefinition() == null) {
throw new ActivitiException("Task form definition for '" + taskId + "' not found");
}
TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
if (taskFormHandler == null) {
return null;
}
FormEngine formEngine = commandContext.getProcessEngineConfiguration().getFormEngines().get(formEngineName);
if (formEngine == null) {
throw new ActivitiException("No formEngine '" + formEngineName + "' defined process engine configuration");
}
TaskFormData taskForm = taskFormHandler.createTaskForm(task);
return formEngine.renderTaskForm(taskForm);
}
Aggregations