org.camunda.bpm.engine.TaskService.getTaskAttachments()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中org.camunda.bpm.engine.TaskService.getTaskAttachments()方法的一些代码示例,展示了TaskService.getTaskAttachments()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TaskService.getTaskAttachments()方法的具体详情如下:
包路径:org.camunda.bpm.engine.TaskService
类名称:TaskService
方法名:getTaskAttachments

TaskService.getTaskAttachments介绍

[英]The list of attachments associated to a task
[中]与任务关联的附件列表

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public List<AttachmentDto> getAttachments() {
 if (!isHistoryEnabled()) {
  return Collections.emptyList();
 }
 ensureTaskExists(Status.NOT_FOUND);
 List<Attachment> taskAttachments = engine.getTaskService().getTaskAttachments(taskId);
 List<AttachmentDto> attachments = new ArrayList<AttachmentDto>();
 for (Attachment attachment : taskAttachments) {
  attachments.add(AttachmentDto.fromAttachment(attachment));
 }
 return attachments;
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public List<AttachmentDto> getAttachments() {
 if (!isHistoryEnabled()) {
  return Collections.emptyList();
 }
 ensureTaskExists(Status.NOT_FOUND);
 List<Attachment> taskAttachments = engine.getTaskService().getTaskAttachments(taskId);
 List<AttachmentDto> attachments = new ArrayList<AttachmentDto>();
 for (Attachment attachment : taskAttachments) {
  attachments.add(AttachmentDto.fromAttachment(attachment));
 }
 return attachments;
}

代码示例来源:origin: camunda/camunda-bpm-platform

private void createTaskAttachmentWithContent(String taskId) {
 taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
 List<Attachment> taskAttachments = taskService.getTaskAttachments(taskId);
 assertEquals(1, taskAttachments.size());
 assertNotNull(taskService.getAttachmentContent(taskAttachments.get(0).getId()));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetTaskAttachmentsWithTaskIdNull() {
 int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
 if (historyLevel> ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
  assertEquals(Collections.<Attachment>emptyList(), taskService.getTaskAttachments(null));
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetTaskAttachmentsForNonExistingAttachments() {
 when(taskServiceMock.getTaskAttachments(EXAMPLE_TASK_ID)).thenReturn(Collections.<Attachment>emptyList());
 given()
  .pathParam("id", EXAMPLE_TASK_ID)
  .header("accept", MediaType.APPLICATION_JSON)
 .then().expect()
  .statusCode(Status.OK.getStatusCode())
  .contentType(ContentType.JSON)
  .body("$.size()", equalTo(0))
 .when()
  .get(SINGLE_TASK_ATTACHMENTS_URL);
}

代码示例来源:origin: camunda/camunda-bpm-platform

when(taskServiceMock.getTaskAttachment(EXAMPLE_TASK_ID, EXAMPLE_TASK_ATTACHMENT_ID)).thenReturn(mockTaskAttachment);
mockTaskAttachments = MockProvider.createMockTaskAttachments();
when(taskServiceMock.getTaskAttachments(EXAMPLE_TASK_ID)).thenReturn(mockTaskAttachments);
when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(mockTaskAttachment);
when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), any(InputStream.class))).thenReturn(mockTaskAttachment);

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentByteArray() {
 // given
 // create case instance
 CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");
 Task task = taskService.createTaskQuery().singleResult();
 String taskId = task.getId();
 taskService.createAttachment("foo", taskId, null, "something", null, new ByteArrayInputStream("someContent".getBytes()));
 // assume
 List<Attachment> attachments = taskService.getTaskAttachments(taskId);
 assertEquals(1, attachments.size());
 String contentId = findAttachmentContentId(attachments);
 terminateAndCloseCaseInstance(caseInstance.getId(), null);
 // when
 historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));
 // then
 attachments = taskService.getTaskAttachments(taskId);
 assertEquals(0, attachments.size());
 verifyByteArraysWereRemoved(contentId);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testGetTaskAttachments() {
 Response response = given().pathParam("id", MockProvider.EXAMPLE_TASK_ID)
  .header("accept", MediaType.APPLICATION_JSON)
  .then().expect()
   .statusCode(Status.OK.getStatusCode()).contentType(ContentType.JSON)
   .body("$.size()", equalTo(1))
  .when().get(SINGLE_TASK_ATTACHMENTS_URL);
 verifyTaskAttachments(mockTaskAttachments, response);
 verify(taskServiceMock).getTaskAttachments(MockProvider.EXAMPLE_TASK_ID);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentUrl() {
 // given
 // create case instance
 String caseInstanceId = caseService.createCaseInstanceByKey("oneTaskCase").getId();
 Task task = taskService.createTaskQuery().singleResult();
 taskService.createAttachment("foo", task.getId(), null, "something", null, "http://camunda.org");
 // assume
 List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
 assertEquals(1, attachments.size());
 terminateAndCloseCaseInstance(caseInstanceId, null);
 // when
 historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstanceId));
 // then
 attachments = taskService.getTaskAttachments(task.getId());
 assertEquals(0, attachments.size());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testCleanupTaskAttachmentWithContent() {
 //given
 final List<String> ids = prepareHistoricProcesses();
 List<Task> taskList = taskService.createTaskQuery().list();
 String taskWithAttachmentId = taskList.get(0).getId();
 createTaskAttachmentWithContent(taskWithAttachmentId);
 //remember contentId
 final String contentId = findAttachmentContentId(taskService.getTaskAttachments(taskWithAttachmentId));
 runtimeService.deleteProcessInstances(ids, null, true, true);
 //when
 historyService.deleteHistoricProcessInstancesBulk(ids);
 //then
 assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());
 assertEquals(0, taskService.getTaskAttachments(taskWithAttachmentId).size());
 //check that attachment content was removed
 verifyByteArraysWereRemoved(contentId);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testTaskAttachments() {
 int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
 if (historyLevel> ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
  Task task = taskService.newTask();
  task.setOwner("johndoe");
  taskService.saveTask(task);
  String taskId = task.getId();
  identityService.setAuthenticatedUserId("johndoe");
  // Fetch the task again and update
  taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", "http://weather.com");
  Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
  assertEquals("weatherforcast", attachment.getName());
  assertEquals("temperatures and more", attachment.getDescription());
  assertEquals("web page", attachment.getType());
  assertEquals(taskId, attachment.getTaskId());
  assertEquals("someprocessinstanceid", attachment.getProcessInstanceId());
  assertEquals("http://weather.com", attachment.getUrl());
  assertNull(taskService.getAttachmentContent(attachment.getId()));
  // Finally, clean up
  taskService.deleteTask(taskId);
  assertEquals(0, taskService.getTaskComments(taskId).size());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());
  taskService.deleteTask(taskId, true);
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine-rest-jaxrs2

@Override
public List<AttachmentDto> getAttachments() {
 if (!isHistoryEnabled()) {
  return Collections.emptyList();
 }
 ensureTaskExists(Status.NOT_FOUND);
 List<Attachment> taskAttachments = engine.getTaskService().getTaskAttachments(taskId);
 List<AttachmentDto> attachments = new ArrayList<AttachmentDto>();
 for (Attachment attachment : taskAttachments) {
  attachments.add(AttachmentDto.fromAttachment(attachment));
 }
 return attachments;
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

private void createTaskAttachmentWithContent(String taskId) {
 taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
 List<Attachment> taskAttachments = taskService.getTaskAttachments(taskId);
 assertEquals(1, taskAttachments.size());
 assertNotNull(taskService.getAttachmentContent(taskAttachments.get(0).getId()));
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
public void testGetTaskAttachmentsWithTaskIdNull() {
 int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
 if (historyLevel> ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
  assertEquals(Collections.<Attachment>emptyList(), taskService.getTaskAttachments(null));
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentByteArray() {
 // given
 // create case instance
 CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");
 Task task = taskService.createTaskQuery().singleResult();
 String taskId = task.getId();
 taskService.createAttachment("foo", taskId, null, "something", null, new ByteArrayInputStream("someContent".getBytes()));
 // assume
 List<Attachment> attachments = taskService.getTaskAttachments(taskId);
 assertEquals(1, attachments.size());
 String contentId = findAttachmentContentId(attachments);
 terminateAndCloseCaseInstance(caseInstance.getId(), null);
 // when
 historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));
 // then
 attachments = taskService.getTaskAttachments(taskId);
 assertEquals(0, attachments.size());
 verifyByteArraysWereRemoved(contentId);
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentUrl() {
 // given
 // create case instance
 String caseInstanceId = caseService.createCaseInstanceByKey("oneTaskCase").getId();
 Task task = taskService.createTaskQuery().singleResult();
 taskService.createAttachment("foo", task.getId(), null, "something", null, "http://camunda.org");
 // assume
 List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
 assertEquals(1, attachments.size());
 terminateAndCloseCaseInstance(caseInstanceId, null);
 // when
 historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstanceId));
 // then
 attachments = taskService.getTaskAttachments(task.getId());
 assertEquals(0, attachments.size());
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testCleanupTaskAttachmentWithContent() {
 //given
 final List<String> ids = prepareHistoricProcesses();
 List<Task> taskList = taskService.createTaskQuery().list();
 String taskWithAttachmentId = taskList.get(0).getId();
 createTaskAttachmentWithContent(taskWithAttachmentId);
 //remember contentId
 final String contentId = findAttachmentContentId(taskService.getTaskAttachments(taskWithAttachmentId));
 runtimeService.deleteProcessInstances(ids, null, true, true);
 //when
 historyService.deleteHistoricProcessInstancesBulk(ids);
 //then
 assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());
 assertEquals(0, taskService.getTaskAttachments(taskWithAttachmentId).size());
 //check that attachment content was removed
 verifyByteArraysWereRemoved(contentId);
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Test
public void testTaskAttachments() {
 int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
 if (historyLevel> ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
  Task task = taskService.newTask();
  task.setOwner("johndoe");
  taskService.saveTask(task);
  String taskId = task.getId();
  identityService.setAuthenticatedUserId("johndoe");
  // Fetch the task again and update
  taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", "http://weather.com");
  Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
  assertEquals("weatherforcast", attachment.getName());
  assertEquals("temperatures and more", attachment.getDescription());
  assertEquals("web page", attachment.getType());
  assertEquals(taskId, attachment.getTaskId());
  assertEquals("someprocessinstanceid", attachment.getProcessInstanceId());
  assertEquals("http://weather.com", attachment.getUrl());
  assertNull(taskService.getAttachmentContent(attachment.getId()));
  // Finally, clean up
  taskService.deleteTask(taskId);
  assertEquals(0, taskService.getTaskComments(taskId).size());
  assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());
  taskService.deleteTask(taskId, true);
 }
}

相关文章

微信公众号

最新文章

更多