⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flowutils.java

📁 使用spring ,hibernate 框架的稽查管理系统
💻 JAVA
字号:
package com.je.ims.util;
import java.rmi.Naming;
import java.util.*;
import openwfe.org.rmi.session.WorkSessionServer;
import openwfe.org.engine.workitem.LaunchItem;
import openwfe.org.engine.workitem.InFlowWorkItem;
import openwfe.org.engine.workitem.StringMapAttribute;
import openwfe.org.worklist.Header;
import java.rmi.RemoteException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import openwfe.org.OpenWfeException;
import openwfe.org.ApplicationContext;
import openwfe.org.engine.workitem.WorkItem;
import openwfe.org.engine.workitem.LaunchItem;
import openwfe.org.engine.workitem.InFlowWorkItem;
import openwfe.org.engine.expressions.FlowExpressionId;
import openwfe.org.worklist.Header;
import openwfe.org.worklist.Launchable;
import openwfe.org.worklist.WorkSession;
import openwfe.org.worklist.LaunchException;
import openwfe.org.worklist.WorkListException;
import openwfe.org.input.InputHelper;
import openwfe.org.worklist.WorkSession;
import openwfe.org.engine.expressions.FlowExpressionId;
import openwfe.org.engine.control.ControlSession;
public class FlowUtils {
	   private WorkSessionServer sessionServer =null;

       private WorkSession workSession = null;
       
       private ControlSession conSession =null;
       private String rmi=null;
       public void setrmi(String rrmi){
    	   this.rmi=rrmi;
       }
       private String name=null;
       public void setname(String nname){
    	   this.name=nname;
       }
       private String pass=null;
       public void setpass(String ppass){
    	   this.pass=ppass;
       }
       private int limit=10;
       public void setlimit(int llimit){
    	   this.limit=llimit;
       }
       
       public FlowUtils() throws Exception{
       }
       public void systest(String msg){
    	   System.out.println(msg);
       }
       void close()throws Exception{
           workSession.close();
       }
       
       public void getconnect()throws Exception{
     	 sessionServer = (WorkSessionServer)Naming
                .lookup(rmi);
  	     workSession = (WorkSession)sessionServer
  	           .login(name, pass);	     
      }
       
       
       
    
    public InFlowWorkItem getworkitem(String store,String ID)throws Exception{
 		List L1=workSession.findFlowInstance(store,ID);
 		InFlowWorkItem workitem=null;
 	    
 		for (int ii=0;ii<L1.size();ii++)
 	    {
 	    	FlowExpressionId O1=(FlowExpressionId)L1.get(ii);
 	    	workitem = workSession.getAndLock(store,O1);
 	    }	        
 		return workitem;
 	}

    
    public String getstorefromid(String ID)throws Exception{
    	String result=null;
    	List stores = this.workSession.getStoreNames();
    	Iterator it = stores.iterator();
    	while (it.hasNext())
    	{
    		String Name = (String)it.next();
    		
    		if(Name.equals((String)"Store.query")){ 
    			
    			 result=null;
    		}   
    		else{
    			
    			try{
    				List L1=workSession.findFlowInstance(Name,ID);
    				if(L1.isEmpty()){
            		}
        			else 
            			result=Name;
    			}catch(Exception e){
    				System.out.println("store name "+Name+" called unexpectedly");
    		    }
    		}
    	}    
    	//systest(result);
    	return result;
    } 
    
    public InFlowWorkItem getWorkItemByID(String ID) throws Exception{
    	getconnect();    	    	    
   	    InFlowWorkItem workitem=getWorkItemByInstanceID(ID);      
		close();
		return workitem;
    	
    }
    
    public InFlowWorkItem getWorkItemByInstanceID(String InstanceID) throws Exception 
    { 
    Thread.sleep(1000);
    InFlowWorkItem work1=null; 
    List LStore=this.workSession.getStoreNames(); 
    boolean found=false; 
    for (int i=0;i<LStore.size();i++) 
    { 
    String store=(String)LStore.get(i); 

        int limit = 500; 

        java.util.List headers = this.workSession.getHeaders(store, limit); 
        System.out.println(store+": size="+headers.size()); 

        if (headers != null) 
        { 

            for (int j=0;j<headers.size();j++) 
            { 
            Header header = (Header)headers.get(j); 
            
              try 
              {
            	InFlowWorkItem workitem = this.workSession.get(store, header.getExpressionId()); 
            	System.out.println(workitem.getParticipantName()); 

            	System.out.println(workitem.getId().getParentWorkflowInstanceId()); 
            	if (InstanceID.equals(workitem.getId().getParentWorkflowInstanceId())) 
            	{ 
            		found=true; 
            		work1=workitem; 
            		break; 
            	}
              } catch (Exception e)
              {
            	  e.printStackTrace();
              }
            } 
        } 

    if (found) break; 
    } 
    return work1; 
    }
    
//    public void cancel(String ID)throws Exception{
//    	sessionServer = (WorkSessionServer)Naming
//              .lookup("rmi://localhost:7089/controlSessionServer");
//         conSession = (ControlSession)sessionServer
//              .login("admin", "admin");
//         
//         InFlowWorkItem workitem=getWorkItemByID(ID);
//         
//         conSession.cancelExpression(workitem.getId());
//    }
    
