回退活动参与者自定义场景
-
回退活动参与者自定义场景
场景描述
有这样一种业务场景,在流程定义时将某活动分配给某机构(非个人的都可以)。该机构下的某人执行了任务后,当需要再回退到该活动时,他既可以将任务分配给机构,也可以将任务直接分配到上次的执行者,本场景讲述如何实现灵活的回退任务配置。
案例简介
示例中提供了一个工作汇报的流程。首先是审核人要求某单位或个人对他提交工作汇报内容,然后进入审核。审核时,若不通过,则可以选择打回目标人。目标人既可以是汇报机构,也可以是该机构下的某个人。
场景实现
部署/运行
- 启动BPS Server,在Myeclipse把项目部署覆盖到tomcat的default应用中,选用Overwrite remote resources – add/replace only 。
- 在bps_example_selectback项目包com.primeton.example.workflow.selectback.flow下选中流程selectback,打开右键菜单,选择部署功能将其部署。其中,流程定义需要单独部署:
- 打开浏览器,在地址栏中输入https://localhost:8080/default/form/login.jsp打开登录页面。
如下图所示:输入tiger,以空密码登录。
- 登录后进入分派工作界面,启动一个com.primeton.example.workflow.selectback.flow.selectback流程,如下图所示:
任务人选择depta和deptb,如下图:
- 改用fish帐号登录,打开”我的任务”列表,选择执行刚才分派的工作。
重新用tiger帐号登录,打开”我的任务”列表,选择执行刚才提交的审核工作。默认界面如下:
审核意见选择为”不通过”,界面会变成:
此时点击<选择…>按钮打开流程参与者选择框时,可以发现只有depta和deptb的信息:
如果审核意见为”不通过”,则需要重做步骤6的动作;如果审核意见为”通过”,则提示流程结束:
- 使用BPS自带的角色关系在BPS Studio的组织模型视图中点击<刷新>按钮,结果如下:
-
新建项目”bps_example_selectback”。
-
业务流程定义
- 绘制业务流程com.primeton.example.workflow.selectback.flow.selectback。
- 绘制业务流程com.primeton.example.workflow.selectback.flow.selectback。
-
流程属性,为方便调试把流程启动者设为”任意人员启动”。
为了示例尽量简单,流程活动业务操作表单均采用的是BPS自带表单来实现的,因此需要在流程属性中定义相关数据。
-
汇报活动的属性,包括活动参与者和表单定义。
- 参与者
- 表单
- 参与者
-
审核活动的属性,包括活动参与者和基本信息的自定义URL。
- 参与者
- 基本信息的自定义URL
- 参与者
-
- 分派工作。
工作分派action代码如下:
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request, HttpServletResponse reponse) {
try {
String title = request.getParameter(“title”);
int i = 1;
ArrayList<WFParticipant> list = new ArrayList<WFParticipant>();
String name = “”;
String typeCode = “”;
while (request.getParameter(“pt[“+i+”]/id”) != null) {
String temp_str = “pt[“+i+”]/id”;
String id = request.getParameter(“pt[“+i+”]/id”);
if(id != null) {
name = request.getParameter(“pt[“+i+”]/name”);
typeCode = request.getParameter(“pt[“+i+”]/typeCode”);
WFParticipant pt = new WFParticipant();
pt.setId(id);
pt.setName(name);
pt.setTypeCode(typeCode);
list.add(pt);
i++;
}
}
HttpSession session = request.getSession(true);
UserInfo user = (UserInfo) session.getAttribute(“userInfo”);
BPSServiceClientFactory.getLoginManager().setCurrentUser(user.getUserID(), user.getUserName());
IBPSServiceClient client = BPSServiceClientFactory.getDefaultClient();
IWFProcessInstManager processInstManager = client.getProcessInstManager();
long processInstID = processInstManager.createProcessInstance(“com.primeton.example.workflow.selectback.flow.selectback”, title, title);
IWFRelativeDataManager relativeDataManager = client.getRelativeDataManager();
relativeDataManager.setRelativeData(processInstID, “title”, title);
relativeDataManager.setRelativeData(processInstID, “pt”, list);
processInstManager.startProcessInstance(processInstID);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward(“success”);
}
说明
本例的流程定义的第一个活动”汇报”的参与者数据是来自于相关数据的。如果进入”汇报”活动前没有给相关数据中的参与者pt变量赋值,那么就会导致该活动没有任何参与者的错误。为避免这个错误,创建流程之后就把参与者信息保存到相关数据区,然后再启动流程。
3.审核。
◦审核jsp页面代码如下:
<%@page pageEncoding=”UTF-8″%>
<%@page import=”java.util.ArrayList” %>
<%@page import=”com.eos.workflow.omservice.WFParticipant” %>
<%@include file=”/common/common.jsp”%>
<%@include file=”/common/skins/skin0/component.jsp”%>
<%@ taglib uri=”https://eos.primeton.com/tags/workflow” prefix=”wf”%>
<h:script src=”/workflow/wfcomponent/web/js/workflow-tag.js”/>
<h:css href=”/css/style1/style-custom.css”/>
<html>
<head>
<title>审核</title>
</head>
<body>
<form id=”form1″ name=”form1″ action=”/default/finshAudit.do” method=”POST”>
<h:hidden name=”_eosFlowAction” value=”verify”/>
<h:hiddendata property=”workitem”/>
<w:panel id=”panel1″ title=”审核” width=”50%”><br>
<table>
<tr>
<td>标题:</td>
<td><b:write property=”relateData/title”/>
</td>
</tr>
<tr>
<td>内容:</td>
<td>
<b:write property=”relateData/content”/>
</td>
</tr>
<tr>
<td>审核意见:</td>
<td onclick=”changeBackTargetStatus()”>
通过
<h:radio name=”reply” value=”1″ checked=”true”/>
不通过
<h:radio name=”reply” value=”0″/>
</td>
</tr>
<tr id=”backTarget” style=”visibility:hidden”>
<td>打回给:</td>
<td>
<%
ArrayList<WFParticipant> ptlsit = new ArrayList<WFParticipant>();
ptlsit = (ArrayList)request.getAttribute(“ptlsit”);
StringBuilder sb = new StringBuilder();
for(int i=0; i<ptlsit.size(); i++) {
WFParticipant tempPt = (WFParticipant)ptlsit.get(i);
sb.append(tempPt.getTypeCode()).append(“{“).append(tempPt.getId()).append(“}”);
if(i<ptlsit.size()-1)
sb.append(“|”);
}
%>
<input id=”participant” name=”ptName” type=”text” size=”31″ class=”textbox”>
<wf:selectParticipant form=”form1″ output=”participant” root='<%=sb.toString() %>’ value=”选择…”
hidden=”pt” hiddenType=”PARTICIPANT”/>
</td>
</tr>
<tr>
<td><br><input type=”submit” name=”sbPlan” value=”提交”>
<input type=”button” name=”sbPlan” value=”返回” onclick=”javascript:history.go(-1);”>
</td>
</tr>
</table>
</w:panel>
</form>
<script>
function changeBackTargetStatus() {
var bt = document.getElementById(“backTarget”);
var reply = getReply();
if(0 == reply) {
bt.style.visibility = “visible”;
} else {
bt.style.visibility = “hidden”;
}
}
function getReply() {
var res = document.getElementsByName(“reply”);
for(var i=0; i<res.length; i++) {
var re = res[i];
if(re.checked)
return re.value;
}
return null;
}
</script>
</body>
</html>
必须给root属性赋值。其规则是typeCode{id}| typeCode1{id1}|……。
typeCode表示参与者类型代码,id表示参与者id。多个参与者用”|”分开。
◦审核action代码片段如下:
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request, HttpServletResponse reponse) {
long wotkitemid = Long.parseLong(request.getParameter(“workitem/workItemID”));
long activityinstid = Long.parseLong(request.getParameter(“workitem/activityInstID”));
long processinstid = Long.parseLong(request.getParameter(“workitem/processInstID”));
String reply = request.getParameter(“reply”);
try {
int i = 1;
ArrayList<WFParticipant> list = new ArrayList<WFParticipant>();
String name = “”;
String typeCode = “”;
while (request.getParameter(“pt[“+i+”]/id”) != null) {
String temp_str = “pt[“+i+”]/id”;
String id = request.getParameter(“pt[“+i+”]/id”);
if(id != null) {
name = request.getParameter(“pt[“+i+”]/name”);
typeCode = request.getParameter(“pt[“+i+”]/typeCode”);
WFParticipant pt = new WFParticipant();
pt.setId(id);
pt.setName(name);
pt.setTypeCode(typeCode);
list.add(pt);
i++;
}
}
HttpSession session = request.getSession(true);
UserInfo user = (UserInfo) session.getAttribute(“userInfo”);
BPSServiceClientFactory.getLoginManager().setCurrentUser(user.getUserID(), user.getUserName());
IBPSServiceClient client = BPSServiceClientFactory.getDefaultClient();
if(reply.equals(“0”)) {
IWFRelativeDataManager relativeDataManager = client.getRelativeDataManager();
relativeDataManager.setRelativeData(processinstid, “pt”, list);
IWFBackActivityManager backActivityManager = client.getBackActivityManager();
backActivityManager.backActivity(activityinstid, “reportActivity”, “path”);
} else {
IWFWorkItemManager workItemManager = client.getWorkItemMananger();
workItemManager.finishWorkItem(wotkitemid, false);
}
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward(“success”);
}
其他
•所有未作特殊说明的属性均保持默认设置。
•角色定义文件在项目的webcontent目录下。
•未作说明的逻辑流和jsp页面可以参考示例源代码。
声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 嗅谱网
转载请注明:转自《回退活动参与者自定义场景》
本文地址:http://www.xiupu.net/archives-7064.html
关注公众号:
微信赞赏
支付宝赞赏