工作流编程方法

1.除流程模板所有者可启动流程外,具有超级权限的用户也可以启动
2.
/*
 * 为对象添加新的权限
 * @param session
 * @param ObjectID 对象系统编号
 * @param strGrouporUserName 用户或组
 * @param basic:Basic Permissions
* @param extended:Extended Permissions(EXECUTE_PROC/CHANGE_LOCATION/CHANGE_STATE/CHANGE_PERMIT/CHANGE_OWNER/DELETE_OBJECT/CHANGE_FOLDER_LINKS) 
 * */
public static void setACL(IDfSession session,String ObjectID,String strGrouporUserName,int basic,String[] extended) throws DfException{
IDfClientX clientX=new DfClientX();
IDfId objId=clientX.getId(ObjectID);
//获取对象
IDfSysObject obj=(IDfSysObject) session.getObject(objId);
//获取对象权限集
IDfACL acl=obj.getACL();
int exCnt=extended.length;
if(exCnt>0){
for(int i=0;i<exCnt;i++){
acl.grant(strGrouporUserName, basic,extended[i]);
}
}else{
acl.grant(strGrouporUserName, basic,null);
}
acl.save();
obj.setACL(acl);
obj.save();
}

3./**
 * 获得工作流信息
 * */
public HashMap getWorkFlowInfo(){
HashMap result=new HashMap();
int arrSize=0;   //result数组大小
try {
//获得result数组大小,即任务数量
dql="Select count(r_object_id) as number From dmi_queue_item q  WHERE  router_id like '4d%' and (name in(select group_name from dm_group where ANY IN i_all_users_names =USER) or name =USER) AND delete_flag=0 and  dependency_type in ('0', '1', '2', '3', '4', '5', '6')  and task_name!='event'";
arrSize=db.getNumOfRecord(dql, session, "number");
HashMap[] conten = new HashMap[arrSize];
//dql="select r_object_id,name,sent_by,date_sent,message  from dmi_queue_item q left join dmi_workitem w on q.item_id=w.r_object_id where dependency_type in ('0', '1', '2', '3', '4', '5', '6') and  name=USER and task_state!='finished' and delete_flag=0 order by date_sent desc";
dql="EXECUTE get_inbox WITH name='"+session.getLoginUserName()+"',cagegory=1,order_by='date_sent desc'";
coll=db.getCollection(dql, session);
//存储对象信息
     int i=0;     
     while(coll.next()){       
conten[i] = new HashMap<String, String>();
conten[i].put("r_object_id", coll.getString("r_object_id"));
conten[i].put("name",coll.getString("name"));
conten[i].put("sent_by",coll.getString("sent_by"));
conten[i].put("date_sent", coll.getString("date_sent"));
conten[i].put("message", coll.getString("message"));
i++;
     }
     result.put("Rows", conten);
result.put("Total", arrSize); 
} catch (DfException e1) {
e1.printStackTrace();
}
return result;
}
/**
 * 删除工作流信息
 * @param wfID 工作流系统编号
 * @throws DfException 
 * */
public void deleteWorkFlow(String wfID) throws DfException{
int userPrivileges=getUserPrivileges();
setUserPrivileges(16);
try{
IDfQueueItem item=(IDfQueueItem) session.getObject(new DfId(wfID));
String sent_by=item.getSentBy();
dql="delete dmi_queue_item objects where delete_flag=0 and r_object_id='"+wfID+"'";
coll=db.getCollection(dql, session);
String notes=user.getUser_name()+"删除了【"+sent_by+"】发来的流程任务!";
 try {
LogManage(notes);
} catch (UnknownHostException e) {
e.printStackTrace();
}//添加日志
}finally{
setUserPrivileges(userPrivileges);
db.closeCollection();
}
}
/**
 * 委托其他用户处理工作流信息
 * @param itemID 任务系统编号
 * @param strUser 用户名称
 * @throws DfException 
 * @throws DfException 
 * @throws DfException 
 * */
