jeecg + activiti 流程设计器

jeecg 3.4.3 + activiti 5.18.0


activiti 流程设计器 示例 源码

https://download.csdn.net/download/anysun7/10354206


项目pom文件添加activiti依赖:

<dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-engine</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-spring</artifactId>

            <version>${activiti.version}</version>

            <exclusions>

                <exclusion>

                    <artifactId>commons-dbcp</artifactId>

                    <groupId>commons-dbcp</groupId>

                </exclusion>

            </exclusions>

        </dependency>

 

        <dependency>

            <groupId>commons-dbcp</groupId>

            <artifactId>commons-dbcp</artifactId>

            <version>1.4</version>

        </dependency>

 

        <dependency>

            <groupId>org.mybatis</groupId>

            <artifactId>mybatis</artifactId>

            <version>3.2.5</version>

        </dependency>

 

        <!--<dependency>

            <groupId>javax.activation</groupId>

            <artifactId>activation</artifactId>

            <version>1.1</version>

        </dependency>-->

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-bpmn-model</artifactId>

            <version>${activiti.version}</version>

        </dependency>

        <dependency>

           <groupId>org.activiti</groupId>

           <artifactId>activiti-bpmn-converter</artifactId>

           <version>${activiti.version}</version>

       </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-bpmn-layout</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-common-rest</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-crystalball</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-diagram-rest</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-explorer</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-image-generator</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-json-converter</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-modeler</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-simple-workflow</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.vaadin.addons</groupId>

            <artifactId>dcharts-widget</artifactId>

            <version>0.10.0</version>

        </dependency>

 

        <dependency>

            <groupId>org.activiti</groupId>

            <artifactId>activiti-process-validation</artifactId>

            <version>${activiti.version}</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>xmlgraphics-commons</artifactId>

            <version>1.2</version>

        </dependency>

 

        <dependency>

            <groupId>com.vaadin</groupId>

            <artifactId>vaadin</artifactId>

            <version>6.8.8</version>

        </dependency>

 

        <dependency>

            <groupId>org.imgscalr</groupId>

            <artifactId>imgscalr-lib</artifactId>

            <version>4.2</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.geronimo.specs</groupId>

            <artifactId>geronimo-servlet_3.0_spec</artifactId>

            <version>1.0</version>

            <scope>provided</scope>

        </dependency>

 

        <!--<dependency>

            <groupId>javax</groupId>

            <artifactId>javaee-api</artifactId>

            <version>7.0</version>

        </dependency>-->

 

        <dependency>

            <groupId>joda-time</groupId>

            <artifactId>joda-time</artifactId>

            <version>2.1</version>

        </dependency>

 

        <!--Batik的包主要是用来解析html中的svg的内容-->

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-transcoder</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-dom</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-bridge</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-css</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-anim</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-codec</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-ext</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-gvt</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-script</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-js</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-parser</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-svg-dom</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-svggen</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-util</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-xml</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-js</artifactId>

            <version>1.7</version>

        </dependency>

 

        <dependency>

            <groupId>xml-apis</groupId>

            <artifactId>xml-apis-ext</artifactId>

            <version>1.3.04</version>

        </dependency>

 

        <dependency>

            <groupId>xml-apis</groupId>

            <artifactId>xml-apis</artifactId>

            <version>1.3.04</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>xmlgraphics-commons</artifactId>

            <version>1.2</version>

        </dependency>

 

        <dependency>

            <groupId>org.apache.xmlgraphics</groupId>

            <artifactId>batik-awt-util</artifactId>

            <version>1.7</version>

        </dependency>

 

配置spring-activiti.xml文件

src/main/resources目录下新建spring-activiti.xml文件,向其中加入以下内容

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

        <property name="dataSource" ref="dataSource" />

        <property name="transactionManager" ref="transactionManager" />

        <property name="databaseSchemaUpdate" value="true" />

        <property name="jobExecutorActivate" value="false" />

    </bean>

    <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>

    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">

        <property name="processEngineConfiguration" ref="processEngineConfiguration" />

    </bean>

    <bean id="repositoryService" factory-bean="processEngine"

          factory-method="getRepositoryService" />

    <bean id="runtimeService" factory-bean="processEngine"

          factory-method="getRuntimeService" />

    <bean id="taskService" factory-bean="processEngine"

          factory-method="getTaskService" />

    <bean id="historyService" factory-bean="processEngine"

          factory-method="getHistoryService" />

    <bean id="managementService" factory-bean="processEngine"

          factory-method="getManagementService" />

    <bean id="identityService" factory-bean="processEngine"

          factory-method="getIdentityService" />

    <bean id="transactionManager"

          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource" />

    </bean>

