Beispiel #1
0
  /** 流程定义列表 */
  public Page<Object[]> processList(Page<Object[]> page, String category) {

    ProcessDefinitionQuery processDefinitionQuery =
        repositoryService
            .createProcessDefinitionQuery()
            .latestVersion()
            .orderByProcessDefinitionKey()
            .asc();

    if (StringUtils.isNotEmpty(category)) {
      processDefinitionQuery.processDefinitionCategory(category);
    }

    page.setCount(processDefinitionQuery.count());

    List<ProcessDefinition> processDefinitionList =
        processDefinitionQuery.listPage(page.getFirstResult(), page.getMaxResults());
    for (ProcessDefinition processDefinition : processDefinitionList) {
      String deploymentId = processDefinition.getDeploymentId();
      Deployment deployment =
          repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
      page.getList().add(new Object[] {processDefinition, deployment});
    }

    return page;
  }
  /**
   * 读取工作流定义的图片或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);
    }
  }
  /**
   * 查看流程定义图
   *
   * @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;
  }
Beispiel #4
0
  /**
   * 读取资源,通过部署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;
  }
  /*
   * (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;
  }
Beispiel #6
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";
  }
Beispiel #7
0
  /** 查询已经部署的流程,并且能够启动他 它(demo) add by hongbin */
  public String menu_process_list() {
    // List<Deployment> list = repositoryService.createDeploymentQuery().list();
    List<Object[]> list = new ArrayList<Object[]>();
    ProcessDefinitionQuery processDefinitionQuery =
        repositoryService
            .createProcessDefinitionQuery()
            .orderByDeploymentId()
            .latestVersion()
            .desc(); // 只需要最新的version就行了
    List<ProcessDefinition> processDefinitionList = processDefinitionQuery.list();

    for (ProcessDefinition processDefinition : processDefinitionList) {
      String deploymentId = processDefinition.getDeploymentId();
      Deployment deployment =
          repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
      // ProcessDefinitionEntity pde = (ProcessDefinitionEntity)processDefinition;
      //            Object model =
      // infActiviti.getVariableByProcessInstanceId(pde.getProcessDefinition().getId(),"model");

      list.add(new Object[] {processDefinition, deployment});
    }

    getAllUserAndGroupInfo();
    rhs.put("list", list);
    return "success";
  }
  /**
   * 级联删除流程定义
   *
   * @return
   */
  public String removeProcessDefinition() {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    ProcessDefinition processDefinition =
        repositoryService.getProcessDefinition(processDefinitionId);

    repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);

    return RELOAD_PROCESS_DEFINITION;
  }
 public static void deleteProcessCascade(String processDefinitionKey) {
   List<ProcessDefinition> processDefinitions =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionKey(processDefinitionKey)
           .list();
   for (ProcessDefinition processDefinition : processDefinitions) {
     repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);
   }
 }
Beispiel #10
0
  /**
   * easyui AJAX请求数据
   *
   * @param request
   * @param response
   * @param dataGrid
   */
  @RequestMapping(params = "datagrid")
  public void datagrid(
      HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

    ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
    List<ProcessDefinition> list = query.list();

    StringBuffer rows = new StringBuffer();
    int i = 0;
    for (ProcessDefinition pi : list) {
      Deployment deployment =
          repositoryService
              .createDeploymentQuery()
              .deploymentId(pi.getDeploymentId())
              .singleResult();
      i++;
      rows.append(
          "{'id':"
              + i
              + ",'processDefinitionId':'"
              + pi.getId()
              + "','deploymentDate':'"
              + new SimpleDateFormat("yyyy-MM-dd").format(deployment.getDeploymentTime())
              + "','resourceName':'"
              + pi.getResourceName()
              + "','deploymentId':'"
              + pi.getDeploymentId()
              + "','key':'"
              + pi.getKey()
              + "','name':'"
              + pi.getName()
              + "','version':'"
              + pi.getVersion()
              + "','isSuspended':'"
              + pi.isSuspended()
              + "'},");
    }
    String rowStr = StringUtils.substringBeforeLast(rows.toString(), ",");

    JSONObject jObject =
        JSONObject.fromObject("{'total':" + query.count() + ",'rows':[" + rowStr + "]}");
    responseDatagrid(response, jObject);
  }
