提交 9105a504 编写于 作者: T tijsrademakers

Merge branch 'save-form-data' of https://github.com/mikedias/Activiti

......@@ -74,6 +74,9 @@ public interface FormService {
/** Completes a task with the user data that was entered as properties in a task form. */
void submitTaskFormData(String taskId, Map<String, String> properties);
/** Save the data that was entered as properties in a task form. */
void saveFormData(String taskId, Map<String, String> properties);
/**
* Retrieves a user defined reference to a start form.
......
......@@ -67,7 +67,7 @@ public class FormServiceImpl extends ServiceImpl implements FormService {
}
public void submitTaskFormData(String taskId, Map<String, String> properties) {
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties, true));
}
public String getStartFormKey(String processDefinitionId) {
......@@ -77,5 +77,9 @@ public class FormServiceImpl extends ServiceImpl implements FormService {
public String getTaskFormKey(String processDefinitionId, String taskDefinitionKey) {
return commandExecutor.execute(new GetFormKeyCmd(processDefinitionId, taskDefinitionKey));
}
public void saveFormData(String taskId, Map<String, String> properties) {
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties, false));
}
}
......@@ -30,11 +30,13 @@ public class SubmitTaskFormCmd extends NeedsActiveTaskCmd<Object> {
protected String taskId;
protected Map<String, String> properties;
public SubmitTaskFormCmd(String taskId, Map<String, String> properties) {
protected boolean completeTask;
public SubmitTaskFormCmd(String taskId, Map<String, String> properties, boolean completeTask) {
super(taskId);
this.taskId = taskId;
this.properties = properties;
this.completeTask = completeTask;
}
protected Object execute(CommandContext commandContext, TaskEntity task) {
......@@ -43,8 +45,10 @@ public class SubmitTaskFormCmd extends NeedsActiveTaskCmd<Object> {
TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
taskFormHandler.submitFormProperties(properties, task.getExecution());
task.complete();
if (completeTask) {
task.complete();
}
return null;
}
......
......@@ -415,5 +415,58 @@ public class FormServiceTest extends PluggableActivitiTestCase {
assertNotNull(task);
assertEquals("test", formService.getTaskFormData(task.getId()).getFormKey());
}
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubmitTaskFormData() {
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
assertEquals(1, processDefinitions.size());
ProcessDefinition processDefinition = processDefinitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinition.getKey());
assertNotNull(processInstance);
Task task = null;
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
Map<String, String> properties = new HashMap<String, String>();
properties.put("room", "5b");
formService.submitTaskFormData(task.getId(), properties);
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNull(task);
}
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSaveFormData() {
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
assertEquals(1, processDefinitions.size());
ProcessDefinition processDefinition = processDefinitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinition.getKey());
assertNotNull(processInstance);
Task task = null;
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
String taskId = task.getId();
Map<String, String> properties = new HashMap<String, String>();
properties.put("room", "5b");
Map<String, String> expectedVariables = new HashMap<String, String>();
expectedVariables.put("room", "5b");
formService.saveFormData(task.getId(), properties);
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(taskId, task.getId());
Map<String, Object> variables = taskService.getVariables(taskId);
assertEquals(expectedVariables, variables);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册