use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class TaskCommentResourceTest method testGetCommentWithCompletedTask.
/**
* Test getting a comment for a completed task.
* GET runtime/tasks/{taskId}/comments/{commentId}
*/
public void testGetCommentWithCompletedTask() 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);
taskService.complete(task.getId());
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());
} finally {
// Clean adhoc-tasks even if test fails
List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
for (HistoricTaskInstance task : tasks) {
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testGetComment.
/**
* Test getting a comment for a historic process instance.
* GET history/historic-process-instances/{processInstanceId}/comments/{commentId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetComment() 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);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), 200);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
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("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())));
assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
assertTrue(responseNode.get("taskUrl").isNull());
assertTrue(responseNode.get("taskId").isNull());
// Test with unexisting process-instance
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
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());
}
}
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testCreateComment.
/**
* Test creating a comment for a process instance.
* POST history/historic-process-instances/{processInstanceId}/comments
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
ProcessInstance pi = null;
try {
pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("message", "This is a comment...");
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());
List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
assertNotNull(commentsOnProcess);
assertEquals(1, commentsOnProcess.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(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), commentsOnProcess.get(0).getId())));
assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
assertTrue(responseNode.get("taskUrl").isNull());
assertTrue(responseNode.get("taskId").isNull());
} finally {
if (pi != null) {
List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
for (Comment c : comments) {
taskService.deleteComment(c.getId());
}
}
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEntityManager method insert.
public void insert(PersistentObject persistentObject) {
checkHistoryEnabled();
super.insert(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_CREATED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class TaskCommentResource method deleteComment.
@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.DELETE)
public void deleteComment(@PathVariable("taskId") String taskId, @PathVariable("commentId") String commentId, HttpServletResponse response) {
// Check if task exists
Task task = getTaskFromRequest(taskId);
Comment comment = taskService.getComment(commentId);
if (comment == null || comment.getTaskId() == null || !comment.getTaskId().equals(task.getId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
}
taskService.deleteComment(commentId);
response.setStatus(HttpStatus.NO_CONTENT.value());
}
Aggregations