org.activiti.engine.task.Comment Java Examples

The following examples show how to use org.activiti.engine.task.Comment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommentEntityManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
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(FlowableEngineEventType.ENTITY_DELETED, persistentObject, processInstanceId, processInstanceId, processDefinitionId));
    }
}
 
Example #2
Source File: PurchaseApplyUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public List<AuditMessageDto> getAuditMessage(@RequestBody PurchaseApplyDto purchaseApplyDto) {

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(purchaseApplyDto.getTaskId()).singleResult();
        String processInstanceId = task.getProcessInstanceId();
        List<Comment> comments = taskService.getProcessInstanceComments(processInstanceId);
        List<AuditMessageDto> auditMessageDtos = new ArrayList<>();
        if (comments == null || comments.size() < 1) {
            return auditMessageDtos;
        }
        AuditMessageDto messageDto = null;
        for (Comment comment : comments) {
            messageDto = new AuditMessageDto();
            messageDto.setCreateTime(comment.getTime());
            messageDto.setUserId(comment.getUserId());
            messageDto.setMessage(comment.getFullMessage());
        }

        return auditMessageDtos;
    }
 
Example #3
Source File: CommentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void insert(CommentEntity commentEntity) {
  checkHistoryEnabled();
  
  insert(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_CREATED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
    getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
  }
}
 
Example #4
Source File: TaskAttachmentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get an attachment on a task", tags = {"Tasks"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the task and attachment were found and the attachment is returned."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found or the tasks doesn’t have a attachment with the given ID.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", method = RequestMethod.GET, produces = "application/json")
public AttachmentResponse getAttachment(@ApiParam(name = "taskId", value="The id of the task to get the attachment for.") @PathVariable("taskId") String taskId,@ApiParam(name = "attachmentId", value="The id of the attachment.") @PathVariable("attachmentId") String attachmentId, HttpServletRequest request) {

  HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);

  Attachment attachment = taskService.getAttachment(attachmentId);
  if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
    throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
  }

  return restResponseFactory.createAttachmentResponse(attachment);
}
 
Example #5
Source File: ComplaintUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
public List<AuditMessageDto> getAuditMessage(@RequestBody ComplaintDto complaintDto) {

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(complaintDto.getTaskId()).singleResult();
        String processInstanceId = task.getProcessInstanceId();
        List<Comment> comments = taskService.getProcessInstanceComments(processInstanceId);
        List<AuditMessageDto> auditMessageDtos = new ArrayList<>();
        if (comments == null || comments.size() < 1) {
            return auditMessageDtos;
        }
        AuditMessageDto messageDto = null;
        for (Comment comment : comments) {
            messageDto = new AuditMessageDto();
            messageDto.setCreateTime(comment.getTime());
            messageDto.setUserId(comment.getUserId());
            messageDto.setMessage(comment.getFullMessage());
        }

        return auditMessageDtos;
    }
 
Example #6
Source File: TaskAttachmentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete an attachment on a task", tags = {"Tasks"})
@ApiResponses(value = {
    @ApiResponse(code = 204, message = "Indicates the task and attachment were found and the attachment is deleted. Response body is left empty intentionally."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found or the tasks doesn’t have a attachment with the given ID.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", method = RequestMethod.DELETE)
public void deleteAttachment(@ApiParam(name = "taskId", value="The id of the task to delete the attachment for.") @PathVariable("taskId") String taskId,@ApiParam(name = "attachmentId", value="The id of the attachment.") @PathVariable("attachmentId") String attachmentId, HttpServletResponse response) {

  Task task = getTaskFromRequest(taskId);

  Attachment attachment = taskService.getAttachment(attachmentId);
  if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
    throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
  }

  taskService.deleteAttachment(attachmentId);
  response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example #7
Source File: HistoricProcessInstanceCommentCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create a new comment on a historic process instance", tags = { "History" }, notes = "Parameter saveProcessInstanceId is optional, if true save process instance id of task with comment.")
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the comment was created and the result is returned."),
    @ApiResponse(code = 400, message = "Indicates the comment is missing from the request."),
    @ApiResponse(code = 404, message = "Indicates that the historic process instance could not be found.") })
@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments", method = RequestMethod.POST, produces = "application/json")
public CommentResponse createComment(@ApiParam("processInstanceId") @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);
}
 
