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);
}
}
}
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);
}
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);
}
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();
}
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();
}
Aggregations