    //通過prop和url就可以launch一?workitem
     public String launch(Properties prop,String url)throws Exception{
    	 systest("------launch-------");
    	 getconnect();
    	 url="http://localhost:7079/"+url+".xml";
    	 systest(url);
    	 String part=launchitem(prop,url); 
    	 close();
    	 return part;
     }
     public String launchitem(Properties prop,String url)throws Exception{
    	 
	     LaunchItem li = new LaunchItem();
	     li.setWorkflowDefinitionUrl(url);
         
	     Enumeration pvalue= prop.elements();
	     Enumeration pname=prop.propertyNames();
	     
	     while(pname.hasMoreElements()){
	    	 li.getAttributes().puts(pname.nextElement().toString(),pvalue.nextElement().toString());
	     }
	     String ss=workSession.launch("mainEngine", li); 
	    
	     StringTokenizer sk=new StringTokenizer(ss);
	      
	     for(int i=0;i<7;i++){
	    	 sk.nextToken();
	     }      
	     String ID;
	     ID=sk.nextToken();
	     systest("ID: "+ID);
	     return ID;
	}   
     //可以直接通過ID來forward一?workitem    
     public String forward(String ID)throws Exception{
    	 systest("------forward-------");
    	 getconnect();    	 
    	 String part=forwarditem(ID);		 
    	 close();
    	 return part;
	}
	public String forwarditem(String ID)throws Exception{
		InFlowWorkItem work1=null; 
		String rejectStore=null;
		
	    List LStore=this.workSession.getStoreNames(); 
	    boolean found=false; 
	    for (int i=0;i<LStore.size();i++) 
	    { 
	        String store=(String)LStore.get(i); 

	        int limit = 500; 

	        java.util.List headers = this.workSession.getHeaders(store, limit); 
//	        System.out.println(store+": size="+headers.size()); 

	        if (headers != null) 
	        { 

	            for (int j=0;j<headers.size();j++) 
	            { 
	            Header header = (Header)headers.get(j); 
	            InFlowWorkItem workitem = this.workSession.get(store, header.getExpressionId()); 
//	            System.out.println(workitem.getParticipantName()); 

//	            System.out.println(workitem.getId().getParentWorkflowInstanceId()); 
	            if (ID.equals(workitem.getId().getParentWorkflowInstanceId())) 
	            { 
	            found=true; 
	            workSession.getAndLock(store, header.getExpressionId());
	            work1=workitem; 
	            rejectStore=store;
	            break; 
	            } 
	            } 
	        } 

	        if (found) break; 
	     } 
		 //
		 if (found)
	     {
			 workSession.forward(rejectStore, work1);
			 //
			 InFlowWorkItem work2=getWorkItemByInstanceID(ID);
			 return work2.getParticipantName(); 
	     }
		 else 
	     {
			 System.out.println("Error, Can not find WorkItem to Forward with.");
			 return null;
	     }
	}
	//可以直接通過ID來reject一?workitem  
	public String reject(String ID)throws Exception{
		systest("------reject-------");
		getconnect();    	 
    	String part=rejectitem(ID);		 
   	    close();
   	    return part;
	}
	public String rejectitem(String ID)throws Exception{
		InFlowWorkItem work1=null; 
		String rejectStore=null;
		
	    List LStore=this.workSession.getStoreNames(); 
	    boolean found=false; 
	    for (int i=0;i<LStore.size();i++) 
	    { 
	        String store=(String)LStore.get(i); 

	        int limit = 500; 

	        java.util.List headers = this.workSession.getHeaders(store, limit); 
//	        System.out.println(store+": size="+headers.size()); 

	        if (headers != null) 
	        { 

	            for (int j=0;j<headers.size();j++) 
	            { 
	            Header header = (Header)headers.get(j); 
	            InFlowWorkItem workitem = this.workSession.get(store, header.getExpressionId()); 
//	            System.out.println(workitem.getParticipantName()); 

//	            System.out.println(workitem.getId().getParentWorkflowInstanceId()); 
	            if (ID.equals(workitem.getId().getParentWorkflowInstanceId())) 
	            { 	            	
	            found=true;
	            workSession.getAndLock(store, header.getExpressionId());
	            work1=workitem; 
	            rejectStore=store;
	            break; 
	            } 
	            } 
	        } 

	    if (found) break; 
	    } 
	           
	     //
	    if (found){
		 work1.getAttributes().setField("AGREE","FALSE");
		 //
		 workSession.forward(rejectStore, work1);		 
		 
		 //
		 InFlowWorkItem work2=getWorkItemByInstanceID(ID);
		 return work2.getParticipantName();
	    }
	    else 
	    {
			 System.out.println("Error, Can not find WorkItem to Reject with.");
			 return null;
	    }
	}

