Search in sources :

Example 6 with Comment

use of org.activiti.engine.task.Comment in project Activiti by Activiti.

the class TaskCommentResourceTest method testGetCommentWithCompletedTask.

/**
   * Test getting a comment for a completed task.
   * GET runtime/tasks/{taskId}/comments/{commentId}
   */
public void testGetCommentWithCompletedTask() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Add a comment as "kermit"
        identityService.setAuthenticatedUserId("kermit");
        Comment comment = taskService.addComment(task.getId(), null, "This is a comment...");
        identityService.setAuthenticatedUserId(null);
        taskService.complete(task.getId());
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId()));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(comment.getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId())));
        assertEquals(task.getId(), responseNode.get("taskId").asText());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
        assertTrue(responseNode.get("processInstanceId").isNull());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : tasks) {
            historyService.deleteHistoricTaskInstance(task.getId());
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with Comment

use of org.activiti.engine.task.Comment in project Activiti by Activiti.

the class HistoricProcessInstanceCommentResourceTest method testGetComment.

/**
   * Test getting a comment for a historic process instance.
   * GET history/historic-process-instances/{processInstanceId}/comments/{commentId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetComment() throws Exception {
    ProcessInstance pi = null;
    try {
        pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        // Add a comment as "kermit"
        identityService.setAuthenticatedUserId("kermit");
        Comment comment = taskService.addComment(null, pi.getId(), "This is a comment...");
        identityService.setAuthenticatedUserId(null);
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), 200);
        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(comment.getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())));
        assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
        assertTrue(responseNode.get("taskUrl").isNull());
        assertTrue(responseNode.get("taskId").isNull());
        // Test with unexisting process-instance
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), "unexistingcomment")), HttpStatus.SC_NOT_FOUND));
    } finally {
        if (pi != null) {
            List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
            for (Comment c : comments) {
                taskService.deleteComment(c.getId());
            }
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 8 with Comment

use of org.activiti.engine.task.Comment in project Activiti by Activiti.

the class HistoricProcessInstanceCommentResourceTest method testCreateComment.

/**
   * Test creating a comment for a process instance.
   * POST history/historic-process-instances/{processInstanceId}/comments
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
    ProcessInstance pi = null;
    try {
        pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("message", "This is a comment...");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());
        List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
        assertNotNull(commentsOnProcess);
        assertEquals(1, commentsOnProcess.size());
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), commentsOnProcess.get(0).getId())));
        assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
        assertTrue(responseNode.get("taskUrl").isNull());
        assertTrue(responseNode.get("taskId").isNull());
    } finally {
        if (pi != null) {
            List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
            for (Comment c : comments) {
                taskService.deleteComment(c.getId());
            }
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Comment(org.activiti.engine.task.Comment) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 9 with Comment

use of org.activiti.engine.task.Comment in project Activiti by Activiti.

the class CommentEntityManager method insert.

public void insert(PersistentObject persistentObject) {
    checkHistoryEnabled();
    super.insert(persistentObject);
    Comment comment = (Comment) persistentObject;
    if (getProcessEngineConfiguration().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 = getProcessInstanceManager().findExecutionById(comment.getProcessInstanceId());
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }
        getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
        getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
    }
}
Also used : Comment(org.activiti.engine.task.Comment)

Example 10 with Comment

use of org.activiti.engine.task.Comment in project Activiti by Activiti.

the class TaskCommentResource method deleteComment.

@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.DELETE)
public void deleteComment(@PathVariable("taskId") String taskId, @PathVariable("commentId") String commentId, HttpServletResponse response) {
    // Check if task exists
    Task task = getTaskFromRequest(taskId);
    Comment comment = taskService.getComment(commentId);
    if (comment == null || comment.getTaskId() == null || !comment.getTaskId().equals(task.getId())) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    taskService.deleteComment(commentId);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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