Beispiel #11
0
  /**
   * 将部署的流程转换为模型
   *
   * @param procDefId
   * @throws UnsupportedEncodingException
   * @throws XMLStreamException
   */
  @Transactional(readOnly = false)
  public org.activiti.engine.repository.Model convertToModel(String procDefId)
      throws UnsupportedEncodingException, XMLStreamException {

    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(procDefId)
            .singleResult();
    InputStream bpmnStream =
        repositoryService.getResourceAsStream(
            processDefinition.getDeploymentId(), processDefinition.getResourceName());
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

    BpmnJsonConverter converter = new BpmnJsonConverter();
    ObjectNode modelNode = converter.convertToJson(bpmnModel);
    org.activiti.engine.repository.Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName());
    modelData.setCategory(processDefinition.getCategory()); // .getDeploymentId());
    modelData.setDeploymentId(processDefinition.getDeploymentId());
    modelData.setVersion(
        Integer.parseInt(
            String.valueOf(
                repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1)));

    ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion());
    modelObjectNode.put(
        ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);

    repositoryService.addModelEditorSource(
        modelData.getId(), modelNode.toString().getBytes("utf-8"));

    return modelData;
  }
  @Deployment(resources = {"org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml"})
  public void testDeleteDeploymentCascadeWithRunningInstances() {
    List<ProcessDefinition> processDefinitions =
        repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, processDefinitions.size());
    ProcessDefinition processDefinition = processDefinitions.get(0);

    runtimeService.startProcessInstanceById(processDefinition.getId());

    // Try to delete the deployment, no exception should be thrown
    repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);
  }
 public void viewXml() throws Exception {
   RepositoryService repositoryService = processEngine.getRepositoryService();
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(processDefinitionId)
           .singleResult();
   String resourceName = processDefinition.getResourceName();
   InputStream resourceAsStream =
       repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
   ServletActionContext.getResponse().setContentType("text/xml;charset=UTF-8");
   IoUtils.copyStream(resourceAsStream, ServletActionContext.getResponse().getOutputStream());
 }
 /** * 显示流程图 * * @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<KickstartWorkflowInfo> convertToWorkflowInfoList(
      List<ProcessDefinition> processDefinitions) {
    List<KickstartWorkflowInfo> infoList = new ArrayList<KickstartWorkflowInfo>();
    for (ProcessDefinition processDefinition : processDefinitions) {
      KickstartWorkflowInfo workflowInfo = new KickstartWorkflowInfo();
      workflowInfo.setId(processDefinition.getId());
      workflowInfo.setKey(processDefinition.getKey());
      workflowInfo.setName(processDefinition.getName());
      workflowInfo.setVersion(processDefinition.getVersion());
      workflowInfo.setDeploymentId(processDefinition.getDeploymentId());

      Date deploymentTime =
          repositoryService
              .createDeploymentQuery()
              .deploymentId(processDefinition.getDeploymentId())
              .singleResult()
              .getDeploymentTime();
      workflowInfo.setCreateTime(deploymentTime);

      workflowInfo.setNrOfRuntimeInstances(
          historyService
              .createHistoricProcessInstanceQuery()
              .processDefinitionId(processDefinition.getId())
              .unfinished()
              .count());
      workflowInfo.setNrOfHistoricInstances(
          historyService
              .createHistoricProcessInstanceQuery()
              .processDefinitionId(processDefinition.getId())
              .finished()
              .count());

      infoList.add(workflowInfo);
    }
    return infoList;
  }
 @RequestMapping(value = "/read-resource")
 public void readResource(
     @RequestParam("pdid") String processDefinitionId,
     @RequestParam("resourceName") String resourceName,
     HttpServletResponse response)
     throws Exception {
   ProcessDefinitionQuery pdq = repositoryService.createProcessDefinitionQuery();
   ProcessDefinition pd = pdq.processDefinitionId(processDefinitionId).singleResult();
   InputStream resourceAsStream =
       repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
   byte[] b = new byte[1024];
   int len = -1;
   while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
     response.getOutputStream().write(b, 0, len);
   }
 }
Beispiel #17
0
  /** 导出图片文件到硬盘 */
  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;
  }
  @Deployment(resources = {"org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml"})
  public void testDeleteDeploymentWithRunningInstances() {
    List<ProcessDefinition> processDefinitions =
        repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, processDefinitions.size());
    ProcessDefinition processDefinition = processDefinitions.get(0);

    runtimeService.startProcessInstanceById(processDefinition.getId());

    // Try to delete the deployment
    try {
      repositoryService.deleteDeployment(processDefinition.getDeploymentId());
      fail("Exception expected");
    } catch (RuntimeException ae) {
      // Exception expected when deleting deployment with running process
    }
  }
 /**
  * 查看资源文件(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);
   }
 }
  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;
  }
  @Test
  public void testClasspathDeployment() throws IOException {

    // 定义classpath
    String bpmnClasspath = "diagrams/userAndGroupInUserTask.bpmn";
    // 添加资源
    repositoryService.createDeployment().addClasspathResource(bpmnClasspath).deploy();
    // 获取流程定义对象
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    String resourceName = pd.getResourceName();
    System.out.println("资源名称:" + resourceName);

    // 读取资源字节流
    InputStream resourceAsStream =
        repositoryService.getResourceAsStream(pd.getDeploymentId(), resourceName);
    // 输出流的内容
    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = resourceAsStream.read(b)) != -1; ) {
      out.append(new String(b, 0, n));
    }
    System.out.println(out);
  }
Beispiel #22
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;
 }
Beispiel #23
0
  /**
   * @Title: myWorkTaskData @Description: TODO
   *
   * @param request
   * @param response
   * @param dataGrid void
   * @throws
   * @exception
   * @author fly
   * @date 2015年6月23日 上午10:20:42
   */
  @RequestMapping(params = "myWorkTaskData")
  public void myWorkTaskData(
      HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

    String userId = ResourceUtil.getSessionUserName().getId();
    // involvedUser 当前用户相关的
    HistoricProcessInstanceQuery query =
        historyService.createHistoricProcessInstanceQuery().involvedUser(userId);

    List<HistoricProcessInstance> historicTasks =
        query
            .orderByProcessInstanceStartTime()
            .desc()
            .listPage(dataGrid.getStart(), dataGrid.getEnd());
    long total = query.count();
    System.out.println(dataGrid.getStart() + " end: " + dataGrid.getEnd());
    StringBuffer rows = new StringBuffer();
    for (HistoricProcessInstance t : historicTasks) {
      ProcessDefinition processDefinition =
          repositoryService.getProcessDefinition(t.getProcessDefinitionId());

      rows.append(
          "{'id':'"
              + t.getId()
              + "','key':'"
              + processDefinition.getName()
              + "-"
              + DateUtils.date_sdf.format(t.getStartTime())
              + "','taskId':'"
              + t.getId()
              + "'");
      // 流程详细查看
      WorkFlowSetEntity workFlowSet =
          systemService.findUniqueByProperty(
              WorkFlowSetEntity.class, "deploymentId", processDefinition.getDeploymentId());
      if (workFlowSet != null) {
        rows.append(",'action':'" + workFlowSet.getDetailUrl() + "'");
      }
      // 流程用户处理
      if (t.getStartUserId() != null) {
        TSUser user = systemService.get(TSUser.class, t.getStartUserId());
        rows.append(",'username':'******'");
      }

      // 流程开始结束时间处理
      if (t.getStartTime() == null) {
        rows.append(",'beginDate':'无'");
      } else {
        rows.append(",'beginDate':'" + DateUtils.datetimeFormat.format(t.getStartTime()) + "'");
      }
      if (t.getEndTime() == null) {
        rows.append(",'endDate':'无','stateType':'办理中'");

      } else {
        rows.append(
            ",'endDate':'"
                + DateUtils.datetimeFormat.format(t.getEndTime())
                + "','stateType':'已完成'");
      }
      rows.append("},");
    }
    String rowStr = StringUtils.substringBeforeLast(rows.toString(), ",");

    JSONObject jObject = JSONObject.fromObject("{'total':" + total + ",'rows':[" + rowStr + "]}");
    responseDatagrid(response, jObject);
  }
  protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processDefinition.getId());

    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {

      boolean didDrawImage = false;

      if (ExplorerApp.get().isUseJavascriptDiagram()) {
        try {

          final InputStream definitionStream =
              repositoryService.getResourceAsStream(
                  processDefinition.getDeploymentId(), processDefinition.getResourceName());
          XMLInputFactory xif = XMLInputFactory.newInstance();
          XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
          BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

          if (bpmnModel.getFlowLocationMap().size() > 0) {

            int maxX = 0;
            int maxY = 0;
            for (String key : bpmnModel.getLocationMap().keySet()) {
              GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
              double elementX = graphicInfo.getX() + graphicInfo.getWidth();
              if (maxX < elementX) {
                maxX = (int) elementX;
              }
              double elementY = graphicInfo.getY() + graphicInfo.getHeight();
              if (maxY < elementY) {
                maxY = (int) elementY;
              }
            }

            Panel imagePanel = new Panel(); // using panel for scrollbars
            imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
            imagePanel.setWidth(100, UNITS_PERCENTAGE);
            imagePanel.setHeight(100, UNITS_PERCENTAGE);
            URL explorerURL = ExplorerApp.get().getURL();
            URL url =
                new URL(
                    explorerURL.getProtocol(),
                    explorerURL.getHost(),
                    explorerURL.getPort(),
                    explorerURL.getPath().replace("/ui", "")
                        + "diagram-viewer/index.html?processDefinitionId="
                        + processDefinition.getId()
                        + "&processInstanceId="
                        + processInstance.getId());
            Embedded browserPanel = new Embedded("", new ExternalResource(url));
            browserPanel.setType(Embedded.TYPE_BROWSER);
            browserPanel.setWidth(maxX + 350 + "px");
            browserPanel.setHeight(maxY + 220 + "px");

            HorizontalLayout panelLayoutT = new HorizontalLayout();
            panelLayoutT.setSizeUndefined();
            imagePanel.setContent(panelLayoutT);
            imagePanel.addComponent(browserPanel);

            panelLayout.addComponent(imagePanel);

            didDrawImage = true;
          }

        } catch (Exception e) {
          LOGGER.error("Error loading process diagram component", e);
        }
      }

      if (didDrawImage == false && processDefinitionEntity.isGraphicalNotationDefined()) {

        StreamResource diagram =
            new ProcessDefinitionImageStreamResourceBuilder()
                .buildStreamResource(processInstance, repositoryService, runtimeService);

        if (diagram != null) {
          Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
          header.addStyleName(ExplorerLayout.STYLE_H3);
          header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
          header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
          panelLayout.addComponent(header);

          Embedded embedded = new Embedded(null, diagram);
          embedded.setType(Embedded.TYPE_IMAGE);
          embedded.setSizeUndefined();

          Panel imagePanel = new Panel(); // using panel for scrollbars
          imagePanel.setScrollable(true);
          imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
          imagePanel.setWidth(100, UNITS_PERCENTAGE);
          imagePanel.setHeight(100, UNITS_PERCENTAGE);

          HorizontalLayout panelLayoutT = new HorizontalLayout();
          panelLayoutT.setSizeUndefined();
          imagePanel.setContent(panelLayoutT);
          imagePanel.addComponent(embedded);

          panelLayout.addComponent(imagePanel);
        }
      }
    }
  }