Liferay7 BPM门户开发之45: 集成Activiti文件上传部署流程BPMN模型

时间:2023-01-28 20:58:56

开发文件上传,部署流程模板。

首先,开发jsp页面,deploy.jsp

<%@ include file="/init.jsp" %>

<h3>${RETURN_MESSAGE}</h3>
<h2><liferay-ui:message key="Deploy"/></h2> <portlet:actionURL var="uploadURL" name="deployUploadAction">
<portlet:param name="mvcRenderCommandName" value="/deployUploadAction" />
</portlet:actionURL> <form action="${uploadURL }" method="post" enctype="multipart/form-data" style="margin-top:1em;">
<input type="file" name="file" /><br>
<input type="submit" value="Upload Model" class="btn" />
</form>
<hr class="soften" />

其中,上传form的action为portlet:actionURL,它的name就是在portlet类中的方法名,即deployUploadAction

接下来开发action代码

对应的上传处理代码段deployUploadAction:

public void deployUploadAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception{

        UploadPortletRequest upr = PortalUtil.getUploadPortletRequest(actionRequest);
String fileFieldName = "file"; if (upr.getSize(fileFieldName) == 0)
{
throw new Exception("空文件!");
}
String fileName = upr.getFileName(fileFieldName);
try {
// 得到输入流(字节流)对象
InputStream fileInputStream = upr.getFileAsStream(fileFieldName);//file.getInputStream();
// 文件的扩展名
String extension = FilenameUtils.getExtension(fileName);
// zip或者bar类型的文件用ZipInputStream方式部署
DeploymentBuilder deployment = repositoryService.createDeployment();
if (extension.equals("zip") || extension.equals("bar")) {
ZipInputStream zip = new ZipInputStream(fileInputStream);
deployment.addZipInputStream(zip);
} else if (extension.equals("xml")){
// xml类型的文件
deployment.addInputStream(fileName, fileInputStream);
}
deployment.deploy();
_log.info(fileName +" deploy success!");
} catch (Exception e) {
_log.error(fileName + " error on deploy process, because of file input stream");
} String message = "BPMN file upload success!";
actionRequest.setAttribute("RETURN_MESSAGE", message);
}

运行界面:

首页,一开始有7个流程模型。

Liferay7 BPM门户开发之45: 集成Activiti文件上传部署流程BPMN模型

上传xml文件,同时也支持zip、bar文件

Liferay7 BPM门户开发之45: 集成Activiti文件上传部署流程BPMN模型

上传成功,部署模板后,发现多出了一个。Liferay7 BPM门户开发之45: 集成Activiti文件上传部署流程BPMN模型

程序调试日志

Liferay7 BPM门户开发之45: 集成Activiti文件上传部署流程BPMN模型

Activiti的集成开发系列文章集合在这里:

http://www.cnblogs.com/starcrm/p/6047486.html

方便索引。

全部工程源代码下载

http://download.csdn.net/detail/starcrm/9713027