use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testDeleteComment.
/**
* Test deleting a comment for a task.
* DELETE runtime/tasks/{taskId}/comments/{commentId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testDeleteComment() 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);
closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), HttpStatus.SC_NO_CONTENT));
// Test with unexisting instance
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
// Test with unexisting comment
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 HistoricProcessInstanceCommentResource method getComment.
@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("commentId") String commentId, HttpServletRequest request) {
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);
}
return restResponseFactory.createRestComment(comment);
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEntityManager method delete.
public void delete(PersistentObject persistentObject) {
checkHistoryEnabled();
super.delete(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_DELETED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class TaskCommentResourceTest method testGetComments.
/**
* Test getting all comments for a task.
* GET runtime/tasks/{taskId}/comments
*/
public void testGetComments() 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_COLLECTION, task.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertTrue(responseNode.isArray());
assertEquals(1, responseNode.size());
ObjectNode commentNode = (ObjectNode) responseNode.get(0);
assertEquals("kermit", commentNode.get("author").textValue());
assertEquals("This is a comment...", commentNode.get("message").textValue());
assertEquals(comment.getId(), commentNode.get("id").textValue());
assertTrue(commentNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), comment.getId())));
assertEquals(task.getId(), commentNode.get("taskId").asText());
assertTrue(commentNode.get("processInstanceUrl").isNull());
assertTrue(commentNode.get("processInstanceId").isNull());
// Test with unexisting task
httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, "unexistingtask"));
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 testCreateCommentWithProcessInstanceId.
@Deployment(resources = { "org/activiti/rest/service/api/oneTaskProcess.bpmn20.xml" })
public void testCreateCommentWithProcessInstanceId() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().singleResult();
ObjectNode requestNode = objectMapper.createObjectNode();
String message = "test";
requestNode.put("message", message);
requestNode.put("saveProcessInstanceId", true);
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(processInstance.getId(), responseNode.get("processInstanceId").asText());
assertEquals(task.getId(), responseNode.get("taskId").asText());
assertEquals(message, responseNode.get("message").asText());
assertNotNull(responseNode.get("time").asText());
assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT, task.getId(), commentsOnTask.get(0).getId())));
assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, processInstance.getId(), commentsOnTask.get(0).getId())));
}
Aggregations