/*
   * (non-Javadoc)
   *
   * @see com.template.service.common.workflow.IProcessDefinitionService#
   * exportProcessPic(org.activiti.engine.repository.ProcessDefinition,
   * java.lang.String)
   */
  @Override
  public boolean exportProcessPic(String deploymentId) {

    boolean flag = true;
    ProcessDefinition processDefinition =
        repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();

    String diagramResourceName = processDefinition.getDiagramResourceName();
    try {
      diagramResourceName = processDefinition.getDiagramResourceName();
      InputStream imageStream =
          repositoryService.getResourceAsStream(
              processDefinition.getDeploymentId(), diagramResourceName);

      byte[] b = new byte[imageStream.available()];
      imageStream.read(b, 0, b.length);

      File file =
          new File(
              workFlowPicPath
                  + File.separator
                  + processDefinition.getKey()
                  + "."
                  + FilenameUtils.getExtension(diagramResourceName));
      FileUtils.writeByteArrayToFile(file, b);
    } catch (IOException e) {
      flag = false;
    }
    return flag;
  }
  /**
   * 读取资源,通过部署ID
   *
   * @param processDefinitionId 流程定义ID
   * @param processInstanceId 流程实例ID
   * @param resourceType 资源类型(xml|image)
   */
  public InputStream resourceRead(String procDefId, String proInsId, String resType)
      throws Exception {

    if (StringUtils.isBlank(procDefId)) {
      ProcessInstance processInstance =
          runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
      procDefId = processInstance.getProcessDefinitionId();
    }
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(procDefId)
            .singleResult();

    String resourceName = "";
    if (resType.equals("image")) {
      resourceName = processDefinition.getDiagramResourceName();
    } else if (resType.equals("xml")) {
      resourceName = processDefinition.getResourceName();
    }

    InputStream resourceAsStream =
        repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
    return resourceAsStream;
  }
