use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class TaskServiceTest method testTaskComments.
public void testTaskComments() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
Task task = taskService.newTask();
task.setOwner("johndoe");
taskService.saveTask(task);
String taskId = task.getId();
Authentication.setAuthenticatedUserId("johndoe");
// Fetch the task again and update
taskService.addComment(taskId, null, "look at this \n isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd");
Comment comment = taskService.getTaskComments(taskId).get(0);
assertThat(comment.getUserId()).isEqualTo("johndoe");
assertThat(comment.getTaskId()).isEqualTo(taskId);
assertThat(comment.getProcessInstanceId()).isNull();
assertThat(((Event) comment).getMessage()).isEqualTo("look at this isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg ...");
assertThat(comment.getFullMessage()).isEqualTo("look at this \n isn't this great? slkdjf sldkfjs ldkfjs ldkfjs ldkfj sldkfj sldkfj sldkjg laksfg sdfgsd;flgkj ksajdhf skjdfh ksjdhf skjdhf kalskjgh lskh dfialurhg kajsh dfuieqpgkja rzvkfnjviuqerhogiuvysbegkjz lkhf ais liasduh flaisduh ajiasudh vaisudhv nsfd");
assertThat(comment.getTime()).isNotNull();
// Finally, delete task
taskService.deleteTask(taskId, true);
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class TaskServiceTest method testCustomTaskComments.
public void testCustomTaskComments() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
Task task = taskService.newTask();
task.setOwner("johndoe");
taskService.saveTask(task);
String taskId = task.getId();
Authentication.setAuthenticatedUserId("johndoe");
String customType1 = "Type1";
String customType2 = "Type2";
Comment comment = taskService.addComment(taskId, null, "This is a regular comment");
Comment customComment1 = taskService.addComment(taskId, null, customType1, "This is a custom comment of type Type1");
Comment customComment2 = taskService.addComment(taskId, null, customType1, "This is another Type1 comment");
Comment customComment3 = taskService.addComment(taskId, null, customType2, "This is another custom comment. Type2 this time!");
assertThat(comment.getType()).isEqualTo(CommentEntity.TYPE_COMMENT);
assertThat(customComment1.getType()).isEqualTo(customType1);
assertThat(customComment3.getType()).isEqualTo(customType2);
assertThat(taskService.getComment(comment.getId())).isNotNull();
assertThat(taskService.getComment(customComment1.getId())).isNotNull();
List<Comment> regularComments = taskService.getTaskComments(taskId);
assertThat(regularComments).hasSize(1);
assertThat(regularComments.get(0).getFullMessage()).isEqualTo("This is a regular comment");
List<Event> allComments = taskService.getTaskEvents(taskId);
assertThat(allComments).hasSize(4);
List<Comment> type2Comments = taskService.getCommentsByType(customType2);
assertThat(type2Comments).hasSize(1);
assertThat(type2Comments.get(0).getFullMessage()).isEqualTo("This is another custom comment. Type2 this time!");
List<Comment> taskTypeComments = taskService.getTaskComments(taskId, customType1);
assertThat(taskTypeComments).hasSize(2);
// Clean up
taskService.deleteTask(taskId, true);
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEntityManagerImpl method insert.
@Override
public void insert(CommentEntity commentEntity) {
checkHistoryEnabled();
insert(commentEntity, false);
Comment comment = (Comment) commentEntity;
if (getEventDispatcher().isEnabled()) {
// Forced to fetch the process-instance to associate the right
// process definition
String processDefinitionId = null;
String processInstanceId = comment.getProcessInstanceId();
if (comment.getProcessInstanceId() != null) {
ExecutionEntity process = getExecutionEntityManager().findById(comment.getProcessInstanceId());
if (process != null) {
processDefinitionId = process.getProcessDefinitionId();
}
}
getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEventsTest method testCommentEntityEvents.
/**
* Test create, update and delete events of comments on a task/process.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testCommentEntityEvents() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertThat(task).isNotNull();
// Create link-comment
Comment comment = taskService.addComment(task.getId(), task.getProcessInstanceId(), "comment");
assertThat(listener.getEventsReceived()).hasSize(2);
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_CREATED);
assertThat(event.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(event.getExecutionId()).isEqualTo(processInstance.getId());
assertThat(event.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
Comment commentFromEvent = (Comment) event.getEntity();
assertThat(commentFromEvent.getId()).isEqualTo(comment.getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_INITIALIZED);
listener.clearEventsReceived();
// Finally, delete comment
taskService.deleteComment(comment.getId());
assertThat(listener.getEventsReceived()).hasSize(1);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_DELETED);
assertThat(event.getProcessInstanceId()).isEqualTo(processInstance.getId());
assertThat(event.getExecutionId()).isEqualTo(processInstance.getId());
assertThat(event.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
commentFromEvent = (Comment) event.getEntity();
assertThat(commentFromEvent.getId()).isEqualTo(comment.getId());
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class ProcessInstanceCommentTest method testAddCommentToProcessInstance.
@Deployment
public void testAddCommentToProcessInstance() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcessInstanceComment");
taskService.addComment(null, processInstance.getId(), "Hello World");
List<Comment> comments = taskService.getProcessInstanceComments(processInstance.getId());
assertThat(comments).hasSize(1);
List<Comment> commentsByType = taskService.getProcessInstanceComments(processInstance.getId(), "comment");
assertThat(commentsByType).hasSize(1);
commentsByType = taskService.getProcessInstanceComments(processInstance.getId(), "noThisType");
assertThat(commentsByType).hasSize(0);
// Suspend process instance
runtimeService.suspendProcessInstanceById(processInstance.getId());
try {
taskService.addComment(null, processInstance.getId(), "Hello World 2");
} catch (ActivitiException e) {
assertThat(e.getMessage()).contains("Cannot add a comment to a suspended execution");
}
// Delete comments again
taskService.deleteComments(null, processInstance.getId());
}
}
Aggregations