Example #8
Source File: HistoricProcessInstanceCommentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a comment on a historic process instance", tags = { "History" }, notes = "")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the historic process instance and comment were found and the comment is returned."),
    @ApiResponse(code = 404, message = "Indicates the requested historic process instance was not found or the historic process instance doesn’t have a comment with the given ID.") })
@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@ApiParam(name="processInstanceId", value="The id of the historic process instance to get the comment for.") @PathVariable("processInstanceId") String processInstanceId,@ApiParam(name="commentId", value="The id of the comment.") @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);
}
 
Example #9
Source File: TaskCommentCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create a new comment on a task", tags = {"Tasks"},  nickname = "createTaskComments")
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the comment was created and the result is returned."),
    @ApiResponse(code = 400, message = "Indicates the comment is missing from the request."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/comments", method = RequestMethod.POST, produces = "application/json")
public CommentResponse createComment(@ApiParam(name = "taskId", value="The id of the task to create the comment for.") @PathVariable String taskId, @RequestBody CommentRequest comment, HttpServletRequest request, HttpServletResponse response) {

  Task task = getTaskFromRequest(taskId);

  if (comment.getMessage() == null) {
    throw new ActivitiIllegalArgumentException("Comment text is required.");
  }

  String processInstanceId = null;
  if (comment.isSaveProcessInstanceId()) {
    Task taskEntity = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    processInstanceId = taskEntity.getProcessInstanceId();
  }
  Comment createdComment = taskService.addComment(task.getId(), processInstanceId, comment.getMessage());
  response.setStatus(HttpStatus.CREATED.value());

  return restResponseFactory.createRestComment(createdComment);
}
 
Example #10
Source File: TaskCommentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = " Get a comment on a task", tags = {"Tasks"}, nickname = "getTaskComment")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the task and comment were found and the comment is returned."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found or the tasks doesn’t have a comment with the given ID.")
})
@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@ApiParam(name = "taskId", value="The id of the task to get the comment for.") @PathVariable("taskId") String taskId,@ApiParam(name = "commentId", value="The id of the comment.") @PathVariable("commentId") String commentId, HttpServletRequest request) {

  HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);

  Comment comment = taskService.getComment(commentId);
  if (comment == null || !task.getId().equals(comment.getTaskId())) {
    throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
  }

  return restResponseFactory.createRestComment(comment);
}
 
Example #11
Source File: HistoricProcessInstanceCommentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a comment on a historic process instance", tags = { "History" }, notes = "")
@ApiResponses(value = {
    @ApiResponse(code = 204, message = "Indicates the historic process instance and comment were found and the comment is deleted. Response body is left empty intentionally."),
    @ApiResponse(code = 404, message = "Indicates the requested historic process instance was not found or the historic process instance doesn’t have a comment with the given ID.") })
@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", method = RequestMethod.DELETE)
public void deleteComment(@ApiParam(name="processInstanceId", value="The id of the historic process instance to delete the comment for.") @PathVariable("processInstanceId") String processInstanceId, @ApiParam(name="commentId", value="The id of the comment.") @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());
}
 
Example #12
Source File: ProcessInstanceLogQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testIncludeTasksandComments() {
	ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId)
		.includeTasks()
		.includeComments()
		.singleResult();
	List<HistoricData> events = log.getHistoricData();
	assertEquals(5, events.size());
	
	for (int i=0; i<5; i++) {
		HistoricData event = events.get(i);
		if (i<2) { // tasks are created before comments
			assertTrue(event instanceof HistoricTaskInstance);
		} else {
			assertTrue(event instanceof Comment);
		}
	}
}
 
Example #13
Source File: TaskCommentResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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())));
}
 
Example #14
Source File: MybatisCommentDataManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Comment> findCommentsByTaskIdAndType(String taskId, String type) {
  Map<String, Object> params = new HashMap<String, Object>();
  params.put("taskId", taskId);
  params.put("type", type);
  return getDbSqlSession().selectListWithRawParameter("selectCommentsByTaskIdAndType", params, 0, Integer.MAX_VALUE);
}
 
