OFBiz集成Spring和Activiti 详细设计说明书

很老的一个东西了
贴出来给大家扩展一下思路
今天整理硬盘发现的


jiasudu.iteye.com
编 号 : _________________ 版 本 : _________________
<OFBiz集 成 Spring和 Activiti> 详细设计说明书
编写:何增耀
2012年 07月 28日
第1章 引言
通过实现 OFBiz 和 Spring 的集成,借助 Spring 和其他系统良好的集成能
1.1 编写目的
力。实现 OFBiz 和任意目标系统的整合和集成。目前的目标系统为 Activiti5.9
1.2 系统版本说明
OFBiz 的版本为 11.04(Kft 模块在 12.04 会报错,没有花时间调试这个问题) Activiti 的版本为 5.9
Spring 的版本为 3.1.1
(备注为 https://github.com/henryyan/kft-activiti-demo 携带版本)
1.3 版本补充说明
如果不包含 Kft 模块的话 OFBiz 的版本为 12.04 Activiti 的版本为 5.9 Spring 的版本为 3.1.1 可以正常集成整合。
1.4 参考资料
2.1 软件结构
第2章 软件结构
序号
资料名
文件编号
发表日期
出版单位
在OFBiz系统中新建Spring模块,Activiti模块,Kft模块。如下:(1)在Spring模块中包含运行 所需要的类库和运行代码及配置信息; (2)在 Activiti 模块,包含运行 Activiti 工作流需要最低层度的
类库和其他配置。 (3)在 Kft 模块,包含运行请假工作流所需要需要代码和配置。三者具有依赖关系, Activiti 模块必须依赖 Spring 模块,才能运行。Kft 模块必须依赖 Spring 模块和 Activiti 模块。
如下图为模块的依赖关系
Kft
Activiti
Spring
2.2 模块清单 模块清单中包括概要设计阶段产生的,还是详细设计阶段产生的模块。
编号
模块名称
依赖模块
1
Spring
2
Activiti
Spring
3
Kft
Spring,Activiti
4
第3章 模块设计 3.1 Spring 模块 (spring)
实现 OFBiz 集成整合 Spring。 3.1.1 模块概述
实现 OFBiz 集成整合 Spring。在 OFBiz 的 Service 服务中可以自由调用 Spring 的 bean。 在 Spring 的 Bean 中可以自由调用 OFBiz 的 Service 服务和实体引擎获取 OFBiz 的资源。
3.1.2 OFBiz 的 Service 调用 Spring 的 Bean 3.1.2.1 描述
给出 OFBiz 的 Serivce 位置,给出 Spring 的 bean 位置。
OFBiz 服务名
调用的 Spring 的 Bean 名称
springEchoClient
echo
位置
/
framework/spring/servicedef/serv
ices.xml
/
framework/spring/config/demo/sp
ring-demo.xml
类
org.ofbiz.client.EchoServices
org.ofbiz.client.Echo
3.1.2.2 查询 OFBiz 服务
3.1.2.3 进入服务,输入参数
3.1.2.4 输入结果

3.1.3 Spring 的 Bean 调用 OFBiz 的 Service 及实体引擎 在 Spring 的 Bean 中可以调用 OFBiz 的 Service 服务和实体引擎获取 OFBiz 的资源。
3.1.3.1 描述
Spring 的 Bean
调用的 OFBiz 服务或 实体引擎
echo
delegator.findByAnd
查看位 置
/framework/spring/config/demo/spring-
demo.xml
org.ofbiz.client.Ec
ho
org.ofbiz.client.Echo
org.ofbiz.client.Ec
ho
3.1.3.2 Spring 配置的 Bean
<bean id="echo" class="org.ofbiz.client.Echo"/>
3.1.3.3 Bean 的 java 类方法调用
public String echoString(String value){ GenericDelegator delegator =
          GenericDelegator.getGenericDelegator("default");
                  LocalDispatcher  dispatcher =
GenericDispatcher.getLocalDispatcher("default",delegator); try {
List<GenericValue> list =delegator.findByAnd("Example", UtilMisc.toMap("statusId", "EXST_IN_DESIGN"));
for(GenericValue gv:list){
value +=";exampleName="+gv.getString("exampleName");
}
} catch (GenericEntityException e) {
Debug.logError(e.getMessage(), module); }
                  //d.runSync(arg0, arg1);
return "echo:"+value; }
3.1.3.4 启用调用 OFBiz 的服务引擎 //d.runSync(arg0, arg1);

3.1.4 Spring 配置信息
在系统的/framework/spring/config/spring-default.xml 可以看到默认的 Spring 的 Bean 配置信息,可以
依据示例进行扩展。
3.1.4.1 配置 activiti 的示例 Bean
<import resource="classpath:/workflow/springTypicalUsageTest-context.xml"/> 3.1.4.2 配置 Kft 的流程示例
          <import resource="classpath:/workflow/applicationContext.xml"/>
3.1.4.3 配置补充说明
因为 applicationContext.xml和 springTypicalUsageTest-context.xml都配置
      了数据源,所以建议仅仅开放一个,把另一个注释。
3.1.5 结 论
spring 整合 OFBiz 的过程和调用示例,到这里就介绍清楚了。如有疑问和调用出现困难,请联系作者。
3.2 Activiti 模块 (工作流基础) 实现 OFBiz 集成整合 Activiti。
3.2.1 模块概述
实现 OFBiz 集成整合 Activiti。在 OFBiz 的 Service 服务中调用 Spring 的 bean,在 Spring 的 Bean 中调用
Activiti 的资源。
3.2.2 OFBiz 的 Service 调用 Activiti
给出 OFBiz 的 Serivce 位置,给出 Spring 的 bean 位置。
OFBiz 服务名
调用的 Spring 的 Bean 名称
springEchoClient
echoFlow
/hot-
deploy/activiti/servicedef/servi
ces.xml
/hot-
deploy/activiti/config/workflow
/springTypicalUsageTest-
context.xml
org.ofbiz.activiti.WorkFlowDemoS ervices
org.ofbiz.activiti.EchoFlow

3.2.3 Spring 的 Bean 调用 Activiti 的方法
public String returnSimpleProcessTaskName() {
        DeploymentBuilder deploymentBuilder =
repositoryService.createDeployment();
deploymentBuilder.addClasspathResource("org/activiti/spring/test/juni
t4/SpringJunit4Test.simpleProcessTest.bpmn20.xml");
        deploymentBuilder.deploy();
        runtimeService.startProcessInstanceByKey("simpleProcess");
        Task task = taskService.createTaskQuery().singleResult();
System.out.println("My Task=="+task.getName()); //assertEquals("My Task", task.getName()); taskService.complete(task.getId());
return "TaskName="+task.getName(); }
3.2.4
OFBiz 的 Service 中调用 Bean 的代码
//调用 SpringContext
SpringContext springctx = GenericSpring.getSpringContext("default"); //调用 spring 的 bean
EchoFlow echoFlow = (EchoFlow) springctx.getBean("echoFlow"); //调用Bean中的Activiti的方法
String outValue = echoFlow.returnSimpleProcessTaskName();
3.2.5 结 论
OFBi 集成 Activiti 的过程和调用示例,到这里就介绍清楚了。 如有疑问和调用出现困难,请联系作者。
3.3 Kft 模块 (工作流示例) 实现工作流示例模块部署进入 OFBiz。
3.3.1 模块概述
实现工作流示例模块部署进入 OFBiz。示例代码位置及注意事项。
3.3.2 OFBiz 的 Service 调用 Kft 的方法示例 给出 OFBiz 的 Serivce 位置,给出 Activiti 的方法的位置。
OFBiz 服务名
调用的 Activiti 方法的位置
findSpringBeanFindTodoTasks
findSpringBeanFindTodoTasks
/hot-
deploy/kft/servicedef/services.x
ml
/hot-
deploy/activiti/config/workflow
/springTypicalUsageTest-
context.xml
org.ofbiz.kft.KftWorkFlowServic
es
org.ofbiz.kft.KftWorkFlowServic
es
3.3.3 OFBiz 的 Service 调用 Activiti 的方法
public static Map<String, Object> findSpringBeanFindTodoTasks(
DispatchContext ctx, Map<String, ? extends Object> context) {
       Locale locale = (Locale) context.get("locale");
String userId = (String) context.get("userId"); System.out.println("userId==" + userId);
String inoutValue = (String) context.get("inoutValue");
try {
SpringContext springctx =
GenericSpring.getSpringContext("default");
TaskService taskService = (TaskService) springctx
                  .getBean("taskService");
           RuntimeService runtimeService = (RuntimeService) springctx
                  .getBean("runtimeService");
           LeaveManager leaveManager = (LeaveManager) springctx
.getBean("leaveManager");
List<Leave> leaveList = new ArrayList<Leave>();
List<Task> tasks = new ArrayList<Task>();
// 根据当前人的ID查询
List<Task> todoList = taskService.createTaskQuery()
sc()
       .taskAssignee(userId).orderByTaskPriority().desc()
       .orderByTaskCreateTime().desc().list();
// 根据当前人未签收的任务
List<Task> unsignedTasks = taskService.createTaskQuery()
       .taskCandidateUser(userId).orderByTaskPriority().de
       .orderByTaskCreateTime().desc().list();
// 合并 tasks.addAll(todoList); tasks.addAll(unsignedTasks);
// 根据流程的业务ID查询实体并关联 for (Task task : tasks) {
              String processInstanceId =
task.getProcessInstanceId();
ult();
ProcessInstance processInstance = runtimeService
       .createProcessInstanceQuery()
       .processInstanceId(processInstanceId).singleRes
String businessKey = processInstance.getBusinessKey();
Leave leave = leaveManager.getLeave(new Long(businessKey));
              leave.setTask(task);
              leave.setProcessInstance(processInstance);
leave.setProcessDefinition(getProcessDefinition(processInstance .getProcessDefinitionId()));
              leaveList.add(leave);
           }
for (Leave leave : leaveList) {
inoutValue += leave.getReason() + "||";
inoutValue += leave.getId() + "||";
inoutValue += leave.getStartTime() + "||"; inoutValue += leave.getUserId() + "||";
inoutValue += leave.getEndTime() + "||"; inoutValue += leave.getLeaveType() + "||"; inoutValue += leave.getProcessInstanceId() + "||";
}
System.out.println("inoutValue" + inoutValue);
Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("inoutValue", inoutValue); result.put("outValue", "out=" + inoutValue); result.put("leaveList", leaveList);
return result;
} catch (BeansException e) {
Debug.logError(e, e.getMessage(), module);
return
ServiceUtil.returnError(UtilProperties.getMessage(resource, "update.write_failure", new Object[]
{ e.getMessage() },
                  locale));
} }
3.3.4 3.3.5
Kft 模块的 Spring 中 bean 的位置 /hot-deploy/kft/config/workflow/applicationContext.xml
Kft 的 webUi 层调用 Spring 的示例说明
根据 Springmvc 的配置说明
/hot-deploy/kft/src/me/kafeitu/demo/activiti/web 包里面所有需要注入 Spring 的 Bean 的地方全部做 了改动。全部通过 SpringContext 来调用业务 Bean 的方法。
例如:UseController 中的 旧代码
    // Activiti Identify Service
    /*private IdentityService identityService;*/
新代码
SpringContext springctx = GenericSpring.getSpringContext("default"); IdentityService identityService =
(IdentityService) springctx.getBean("identityService");
类LeaveController,ActivitiController也做了同性质的改动。具体请详见代码。
3.3.6 结 论
OFBiz 集成 Kft 的过程和调用示例,到这里就介绍清楚了。 如有疑问和调用出现困难,请联系作者。
3.4 Spring 系列模块配置信息

Spring 配置信息相关列举。 3.4.1 模块概述
列举出这三个模块需要进行配置的信息和位置。简要说明这些模块配置信息的作用和功能 3.4.2 Spring 模块的配置信息
位置
作用描述
/
framework/spring/config/spring-
default.xml
扩展和定义新的 spring 的 Bean 信息
/
framework/spring/config/demo/spr
ing-demo.xml
注入 Spring 的示例 Bean 的配置
org.ofbiz.framework.spring
spring 构造的 OFBiz 容器类
org.ofbiz.framework.config
读取 spring 配置信息的解析类
/
framework/spring/servicedef/serv
ices.xml
OFBiz 的 service 配置文件,内包含方 法为 OFBiz 服务调用 Spring 的 Bean 的 方法
3.4.3 Activiti 模块的配置信息
位置 作用描述
/framework/spring/config/spring-
default.xml
在该文件内修改需要引入的配置文件
/hot- deploy/activiti/config/workflow/springTypical UsageTest-context.xml
注入 Spring 的 Activiti 的示例 Bean 的 配置
/hot- deploy/activiti/config/org/activiti/spring/test
该包内包含的内容均为 Activiti 中单元测 试的所需文件
/hot-deploy/activiti/src/org/ofbiz/activiti
为 Activiti 的在 OFBiz 规范写的示例程序
/hot-deploy/activiti/servicedef/services.xml
OFBiz 的 service 配置文件,内包含方法 为 OFBiz 服务调用 Activiti 的 Bean 的 方法
3.4.4 Kft 模块的配置信息
位置
作用描述
/framework/spring/config/spring-
default.xml
在该文件内修改需要引入的配置文件
/hot- deploy/kft/config/workflow/applicationContext .xml
注入 Spring 的 Kft 的示例 Bean 的配置
/hot-deploy/kft/config/diagrams/leave
该包内包含的内容为 Kft 请假流程的所需 文件
/hot-deploy/kft/src/org/ofbiz/kft
为 Kft 的在 OFBiz 规范写的 OFBiz 调用 Kft 的示例程序
/hot-deploy/kft/servicedef/services.xml
OFBiz 的 service 配置文件,内包含方法 为 OFBiz 服务调用 kft 的 Bean 的方法
3.4.5 结 论
OFBi 集成 Spring 系列模块需要的配置文件,我就全部列举清楚了。 如有疑问和调用出现困难,请联系作者。
第4章 运行项目
4.1 默认数据库 启动相关数据库。
4.1.1 启动 Kft 所需的数据库 H2
在文件夹 h2database 中执行
java -cp h2*.jar org.h2.tools.Server 启动 h2 数据库
例如
user@dell:~$ java -cp h2*.jar org.h2.tools.Server
Web Console server running at http://127.0.1.1:8082 (only local connections) 已在现有的浏览器会话中创建新的窗口。
TCP server running at tcp://127.0.1.1:9092 (only local connections)
PG server running at pg://127.0.1.1:5435 (only local connections)
4.1.2 OFBiz 的默认 debry 数据库 /framework/entity/config/entityengine.xml 默认为 debry 数据库,不
做修改即可
4.1.3 Kft默认H2数据库
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-
method="close">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:tcp://127.0.1.1:9092/kft-activiti-demo" /> <property name="username" value="sa" />
<property name="password" value="" />
.
4.1.4
</bean>
结 论 使用默认数据库,可以立刻看到集成效果。不需做其他工作
4.2 外部数据库 (Mysql) 实现工作流示例模块部署进入 OFBiz。
4.2.1 新建 Mysql 的数据库
在数据库中新建名称为 kft 的数据库
在数据库中新建名称为 kftactiviti 的数据库。
便于测试所以分开安装 2 个数据库,生产环境中可以只安装一个数据库
4.2.2 配置 KftActiviti 的 mysql 连接
<bean class="org.apache.commons.dbcp.BasicDataSource"
method="close">
<property name="driverClassName"
value="com.mysql.jdbc.Driver" /> <property name="url"
id="dataSource" destroy-
value="jdbc:mysql://192.168.1.102/kftactiviti?autoReconnect=true" /> <property name="username" value="ofbiz" />
<property name="password" value="ofbiz" />
</bean>
4.2.3 配置 OFBiz 的 mysql 连接
修改<group-map group-name="org.ofbiz" datasource-name="localderby"/>
为<group-map group-name="org.ofbiz" datasource-name="kftmysql"/> 底部增加
<datasource name="kftmysql" helper-
class="org.ofbiz.entity.datasource.GenericHelperDAO" field-type-name="mysql"
check-on-start="true" add-missing-on-start="true" check-pks-on-start="false" use-foreign-keys="true" join-style="ansi-no-parenthesis" alias-view-columns="false" drop-fk-use-foreign-key-keyword="true" table-type="InnoDB" character-set="uft8" collate="utf8_general_ci">
<read-data reader-name="seed"/> <read-data reader-name="seed-initial"/> <read-data reader-name="demo"/> <read-data reader-name="ext"/> <inline-jdbc
jdbc-driver="com.mysql.jdbc.Driver"
jdbc-uri="jdbc:mysql://192.168.0.70/kft? autoReconnect=true&amp;characterEncoding=UTF-8"
jdbc-username="ofbiz"
jdbc-password="ofbiz" isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250" time-between-eviction-runs-millis="600000"/><!--
Please note that at least one person has experienced a problem with this value with MySQL
                and had to set it to -1 in order to avoid this issue.
                For more look at
http://markmail.org/thread/5sivpykv7xkl66px and
http://commons.apache.org/dbcp/configuration.html-->
        <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-
name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
</datasource>
4.2.4 Kft 模块的 Spring 中 bean 的位置
/hot-deploy/kft/config/workflow/applicationContext.xml
4.2.5 结 论
OFBi 集成 Kft 的过程和调用示例,到这里就介绍清楚了。 如有疑问和调用出现困难,请联系作者。
4.3 启动 OFBiz 。
4.3.1 访问Kft模块 http://localhost:8080/kft
4.3.2 访 问 OFBiz 的 Webtools 模 块 https://localhost:8443/webtools
给出 OFBiz 的 Serivce 列表位置。 https://localhost:8443/webtools/control/ServiceList
4.3.3 Kft 模块修改建议
kft 模块采用 Spring 的 mvc 框架,建议保留 spring 的 Bean 方法,移除 spring 的 mvc
框架,全部前台界面采用 OFBiz 实现。
4.3.4 结论
OFBi 启动及数据库配置的过程和调用示例,到这里就介绍清楚了。 如有疑问和调用出现困难,请联系作者。
5.1 关于 Spring 模块
第5章 沟通及建议
5.1.1 概 述
spring 的版本从 2.5-3.1 等等都经过测试,可以无障碍的集成整合进入 OFBiz9.04-12.04 的
各个版本中。
5.1.2 建 议 无
5.2 关于 Activiti 模块
5.2.1 概述
Activiti 整合进入 OFBiz 的版本为 5.2,5.6,及 5.9。只要跟 spring 版本对应整合进入 OFBiz 应 该无障碍。
OFBiz 的版本为 9.04,10.04,11.04,12.04 及期间任意 trunk 版本。
5.2.2 建议
采用 avtiviti 最新稳定版本
5.3 关于 Kft 模块
5.3.1 概述
Kft 整合进入 OFBiz12.04 的遇到一些 java 冲突的问题。主要问题定位为 Kft 经测试的版本为 tomcat6 中运行正常,OFBiz 的 1204 版本中 tomcat 为 7.0
OFBiz 为所有内置容器为 tomcat6 的版本。
5.3.2 沟通及建议
1 建议采用 OFBiz11.04 开展开发工作,其他不修改。
2 建议保留 kft 的后台逻辑,ui 全部采用 OFBiz 的界面重新编写,这样可以运行在 OFBiz12.04 中。
3 调试 Kft 模块,使之兼容 tomcat7 的版本。修改之后的模块,应该可以无障碍部署 进入 OFBiz12.04。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值