提交 eb0d256d 编写于 作者: B Bassam Al-Sarori 提交者: salaboy

allow updating task formKey (#2130)

上级 ed53a4dd
......@@ -254,6 +254,12 @@ public class TaskRuntimeImpl implements TaskRuntime {
if (updateTaskPayload.getDueDate() != null) {
internalTask.setDueDate(updateTaskPayload.getDueDate());
}
if (updateTaskPayload.getParentTaskId() != null) {
internalTask.setParentTaskId(updateTaskPayload.getParentTaskId());
}
if (updateTaskPayload.getFormKey() != null) {
internalTask.setFormKey(updateTaskPayload.getFormKey());
}
//@TODO: add check to see if something was changed before saving + add all other updateable values
taskService.saveTask(internalTask);
Task convertedTask = task(updateTaskPayload.getTaskId());
......@@ -306,6 +312,7 @@ public class TaskRuntimeImpl implements TaskRuntime {
task.setAssignee(createTaskPayload.getAssignee());
}
task.setParentTaskId(createTaskPayload.getParentTaskId());
task.setFormKey(createTaskPayload.getFormKey());
task.setOwner(securityManager.getAuthenticatedUserId());
taskService.saveTask(task);
taskService.addCandidateUser(task.getId(),
......
/*
* Copyright 2018 Alfresco, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.spring.boot;
import org.activiti.api.process.model.ProcessDefinition;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.spring.boot.security.util.SecurityUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class ProcessDefinitionFormKeyIT {
private static final String SINGLE_TASK_PROCESS = "SingleTaskProcess";
@Autowired
private SecurityUtil securityUtil;
@Autowired
private ProcessRuntime processRuntime;
@Test
public void processDefinitionHasFormKey() {
securityUtil.logInAs("garth");
ProcessDefinition processDefinition = processRuntime.processDefinition(SINGLE_TASK_PROCESS);
assertThat(processDefinition.getFormKey()).isEqualTo("startForm");
}
}
\ No newline at end of file
/*
* Copyright 2018 Alfresco, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.spring.boot.tasks;
import org.activiti.api.process.model.builders.ProcessPayloadBuilder;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.api.runtime.shared.query.Page;
import org.activiti.api.runtime.shared.query.Pageable;
import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.builders.TaskPayloadBuilder;
import org.activiti.api.task.model.builders.UpdateTaskPayloadBuilder;
import org.activiti.api.task.runtime.TaskRuntime;
import org.activiti.spring.boot.security.util.SecurityUtil;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ContextConfiguration
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TaskRuntimeFormKeyTest {
private static final String SINGLE_TASK_PROCESS = "SingleTaskProcess";
@Autowired
private TaskRuntime taskRuntime;
@Autowired
private ProcessRuntime processRuntime;
@Autowired
private SecurityUtil securityUtil;
@Test
public void standaloneTaskHasFormKey() {
securityUtil.logInAs("garth");
taskRuntime.create(TaskPayloadBuilder.create()
.withName("atask")
.withAssignee("garth")
.withFormKey("aFormKey")
.build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0,
50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getFormKey()).isEqualTo("aFormKey");
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
}
@Test
public void shouldUpdateTaskFormKey() {
securityUtil.logInAs("garth");
taskRuntime.create(TaskPayloadBuilder.create()
.withName("atask")
.withAssignee("garth")
.build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0,
50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
taskRuntime.update(new UpdateTaskPayloadBuilder()
.withTaskId(task.getId())
.withFormKey("aFormKey")
.build());
task = taskRuntime.task(task.getId());
assertThat(task.getFormKey()).isEqualTo("aFormKey");
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
}
@Test
public void processTaskHasFormKey() {
securityUtil.logInAs("garth");
processRuntime.start(ProcessPayloadBuilder.start()
.withProcessDefinitionKey(SINGLE_TASK_PROCESS)
.build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0,
50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getFormKey()).isEqualTo("taskForm");
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:activiti="http://activiti.org/bpmn" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:process id="SingleTaskProcess" name="single-task" isExecutable="true">
<bpmn2:startEvent id="StartEvent_1" activiti:formKey="startForm">
<bpmn2:outgoing>SequenceFlow_1tec9n0</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:sequenceFlow id="SequenceFlow_1tec9n0" sourceRef="StartEvent_1" targetRef="Task_03l0zc2" />
<bpmn2:endEvent id="EndEvent_00jfcl0">
<bpmn2:incoming>SequenceFlow_00ryslt</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="SequenceFlow_00ryslt" sourceRef="Task_03l0zc2" targetRef="EndEvent_00jfcl0" />
<bpmn2:userTask id="Task_03l0zc2" name="my-task" activiti:assignee="garth" activiti:formKey="taskForm">
<bpmn2:incoming>SequenceFlow_1tec9n0</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_00ryslt</bpmn2:outgoing>
</bpmn2:userTask>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="SingleTaskProcess">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="412" y="240" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1tec9n0_di" bpmnElement="SequenceFlow_1tec9n0">
<di:waypoint x="448" y="258" />
<di:waypoint x="498" y="258" />
<bpmndi:BPMNLabel>
<dc:Bounds x="473" y="236.5" width="0" height="13" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="EndEvent_00jfcl0_di" bpmnElement="EndEvent_00jfcl0">
<dc:Bounds x="648" y="240" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="666" y="279" width="0" height="13" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_00ryslt_di" bpmnElement="SequenceFlow_00ryslt">
<di:waypoint x="598" y="258" />
<di:waypoint x="648" y="258" />
<bpmndi:BPMNLabel>
<dc:Bounds x="623" y="236.5" width="0" height="13" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_07zs0fg_di" bpmnElement="Task_03l0zc2">
<dc:Bounds x="498" y="218" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册