Example #15
Source File: JumpTaskCmd.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Comment execute(CommandContext commandContext) {

    for (TaskEntity taskEntity : commandContext.getTaskEntityManager().findTasksByExecutionId(executionId)) {
        commandContext.getTaskEntityManager().deleteTask(taskEntity, "jump", false);
    }
    ExecutionEntity executionEntity = Context.getCommandContext().getExecutionEntityManager().findExecutionById(executionId);
    ProcessDefinitionImpl processDefinition = executionEntity.getProcessDefinition();
    ActivityImpl activity = processDefinition.findActivity(activityId);
    executionEntity.executeActivity(activity);

    return null;
}
 
Example #16
Source File: GetProcessInstanceCommentsCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Comment> execute(CommandContext commandContext) {
    if (StringUtils.isNotBlank(type)) {
        List<Comment> commentsByProcessInstanceId = commandContext
                .getCommentEntityManager()
                .findCommentsByProcessInstanceId(processInstanceId, type);
        return commentsByProcessInstanceId;
    } else {
        return commandContext
                .getCommentEntityManager()
                .findCommentsByProcessInstanceId(processInstanceId);
    }
}
 
Example #17
Source File: HistoricProcessInstanceCommentResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
      }
    }
  }
}
 
Example #18
Source File: StandaloneCommentEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
	super.setUp();
	
	listener = new TestActiviti6EntityEventListener(Comment.class);
	processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #19
Source File: CommentEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
	super.setUp();
	
	listener = new TestActivitiEntityEventListener(org.activiti5.engine.task.Comment.class);
	processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #20
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Comment addComment(String taskId, String processInstanceId, String type, String message) {
  try {
    return new Activiti5CommentWrapper(getProcessEngine().getTaskService().addComment(taskId, processInstanceId, type, message));
    
  } catch (org.activiti5.engine.ActivitiException e) {
    handleActivitiException(e);
    return null;
  }
}
 
Example #21
Source File: CommentEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public List<Comment> findCommentsByProcessInstanceId(String processInstanceId, String type) {
    checkHistoryEnabled();
    Map<String, Object> params = new HashMap<>();
    params.put("processInstanceId", processInstanceId);
    params.put("type", type);
    return getDbSqlSession().selectListWithRawParameter("selectCommentsByProcessInstanceIdAndType", params, 0, Integer.MAX_VALUE);
}
 
Example #22
Source File: CommentEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Comment> findCommentsByTaskIdAndType(String taskId, String type) {
    checkHistoryEnabled();
    Map<String, Object> params = new HashMap<>();
    params.put("taskId", taskId);
    params.put("type", type);
    return getDbSqlSession().selectListWithRawParameter("selectCommentsByTaskIdAndType", params, 0, Integer.MAX_VALUE);
}
 
Example #23
Source File: GetProcessInstanceCommentsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Comment> execute(CommandContext commandContext) {
  if (StringUtils.isNotBlank(type)) {
    List<Comment> commentsByProcessInstanceId = commandContext.getCommentEntityManager().findCommentsByProcessInstanceId(processInstanceId, type);
    return commentsByProcessInstanceId;
  } else {
    return commandContext.getCommentEntityManager().findCommentsByProcessInstanceId(processInstanceId);
  }
}
 
Example #24
Source File: ProcessInstanceLogQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testIncludeComments() {
  ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeComments().singleResult();
  List<HistoricData> events = log.getHistoricData();
  assertEquals(3, events.size());

  for (HistoricData event : events) {
    assertTrue(event instanceof Comment);
  }
}
 
Example #25
Source File: ProcessInstanceLogQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {

  for (Comment comment : taskService.getProcessInstanceComments(processInstanceId)) {
    taskService.deleteComment(comment.getId());
  }

  super.tearDown();
}
 
