Search in sources :

Example 21 with Comment

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

the class TaskCommentResourceTest method testCreateComment.

/**
   * Test creating a comment for a task.
   * POST runtime/tasks/{taskId}/comments
   */
public void testCreateComment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("message", "This is a comment...");
        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("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(commentsOnTask.get(0).getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).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<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
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) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 22 with Comment

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

the class TaskCommentCollectionResource method createComment.

@RequestMapping(value = "/runtime/tasks/{taskId}/comments", method = RequestMethod.POST, produces = "application/json")
public CommentResponse createComment(@PathVariable String taskId, @RequestBody CommentRequest comment, HttpServletRequest request, HttpServletResponse response) {
    Task task = getTaskFromRequest(taskId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    String processInstanceId = null;
    if (comment.isSaveProcessInstanceId()) {
        Task taskEntity = taskService.createTaskQuery().taskId(task.getId()).singleResult();
        processInstanceId = taskEntity.getProcessInstanceId();
    }
    Comment createdComment = taskService.addComment(task.getId(), processInstanceId, comment.getMessage());
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createRestComment(createdComment);
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Comment

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

the class TaskCommentResource method getComment.

@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@PathVariable("taskId") String taskId, @PathVariable("commentId") String commentId, HttpServletRequest request) {
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    Comment comment = taskService.getComment(commentId);
    if (comment == null || !task.getId().equals(comment.getTaskId())) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    return restResponseFactory.createRestComment(comment);
}
Also used : Comment(org.activiti.engine.task.Comment) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with Comment

use of org.activiti.engine.task.Comment in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method deleteComment.

@DELETE
@Path("/{processInstanceId}/comments/{commentId}")
public Response deleteComment(@PathParam("processInstanceId") String processInstanceId, @PathParam("commentId") String commentId) {
    TaskService taskService = BPMNOSGIService.getTaskService();
    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);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : Comment(org.activiti.engine.task.Comment) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 25 with Comment

use of org.activiti.engine.task.Comment in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method createComment.

@POST
@Path("/{processInstanceId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createComment(@PathParam("processInstanceId") String processInstanceId, CommentResponse comment) {
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    Comment createdComment = taskService.addComment(null, instance.getId(), comment.getMessage());
    CommentResponse commentResponse = new RestResponseFactory().createRestComment(createdComment, uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(commentResponse).build();
}
Also used : Comment(org.activiti.engine.task.Comment) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

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