Integrate Activiti Modeler using Maven

ⅰ亾dé卋堺 提交于 2019-12-01 10:29:37

I have managed to do this using Maven overlay feature:

1) include overlay of Explorer web app, but include only the Modeler files:

pom.xml:

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-webapp-explorer2</artifactId>
        <version>${activiti-version}</version>
        <type>war</type>
        <scope>compile</scope>
    </dependency>
....
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <overlays>
                    <overlay>
                        <groupId>org.activiti</groupId>
                        <artifactId>activiti-webapp-explorer2</artifactId>
                        <includes>
                            <include>WEB-INF/classes/stencilset.json</include>   
                            <include>editor-app/**</include>   
                            <include>modeler.html</include>   
                        </includes>
                    </overlay>
                </overlays>
            </configuration>
        </plugin>

2) add modeler Spring resources. They are used to retrieve and to save models (note: not process definitions, it's kinda different thing) and also to serve the stencilset:

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-modeler</artifactId>
        <version>${activiti-version}</version>
    </dependency>

3) that would be it but it won't actually work in your application unless it is called "activiti-explorer". Add a file to your project called "editor-app/app-cfg.js", and add the following content there:

editor-app/app-cfg.js:

'use strict';
var ACTIVITI = ACTIVITI || {};
ACTIVITI.CONFIG = {
        'contextRoot' : window.location.pathname.substring(0,window.location.pathname.lastIndexOf('/')),
};

This is actually a copy of the native app-cfg, which contains the strange "/activiti-explorer/service" setting for context root. We change it to more generic setting. It will be used to retrieve models from the repository. Our file will overlay the one that ships with explorer webapp.

Notes:

a) you have to manage conversion of process definitions to models by yourselves. For an idea, see https://github.com/Activiti/Activiti/blob/activiti-5.19.0.1/modules/activiti-explorer/src/main/java/org/activiti/editor/ui/ConvertProcessDefinitionPopupWindow.java

b) I had to avoid using one Jackson Object Mapper for everything, I haven't research why this didn't work:

<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
</bean>    
<mvc:annotation-driven>
    <!-- using the same objectMapper leads to stencilset resource being served as string -->
    <mvc:message-converters register-defaults="true">
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="objectMapper"/>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

Don't do this or research more, as this actually breaks the stencilcet resurce serving part of the "activiti-modeler". It starts serving stencilset as a malformed string instead normal json.

c) I had no idea how to inject CSRF security headers in the Modeler saving function, so I switched it off - if you don't use Spring Security, discard this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!