Activiti6--[3] 整合Activiti6流程設計器

1 目的

基於【2】中的項目將流程圖設計相關頁面拷貝遷移到項目中。

2 準備

2.1 項目結構

activiti-1

2.2. 項目依賴

 	<properties>
		<java.version>1.8</java.version>
		<apache.xmlgraphics.version>1.7</apache.xmlgraphics.version>

	</properties>


	<dependencies>

		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-spring-boot-starter-basic</artifactId>
			<version>6.0.0</version>
		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-json-converter</artifactId>
			<version>6.0.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.activiti</groupId>
					<artifactId>activiti-bpmn-model</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-codec</artifactId>
			<version>${apache.xmlgraphics.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-css</artifactId>
			<version>${apache.xmlgraphics.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-svg-dom</artifactId>
			<version>${apache.xmlgraphics.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-svggen</artifactId>
			<version>${apache.xmlgraphics.version}</version>
		</dependency>
	</dependencies>

3 拷貝資源

路徑:activiti-6.0.0 > wars > activiti-app > editor > editor-app
activiti-2

3.1 拷貝靜態資源

activiti-3

3.2 拷貝主頁

activiti-4
activiti-5

3.3 拷貝libs

將activiti-app中的libs拷貝到項目中靜態資源的libs中
activiti-6
activiti-7

3.4 拷貝css和js

【1】將activiti-app下的styles下的資源拷貝到css文件夾中

在這裏插入圖片描述
在這裏插入圖片描述

【2】拷貝style-editor.css到css文件夾中

在這裏插入圖片描述
在這裏插入圖片描述

【3】拷貝scripts到editor-app

在這裏插入圖片描述
在這裏插入圖片描述

  • activiti-app中editor下的scripts的controllers、services、*.js拷貝到common文件夾下
    在這裏插入圖片描述
    在這裏插入圖片描述
  • activiti-app中editor下的scripts的configuration下的文件拷貝到項目中configuration中。
    在這裏插入圖片描述

3.5 修改index.html引用路徑

<!doctype html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Activiti Editor</title>
    <link rel="icon" type="image/ico" href="favicon.ico">
    <meta name="description" content="">
    <meta name="viewport"
          content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

    <link rel="Stylesheet" href="editor-app/libs/ui-grid_3.0.0/ui-grid.css" type="text/css"/>

    <!-- build:css styles/3thparty.css -->
    <link rel="stylesheet" href="editor-app/libs/bootstrap_3.1.1/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="editor-app/libs/bootstrap-tour_0.9.1/bootstrap-tour.min.css"/>
    <link rel="stylesheet" href="editor-app/libs/angular-spectrum-colorpicker_1.0.13/spectrum.css"/>
    <!-- endbuild -->

    <link rel="Stylesheet" media="screen" href="editor-app/editor/css/editor.css?v=2" type="text/css"/>
    <link rel="stylesheet" href="editor-app/css/style.css?v=2" type="text/css"/>

    <!-- build:css styles/style.css -->
    <link href="editor-app/css/common/style.css" rel="stylesheet">
    <link href="editor-app/css/common/style-retina.css" rel="stylesheet">
    <link rel="stylesheet" href="editor-app/css/style-editor.css">
    <!-- endbuild -->

</head>
<body ng-app="activitiModeler" ng-cloak>

    <div class="navbar navbar-fixed-top navbar-inverse" role="navigation" id="main-header">
        <div class="fixed-container">
            <div class="navbar-header">
                <a ng-click="backToLanding()" class="landing-logo" ng-if="account != null && account != undefined" title="{{'GENERAL.MAIN-TITLE' | translate}}">
                    <img ng-if="account.tenantPictureId && account.tenantId"
                         ng-src="{{restRootUrl()}}/app/rest/tenants/{{account.tenantId}}/logo">

                    <img ng-if="!account.tenantPictureId" ng-src="{{appResourceRoot}}../images/activiti-logo.png">
                </a>
                <ul class="nav navbar-nav" id="main-nav" ng-show="authenticated">
                    <li ng-class="{'active' : item.id == mainPage.id}" ng-repeat="item in mainNavigation"
                        ng-show="(authenticated && !item.unauthenticated) || (item.unauthenticated && !authenticated)">
                        <a ng-click="setMainPage(item)">{{item.title | translate}}</a>
                    </li>
                </ul>
            </div>
            <div class="pull-right {{currentAppDefinition.definition.theme}}"
                 ng-class="{'app-indicator': currentAppDefinition}" ng-if="authenticated" ng-cloack>
                <span ng-if="currentAppDefinition.definition.theme">
                    {{currentAppDefinition.name}}
                </span>
                <i class="glyphicon {{currentAppDefinition.definition.icon}}"></i>

                <div class="dropdown btn-group btn-group-sm" activiti-fix-dropdown-bug>
                    <button type="button" class="btn btn-default dropdown-toggle"
                            data-toggle="dropdown">{{account.firstName}} {{account.lastName}}
                        <span class="glyphicon glyphicon-chevron-down" style="font-size: 10px" aria-hidden="true"></span>
                    </button>
                    <ul class="dropdown-menu pull-right">
                        <li><a href="" ng-click="logout()" translate>GENERAL.ACTION.LOGOUT</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <!--[if lt IE 9]>
    <div class="unsupported-browser">
        <p class="alert error">You are using an unsupported browser. Please upgrade your browser in order to use the
            editor.</p>
    </div>
    <![endif]-->
    <!--[if IE 9]>
    <div id="no-flash-message" class="unsupported-browser" style="display: none">
        <p class="alert error">No Adobe Flash installed. Please install Adobe Flash in order to use the file upload capabilities on this version of Internet Explorer.</p>
    </div>
    <script>
        var hasFlash = false;
        try {
            hasFlash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
        } catch(exception) {
            hasFlash = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash']);
        }
        if (!hasFlash) {
            var showNoFlashMessage = function () {
                var element = document.getElementById('no-flash-message');
                element.style.display="block";
            };
            showNoFlashMessage();
        }
    </script>
    <![endif]-->
    <div class="alert-wrapper" ng-cloak>
        <div class="alert fadein {{alerts.current.type}}" ng-show="alerts.current" ng-click="dismissAlert()">
            <i class="glyphicon"
               ng-class="{'glyphicon-ok': alerts.current.type == 'info', 'glyphicon-remove': alerts.current.type == 'error'}"></i>
            <span>{{alerts.current.message}}</span>

            <div class="pull-right" ng-show="alerts.queue.length > 0">
                <span class="badge">{{alerts.queue.length + 1}}</span>
            </div>
        </div>
    </div>

    <div id="main" class="wrapper full clearfix" ng-view="" ng-cloak ng-style="{height: window.height + 'px'}">
    </div>

<!--[if lt IE 9]>
<script src="editor-app/libs/es5-shim-15.3.4.5/es5-shim.js"></script>
<script src="editor-app/libs/json3_3.2.6/lib/json3.min.js"></script>
<![endif]-->

<script src="editor-app/libs/jquery_1.11.0/jquery.min.js"></script>
<script src="editor-app/libs/jquery-ui-1.10.3.custom.min.js"></script>

<script src="editor-app/libs/angular_1.3.13/angular.min.js"></script>
<script src="editor-app/libs/angular-animate_1.3.13/angular-animate.min.js"></script>
<script src="editor-app/libs/bootstrap_3.1.1/js/bootstrap.min.js"></script>
<script src="editor-app/libs/angular-resource_1.3.13/angular-resource.min.js"></script>
<script src="editor-app/libs/angular-cookies_1.3.13/angular-cookies.min.js"></script>
<script src="editor-app/libs/angular-sanitize_1.3.13/angular-sanitize.min.js"></script>
<script src="editor-app/libs/angular-route_1.3.13/angular-route.min.js"></script>
<script src="editor-app/libs/angular-translate_2.4.2/angular-translate.min.js"></script>
<script src="editor-app/libs/angular-translate-storage-cookie/angular-translate-storage-cookie.js"></script>
<script src="editor-app/libs/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
<script src="editor-app/libs/angular-strap_2.1.6/angular-strap.min.js"></script>
<script src="editor-app/libs/angular-strap_2.1.6/angular-strap.tpl.min.js"></script>
<script src="editor-app/libs/momentjs_2.5.1/momentjs.min.js"></script>
<script src="editor-app/libs/bootstrap-tour_0.9.1/bootstrap-tour.min.js"></script>
<script src="editor-app/libs/ng-file-upload/ng-file-upload-shim.min.js"></script>
<script src="editor-app/libs/ng-file-upload/ng-file-upload.min.js"></script>

<script src="editor-app/libs/ui-utils.min-0.2.1.js" type="text/javascript"></script>
<script src="editor-app/libs/ui-grid_3.0.0/ui-grid.js" type="text/javascript"></script>
<script src="editor-app/libs/angular-dragdrop_1.0.11/angular-dragdrop.min.js" type="text/javascript"></script>
<script src="editor-app/libs/mousetrap-1.4.5.min.js" type="text/javascript"></script>
<script src="editor-app/libs/jquery.autogrow-textarea.js" type="text/javascript"></script>

<script src="editor-app/libs/prototype-1.5.1.js" type="text/javascript"></script>
<script src="editor-app/libs/path_parser.js" type="text/javascript"></script>

<script src="editor-app/libs/angular-spectrum-colorpicker_1.0.13/spectrum.js" type="text/javascript"></script>
<script src="editor-app/libs/angular-spectrum-colorpicker_1.0.13/angular-spectrum-colorpicker.min.js" type="text/javascript"></script>
<script src="editor-app/libs/angular-scroll_0.5.7/angular-scroll.min.js" type="text/javascript"></script>
<script src="editor-app/libs/angular-drag-and-drop-lists_1.2.0/angular-drag-and-drop-lists.js" type="text/javascript"></script>
<script src="editor-app/libs/html2canvas_0.4.1/html2canvas.js"></script>

<!-- Configuration -->
<script src="editor-app/app-cfg.js?v=2"></script>

<!-- build:js scripts/scripts.js -->
<script src="editor-app/editor/i18n/translation_en_us.js" type="text/javascript"></script>
<script src="editor-app/editor/i18n/translation_signavio_en_us.js" type="text/javascript"></script>
<script src="editor-app/editor/oryx.js" type="text/javascript"></script>

<script src="editor-app/common/http-auth-interceptor.js"></script>
<script src="editor-app/common/services/auth-services.js"></script>
<script src="editor-app/common/app.js"></script>
<script src="editor-app/common/editor-directives.js"></script>
<script src="editor-app/common/controllers/processes.js"></script>
<script src="editor-app/common/controllers/process.js"></script>
<script src="editor-app/common/controllers/forms.js"></script>
<script src="editor-app/common/controllers/form.js"></script>
<script src="editor-app/common/controllers/decision-tables.js"></script>
<script src="editor-app/common/controllers/decision-table.js"></script>
<script src="editor-app/common/controllers/app-definitions.js"></script>
<script src="editor-app/common/controllers/app-definition.js"></script>
<script src="editor-app/common/controllers/model-common-actions.js"></script>

<script src="editor-app/common/services/util-services.js"></script>
<script src="editor-app/common/services/identity-services.js"></script>

<script src="editor-app/common/services/form-services.js"></script>
<script src="editor-app/common/controllers/form-builder.js"></script>
<script src="editor-app/configuration/form-builder-toolbar-default-actions.js" type="text/javascript"></script>
<script src="editor-app/configuration/form-builder-toolbar.js" type="text/javascript"></script>
<script src="editor-app/common/controllers/form-toolbar-controller.js" type="text/javascript"></script>
<script src="editor-app/common/controllers/form-readonly-view.js"></script>

<script src="editor-app/common/services/decision-table-service.js"></script>
<script src="editor-app/common/controllers/decision-table-editor.js"></script>
<script src="editor-app/configuration/decision-table-toolbar-default-actions.js" type="text/javascript"></script>
<script src="editor-app/configuration/decision-table-toolbar.js" type="text/javascript"></script>
<script src="editor-app/common/controllers/decision-table-toolbar-controller.js" type="text/javascript"></script>

<script src="editor-app/common/controllers/app-definition-builder.js"></script>
<script src="editor-app/configuration/app-definition-toolbar-default-actions.js" type="text/javascript"></script>
<script src="editor-app/configuration/app-definition-toolbar.js" type="text/javascript"></script>
<script src="editor-app/common/controllers/app-definition-toolbar-controller.js" type="text/javascript"></script>

<script src="editor-app/eventbus.js" type="text/javascript"></script>

<script src="editor-app/editor-controller.js" type="text/javascript"></script>
<script src="editor-app/stencil-controller.js" type="text/javascript"></script>
<script src="editor-app/toolbar-controller.js" type="text/javascript"></script>
<script src="editor-app/header-controller.js" type="text/javascript"></script>
<script src="editor-app/select-shape-controller.js" type="text/javascript"></script>
<script src="editor-app/define-data-controller.js" type="text/javascript"></script>

<script src="editor-app/tour.js" type="text/javascript"></script>
<script src="editor-app/editor-utils.js" type="text/javascript"></script>
<script src="editor-app/configuration/toolbar-default-actions.js" type="text/javascript"></script>

<script src="editor-app/configuration/properties-default-controllers.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-execution-listeners-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-event-listeners-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-assignment-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-fields-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-form-properties-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-in-parameters-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-multiinstance-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-out-parameters-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-task-listeners-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-collapsed-subprocess-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-form-reference-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-sequenceflow-order-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-condition-expression-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-signal-definitions-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-signal-scope-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-message-definitions-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-message-scope-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-duedate-controller.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-decisiontable-reference-controller.js" type="text/javascript"></script>

<script src="editor-app/editor-config.js" type="text/javascript"></script>

<script src="editor-app/configuration/url-config.js" type="text/javascript"></script>

<script src="editor-app/configuration/toolbar.js" type="text/javascript"></script>
<script src="editor-app/configuration/toolbar-custom-actions.js" type="text/javascript"></script>

<script src="editor-app/configuration/properties.js" type="text/javascript"></script>
<script src="editor-app/configuration/properties-custom-controllers.js" type="text/javascript"></script>

<script src="editor-app/configuration/kis-header-custom.js" type="text/javascript"></script>
<script src="editor-app/configuration/kis-toolbar-custom-actions.js" type="text/javascript"></script>

<script src="editor-app/common/services/related-content-service.js"></script>
<script src="editor-app/common/directives.js"></script>
<script src="editor-app/common/providers-config.js"></script>
<script src="editor-app/common/services/resource-service.js"></script>
<script src="editor-app/common/services/recursion-helper.js"></script>
<script src="editor-app/common/services/authentication-service.js"></script>
<script src="editor-app/common/services/runtime-app-definition-service.js"></script>
<script src="editor-app/common/controllers/about.js"></script>
<!-- endbuild -->

<!-- Integration extensions -->
<script src="editor-app/resource-loader.js?v=2" app="editor"></script>

</body>
</html>

4 訪問index.html

訪問會出現報錯,經【5】問題解決後,再繼續下面的測試。
【1】先創建模型,拿到模型id然後訪問以下地址即可
在這裏插入圖片描述
【2】訪問http://localhost:8083/index.html#/editor/模型id
例如:http://localhost:8083/index.html#/editor/45001
在這裏插入圖片描述

5 問題記錄

5.1 控制層

5.1.1 創建模型並返回模型id

package com.ft.spring.activiti.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
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.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author luobaimang
 * @date 2019/11/28
 */
@Controller
public class ModelController {

    private static final Logger logger = LoggerFactory.getLogger(ModelController.class);

    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private ObjectMapper objectMapper;

    /**
     * 創建模型
     * @param response
     * @param name 模型名稱
     * @param key 模型key
     */
    @RequestMapping("/create")
    @ResponseBody
    public String create(HttpServletResponse response, String name, String key) throws IOException {
        logger.info("創建模型入參name:{},key:{}",name,key);
        Model model = repositoryService.newModel();
        ObjectNode modelNode = objectMapper.createObjectNode();
        modelNode.put(ModelDataJsonConstants.MODEL_NAME, name);
        modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, "");
        modelNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
        model.setName(name);
        model.setKey(key);
        model.setMetaInfo(modelNode.toString());
        repositoryService.saveModel(model);
        createObjectNode(model.getId());
        logger.info("創建模型結束,返回模型ID:{}",model.getId());
        return model.getId();
    }

    /**
     * 創建模型時完善ModelEditorSource
     * @param modelId
     */
    @SuppressWarnings("deprecation")
    private void createObjectNode(String modelId){
        logger.info("創建模型完善ModelEditorSource入參模型ID:{}",modelId);
        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);
        try {
            repositoryService.addModelEditorSource(modelId,editorNode.toString().getBytes("utf-8"));
        } catch (Exception e) {
            logger.info("創建模型時完善ModelEditorSource服務異常:{}",e);
        }
        logger.info("創建模型完善ModelEditorSource結束");
    }

}


5.1.2 工作流需要的接口

package com.ft.spring.activiti.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @author luobaimang
 * @date 2019/11/28
 */
@RestController
@RequestMapping("service")
public class ModelRestController implements ModelDataJsonConstants {

        protected static final Logger LOGGER = LoggerFactory.getLogger(ModelRestController.class);

        @Autowired
        private RepositoryService repositoryService;

        @Autowired
        private ObjectMapper objectMapper;

        /**
         * 更新流程
         *
         * @param modelId     模型ID
         * @param name        流程模型名稱
         * @param description
         * @param json_xml    流程文件
         * @param svg_xml     圖片
         */
        @RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
        @ResponseStatus(value = HttpStatus.OK)
        public void saveModel(@PathVariable String modelId
                , String name, String description
                , String json_xml, String svg_xml) {
            try {

                Model model = repositoryService.getModel(modelId);

                ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());

                modelJson.put(MODEL_NAME, name);
                modelJson.put(MODEL_DESCRIPTION, description);
                modelJson.put(ModelDataJsonConstants.MODEL_REVISION, model.getVersion() + 1);
                model.setMetaInfo(modelJson.toString());
                model.setName(name);
                repositoryService.saveModel(model);

                repositoryService.addModelEditorSource(model.getId(), json_xml.getBytes("utf-8"));

                InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8"));
                TranscoderInput input = new TranscoderInput(svgStream);

                PNGTranscoder transcoder = new PNGTranscoder();
                // Setup output
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                TranscoderOutput output = new TranscoderOutput(outStream);

                // Do the transformation
                transcoder.transcode(input, output);
                final byte[] result = outStream.toByteArray();
                repositoryService.addModelEditorSourceExtra(model.getId(), result);
                outStream.close();
            } catch (Exception e) {
                LOGGER.error("Error saving model", e);
                throw new ActivitiException("Error saving model", e);
            }
        }


    /**
     * 獲取model的節點信息,編輯器根據返回的json進行繪圖
     *
     * @param modelId
     * @return
     */
    @SuppressWarnings("deprecation")
    @RequestMapping(value = "/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json")
    public ObjectNode getEditorJson(@PathVariable String modelId) {
        ObjectNode modelNode = null;
        Model model = repositoryService.getModel(modelId);
        if (model != null) {
            try {
                if (StringUtils.isNotEmpty(model.getMetaInfo())) {
                    modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
                } else {
                    modelNode = objectMapper.createObjectNode();
                    modelNode.put(MODEL_NAME, model.getName());
                }
                modelNode.put(MODEL_ID, model.getId());
                ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(
                        new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
                modelNode.put("model", editorJsonNode);
            } catch (Exception e) {
                LOGGER.error("Error creating model JSON", e);
                throw new ActivitiException("Error creating model JSON", e);
            }
        }
        return modelNode;
    }

    /**
     * 獲取編輯器組件及配置項信息
     * 獲取流程json文件
     *
     * @return
     */
    @RequestMapping(value = "/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getStencilset() {
        InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
        try {
            return IOUtils.toString(stencilsetStream, "utf-8");
        } catch (Exception e) {
            throw new ActivitiException("Error while loading stencil set", e);
        }
    }
}

5.2 修改js

5.2.1 去掉權限驗證

原因訪問index.html重定向到登陸界面
http://localhost:8083/#/login?redirectUrl=http:%2F%2Flocalhost:8083%2Findex.html%23%2Fprocesses
【1】修改app.js
在這裏插入圖片描述
在這裏插入圖片描述

5.2.2 拷貝en.json

在這裏插入圖片描述

5.2.3 修改base路徑,正確訪問editor頁面

在這裏插入圖片描述

5.2.4 修改url-config.js

根據5.1.2 修改成以下訪問地址

var KISBPM = KISBPM || {};
KISBPM.URL = {
    getModel: function(modelId) {
        return ACTIVITI.CONFIG.contextRoot + '/model/' + modelId + '/json';
    },

    getStencilSet: function() {
        return ACTIVITI.CONFIG.contextRoot + '/editor/stencilset?version=' + Date.now();
    },

    putModel: function(modelId) {
        return ACTIVITI.CONFIG.contextRoot + '/model/' + modelId + '/save';
    }
};

5.2.5 修改app-cfg.js

ACTIVITI.CONFIG = {
	'onPremise' : true,
	'contextRoot' : '/service',
	'webContextRoot' : '/activiti-app'
};

5.2.6 修改oryx.debug.js、oryx.js

因訪問報錯404:http://localhost:8083/service/app/rest/stencil-sets/editor?version=1574941194439
在這裏插入圖片描述
因訪問地址改了,故需要訪問請求地址,讓其能正確訪問。修改如下:
在這裏插入圖片描述
在這裏插入圖片描述

5.2.7 修改editor-controller.js

報:TypeError: Cannot read property ‘firstName’ of undefined
at Object.gettingStarted
註釋掉該行。
在這裏插入圖片描述

5.3 新增漢化文件

在這裏插入圖片描述

5.4 新增fonts

報:http://localhost:8083/editor-app/fonts/lato-bold-webfont.woff net::ERR_ABORTED 404
jquery.min.js:4 GET http://localhost:8083/editor-app/fonts/lato-regular-webfont.woff net::ERR_ABORTED 404
GET http://localhost:8083/editor-app/fonts/lato-bold-webfont.ttf net::ERR_ABORTED 404
editor-app/fonts/lato-regular-webfont.ttf:1 GET http://localhost:8083/editor-app/fonts/lato-regular-webfont.ttf net::ERR_ABORTED 404
在這裏插入圖片描述

6 項目地址

https://gitee.com/idcory/ft-spring-demo/tree/master/ft-demo-activiti

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章