Search in sources :

Example 11 with Comment

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();
}
Also used : Comment(org.activiti.engine.task.Comment) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 12 with Comment

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));
    }
}
Also used : Comment(org.activiti.engine.task.Comment)

Example 13 with Comment

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;
}
Also used : Comment(org.activiti.engine.task.Comment) CommentEntityManager(org.activiti.engine.impl.persistence.entity.CommentEntityManager) ArrayList(java.util.ArrayList) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 14 with Comment

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());
            }
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

Example 15 with Comment

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());
            }
        }
    }
}
Also used : Comment(org.activiti.engine.task.Comment) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Comment (org.activiti.engine.task.Comment)30 Task (org.activiti.engine.task.Task)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 Deployment (org.activiti.engine.test.Deployment)7 HttpGet (org.apache.http.client.methods.HttpGet)7 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 ArrayList (java.util.ArrayList)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 Event (org.activiti.engine.task.Event)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2