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