Search in sources :

Example 26 with Comment

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);
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) Event(org.activiti.engine.task.Event)

Example 27 with Comment

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);
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) Event(org.activiti.engine.task.Event)

Example 28 with Comment

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));
    }
}
Also used : Comment(org.activiti.engine.task.Comment)

Example 29 with Comment

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());
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 30 with Comment

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());
    }
}
Also used : Comment(org.activiti.engine.task.Comment) ActivitiException(org.activiti.engine.ActivitiException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Comment (org.activiti.engine.task.Comment)30 Task (org.activiti.engine.task.Task)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 Deployment (org.activiti.engine.test.Deployment)7 HttpGet (org.apache.http.client.methods.HttpGet)7 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 ArrayList (java.util.ArrayList)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 Event (org.activiti.engine.task.Event)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2