use of org.activiti.engine.task.Comment in project carbon-business-process by wso2.
the class HistoricProcessInstanceService method getComment.
@GET
@Path("/{processInstanceId}/comments/{commentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getComment(@PathParam("processInstanceId") String processInstanceId, @PathParam("commentId") String commentId) {
HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
TaskService taskService = BPMNOSGIService.getTaskService();
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);
}
CommentResponse commentResponse = new RestResponseFactory().createRestComment(comment, uriInfo.getBaseUri().toString());
return Response.ok().entity(commentResponse).build();
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEntityManagerImpl method delete.
@Override
public void delete(CommentEntity commentEntity) {
checkHistoryEnabled();
delete(commentEntity, false);
Comment comment = (Comment) commentEntity;
if (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 = getExecutionEntityManager().findById(comment.getProcessInstanceId());
if (process != null) {
processDefinitionId = process.getProcessDefinitionId();
}
}
getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class DeleteCommentCmd method execute.
public Void execute(CommandContext commandContext) {
CommentEntityManager commentManager = commandContext.getCommentEntityManager();
if (commentId != null) {
// Delete for an individual comment
Comment comment = commentManager.findComment(commentId);
if (comment == null) {
throw new ActivitiObjectNotFoundException("Comment with id '" + commentId + "' doesn't exists.", Comment.class);
}
commentManager.delete((CommentEntity) comment);
} else {
// Delete all comments on a task of process
ArrayList<Comment> comments = new ArrayList<Comment>();
if (processInstanceId != null) {
comments.addAll(commentManager.findCommentsByProcessInstanceId(processInstanceId));
}
if (taskId != null) {
comments.addAll(commentManager.findCommentsByTaskId(taskId));
}
for (Comment comment : comments) {
commentManager.delete((CommentEntity) comment);
}
}
return null;
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class CommentEventsTest method testCommentEntityEventsStandaloneTask.
public void testCommentEntityEventsStandaloneTask() throws Exception {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
Task task = null;
try {
task = taskService.newTask();
taskService.saveTask(task);
assertThat(task).isNotNull();
// Create link-comment
Comment comment = taskService.addComment(task.getId(), null, "comment");
assertThat(listener.getEventsReceived()).hasSize(2);
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_CREATED);
assertThat(event.getProcessInstanceId()).isNull();
assertThat(event.getExecutionId()).isNull();
assertThat(event.getProcessDefinitionId()).isNull();
Comment commentFromEvent = (Comment) event.getEntity();
assertThat(commentFromEvent.getId()).isEqualTo(comment.getId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_INITIALIZED);
listener.clearEventsReceived();
// Finally, delete comment
taskService.deleteComment(comment.getId());
assertThat(listener.getEventsReceived()).hasSize(1);
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertThat(event.getType()).isEqualTo(ActivitiEventType.ENTITY_DELETED);
assertThat(event.getProcessInstanceId()).isNull();
assertThat(event.getExecutionId()).isNull();
assertThat(event.getProcessDefinitionId()).isNull();
commentFromEvent = (Comment) event.getEntity();
assertThat(commentFromEvent.getId()).isEqualTo(comment.getId());
} finally {
if (task != null && task.getId() != null) {
taskService.deleteTask(task.getId());
historyService.deleteHistoricTaskInstance(task.getId());
}
}
}
}
use of org.activiti.engine.task.Comment in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testGetComments.
/**
* Test getting all comments for a historic process instance.
* GET history/historic-process-instances/{processInstanceId}/comments
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetComments() 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_COLLECTION, pi.getId())), HttpStatus.SC_OK);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
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("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())));
assertEquals(pi.getProcessInstanceId(), commentNode.get("processInstanceId").asText());
assertTrue(commentNode.get("taskUrl").isNull());
assertTrue(commentNode.get("taskId").isNull());
// Test with unexisting task
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COMMENT_COLLECTION, "unexistingtask")), HttpStatus.SC_NOT_FOUND));
} finally {
if (pi != null) {
List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
for (Comment c : comments) {
taskService.deleteComment(c.getId());
}
}
}
}
Aggregations