public void delegateWorkFlow(String objid,String strUser) throws DfException {
int userPrivileges=getUserPrivileges();
setUserPrivileges(16);
IDfClientX clientX=new DfClientX();
dql="select item_id from dmi_queue_item where r_object_id='"+objid+"'";
try {
coll=db.getCollection(dql, session);
coll.next();
String itemID=coll.getString("item_id");
IDfWorkitem wfitem=(IDfWorkitem) session.getObject(clientX.getId(itemID));
/*IDfActivity activity=wfitem.getActivity();
activity.setPerformerName(strUser);
activity.setPerformerFlag(3);
String[] ag={"EXECUTE_PROC","CHANGE_LOCATION","CHANGE_STATE","CHANGE_PERMIT"};*/     
     //为执行者设置对附件操作的权限
     //setACL(session, "0b00000180065d01", strUser, 6, ag);
//0:Dormant 1:Acquired 2:Finished 3:Paused
int i_state=wfitem.getRuntimeState();
if(i_state==0)
{
wfitem.acquire();
wfitem.delegateTask(strUser);
}else{
//wfitem.complete();
wfitem.delegateTask(strUser);
System.out.println("转批.........................");
}
/*if(wfitem.isDelegatable()){
System.out.println("可以delegate");
}else
{System.out.println("不可以delegate");
IDfUser usr=session.getUser(strUser);
usr.setWorkflowDisabled(false);
activity.setPerformerFlag(1);
if(i_state==0)
{
wfitem.acquire();
wfitem.delegateTask(strUser);
}else{
wfitem.delegateTask(strUser);
}
}*/
String notes=user.getUser_name()+"将流程任务委派给【"+strUser+"】进行处理!";
 try {
LogManage(notes);
} catch (UnknownHostException e) {
e.printStackTrace();
}//添加日志
} catch (DfException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
setUserPrivileges(userPrivileges);
}
}
/**
 * 设置工作流的某个activity的执行者
 * @param processId
 * @param actName
 * @param performer
 * @throws DfException
 */
public static void setActivityPerformer(IDfWorkflow wf, String actName,String performer) throws DfException 
{
IDfList idflist = new DfList();
idflist.append(performer);
wf.setPerformers(actName, idflist);
}

4./**
 * 获取工作流附件或包
 * @throws DfException 
 * */
public HashMap getwfAttachments(String objid) throws DfException
{
String strID="";
IDfClientX clientx=new DfClientX();
dql="select item_id from dmi_queue_item where r_object_id='"+objid+"'";
coll=db.getCollection(dql, session);
coll.next();
String itemID=coll.getString("item_id");
IDfWorkitem wi=(IDfWorkitem) session.getObject(clientx.getId(itemID));
IDfQueueItem item = (IDfQueueItem) session.getObject(wi.getQueueItemId());
//获取工作流对象ID
IDfId wfId=wi.getWorkflowId();
//通过包获取对象ID
dql="select r_component_id from dmi_package where r_workflow_id='"+wfId.toString()+"'";
coll=db.getCollection(dql, session);
while(coll.next())
{
strID+="'"+coll.getString("r_component_id")+"',";
}
//通过附件获取对象ID
dql="select r_component_id from dmi_wf_attachment where r_workflow_id='"+wfId.toString()+"'";
coll=db.getCollection(dql, session);
while(coll.next())
{
strID+="'"+coll.getString("r_component_id")+"',";
}
strID="("+strID.substring(0, strID.length()-1)+")";
HashMap wresult=new HashMap();
int arrSize=0;   //result数组大小
try {
//获得result数组大小
dql="Select count(r_object_id) as number From dm_folder  WHERE r_object_id in"+strID;
arrSize=db.getNumOfRecord(dql, session, "number");
HashMap[] conten = new HashMap[arrSize];
dql="Select r_object_id,object_name,a_content_type,r_creation_date From dm_folder  WHERE r_object_id in"+strID;
coll=db.getCollection(dql, session);
//存储对象信息
     int i=0;     
     while(coll.next()){       
conten[i] = new HashMap<String, String>();
conten[i].put("r_object_id", coll.getString("r_object_id"));
conten[i].put("object_name",coll.getString("object_name"));
conten[i].put("a_content_type",coll.getString("a_content_type"));
conten[i].put("r_creation_date", coll.getString("r_creation_date"));
i++;
     }
     wresult.put("Rows", conten);
     wresult.put("Total", arrSize); 
} finally {
db.closeCollection();
}
return wresult;
}
/**
 * 为工作流添加附件
 * @param objid dmi_queue_item系统对象
 * @param session
 * @param attachmentId 附件ID,以逗号分隔
 * @throws DfException
 */
public  void addAttachment(String objid,String attachmentId) throws DfException {
try{
IDfClientX clientx=new DfClientX();
dql="select item_id from dmi_queue_item where r_object_id='"+objid+"'";
coll=db.getCollection(dql, session);
coll.next();
String itemID=coll.getString("item_id");
IDfWorkitem wi=(IDfWorkitem) session.getObject(clientx.getId(itemID));
//获取工作流对象ID
IDfId wfId=wi.getWorkflowId();
IDfWorkflow wf=(IDfWorkflow) session.getObject(wfId);
if ("".equals(attachmentId))
return;
String[] item = attachmentId.split(",");
for (int i = 0; i < item.length; i++) {
IDfId id = new DfId(item[i]);
IDfSysObject obj = (IDfSysObject) session.getObject(id);
String typeName = obj.getType().getName();
wf.addAttachment(typeName, id);
}
}finally{
db.closeCollection();
}
}
/**
 * 移除工作流附件
 * @param objid dmi_queue_item系统对象
 * @param session
 * @param attachmentId 附件ID,以逗号分隔
 * @throws DfException 
 * @throws DfException
 */
