上个周末女朋友考试去了,闲得慌,浏览D盘发现里面有个osworkflow 2.7,自己向往工作流已久(上个月写了一个基于jgraph的工作流流程可视化配置程序,
人家给我的只有一个xml流程文件的格式,自己对工作流也不甚了解),无事就拿来学学,我的java史也有才4个月了,呵呵
1.在mysql上建立shop数据库,把/etc/deployment/jdbc/mysql.sql 脚本执行,建立数据表
2.在jboss中建立数据源jdbc/mySQL-shop,server/default/deploy目录下得mysql-shop-ds.xml内容如下(不过要记得下载mysql的jdbc驱动)
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mysql-ds.xml,v 1.3.2.1 2004/12/01 11:46:00 schrouf Exp $ -->
<!-- Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/mySQL-shop</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:3306/shop</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>mysql</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
3.将osworkexample.war 解压缩到 webapp目录 webapp可以在任何地方
修改webapp/WEB-INF/classes下得osworkflow.xml文件 内容如下
<osworkflow>
<persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
<property key="datasource" value="java:jdbc/mySQL-shop"/>
<property key="entry.sequence" value="select count(*) + 1 from os_wfentry"/>
<property key="entry.table" value="OS_WFENTRY"/>
<property key="entry.id" value="ID"/>
<property key="entry.name" value="NAME"/>
<property key="entry.state" value="STATE"/>
<property key="step.sequence" value="select sum(c1) from (select 1 tb, count(*) c1 from os_currentstep union select 2 tb, count(*) c1 from os_historystep)"/>
<property key="history.table" value="OS_HISTORYSTEP"/>
<property key="current.table" value="OS_CURRENTSTEP"/>
<property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
<property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
<property key="step.id" value="ID"/>
<property key="step.entryId" value="ENTRY_ID"/>
<property key="step.stepId" value="STEP_ID"/>
<property key="step.actionId" value="ACTION_ID"/>
<property key="step.owner" value="OWNER"/>
<property key="step.caller" value="CALLER"/>
<property key="step.startDate" value="START_DATE"/>
<property key="step.finishDate" value="FINISH_DATE"/>
<property key="step.dueDate" value="DUE_DATE"/>
<property key="step.status" value="STATUS"/>
<property key="step.previousId" value="PREVIOUS_ID"/>
<property key="step.sequence.increment" value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
<property key="step.sequence.retrieve" value="SELECT max(ID) FROM OS_STEPIDS"/>
</persistence>
<factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
<property key="resource" value="workflows.xml" />
</factory>
</osworkflow>
4.修改webapp/WEB-INF/classes/osuser.xml文件
<opensymphony-user>
<provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
<property name="user.table">os_user</property>
<property name="group.table">os_group</property>
<property name="membership.table">os_membership</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:jdbc/mySQL-shop</property>
</provider>
<provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
<property name="user.table">os_user</property>
<property name="group.table">os_group</property>
<property name="membership.table">os_membership</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:jdbc/mySQL-shop</property>
</provider>
<provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
<property name="user.table">os_user</property>
<property name="group.table">os_group</property>
<property name="membership.table">os_membership</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:jdbc/mySQL-shop</property>
</provider>
<authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
</opensymphony-user>
5.增加webapp/WEB-INF/classes/propertyset.xml 文件
<propertysets>
<propertyset name="jdbc" class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
<arg name="table.name" value="os_propertyentry"/>
<arg name="col.globalKey" value="GLOBAL_KEY"/>
<arg name="col.itemKey" value="ITEM_KEY"/>
<arg name="col.itemType" value="ITEM_TYPE"/>
<arg name="col.string" value="STRING_VALUE"/>
<arg name="col.date" value="DATE_VALUE"/>
<arg name="col.data" value="DATA_VALUE"/>
<arg name="col.float" value="FLOAT_VALUE"/>
<arg name="col.number" value="NUMBER_VALUE"/>
<arg name="datasource" value="java:jdbc/mySQL-shop"/>
<arg name="" value=""/>
</propertyset>
</propertysets>
到这里就配置文件就差不多了,剩下得就是将 webapp目录下得文件打包成 osworkflowExample.war 拷贝到jboss 得server/default/deploy目录下, 重新启动jboss
用http://127.0.0.1:8080/osworkflowExample 就可以访问例子程序了,
运行例子程序,先建立三个group :(foos,bazs,bars),再建立一个用户test,test属于foos,bazs,bars组
这样就可以启动工作流,执行工作流部骤了
在家弄了两个上午才搞成功这个东西,特别是osuer.xml,propertyset.xml这两个文件,因为家里不能上网,没有资料,只好用小聪反编译软件把oscore.jar,ospropertyset.jar
反编译,看源码才弄出这两个文件,这只是我学习osworkflow的开始,路还很长