Exemple #3
0
  /**
   * 跳转到流程图型显示页面
   *
   * @return
   */
  public String process_diagram() {
    String processDefinitionId = getpara("processDefinitionId");
    String processInstanceId = getpara("processInstanceId");

    if (processDefinitionId.equals("")) {
      ProcessInstance processInstance =
          runtimeService
              .createProcessInstanceQuery()
              .processInstanceId(processInstanceId)
              .singleResult();
      processDefinitionId = processInstance.getProcessDefinitionId();
    }
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId)
            .singleResult();
    InputStream in =
        repositoryService.getResourceAsStream(
            processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());
    try {
      rhs.put("imgWidth", ImageIO.read(in).getWidth());
      in.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    rhs.put("processDefinitionId", processDefinitionId);
    rhs.put("processInstanceId", processInstanceId);
    return "success";
  }
  /**
   * 查看流程定义图
   *
   * @param request
   * @param processDefId 流程定义id
   * @return
   */
  @RequestMapping(value = "/viewprocessDefImage.do")
  public String viewprocessDefImage(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("processDefId") String processDefId)
      throws Exception {
    // 根据流程定义id查询流程定义
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(processDefId)
            .singleResult();

    InputStream inputStream =
        repositoryService.getResourceAsStream(
            processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());

    //        // 输出资源内容到相应对象
    //        byte[] b = new byte[1024];
    //        int len;
    //        while ((len = inputStream.read(b, 0, 1024)) != -1) {
    //        	response.getOutputStream().write(b, 0, len);
    //        }

    response.getOutputStream().write(IoUtil.readInputStream(inputStream, "processDefInputStream"));

    return null;
  }
  /**
   * 读取工作流定义的图片或xml
   *
   * @throws Exception
   */
  @RequestMapping(params = "resourceRead")
  public void resourceRead(
      @RequestParam("processDefinitionId") String processDefinitionId,
      @RequestParam("resourceType") String resourceType,
      HttpServletResponse response)
      throws Exception {
    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId)
            .singleResult();
    String resourceName = "";
    if (resourceType.equals("image")) {
      resourceName = processDefinition.getDiagramResourceName();
    } else if (resourceType.equals("xml")) {
      resourceName = processDefinition.getResourceName();
    }
    InputStream resourceAsStream =
        repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
    byte[] b = new byte[1024];
    int len = -1;

    while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
      response.getOutputStream().write(b, 0, len);
    }
  }
  public StreamResource buildStreamResource(
      ProcessDefinition processDefinition, RepositoryService repositoryService) {

    StreamResource imageResource = null;

    if (processDefinition.getDiagramResourceName() != null) {
      final InputStream definitionImageStream =
          repositoryService.getResourceAsStream(
              processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());

      StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);

      // Creating image name based on process-definition ID is fine, since the diagram image cannot
      // be altered once deployed.
      String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
      String fileName = processDefinition.getId() + "." + imageExtension;

      imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
    }

    return imageResource;
  }
 /** * 显示流程图 * * @return * @throws Exception */
 public String getProcessPic() throws Exception {
   // String taskId = //
   // "2901";//request.getParameter("taskId");3016,552,3020
   String procDefId = ""; // request.getParameter("procDefId");
   ProcessDefinition procDef =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(procDefId)
           .singleResult();
   String diagramResourceName = procDef.getDiagramResourceName();
   InputStream imageStream =
       repositoryService.getResourceAsStream(procDef.getDeploymentId(), diagramResourceName);
   // request.setAttribute("inputStream", imageStream);
   return "SUCCESS";
 }
  /** 导出图片文件到硬盘 */
  public List<String> exportDiagrams(String exportDir) throws IOException {
    List<String> files = new ArrayList<String>();
    List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();

    for (ProcessDefinition processDefinition : list) {
      String diagramResourceName = processDefinition.getDiagramResourceName();
      String key = processDefinition.getKey();
      int version = processDefinition.getVersion();
      String diagramPath = "";

      InputStream resourceAsStream =
          repositoryService.getResourceAsStream(
              processDefinition.getDeploymentId(), diagramResourceName);
      byte[] b = new byte[resourceAsStream.available()];

      @SuppressWarnings("unused")
      int len = -1;
      resourceAsStream.read(b, 0, b.length);

      // create file if not exist
      String diagramDir = exportDir + "/" + key + "/" + version;
      File diagramDirFile = new File(diagramDir);
      if (!diagramDirFile.exists()) {
        diagramDirFile.mkdirs();
      }
      diagramPath = diagramDir + "/" + diagramResourceName;
      File file = new File(diagramPath);

      // 文件存在退出
      if (file.exists()) {
        // 文件大小相同时直接返回否则重新创建文件(可能损坏)
        logger.debug("diagram exist, ignore... : {}", diagramPath);

        files.add(diagramPath);
      } else {
        file.createNewFile();
        logger.debug("export diagram to : {}", diagramPath);

        // wirte bytes to file
        FileUtils.writeByteArrayToFile(file, b, true);

        files.add(diagramPath);
      }
    }

    return files;
  }
 /**
  * 查看资源文件(bpmn文件和png图片文件)
  *
  * @throws IOException
  */
 public void viewResource() throws IOException {
   // 1.获得流程定义
   ProcessDefinition pd =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(model.getId())
           .singleResult();
   System.out.println(pd.getId());
   // 2.读取资源流
   InputStream inputStream =
       repositoryService.getResourceAsStream(pd.getDeploymentId(), pd.getDiagramResourceName());
   // 3.输出资源内容到页面
   byte[] b = new byte[1024];
   int len = -1;
   while ((len = inputStream.read(b, 0, 1024)) != -1) {
     response.getOutputStream().write(b, 0, len);
   }
 }
Exemple #10
0
 /**
  * 流程图型显示
  *
  * @return
  */
 public String process_diagram_simple() {
   try {
     HttpServletResponse resp = ServletActionContext.getResponse();
     String processDefinitionId = getpara("processDefinitionId");
     ProcessDefinition processDefinition =
         repositoryService
             .createProcessDefinitionQuery()
             .processDefinitionId(processDefinitionId)
             .singleResult();
     InputStream in =
         repositoryService.getResourceAsStream(
             processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());
     /*ImageIO.read(in).getWidth();
     resp.setContentType("image/png");
     ServletOutputStream out = resp.getOutputStream();
     BufferedInputStream bin = new BufferedInputStream(in);
     byte[] b = new byte[1024];
     int l = bin.read(b);
     while (l != -1) {
     	out.write(b);
     	l = bin.read(b);
     }
     bin.close();
     in.close();
     out.flush();
     out.close();*/
     // resp.setContentType("image/png");
     byte[] b = new byte[1024];
     int len = -1;
     while ((len = in.read(b, 0, 1024)) != -1) {
       resp.getOutputStream().write(b, 0, len);
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }