5.獲取流程定義文檔的資源(查看流程圖附件)
/**
* 功能: 獲取流程圖.<br/>
* date: 2014年12月16日 下午4:22:30 <br/>
*
* @author [email protected]
* @throws IOException
*/
@Test
public void viewPicture() throws IOException {
// 部署Id
String deploymentId = "1001";
// 獲取圖片資源名稱
List<String> list = processEngine.getRepositoryService().getDeploymentResourceNames(deploymentId);
// 定義圖片資源名稱
String resourceName = "";
if (null != list && list.size() > 0) {
for (String name : list) {
if (name.indexOf(".png") >= 0) {
resourceName = name;
}
}
}
// 獲取圖片的輸入流
InputStream in = processEngine.getRepositoryService().getResourceAsStream(deploymentId, resourceName);
// 將輸入流的圖片寫到D盤
FileUtils.copyInputStreamToFile(in, new File("D:/" + resourceName));
}
說明:
1)deploymentId爲流程部署ID
2)resourceName爲act_ge_bytearray表中NAME_列的值
3)使用repositoryService的getDeploymentResourceNames方法可以獲取指定部署下得所有文件的名稱
4)使用repositoryService的getResourceAsStream方法傳入部署ID和資源圖片名稱可以獲取部署下指定名稱文件的輸入流
5)最後的有關IO流的操作,使用FileUtils工具的copyInputStreamToFile方法完成流程流程到文件的拷貝,將資源文件以流的形式輸出到指定文件夾下
6.查詢最新版本的流程定義
/**
* 功能: 查詢最新版本的流程定義.<br/>
* date: 2014年12月16日 下午4:56:04 <br/>
*
* @author [email protected]
*/
@Test
public void queryUltimatelyVersionProcessDefinition() {
List<ProcessDefinition> list = processEngine.getRepositoryService().createProcessDefinitionQuery()
.orderByProcessDefinitionVersion().asc()// 使用流程定義版本升序排列
.list();
// 當map集合key相同時,後一次的值將替換原來的值
Map<String, ProcessDefinition> map = new LinkedHashMap<>();
if (null != list && list.size() > 0) {
for (ProcessDefinition pd : list) {
map.put(pd.getKey(), pd);
}
}
List<ProcessDefinition> pdList = new ArrayList<>(map.values());
if (null != pdList && pdList.size() > 0) {
for (ProcessDefinition pd : pdList) {
System.out.println("流程定義ID:" + pd.getId()); // key + 版本 + 隨機數
System.out.println("流程定義的名稱:" + pd.getName()); // 對應bpmn文件中Name屬性
System.out.println("流程定義的key:" + pd.getKey()); // 對應bpmn文件中ID屬性
System.out.println("流程定義的版本:" + pd.getVersion()); // 當流程定義的key值相同下,版本升級,默認是1
System.out.println("部署對象的ID:" + pd.getDeploymentId());
System.out.println("資源文件bpmn名稱:" + pd.getResourceName());
System.out.println("資源文件png名稱:" + pd.getDiagramResourceName());
System.out.println("############################################");
}
}
}
7.刪除流程定義(key相同的所有不同版本的流程定義)
/**
* 功能: 刪除流程定義(key相同的所有不同版本的流程定義).<br/>
* date: 2014年12月16日 下午5:06:10 <br/>
*
* @author [email protected]
*/
@Test
public void deleteProcessDefinitionByKey() {
// 流程定義的key
String processDefinitionKey = "helloworld";
// 先根據key查詢處所有版本的流程定義
List<ProcessDefinition> list = processEngine.getRepositoryService().createProcessDefinitionQuery()
.processDefinitionKey(processDefinitionKey) // 使用流程定義的key查詢
.list();
if (null != list && list.size() > 0) {
for (ProcessDefinition pd : list) {
// 獲取部署Id
String deploymentId = pd.getDeploymentId();
processEngine.getRepositoryService().deleteDeployment(deploymentId, true);
}
}
}
總結:
- Deployment 部署對象
1 .一次部署的多個文件的信息。對於不需要的流程可以刪除和修改。
2 .對應的表:
act_re_deployment :部署對象表
act_re_procdef :流程定義表
act_ge_bytearray :資源文件表
act_ge_property :主鍵生成策略表
- ProcessDefinition流程定義