public void removeAttachment(String objid,String attachmentId) throws DfException {
IDfClientX clientx=new DfClientX();
dql="select item_id from dmi_queue_item where r_object_id='"+objid+"'";
try {
coll=db.getCollection(dql, session);
coll.next();
String itemID=coll.getString("item_id");
IDfWorkitem wfitem=(IDfWorkitem) session.getObject(clientx.getId(itemID));
//获取工作流对象ID
IDfId wfId=wfitem.getWorkflowId();
IDfWorkflow wf=(IDfWorkflow) session.getObject(wfId);
//0:Dormant 1:Acquired 2:Finished 3:Paused
int i_state=wfitem.getRuntimeState();
String dql_attrtach="delete dmi_wf_attachment object where r_component_id='"+attachmentId+"' and r_workflow_id='"+wfId.toString()+"'";
String dql_package="delete dmi_package object where r_component_id='"+attachmentId+"' and r_workflow_id='"+wfId.toString()+"'";
if(i_state==0)
{
wfitem.acquire();
//wfitem.removeAttachment(clientx.getId(attachmentId));
db.getCollection(dql_attrtach, session);
db.getCollection(dql_package, session);
}else{
//wfitem.removeAttachment(clientx.getId(attachmentId));
db.getCollection(dql_attrtach, session);
db.getCollection(dql_package, session);
}
} finally {
db.closeCollection();
}
}

/**
 * 获取附件ID
 * @param id
 * @param wId
 * @return
 * @throws DfException 
 */
public  String getAttIdByComponentId(String id, String wId) throws DfException{
String dfId = null;
IDfWorkflowAttachment obj = (IDfWorkflowAttachment)session.getObjectByQualification("dmi_wf_attachment where r_component_id='"+id+"' and r_workflow_id='"+wId+"'");
dfId=((obj!=null)?obj.getObjectId().toString():null);
return dfId;
}
/**
 * 拒绝流程
 * @param objid dmi_queue_item对象id
 * @throws DfException 
 * */
public boolean rejectWF(String objid) throws DfException
{
boolean flag=false;
dql="select count(*) as number from dmi_queue_item where router_id =(select router_id  from dmi_queue_item where r_object_id='"+objid+"')";
coll=db.getCollection(dql, session);
int number=0;
if(coll.next())
{
number=Integer.parseInt(coll.getString("number"));
if(number>1)
{
dql="select sent_by  from dmi_queue_item where r_object_id='"+objid+"' and router_id like '4d%'";
coll=db.getCollection(dql, session);
if(coll.next())
{
String sent_by=coll.getString("sent_by");
delegateWorkFlow(objid,sent_by);
flag=true;
}
}
}
return flag;
}
/*
 * 为对象添加新的权限
 * @param session
 * @param ObjectID 对象系统编号
 * @param strGrouporUserName 用户或组
 * @param basic:Basic Permissions
 * @param extended:Extended Permissions(EXECUTE_PROC/CHANGE_LOCATION/CHANGE_STATE/CHANGE_PERMIT/CHANGE_OWNER/DELETE_OBJECT/CHANGE_FOLDER_LINKS) 
 * */
public  void setACL(IDfSession session,String ObjectID,String strGrouporUserName,int basic,String[] extended) throws DfException{
IDfClientX clientX=new DfClientX();
IDfId objId=clientX.getId(ObjectID);
//获取对象
IDfSysObject obj=(IDfSysObject) session.getObject(objId);
//获取对象权限集
IDfACL acl=obj.getACL();
int exCnt=extended.length;
if(exCnt>0){
for(int i=0;i<exCnt;i++){
acl.grant(strGrouporUserName, basic,extended[i]);
}
}else{
acl.grant(strGrouporUserName, basic,null);
}
acl.save();
obj.setACL(acl);
obj.save();
}
/**
 * 获取当前用户基本权限
 * */
public int getUserPrivileges() throws DfException
{
int userPrivileges=1;
IDfSession superSession=null;
try{
superSession=SessionFactory.getSuperIDfSession();
IDfUser usr=superSession.getUser(user.getUser_name());
userPrivileges=usr.getUserPrivileges();
}finally{
SessionFactory.releaseSession(superSession);
}
return userPrivileges;
}
/**
 * 设置用户基本权限
 * @param userPrivileges
 * */
public void setUserPrivileges(int userPrivileges) throws DfException
{
IDfSession superSession=null;
try{
superSession=SessionFactory.getSuperIDfSession();
IDfUser usr=superSession.getUser(user.getUser_name());
usr.setUserPrivileges(userPrivileges);
usr.save();
}finally{
SessionFactory.releaseSession(superSession);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值