Example #26
Source File: DocumentApproveTest.java    From maven-framework-project with MIT License 5 votes vote down vote up
@Test
public void testDocApprovalFlow() throws InterruptedException {
    setSpringSecurity("kermit");
    Document doc = new Document();
    doc.setGroupId("engineering");
    doc.setCreatedDate(new Date());
    doc.setTitle("title");
    doc.setSummary("Summary");
    doc.setContent("content");
    doc.setAuthor("kermit");
    String docId;
    docId = documentService.createDocument(doc);
    log.debug("new doc id: " + docId);
    this.documentService.submitForApproval(docId);

    setSpringSecurity("fozzie");
    List<TaskForm> tasks = this.localTaskService.getTasks("fozzie");
    assertTrue(tasks.size() == 1);
    log.debug("got task: " + tasks.get(0).getName());
    localTaskService.approveTask(true, "task approved blah blah blah", tasks.get(0).getId());
    HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().
            includeProcessVariables().processInstanceBusinessKey(docId).singleResult();

    assertNotNull(pi);
    log.debug("Duration time in millis: " + pi.getDurationInMillis());
    List<HistoricTaskInstance> hTasks;
    hTasks = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().processInstanceBusinessKey(docId).list();
    assertTrue(hTasks.size() == 2);
    HistoricTaskInstance approval = hTasks.get(1);
    Map<String, Object> vars = approval.getTaskLocalVariables();
    List<Comment> comments = taskService.getTaskComments(approval.getId());
}
 
Example #27
Source File: CommentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public Comment findComment(String commentId) {
  return commentDataManager.findComment(commentId);
}
 
Example #28
Source File: GetCommentCmd.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Comment execute(CommandContext commandContext) {
  return commandContext.getCommentEntityManager().findComment(commentId);
}
 
Example #29
Source File: GetTaskCommentsCmd.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public List<Comment> execute(CommandContext commandContext) {
  return commandContext.getCommentEntityManager().findCommentsByTaskId(taskId);
}
 
Example #30
Source File: GlobalEventHandlerTest.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 执行流程
 */
private void execute() {
    // 验证是否部署成功
    long count = repositoryService.createProcessDefinitionQuery().count();
    assertEquals(1, count);

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult();

    // 设置当前用户
    String currentUserId = "henryyan";
    identityService.setAuthenticatedUserId(currentUserId);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Map<String, String> variables = new HashMap<String, String>();
    Calendar ca = Calendar.getInstance();
    String startDate = sdf.format(ca.getTime());
    ca.add(Calendar.DAY_OF_MONTH, 2); // 当前日期加2天
    String endDate = sdf.format(ca.getTime());

    // 启动流程
    variables.put("startDate", startDate);
    variables.put("endDate", endDate);
    variables.put("reason", "公休");
    ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), variables);
    assertNotNull(processInstance);

    // 部门领导审批通过
    Task deptLeaderTask = taskService.createTaskQuery().taskCandidateGroup("deptLeader").singleResult();
    variables = new HashMap<String, String>();
    variables.put("deptLeaderApproved", "true");
    formService.submitTaskFormData(deptLeaderTask.getId(), variables);

    // 人事审批通过
    Task hrTask = taskService.createTaskQuery().taskCandidateGroup("hr").singleResult();
    variables = new HashMap<String, String>();
    variables.put("hrApproved", "true");
    formService.submitTaskFormData(hrTask.getId(), variables);

    // 销假(根据申请人的用户ID读取)
    Task reportBackTask = taskService.createTaskQuery().singleResult();
    List<Comment> taskComments = taskService.getTaskComments(reportBackTask.getId(), "delegate");
    for (Comment taskComment : taskComments) {
        System.out.println("任务相关事件:" + taskComment.getFullMessage());
    }
    assertEquals(currentUserId, reportBackTask.getAssignee());
    variables = new HashMap<String, String>();
    variables.put("reportBackDate", sdf.format(ca.getTime()));
    formService.submitTaskFormData(reportBackTask.getId(), variables);

    // 验证流程是否已经结束
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().finished().singleResult();
    assertNotNull(historicProcessInstance);

    // 读取历史变量
    Map<String, Object> historyVariables = packageVariables(processInstance.getId());

    // 验证执行结果
    assertEquals("ok", historyVariables.get("result"));
}