提交 c31849e5 编写于 作者: T tombaeyens

ACT-688 Add comments to tasks and process instances

上级 ce004913
......@@ -73,8 +73,12 @@ 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);
/** */
void addTaskComment(String taskId, String message);
/** Add a comment to a task and/or process instance. */
void addComment(String taskId, String processInstanceId, String message);
/** The comments related to the given task. */
List<Comment> getTaskComments(String taskId);
/** The comments related to the given process instance. */
List<Comment> getProcessInstanceComments(String processInstanceId);
}
......@@ -64,6 +64,7 @@ public interface TaskService {
* Deletes the given task.
* @param taskId The id of the task that will be deleted, cannot be null. If no task
* exists with the given taskId, the operation is ignored.
* @param cascade If cascade is true, also the historic information related to this task is deleted.
*/
void deleteTask(String taskId, boolean cascade);
......@@ -71,6 +72,7 @@ public interface TaskService {
* Deletes all tasks of the given collection.
* @param taskIds The id's of the tasks that will be deleted, cannot be null. All
* id's in the list that don't have an existing task will be ignored.
* @param cascade If cascade is true, also the historic information related to this task is deleted.
*/
void deleteTasks(Collection<String> taskIds, boolean cascade);
......
......@@ -13,6 +13,8 @@
package org.activiti.engine.form;
import java.util.Date;
/**
* @author Tom Baeyens
......@@ -20,5 +22,8 @@ package org.activiti.engine.form;
public interface Comment {
String getUserId();
Date getTime();
String getTaskId();
String getProcessInstanceId();
String getMessage();
}
......@@ -20,9 +20,12 @@ import org.activiti.engine.FormService;
import org.activiti.engine.form.Comment;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.cmd.AddCommentCmd;
import org.activiti.engine.impl.cmd.GetProcessInstanceCommentsCmd;
import org.activiti.engine.impl.cmd.GetRenderedStartFormCmd;
import org.activiti.engine.impl.cmd.GetRenderedTaskFormCmd;
import org.activiti.engine.impl.cmd.GetStartFormCmd;
import org.activiti.engine.impl.cmd.GetTaskCommentsCmd;
import org.activiti.engine.impl.cmd.GetTaskFormCmd;
import org.activiti.engine.impl.cmd.SubmitStartFormCmd;
import org.activiti.engine.impl.cmd.SubmitTaskFormCmd;
......@@ -70,12 +73,15 @@ public class FormServiceImpl extends ServiceImpl implements FormService {
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
}
@Override
public void addTaskComment(String taskId, String message) {
public void addComment(String taskId, String processInstance, String message) {
commandExecutor.execute(new AddCommentCmd(taskId, processInstance, message));
}
@Override
public List<Comment> getTaskComments(String taskId) {
return null;
return commandExecutor.execute(new GetTaskCommentsCmd(taskId));
}
public List<Comment> getProcessInstanceComments(String processInstanceId) {
return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId));
}
}
/* 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.engine.impl.cmd;
import org.activiti.engine.impl.form.CommentEntity;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.util.ClockUtil;
/**
* @author Tom Baeyens
*/
public class AddCommentCmd implements Command<Object> {
protected String taskId;
protected String processInstanceId;
protected String message;
public AddCommentCmd(String taskId, String processInstanceId, String message) {
this.taskId = taskId;
this.processInstanceId = processInstanceId;
this.message = message;
}
public Object execute(CommandContext commandContext) {
String userId = Authentication.getAuthenticatedUserId();
CommentEntity comment = new CommentEntity();
comment.setUserId(userId);
comment.setTime(ClockUtil.getCurrentTime());
comment.setTaskId(taskId);
comment.setProcessInstanceId(processInstanceId);
comment.setMessage(message);
commandContext
.getDbSqlSession()
.insert(comment);
return null;
}
}
......@@ -81,6 +81,9 @@ public class DeleteTaskCmd implements Command<Void> {
dbSqlSession.delete(HistoricDetailEntity.class, historicTaskDetail.getId());
}
}
if (historyLevel>=ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
dbSqlSession.delete("deleteCommentsByTaskId", taskId);
}
}
}
}
/* 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.engine.impl.cmd;
import java.util.List;
import org.activiti.engine.form.Comment;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
/**
* @author Tom Baeyens
*/
public class GetProcessInstanceCommentsCmd implements Command<List<Comment>> {
protected String processInstanceId;
public GetProcessInstanceCommentsCmd(String processInstanceId) {
this.processInstanceId = processInstanceId;
}
@SuppressWarnings("unchecked")
public List<Comment> execute(CommandContext commandContext) {
return commandContext
.getDbSqlSession()
.getSqlSession()
.selectList("selectCommentsByProcessInstanceId", processInstanceId);
}
}
/* 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.engine.impl.cmd;
import java.util.List;
import org.activiti.engine.form.Comment;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
/**
* @author Tom Baeyens
*/
public class GetTaskCommentsCmd implements Command<List<Comment>> {
protected String taskId;
public GetTaskCommentsCmd(String taskId) {
this.taskId = taskId;
}
@SuppressWarnings("unchecked")
public List<Comment> execute(CommandContext commandContext) {
return commandContext
.getDbSqlSession()
.getSqlSession()
.selectList("selectCommentsByTaskId", taskId);
}
}
/* 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.engine.impl.form;
import java.util.Date;
import org.activiti.engine.form.Comment;
import org.activiti.engine.impl.db.PersistentObject;
/**
* @author Tom Baeyens
*/
public class CommentEntity implements Comment, PersistentObject {
protected String id;
protected String userId;
protected Date time;
protected String taskId;
protected String processInstanceId;
protected String message;
public Object getPersistentState() {
return CommentEntity.class;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getProcessInstanceId() {
return processInstanceId;
}
public void setProcessInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
}
}
......@@ -612,4 +612,46 @@
</where>
</sql>
<!-- COMMENT INSERT -->
<insert id="insertComment" parameterType="org.activiti.engine.impl.form.CommentEntity">
insert into ACT_HI_DETAIL (ID_, TYPE_, NAME_, TIME_, TASK_ID_, PROC_INST_ID_, TEXT_)
values (
#{id ,jdbcType=VARCHAR},
'comment',
#{userId ,jdbcType=VARCHAR},
#{time ,jdbcType=TIMESTAMP},
#{taskId ,jdbcType=VARCHAR},
#{processInstanceId ,jdbcType=VARCHAR},
#{message ,jdbcType=VARCHAR}
)
</insert>
<!-- COMMENT DELETE -->
<delete id="deleteCommentsByTaskId" parameterType="string">
delete from ACT_HI_DETAIL where TASK_ID_ = #{taskId}
</delete>
<!-- COMMENT RESULTMAP -->
<resultMap id="commentResultMap" type="org.activiti.engine.impl.form.CommentEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="userId" column="NAME_" jdbcType="VARCHAR" />
<result property="time" column="TIME_" jdbcType="TIMESTAMP" />
<result property="taskId" column="TASK_ID_" jdbcType="VARCHAR" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="message" column="TEXT_" jdbcType="VARCHAR" />
</resultMap>
<!-- COMMENT SELECT -->
<select id="selectCommentsByTaskId" parameterType="string" resultMap="commentResultMap">
select * from ACT_HI_DETAIL where TASK_ID_ = #{taskId,jdbcType=VARCHAR}
</select>
<select id="selectCommentsByProcessInstanceId" parameterType="string" resultMap="commentResultMap">
select * from ACT_HI_DETAIL where PROC_INST_ID_ = #{processInstanceId,jdbcType=VARCHAR}
</select>
</mapper>
......@@ -8,6 +8,7 @@ create table ACT_ID_INFO (
TYPE_ varchar(64),
KEY_ varchar(255),
VALUE_ varchar(255),
PASSWORD_ varchar(255),
PASSWORD_ longvarbinary,
PARENT_ID_ varchar(255),
primary key (ID_)
);
......@@ -17,10 +17,13 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.Comment;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
......@@ -28,8 +31,8 @@ import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.DelegationState;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.IdentityLinkType;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
/**
......@@ -90,6 +93,40 @@ public class TaskServiceTest extends PluggableActivitiTestCase {
taskService.deleteTask(task.getId(), true);
}
public void testTaskComments() {
Task task = taskService.newTask();
task.setOwner("johndoe");
taskService.saveTask(task);
String taskId = task.getId();
identityService.setAuthenticatedUserId("johndoe");
// Fetch the task again and update
formService.addComment(taskId, null, "look at this");
Comment comment = formService.getTaskComments(taskId).get(0);
assertEquals("johndoe", comment.getUserId());
assertEquals(taskId, comment.getTaskId());
assertNull(comment.getProcessInstanceId());
assertEquals("look at this", comment.getMessage());
assertNotNull(comment.getTime());
formService.addComment(taskId, "pid", "one");
formService.addComment(taskId, "pid", "two");
Set<String> expectedComments = new HashSet<String>();
expectedComments.add("one");
expectedComments.add("two");
Set<String> comments = new HashSet<String>();
for (Comment cmt: formService.getProcessInstanceComments("pid")) {
comments.add(cmt.getMessage());
}
assertEquals(expectedComments, comments);
// Finally, delete task
taskService.deleteTask(taskId, true);
}
public void testTaskDelegation() {
Task task = taskService.newTask();
task.setOwner("johndoe");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册