Search in sources :

Example 1 with Comment

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

the class HistoricProcessInstanceCommentCollectionResource method createComment.

@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments", method = RequestMethod.POST, produces = "application/json")
public CommentResponse createComment(@PathVariable String processInstanceId, @RequestBody CommentResponse comment, HttpServletRequest request, HttpServletResponse response) {
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    Comment createdComment = taskService.addComment(null, instance.getId(), comment.getMessage());
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createRestComment(createdComment);
}
Also used : Comment(org.activiti.engine.task.Comment) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Comment

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

the class HistoricProcessInstanceCommentResource method deleteComment.

@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", method = RequestMethod.DELETE)
public void deleteComment(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("commentId") String commentId, HttpServletRequest request, HttpServletResponse response) {
    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);
    }
    taskService.deleteComment(commentId);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
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 3 with Comment

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

the class RestResponseFactory method createRestCommentList.

public List<CommentResponse> createRestCommentList(List<Comment> comments) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<CommentResponse> responseList = new ArrayList<CommentResponse>();
    for (Comment instance : comments) {
        responseList.add(createRestComment(instance, urlBuilder));
    }
    return responseList;
}
Also used : CommentResponse(org.activiti.rest.service.api.engine.CommentResponse) Comment(org.activiti.engine.task.Comment) ArrayList(java.util.ArrayList)

Example 4 with Comment

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

the class TaskCommentResourceTest method testGetComment.

/**
   * Test getting a comment for a task.
   * GET runtime/tasks/{taskId}/comments/{commentId}
   */
public void testGetComment() 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, 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());
        // Test with unexisting task
        httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, "unexistingtask", "123"));
        closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
        // Test with unexisting comment
        httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), "unexistingcomment"));
        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) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with Comment

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

the class TaskCommentResourceTest method testDeleteComment.

/**
   * Test deleting a comment for a task.
   * DELETE runtime/tasks/{taskId}/comments/{commentId}
   */
public void testDeleteComment() 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);
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId()));
        closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
        // Test with unexisting task
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, "unexistingtask", "123"));
        closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
        // Test with unexisting comment
        httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), "unexistingcomment"));
        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) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet)

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