用osworkflow写一个请假例子
用osworkflow写一个请假例子 Posted on 2007-03-02 16:07 dennis 阅读(11062) 评论(26) 编辑 收藏 所属分类: java 、工作流
用osworkflow写一个请假例子
Posted on 2007-03-02 16:07 dennis 阅读(11062) 评论(26) 编辑 收藏 所属分类: java 、工作流
update:这个例子是不当的,更合适的例子请自己上javaeye上搜索个帖子。源码俺早就丢了,请不要再发邮件给我,谢谢。
osworkflow扩展非常容易,跟我们的应用结合起来使用也很容易。假设一个请假流程:员工请假,需要经过部门经理和人力资源部经理两人共同审批,只有当两人都许可时才通过,任一人驳回就失效,也就是一个and split和and Join流程,并且我们附加一个要求,当发送请假请求、许可和驳回这几个操作时都将发送一条消息给相应的用户。
流程定义文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.7//EN"
"http://www.opensymphony.com/osworkflow/workflow_2_7.dtd">
<workflow>
<initial-actions>
<action id="0" name="开始">
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
status="Underway" step="1" owner="${caller}" />
</results>
</action>
</initial-actions>
<steps>
<step id="1" name="填假单">
<external-permissions>
<permission name="permA">
<restrict-to>
<conditions type="AND">
<condition type="class"><!--流程处于Underway状态(流程已经启动)-->
<arg name="class.name">
com.opensymphony.workflow.util.StatusCondition
</arg>
<arg name="status">Underway</arg>
</condition>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.AllowOwnerOnlyCondition
</arg>
</condition>
</conditions>
</restrict-to>
</permission>
</external-permissions>
<actions>
<action id="1" name="送出">
<restrict-to>
<conditions type="AND">
<condition type="class"><!--流程处于Underway状态(流程已经启动)-->
<arg name="class.name">
com.opensymphony.workflow.util.StatusCondition
</arg>
<arg name="status">Underway</arg>
</condition>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.AllowOwnerOnlyCondition
</arg>
</condition>
</conditions>
</restrict-to>
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
split="1" status="Queued">
<post-functions>
<function type="class">
<arg name="class.name">
net.rubyeye.leavesys.service.workflow.SendRemindInfFunction
</arg>
<arg name="groupName">
AND (GROUPNAME='dept_manager' or
GROUPNAME='comp_manager')
</arg>
<arg name="content">
you have leavemsg to
check!please check it!
</arg>
</function>
</post-functions>
</unconditional-result>
</results>
</action>
</actions>
</step>
<step id="2" name="部门经理批假单">
<actions>
<action id="2" name="准许">
<restrict-to>
<conditions>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.OSUserGroupCondition
</arg>
<arg name="group">dept_manager</arg>
</condition>
</conditions>
</restrict-to>
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
<function type="beanshell">
<arg name="script">
propertySet.setString("action1",
"success");
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
status="Queued" join="1" owner="${caller}" />
</results>
</action>
<action id="3" name="驳回">
<restrict-to>
<conditions>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.OSUserGroupCondition
</arg>
<arg name="group">dept_manager</arg>
</condition>
</conditions>
</restrict-to>
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
<function type="beanshell">
<arg name="script">
propertySet.setString("action1",
"fail");
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
status="Queued" join="2" owner="${caller}" />
</results>
</action>
</actions>
</step>
<step id="3" name="公司经理批假单">
<actions>
<action id="4" name="准许">
<restrict-to>
<conditions>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.OSUserGroupCondition
</arg>
<arg name="group">comp_manager</arg>
</condition>
</conditions>
</restrict-to>
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
<function type="beanshell">
<arg name="script">
propertySet.setString("action2",
"success");
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
status="Queued" join="1" owner="${caller}" />
</results>
</action>
<action id="5" name="驳回">
<restrict-to>
<conditions>
<condition type="class">
<arg name="class.name">
com.opensymphony.workflow.util.OSUserGroupCondition
</arg>
<arg name="group">dept_manager</arg>
</condition>
</conditions>
</restrict-to>
<pre-functions>
<function type="class">
<arg name="class.name">
com.opensymphony.workflow.util.Caller
</arg>
</function>
<function type="beanshell">
<arg name="script">
propertySet.setString("action2",
"fail");
</arg>
</function>
</pre-functions>
<results>
<unconditional-result old-status="Finished"
status="Queued" join="2" owner="${caller}" />
</results>
</action>
</actions>
</step>
<step id="4" name="停止" />
</steps>
<splits>
<split id="1">
<unconditional-result old-status="Finished" status="Queued"
step="2" />
<unconditional-result old-status="Finished" status="Queued"
step="3" />
</split>
</splits>
<joins>
<join id="1">
<conditions type="AND">
<condition type="beanshell">
<arg name="script">
<![CDATA[
"Finished".equals(jn.getStep(2).getStatus()) &&
"Finished".equals(jn.getStep(3).getStatus())&&"success".equals(propertySet.getString("action1"))&&
"success".equals(propertySet.getString("action2"))
]]>
</arg>
</condition>
</conditions>
<unconditional-result old-status="Finished" status="Queued"
step="4"/>
</join>
<join id="2">
<conditions type="OR">
<condition type="beanshell">
<arg name="script">
<![CDATA[
"Finished".equals(jn.getStep(2).getStatus()) &&"fail".equals(propertySet.getString("action1"))
]]>
</arg>
</condition>
<condition type="beanshell">
<arg name="script">
<![CDATA[
"Finished".equals(jn.getStep(3).getStatus())&&"fail".equals(propertySet.getString("action2"))
]]>
</arg>
</condition>
</conditions>
<unconditional-result old-status="Finished" step="4"
status="Queued">
<post-functions>
<function type="class">
<arg name="class.name">
net.rubyeye.leavesys.service.workflow.SendRemindInfFunction
</arg>
<arg name="groupName">
AND GROUPNAME='employee'
</arg>
<arg name="content">
you leveamsg is fail!!!
</arg>
</function>
</post-functions>
</unconditional-result>
</join>
</joins>
</workflow>
请注意,我们在许可或者通过的时候propertySet.setString("action2",......),propertySet.setString("action3",......),然后在join点判断,如果两个都是success,流程结束;如果一个是fail,就发送一个消息给员工。
发送消息的function像这样:
package net.rubyeye.leavesys.service.workflow;
import java.sql.SQLException;
import java.util.Map;
import net.rubyeye.leavesys.domain.RemindInf;
import net.rubyeye.leavesys.service.ManagerFactory;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.FunctionProvider;
import com.opensymphony.workflow.WorkflowException;
public class SendRemindInfFunction implements FunctionProvider {
public void execute(Map transientVars, Map args, PropertySet ps)
throws WorkflowException {
String groupName = (String) args.get("groupName");
String content = (String) args.get("content");
RemindInf remindInf = new RemindInf();
remindInf.setContent(content);
try {
ManagerFactory.getRemindService().addRemindInfByGroupName(
groupName, remindInf);
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
得到两个参数groupName和content(消息内容),调用业务对象发送消息。
完整代码下载在《LeaveSystem》
代码用到了自己过去写的一个MVC框架和持久层,对此有兴趣的参考这三篇文章:
《设计自己的MVC框架》
《设计模式之事务处理》
《使用Annotation设计持久层》
如果仅仅是想了解osworkflow的应用,建议您跑下流程,读读相关几个业务类(LeaveServiceImpl.java,SendRemindInfFunction.java,service包下)即可。解压缩后的文件可以直接导入myeclipse工程,部署在tomcat下,数据库用的是oracle。跑起来以后可以用3个用户登录,test是雇员组,dennis是部门经理组,jordan是公司经理,都不需要密码。写的比较简单,只是实验性质,见谅。
我认为使用osworkflow,只要了解了它的表结构和主要原理,根据你的业务需要结合几张主要表(os_wfentry,os_currentstep,os_historystep等)合理设计数据库和业务流程,可以省去过去为每个业务流程对象创建的一大堆flag(标志,目前的流程状态)的累赘,充分利用工作流的威力。比如为部门经理和人力资源部经理显示不同的需要审批的假单列表,只要结合os_historystep表进行联合查询,部门经理的应该是执行了未执行acion2,step在3的;而人力资源部经理得到的同样是step在3,action未执行3的。
手痒痒,很想把去年为一家公司写的绩效考核系统改写一下,当时设计的一个contract对象拥有7,8个flag来标志合约状态(直接上级审核,人力资源评价,KPI评价等),搞的非常混乱,而且流程写死在代码里,如果以后要改变考核流程,只有重新写过一套。不过那家公司是国有企业,每年的固定的预算费用一定要花掉,反正大家一起赚国家的钱嘛。
评论
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-02 17:38 by BeanSoft
气氛有点冷清...
# re: 用osworkflow写一个请假例子[未登录] 回复 更多评论
2007-03-02 18:11 by test
没有运行代码下载啊?
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-02 18:54 by dennis
@test
放上去了,因为用到过去自己写一些基础框架,怕误导人,一开始没敢放上去,下载地址
http://www.blogjava.net/Files/killme2008/LeaveSystem.rar
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-05 14:21 by kk
请问下您的这个例子如何配置运行,我部署在tomcat下好象运行不了。
我的邮箱BreatheTakingBeauty@hotmail.com
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-05 21:23 by hello
最近公司 在 osworkflow & jbpm 间做 选择,
我研究 osworkflow ,看到 你 的 例子 ,不错 ,赞一个 ,
可代码 不能 下 吗??
可否发 给 本人,谢谢
truthyd@126.com
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-06 08:46 by dennis
@hello
我对osworkflow也在学习阶段,这几天看了下代码,这个例子还是写的太差,特别是没有用到osworkflow的状态查询功能,而是直接结合表来查询数据库,导致代码写死了。没什么参考价值,准备改改
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-06 10:11 by allan
你好,你的那个例子似乎不能下,能不能发给我一份?
地址:allan0410@qq.com
也交个朋友,我现在急需一个像你的这个例子,对于初学osworkflow的帮助很大。。。
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-06 10:15 by allan
在线等待。。。!~
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-06 11:26 by dennis
@allan
又放上去了,例子写的确实不好,有空修改下,最好的方式还是调用osworkflow的查询API来进行状态查询,而非我现在做的直接查询数据库。倒有点后悔放上去了,希望没误导人
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-06 15:11 by allan
怎么用eclipse3.2打开包错啊?。。。
似乎没包
# re: 用osworkflow写一个请假例子(提供代码下载) 回复 更多评论
2007-03-06 15:17 by allan
能不能告诉我你那个工程要导入那些包??
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-06 16:24 by allan
跪求myutil.jar包,楼主能不能将源码发给我。。。
感激泣零
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-06 16:29 by dennis
@allan
myutll.jar在WEB-INF/lib下,其他的就是需要osworflow的支持包,请自行下载
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-07 13:21 by dennis
那里需要重写ConnectionManager,你所需要做的只是配置数据源而已,我不是在db_setup目录下方了一个leave.xml,修改下里面的数据库名配置,拷贝到tomcat安装目录下的\conf\Catalina\localhost就可以了
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-07 14:19 by allan
昏,问题解决了。。。
原来是要拷到tomcat-common-lib下面
这种连接方式太依赖服务器了。。。
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-07 15:16 by dennis
@allan
哎,本来就是个例子,你指望他干什么呢?我本来就不想把代码放上来的。请别再刷评论了,谢谢
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-14 10:30 by zyg
hi,你那个例子连接失效,能不能发邮件给我一个,万分感谢
我的邮箱地址 yg_zhangyg@tecamo.com
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-22 15:01 by hiya
代码下不了。是否已经删了。
我的邮箱:chf@tsinghua.org.cn
有BaseJDBCProvider.java文件吗,发一个,谢谢先。
我连不上数据源
Could not look up DataSource错。
请教!!!!
急!!!!
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-03-27 10:34 by aa
代码下不了。是否已经删了。
我的邮箱:zzzyqqq@163.com
有BaseJDBCProvider.java文件吗,发一个,谢谢先。
# re: 用osworkflow写一个请假例子[未登录] 回复 更多评论
2007-04-05 23:45 by Jeff
代码下不了? 我的邮箱是wji@ryerson.ca 请发一份好吗?
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-04-13 15:40 by yangrong
能把你的例子给我发一份吗?
yangrongqiang@163.com,谢谢。
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-04-15 11:04 by dennis
@yangrong
sorry,这个代码我已经删除了,我觉的写的很烂,那时对osworkflow的理解还停留在初步了解,代码不能见人的。请搜索CSDN java版上一个帖子,我记的有一个别人写的例子非常不错。
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-04-20 16:17 by G_G
房主不厚道
:(
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-06-12 17:17 by yuzhongren
那位有原码的能不能发给我一份阿,谢谢了zfjwzh@163.com
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-06-13 13:54 by zhangying
你好
能给我发一份吗>我的邮箱zhangy@sict.ac.cn
非常感谢
# re: 用osworkflow写一个请假例子 回复 更多评论
2007-07-03 14:13 by e
你好 。
给我也发一份。
guzhuopiao@hotmail.com
update:这个例子是不当的,更合适的例子请自己上javaeye上搜索个帖子。源码俺早就丢了,请不要再发邮件给我,谢谢。 osworkflow扩展非常容易,跟我们的应用结合起来使用也很容易。假设一个请假流程:员工请假,需要经过部门经理和人力资源部经理两人共同审批,只有当两人都许可时才通过,任一人驳回就失效,也就是一个and split和and Join流程,并且我们附加一个要求,当发送请假请求、许可和驳回这几个操作时都将发送一条消息给相应的用户。 流程定义文件如下:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.7//EN" "http://www.opensymphony.com/osworkflow/workflow_2_7.dtd"> <workflow> <initial-actions> <action id="0" name="开始"> <pre-functions> <function type="class"> <arg name="class.name"> com.opensymphony.workflow.util.Caller </arg> </function> </pre-functions> <results> <unconditional-result old-status="Finished" status="Underway" step="1" owner="${caller}" /> </results> </action> </initial-actions>
<steps> <step id="1" name="填假单"> <external-permissions> <permission name="permA"> <restrict-to> <conditions type="AND"> <condition type="class"><!--流程处于Underway状态(流程已经启动)--> <arg name="class.name"> com.opensymphony.workflow.util.StatusCondition </arg> <arg name="status">Underway</arg> </condition> <condition type="class"> <arg name="class.name"> com.opensymphony.workflow.util.AllowOwnerOnlyCondition </arg> </condition> </conditions> </restrict-to> </permission> </external-permissions> <actions> <action id="1" name="送出"> <restrict-to> <conditions type="AND"> <condition type="class"><!--流程处于Underway状态(流程已经启动)--> <arg name="class.name"> com.opensymphony.workflow.util.StatusCondition </arg> <arg name="status">Underway</arg> </condition> <condition type="class"> <
<steps> <step id="1" name="填假单"> <external-permissions> <permission name="permA"> <restrict-to> <conditions type="AND"> <condition type="class"><!--流程处于Underway状态(流程已经启动)--> <arg name="class.name"> com.opensymphony.workflow.util.StatusCondition </arg> <arg name="status">Underway</arg> </condition> <condition type="class"> <arg name="class.name"> com.opensymphony.workflow.util.AllowOwnerOnlyCondition </arg> </condition> </conditions> </restrict-to> </permission> </external-permissions> <actions> <action id="1" name="送出"> <restrict-to> <conditions type="AND"> <condition type="class"><!--流程处于Underway状态(流程已经启动)--> <arg name="class.name"> com.opensymphony.workflow.util.StatusCondition </arg> <arg name="status">Underway</arg> </condition> <condition type="class"> <
