可以这么说史帝芬的http://my.so-net.net.tw/idealist/OSWorkflow/osworkflow资料是目前华文osworkflow资料中最好的一份入门教程。去面的时候在mssql中中实践过这份入门资料,感觉非常顺利。但感觉按作者的顺序把教程中的例子跑完了,还不完全清楚的明白osworkflow的架构。前些在mysql5.0中重做一次,遇到了挺多问题,我通过一步一步的跟踪原代码调试终于把这些问题搞定。下图是把osworkflow所提供的mysql下的数据表的ER图:
如果你的osworkflow持久化到mysql中你的osworkflow.xml文件内如必需按如下格式来写:
<osworkflow>
<persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
<property key="datasource" value="jdbc/DefaultDS"/>
<property key="step.sequence.increment" value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
<property key="step.sequence.retrieve" value="SELECT count(ID) FROM OS_STEPIDS"/>
<property key="entry.sequence.increment" value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>
<property key="entry.sequence.retrieve" value="SELECT count(ID) FROM OS_ENTRYIDS"/>
<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="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"/>
</persistence>
<factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
<property key="resource" value="workflows.xml"/>
</factory>
</osworkflow>
propertyset.xml文件格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<propertysets>
<propertyset name="jdbc"
class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
<arg name="datasource" value="java:comp/env/jdbc/DefaultDS"/>
<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"/>
</propertyset>
</propertysets>
workflows.xml文件格式如下:
<workflows>
<workflow name="leave" type="resource" location="leave.xml"/>
</workflows>
osuser.xml文件格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<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:comp/env/jdbc/DefaultDS</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:comp/env/jdbc/DefaultDS</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:comp/env/jdbc/DefaultDS</property>
</provider>
<authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
</opensymphony-user>
请假列子的配置如下:
package com.pdw.wfbo;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.workflow.*;
import com.opensymphony.workflow.basic.BasicWorkflow;
import com.opensymphony.workflow.config.DefaultConfiguration;
public class LeaveWFBO {
/**
* 送出假单
* @param employee
* @return
*/
public long send(String employee) {
Workflow workflow=new BasicWorkflow("peidw");
DefaultConfiguration config=new DefaultConfiguration();
workflow.setConfiguration(config);
long workflowId=-1;
try {
workflowId=workflow.initialize("leave",0,null);//leave是workflows.xml里配置的工作流名称
workflow.doAction(workflowId,1,null);
}catch(Exception e) {
e.printStackTrace();
}
return workflowId;
}
/**
* 批假
* @param workflowId 工作流编号
* @param actionId 工作编号,2 准许,3 驳回
*/
public void allow(long workflowId,int actionId) {
Workflow workflow=new BasicWorkflow("peidw");
DefaultConfiguration config=new DefaultConfiguration();
workflow.setConfiguration(config);
try {
System.out.println("actionId->"+actionId);
System.out.println("workflowId->"+workflowId);
workflow.doAction(workflowId,actionId,null);
}catch(Exception e) {
e.printStackTrace();
}
}
}
这是上面的这个例子的一个说明
|
(史帝芬, 2005/6/6, [email protected]) |
看完 第一支程式,相信讀者會有許多疑問,這些先就流程的設定做初步的介紹。首先,讀者應該注意到了,第一支程式的用到三個xml設定檔,沒錯,這三個是設定流程的設定檔。
這裡針對leave.xml做些說明…
|