	public void cancel(String ID)throws Exception{
		systest("------cancel-------");
		getconnect();    	 
    	cancelitem(ID);		 
   	    close();
   	    return ;
	}
	public void cancelitem(String ID)throws Exception{
		InFlowWorkItem work1=null; 
		String rejectStore=null;
		
	    List LStore=this.workSession.getStoreNames(); 
	    boolean found=false; 
	    for (int i=0;i<LStore.size();i++) 
	    { 
	        String store=(String)LStore.get(i); 

	        int limit = 500; 

	        java.util.List headers = this.workSession.getHeaders(store, limit); 
//	        System.out.println(store+": size="+headers.size()); 

	        if (headers != null) 
	        { 

	            for (int j=0;j<headers.size();j++) 
	            { 
	            Header header = (Header)headers.get(j); 
	            InFlowWorkItem workitem = this.workSession.get(store, header.getExpressionId()); 
//	            System.out.println(workitem.getParticipantName()); 

//	            System.out.println(workitem.getId().getParentWorkflowInstanceId()); 
	            if (ID.equals(workitem.getId().getParentWorkflowInstanceId())) 
	            { 	            	
	            found=true;
	            workSession.getAndLock(store, header.getExpressionId());
	            work1=workitem; 
	            rejectStore=store;
	            break; 
	            } 
	            } 
	        } 

	    if (found) break; 
	    } 
	           
	     //
	    if (found){
		 work1.getAttributes().setField("CANCEL","TRUE");
		 //
		 workSession.forward(rejectStore, work1);		 
		 
		 //
//		 InFlowWorkItem work2=getWorkItemByInstanceID(ID);
//		 return work2.getParticipantName();
	    }
	    else 
	    {
			 System.out.println("Error, Can not find WorkItem to Camcel with.");
	    }
		 return ;
	}

	
	
	public Map  getArributes(String ID)throws Exception{
		systest("------getArributes-------");
		getconnect();    	   	    
    	InFlowWorkItem workitem=getWorkItemByInstanceID(ID);
    	Map M1=workitem.getAttributes().getMap();
		close();
		return M1;
	}
		
    public String getParticipantName(String ID)throws Exception{
    	String S1=null;
    	getconnect();    	 
    	Thread.sleep(1000);
    	 InFlowWorkItem workitem=getWorkItemByInstanceID(ID);
    	 if (workitem!=null) S1= workitem.getParticipantName();
		 close();
		 return S1;
    }
  
    public String getAttribute(String id,String attributeID) throws Exception
    {
    	String S1=null;
		systest("------getArribute "+ attributeID +"-------");
		getconnect();    	   	   
		System.out.println("getAttribute("+id+" , "+attributeID+")");
    	InFlowWorkItem workitem=getWorkItemByInstanceID(id);
    	
    	openwfe.org.engine.workitem.Attribute att=workitem.getAttributes().get(attributeID);
    	if (att!=null) S1=att.toString();
		close();
    	
		System.out.println(S1);
    	return S1;
    }
    
    public static void main (String[] args) throws Exception
    {
    	Properties prop=new Properties();
    	prop.put("__subject__", "Test2");
	    prop.put("DEVISION","ROOT");
    	//
    	String url="NOTION";
    	String ID="1157784391046";
    	//
    	FlowUtils  te=new FlowUtils(); 
    	te.setlimit(10);
    	te.setname("admin");
    	te.setpass("admin");
    	te.setrmi("rmi://localhost:7099/workSessionServer");

    	te.systest(te.getAttribute("1158822699468","ACTION"));
  //  	te.systest(te.getAttribute("1158816281187","ACTION"));
//   	String ss=new String(te.launch(prop,url)); 
//    	te.systest(ss);
 //   	te.systest("First step:"+te.getParticipantName(ss));
//    	te.systest(te.forward(ss));
 //   	te.systest("After Forward:"+te.getParticipantName(ss));
//    	String SValue=te.getAttribute(ss,"EDITSTATE");
//    	System.out.println("get EDITSTATE Value:"+SValue);
//    	te.systest(te.reject(ss));
//    	te.systest("After Reject:"+te.getParticipantName(ss));
//    	te.cancel(ss);
//    	te.systest("After Cancel:"+te.getParticipantName(ss));
//    	te.cancel(ss);
//    	te.systest("After Cancel:"+te.getParticipantName(ss));
    	
    	
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -