org.activiti.engine.task.Attachment Java Examples

The following examples show how to use org.activiti.engine.task.Attachment. 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: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #2
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    String processInstanceId = processInstance.getId();
    taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com");
    Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0);
    assertEquals("weatherforcast", attachment.getName());
    assertEquals("temperatures and more", attachment.getDescription());
    assertEquals("web page", attachment.getType());
    assertEquals(processInstanceId, attachment.getProcessInstanceId());
    assertNull(attachment.getTaskId());
    assertEquals("http://weather.com", attachment.getUrl());
    assertNull(taskService.getAttachmentContent(attachment.getId()));

    // Finally, clean up
    taskService.deleteAttachment(attachment.getId());

    // TODO: Bad API design. Need to fix attachment/comment properly
    ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
  }
}
 
Example #3
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #4
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public AttachmentResponse createAttachmentResponse(Attachment attachment, RestUrlBuilder urlBuilder) {
  AttachmentResponse result = new AttachmentResponse();
  result.setId(attachment.getId());
  result.setName(attachment.getName());
  result.setDescription(attachment.getDescription());
  result.setTime(attachment.getTime());
  result.setType(attachment.getType());
  result.setUserId(attachment.getUserId());

  if (attachment.getUrl() == null && attachment.getTaskId() != null) {
    // Attachment content can be streamed
    result.setContentUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, attachment.getTaskId(), attachment.getId()));
  } else {
    result.setExternalUrl(attachment.getUrl());
  }

  if (attachment.getTaskId() != null) {
    result.setUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_ATTACHMENT, attachment.getTaskId(), attachment.getId()));
    result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, attachment.getTaskId()));
  }
  if (attachment.getProcessInstanceId() != null) {
    result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, attachment.getProcessInstanceId()));
  }
  return result;
}
 
Example #5
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 #6
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #7
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 #8
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #9
Source File: TaskAttachmentCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get all attachments on a task", tags = {"Tasks"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the task was found and the attachments are returned."),
    @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})  
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.GET, produces = "application/json")
public List<AttachmentResponse> getAttachments(@ApiParam(name = "taskId", value="The id of the task to get the attachments for.") @PathVariable String taskId, HttpServletRequest request) {
  List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
  HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);

  for (Attachment attachment : taskService.getTaskAttachments(task.getId())) {
    result.add(restResponseFactory.createAttachmentResponse(attachment));
  }

  return result;
}
 
Example #10
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #11
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 文件类型的附件
 */
@RequestMapping(value = "new/file")
public String newFile(@RequestParam("taskId") String taskId, @RequestParam(value = "processInstanceId", required = false) String processInstanceId,
                      @RequestParam("attachmentName") String attachmentName, @RequestParam(value = "attachmentDescription", required = false) String attachmentDescription,
                      @RequestParam("file") MultipartFile file, HttpSession session) {
    try {
        String attachmentType = file.getContentType() + ";" + FilenameUtils.getExtension(file.getOriginalFilename());
        identityService.setAuthenticatedUserId(UserUtil.getUserFromSession(session).getId());
        Attachment attachment = taskService.createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription,
                file.getInputStream());
        taskService.saveAttachment(attachment);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "redirect:/chapter6/task/getform/" + taskId;
}
 
Example #12
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    
    String processInstanceId = processInstance.getId();
    taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com");
    Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0);
    assertEquals("weatherforcast", attachment.getName());
    assertEquals("temperatures and more", attachment.getDescription());
    assertEquals("web page", attachment.getType());
    assertEquals(processInstanceId, attachment.getProcessInstanceId());
    assertNull(attachment.getTaskId());
    assertEquals("http://weather.com", attachment.getUrl());
    assertNull(taskService.getAttachmentContent(attachment.getId()));
    
    // Finally, clean up
    taskService.deleteAttachment(attachment.getId());
    
    // TODO: Bad API design. Need to fix attachment/comment properly
    ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
  }
}
 
Example #13
Source File: StandaloneAttachmentEventsTest.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(Attachment.class);
	processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #14
Source File: AttachmentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteAttachmentsByTaskId(String taskId) {
  checkHistoryEnabled();
  List<AttachmentEntity> attachments = findAttachmentsByTaskId(taskId);
  boolean dispatchEvents = getEventDispatcher().isEnabled();

  String processInstanceId = null;
  String processDefinitionId = null;
  String executionId = null;

  if (dispatchEvents && attachments != null && !attachments.isEmpty()) {
    // Forced to fetch the task to get hold of the process definition
    // for event-dispatching, if available
    Task task = getTaskEntityManager().findById(taskId);
    if (task != null) {
      processDefinitionId = task.getProcessDefinitionId();
      processInstanceId = task.getProcessInstanceId();
      executionId = task.getExecutionId();
    }
  }

  for (Attachment attachment : attachments) {
    String contentId = attachment.getContentId();
    if (contentId != null) {
      getByteArrayEntityManager().deleteByteArrayById(contentId);
    }
    
    attachmentDataManager.delete((AttachmentEntity) attachment);
    
    if (dispatchEvents) {
      getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId));
    }
  }
}
 
Example #15
Source File: StandaloneAttachmentEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testAttachmentEntityEventsOnHistoricTaskDelete() throws Exception {
	if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
		Task task = null;
		try {
			task = taskService.newTask();
			taskService.saveTask(task);
			assertNotNull(task);
			
			// Create link-attachment
			Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
			listener.clearEventsReceived();
			
			// Delete task and historic task
			taskService.deleteTask(task.getId());
			historyService.deleteHistoricTaskInstance(task.getId());
			
			assertEquals(1, listener.getEventsReceived().size());
			ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
			assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
			assertNull(event.getProcessInstanceId());
			assertNull(event.getExecutionId());
			assertNull(event.getProcessDefinitionId());
			Attachment attachmentFromEvent = (Attachment) event.getEntity();
			assertEquals(attachment.getId(), attachmentFromEvent.getId());
			
		} finally {
			if(task != null && task.getId() != null) {
				taskService.deleteTask(task.getId());
				historyService.deleteHistoricTaskInstance(task.getId());
			}
		}
	}
}
 
Example #16
Source File: TaskAttachmentCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected AttachmentResponse createSimpleAttachment(AttachmentRequest attachmentRequest, Task task) {

    if (attachmentRequest.getName() == null) {
      throw new ActivitiIllegalArgumentException("Attachment name is required.");
    }

    Attachment createdAttachment = taskService.createAttachment(attachmentRequest.getType(), task.getId(), task.getProcessInstanceId(), attachmentRequest.getName(),
        attachmentRequest.getDescription(), attachmentRequest.getExternalUrl());

    return restResponseFactory.createAttachmentResponse(createdAttachment);
  }
 
Example #17
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #18
Source File: AttachmentEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testAttachmentEntityEventsOnHistoricTaskDelete() throws Exception {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = null;
    try {
      task = taskService.newTask();
      taskService.saveTask(task);
      assertNotNull(task);

      // Create link-attachment
      Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
      listener.clearEventsReceived();

      // Delete task and historic task
      taskService.deleteTask(task.getId());
      historyService.deleteHistoricTaskInstance(task.getId());

      assertEquals(1, listener.getEventsReceived().size());
      ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
      assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
      assertNull(event.getProcessInstanceId());
      assertNull(event.getExecutionId());
      assertNull(event.getProcessDefinitionId());
      Attachment attachmentFromEvent = (Attachment) event.getEntity();
      assertEquals(attachment.getId(), attachmentFromEvent.getId());

    } finally {
      if (task != null && task.getId() != null) {
        taskService.deleteTask(task.getId());
        historyService.deleteHistoricTaskInstance(task.getId());
      }
    }
  }
}
 
Example #19
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testTaskAttachments() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    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, null, "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());
    assertNull(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);
  }
}
 
Example #20
Source File: AttachmentEventsTest.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.Attachment.class);
	processEngineConfiguration.getEventDispatcher().addEventListener(listener);
}
 
Example #21
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Attachment createAttachment(String attachmentType, String taskId, String processInstanceId, String attachmentName, String attachmentDescription, InputStream content, String url) {
  try {
    org.activiti5.engine.impl.identity.Authentication.setAuthenticatedUserId(Authentication.getAuthenticatedUserId());
    if (content != null) {
      return new Activiti5AttachmentWrapper(getProcessEngine().getTaskService().
          createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription, content));
    } else {
      return new Activiti5AttachmentWrapper(getProcessEngine().getTaskService().
          createAttachment(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription, url));
    }
  } catch (org.activiti5.engine.ActivitiException e) {
    handleActivitiException(e);
    return null;
  }
}
 
Example #22
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testSaveTaskAttachment() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    Task task = taskService.newTask();
    task.setOwner("johndoe");
    taskService.saveTask(task);
    String taskId = task.getId();
    identityService.setAuthenticatedUserId("johndoe");
    
    // Fetch attachment and update its name
    taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", "http://weather.com");
    Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
    attachment.setName("UpdatedName");
    taskService.saveAttachment(attachment);
    
    // Refetch and verify
    attachment = taskService.getTaskAttachments(taskId).get(0);
    assertEquals("UpdatedName", attachment.getName());
    
    // Finally, clean up
    taskService.deleteTask(taskId);
    
    assertEquals(0, taskService.getTaskComments(taskId).size());
    assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());

    taskService.deleteTask(taskId, true);
  }
}
 
Example #23
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #24
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #25
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #26
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查看已结束任务
 */
@RequestMapping(value = "task/archived/{taskId}")
public ModelAndView viewHistoryTask(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form-archived";
    ModelAndView mav = new ModelAndView(viewName);
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
    if (task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }
    mav.addObject("task", task);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example #27
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #28
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查看已结束任务
 */
@RequestMapping(value = "task/archived/{taskId}")
public ModelAndView viewHistoryTask(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form-archived";
    ModelAndView mav = new ModelAndView(viewName);
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
    if (task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }
    mav.addObject("task", task);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example #29
Source File: AttachmentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 下载附件
 *
 * @throws IOException
 */
@RequestMapping(value = "download/{attachmentId}")
public void downloadFile(@PathVariable("attachmentId") String attachmentId, HttpServletResponse response) throws IOException {
    Attachment attachment = taskService.getAttachment(attachmentId);
    InputStream attachmentContent = taskService.getAttachmentContent(attachmentId);
    String contentType = StringUtils.substringBefore(attachment.getType(), ";");
    response.addHeader("Content-Type", contentType + ";charset=UTF-8");
    String extensionFileName = StringUtils.substringAfter(attachment.getType(), ";");
    String fileName = attachment.getName() + "." + extensionFileName;
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    IOUtils.copy(new BufferedInputStream(attachmentContent), response.getOutputStream());
}
 
Example #30
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 查看已结束任务
 */
@RequestMapping(value = "task/archived/{taskId}")
public ModelAndView viewHistoryTask(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form-archived";
    ModelAndView mav = new ModelAndView(viewName);
    HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
    if (task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }
    mav.addObject("task", task);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}