</beans>

 

web.xml文件,修改context-param添加了classpath:spring-activiti.xml

 

复制设计器文件

下载activiti-webapp-explorer2的源代码,

1. activiti-explorer工程中的diagram-viewereditor-appmodeler.html复制到工程的src/main/webapp目录下

 

2. activiti-explorer工程中WEB-INF/classes文件下的stencilset.jsonui.propertiesui.properties.alfresco复制到工程的src/main/resources目录下

 

3.modules/目录中找到org\activiti\rest\diagramorg\activiti\rest\editor这两个包,将他们整个复制到工程的src/main/java目录下

 

4.修改spring-mvc.xml文件,在其中加入以下内容,使spring在扫描controller类的时候,也扫描这些包里面的类

 

5.向工程的web.xml文件中添加以下内容,让spring也管理起来带/service/的链接

<!-- activiti -->

    <servlet-mapping>

        <servlet-name>springMvc</servlet-name>

        <url-pattern>/service/*</url-pattern>

    </servlet-mapping>

 

6.打开editor-app/app-cfg.js, 将其中的activiti-explorer”修改为“jeecg”。当然,具体项目中这里可能会经常变化,我们可以写一个js函数来自动获取工程的名字,这样以后将设计器集成到其他工程的时候,就不需要修改这里的内容了

 

7.工程的src\main\java\org\activiti\rest\editor目录下新建一个java文件,命名为ModuleController

package org.activiti.rest.editor;

 

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import org.activiti.editor.constants.ModelDataJsonConstants;

import org.activiti.engine.RepositoryService;

import org.activiti.engine.repository.Model;

import org.apache.commons.lang3.StringUtils;

import org.jeecgframework.core.common.controller.BaseController;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

 

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.databind.node.ObjectNode;

 

@Controller

@RequestMapping("/model")

public class ModuleController extends BaseController{

private Logger logger = LoggerFactory.getLogger(ModuleController.class);

@Autowired

private RepositoryService repositoryService;

@RequestMapping(params = "create")

  public void create(HttpServletRequest request, HttpServletResponse response) {

    try {

          String name = "test";

          String key = "test";

          String description = "testModel";

 

          ObjectMapper objectMapper = new ObjectMapper();

      ObjectNode editorNode = objectMapper.createObjectNode();

      editorNode.put("id", "canvas");

      editorNode.put("resourceId", "canvas");

      ObjectNode stencilSetNode = objectMapper.createObjectNode();

      stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");

      editorNode.put("stencilset", stencilSetNode);

      Model modelData = repositoryService.newModel();

 

      ObjectNode modelObjectNode = objectMapper.createObjectNode();

      modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);

      modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);

      description = StringUtils.defaultString(description);

      modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);

      modelData.setMetaInfo(modelObjectNode.toString());

      modelData.setName(name);

      modelData.setKey(StringUtils.defaultString(key));

 

      repositoryService.saveModel(modelData);

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

 

      response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());

    } catch (Exception e) {

      logger.error("创建模型失败:", e);

    }

  }

}

 

8. 访问:http://localhost:8080/jeecg/model.do?create

 

 

注:

新版(3.7.2jeecgresponse的处理,添加了org.jeecgframework.core.aop.Wrapper,导致json数据返回解析出错。整合时,需处理。

Jeecg修改pom内容

Maven版本改为 5.18.0

添加:

<dependency> 

<groupId>com.fasterxml.jackson.core</groupId> 

<artifactId>jackson-databind</artifactId> 

<version>2.2.3</version> 

</dependency>

Springmvc添加 (rest请求数据 /jeecg/service/model/5001/json

<mvc:annotation-driven />


中途bug:

TypeError: Cannot read property 'split' of undefined

    at Object.ORYX.Core.StencilSet.stencilSet (oryx.debug.js:8647)
    at oryx.debug.js:8625
    at prototype-1.5.1.js:446
    at Array._each (prototype-1.5.1.js:672)
    at Array.each (prototype-1.5.1.js:445)
    at Object.ORYX.Core.StencilSet.stencilSets (oryx.debug.js:8624)
    at classDef.getStencilSets (oryx.debug.js:11715)
    at classDef._createCanvas (oryx.debug.js:11201)
    at classDef.construct (oryx.debug.js:10930)
    at new classDef (oryx.debug.js:1747)

解决思路:遇到该错误,主要原因是后台返回json数据时,格式存在问题,请查看response中最终返回到页面之前的数据。查看是否是框架对数据做了处理,寻找相应解决方法。






另转:

activiti-modeler 工作流设计器代码分析

https://blog.csdn.net/fgstudent/article/details/50668086

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页