activiti自定义流程之整合(四):整合自定义表单部署流程定义

来源:互联网 发布:nico sm是什么软件 编辑:程序博客网 时间:2024/05/18 00:40
综合前几篇博文内容,我想在整合这一部分中应该会有很多模块会跳过不讲,就如自定义表单的表单列表那一块,因为这些模块在整合的过程中都几乎没有什么改动,再多讲也是重复无用功。


正因为如此,在创建了流程模型之后,模型列表的展示也是和之前的没有什么区别,而且都是很简单的后台查询以及前台展示,这一部分也就不过多的讲了。


模型列表页面如下:


 
至于其中的修改和删除也没什么多讲的,删除很简单,而修改也是activiti-modeler实现的主要功能,我们只需要跳转过去就行。


重要的部分在于部署,因为点击部署到达后台以后,activiti就要和自定义的form表单打赏关系。
以上页面的html代码如下:
<div id="logdiv1" ng-init="init();">     <p style="font-size:24px;margin:3px">模型列表</p>     <center>    <table border="1px" style="margin-top:1px;width:87%;font-size:18px;text-align:center;margin-left:2px;margin-top:auto;position:relative;float:left;" cellSpacing="0px" cellPadding="0px">      <tr style="background-color:#ccc">         <td>ID</td>         <td>NAME</td>         <td>KEY</td>         <td>描 述</td>         <td>版本</td>         <td>创建时间</td>         <td>修改时间</td>         <td>操 作</td>      </tr>      <tr ng-repeat="model in modelList | orderBy:'id'" >         <td>{{model.id}}</td>         <td>{{model.name}}</td>         <td>{{model.key}}</td>         <td>{{model.metaInfo}}</td>         <td>{{model.version}}</td>         <td>{{model.createTime | date:"yyyy-MM-dd HH:mm:ss"}}</td>         <td>{{model.lastUpdateTime | date:"yyyy-MM-dd HH:mm:ss"}}</td>         <td><a href="script:;" ng-click="deploye(model)">部署</a>          <a href="script:;" ng-click="delete(model)">删除</a>          <a href="script:;" ng-click="update(model.id)">修改</a>         </td>      </tr>   </table>     </center> </div>  

点击部署要走到后台,前台就需要js控制,相应的js代码如下:
angular.module('activitiApp')  .controller('modelCtr', ['$rootScope','$scope','$http','$location', function($rootScope,$scope,$http,$location){  $scope.init=function(){        $http.post("./modelList.do").success(function(result) {        if(result.isLogin==="yes"){        $rootScope.userName=result.userName;            console.log(result.data);             $scope.modelList=result.data;        }else{        $location.path("/login");        }        });}          $scope.deploye=function(model){        console.log(model);        $http.post("./deploye.do",model).success(function(deployResult){        $location.path("/processList");        });        }                $scope.update=function(modelId){        window.open("http://localhost:8080/activitiTest1/service/editor?id="+modelId);        }        }])  



而后程序到达后台,后台代码如下:
/** * 根据模型id部署流程定义 *  * @author:tuzongxun * @Title: deploye * @param @param activitiModel * @param @param redirectAttributes * @param @return * @return Object * @date Mar 17, 2016 12:30:05 PM * @throws */@RequestMapping(value = "/deploye.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")@ResponseBodypublic Object deploye(@RequestBody ActivitiModel activitiModel,HttpServletRequest req) {Map<String, Object> map = new HashMap<String, Object>();boolean isLogin = this.isLogin(req);if (isLogin) {String modelId = activitiModel.getId();try {// 获取forms拿到formnameModel modelData = repositoryService.getModel(modelId);ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));byte[] bpmnBytes = null;BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);bpmnBytes = new BpmnXMLConverter().convertToXML(model);DeploymentBuilder db = repositoryService.createDeployment().name(modelData.getName());                 //区别在这里List<JsonNode> forms = modelNode.findValues("formkeydefinition");for (JsonNode node : forms) {// aaa.formString formName = node.textValue();if (!"".equals(formName)) {// 就是页面的html代码根据formName找到String formContent = myFormService.findFormByFormName(formName);ByteArrayInputStream bi = new ByteArrayInputStream(formContent.getBytes());db.addInputStream(formName, bi);break;}}Deployment deployment = db.addString(modelData.getName() + ".bpmn20.xml",new String(bpmnBytes)).deploy();if (deployment != null && deployment.getId() != null) {map.put("isLogin", "yes");map.put("userName",(String) req.getSession().getAttribute("userName"));map.put("result", "success");}} catch (Exception e) {e.printStackTrace();}} else {map.put("isLogin", "no");}return map;}


拿这段代码和之前单独的activiti流程部署的代码相比,就可以看到这里多出了查询form的操作以及部署时新的inputStream的设置。



在这段代码中,需要我们自己根据formKey(即自定义的表单的文件名)从数据中查询出相应的html表单代码,这段代码也是自己写的,如下:
public Connection getDb() {Connection connection = null;try {Class.forName("com.mysql.jdbc.Driver");connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testtu", "root", "123456");} catch (Exception e) {e.printStackTrace();}return connection;}public String findFormByFormName(String formName) {String formString = null;Connection connection = this.getDb();Statement statement;try {statement = connection.createStatement();PreparedStatement ps = connection.prepareStatement("select * from formtest where formType=?");ps.setString(1, formName);ResultSet resultSet = ps.executeQuery();while (resultSet.next()) {formString = resultSet.getString(3);};} catch (Exception e) {e.printStackTrace();}return formString;}


实现这个表单设置的目的实际上是为了之后启动流程时的操作,因为部署之后就有了流程定义列表,在流程定义列表中就可以启动流程,只有在这里设置了,那么点击启动流程时才能调用activitiService的相关方法获取对应节点的表单。


有了这个操作,在我们部署成功之后,可以看到与之前的部署相比,在数据库ac_ge_bytearray表中会再多出一条表单相关的数据,如图:



那么至此,整合自定义表单部署流程结束。

1 0
原创粉丝点击