Search in sources :

Example 16 with Comment

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

the class HistoricProcessInstanceCommentResourceTest method testDeleteComment.

/**
   * Test deleting a comment for a task.
   * DELETE runtime/tasks/{taskId}/comments/{commentId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testDeleteComment() 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);
        closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), HttpStatus.SC_NO_CONTENT));
        // Test with unexisting instance
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
        // Test with unexisting comment
        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) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 17 with Comment

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

the class HistoricProcessInstanceCommentResource method getComment.

@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("commentId") String commentId, HttpServletRequest request) {
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    Comment comment = taskService.getComment(commentId);
    if (comment == null || comment.getProcessInstanceId() == null || !comment.getProcessInstanceId().equals(instance.getId())) {
        throw new ActivitiObjectNotFoundException("Process instance '" + instance.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    return restResponseFactory.createRestComment(comment);
}
Also used : Comment(org.activiti.engine.task.Comment) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Comment

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

the class CommentEntityManager method delete.

public void delete(PersistentObject persistentObject) {
    checkHistoryEnabled();
    super.delete(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_DELETED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
    }
}
Also used : Comment(org.activiti.engine.task.Comment)

Example 19 with Comment

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

the class TaskCommentResourceTest method testGetComments.

/**
   * Test getting all comments for a task.
   * GET runtime/tasks/{taskId}/comments
   */
public void testGetComments() 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);
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, task.getId()));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertTrue(responseNode.isArray());
        assertEquals(1, responseNode.size());
        ObjectNode commentNode = (ObjectNode) responseNode.get(0);
        assertEquals("kermit", commentNode.get("author").textValue());
        assertEquals("This is a comment...", commentNode.get("message").textValue());
        assertEquals(comment.getId(), commentNode.get("id").textValue());
        assertTrue(commentNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId())));
        assertEquals(task.getId(), commentNode.get("taskId").asText());
        assertTrue(commentNode.get("processInstanceUrl").isNull());
        assertTrue(commentNode.get("processInstanceId").isNull());
        // Test with unexisting task
        httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, "unexistingtask"));
        closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 20 with Comment

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

the class TaskCommentResourceTest method testCreateCommentWithProcessInstanceId.

@Deployment(resources = { "org/activiti/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testCreateCommentWithProcessInstanceId() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().singleResult();
    ObjectNode requestNode = objectMapper.createObjectNode();
    String message = "test";
    requestNode.put("message", message);
    requestNode.put("saveProcessInstanceId", true);
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, task.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    List<Comment> commentsOnTask = taskService.getTaskComments(task.getId());
    assertNotNull(commentsOnTask);
    assertEquals(1, commentsOnTask.size());
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("processInstanceId").asText());
    assertEquals(task.getId(), responseNode.get("taskId").asText());
    assertEquals(message, responseNode.get("message").asText());
    assertNotNull(responseNode.get("time").asText());
    assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).getId())));
    assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, processInstance.getId(), commentsOnTask.get(0).getId())));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) 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)

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