この記事の例では、Activiti フローチャート表示の実装方法を示します。具体的な手順は次のとおりです。
1. 画像コードを表示するテスト ケースは次のとおりです。
public void viewImage() throws Exception { // ウェアハウス サービス オブジェクトを作成します。 RepositoryService repositoryService = processEngine.getRepositoryService(); // ウェアハウスから表示する必要があるファイルを検索します。 repositoryService.getDeploymentResourceNames (deploymentId); String imageName = null for (String name : names); if(name.indexOf(".png")>=0){ imageName = name; } } if(imageName!=null){// File f = new File("e: /"+ imageName); // デプロイメント ID とファイル名を通じてファイルの入力ストリームを取得します。 InputStream in = repositoryService.getResourceAsStream(deploymentId, imageName); FileUtils.copyInputStreamToFile(in, f);
例証します:
1)deploymentIdはプロセスのデプロイメントIDです。
2) resourceName は、act_ge_bytearray テーブルの NAME_ 列の値です。
3) repositoryService の getDeploymentResourceNames メソッドを使用して、指定されたデプロイメント内のすべてのファイルの名前を取得します。
4) repositoryService の getResourceAsStream メソッドを使用してデプロイメント ID とファイル名を渡し、デプロイメントの下で指定された名前を持つファイルの入力ストリームを取得します。
5) 最後の IO ストリーム操作では、FileUtils ツールの copyInputStreamToFile メソッドを使用して、プロセス フローのファイルへのコピーを完了します。
2. Web プロジェクトのプロセス定義ページで画像を表示します。
public String viewImage(){InputStream in = repositoryService.getResourceAsStream.getImageStream(deploymentId,imageName);//ここでのメソッドの実際のプロジェクトはサービス HttpServletResponse resp = ServletActionContext.getResponse();try { OutputStream out = resp に配置する必要があります.getOutputStream( ); // 画像入力プロセスをそれぞれの出力ストリームに書き込みます byte[] b = new byte[1024]; for (int len = -1; (len= in.read(b))!=-1; ) { out.write(b, 0, len) } // ストリームを閉じる.close( ); in.close();} catch (IOException e) { e.printStackTrace();}return null;}
例証します:
1)deploymentIdはプロセスデプロイメントID、imageNameはイメージ名です。
2) プロセス定義一覧ページからイメージを参照するため、プロセス定義(ProcessDefinition)からidとimageNameを取得できます(String getDeploymentId();、String getDiagramResourceName();)。
3) Web ページ タグ <a target="_blank" href="viewImage?deploymentId=1&imageName=imageName.png" rel="external nofollow" >フローチャートを表示</a>
3. Web プロジェクトの現在のフローチャートを表示する
public String viewCurrentImage(){ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId);// 1. プロセス デプロイメント ID を取得します putContext("deploymentId", pd.getDeploymentId());// 2. プロセス イメージの名前を取得します putContext ("imageName" , pd.getDiagramResourceName());// 3. 現在のアクティビティの座標を取得します。 Map<String,Object> currentActivityCoowned =service.getCurrentActivityCoowned(taskId);putContext("acs", currentActivityCoowned);return "image";}
service.getProcessDefinitionByTaskId(taskId) のコード実装は次のとおりです。
public ProcessDefinition getProcessDefinitionByTaskId(String taskId) {// 1. taskTask を取得します task = taskService.createTaskQuery().taskId(taskId).singleResult();// 2. タスク オブジェクトの pdid を通じてプロセス定義オブジェクト ProcessDefinition を取得します pd = repositoryService.getProcessDefinition (task.getProcessDefinitionId());return PD;}
service.getCurrentActivityCoowned(taskId); のコード実装は次のとおりです。
public Map<String, Object> getCurrentActivityCoowned(String taskId) {Map<String, Object> 座標 = new HashMap<String, Object>() // 1. 現在アクティブな IDTask タスクを取得します = taskService.createTaskQuery().taskId ( taskId).singleResult();ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();String currentActivitiId = pi.getActivityId();// 2. プロセス定義を取得します ProcessDefinitionEntity pd = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(task.getProcessDefinitionId() ));// 3. プロセス定義を使用して、currentActivitiId を通じてアクティビティ オブジェクト ActivityImpl を取得します。 activity = pd.findActivity(currentActivitiId);// 4. アクティビティの座標を取得します。 put("y" , activity.getY());座標.put("幅", activity.getWidth());座標.put("高さ", activity.getHeight());座標を返します;}
画像ページ部分:
個人タスク リスト ページから、<a target="_blank" href="/viewCurrentImage?taskId=1" rel="external nofollow" >現在のフローチャートを表示</a> をクリックして、次のページに移動します。
<body><!-- 1. ルール フローチャートを取得します。ここでは、strust2 タグを使用して、上の値スタックに入れられた値を取得します--><img style="position:Absolute;top:0px;left:0px。 ; " src="viewImage?deploymentId=<s:property value='#deploymentId'/>&imageName=<s:property value='#imageName'/>"><!-- 2. 現在のアクティビティの座標に従って DIV を動的に描画します --><div style="position:Absolute;border:1px Solid red;top:<s:プロパティ値 ='#acs.y'/>px;左: <s:property value='#acs.x'/>px;幅: <s:property value='#acs.width'/>px;height:<s:property value='#acs.height'/>px; "></div></body>