001: package client.Java_client;
002:
003: import javax.security.auth.login.LoginContext;
004: import hero.client.test.SimpleCallbackHandler;
005:
006: import hero.historic.NodeHistoric;
007: import hero.historic.ProjectHistoric;
008: import hero.historic.PropertyHistoric;
009: import hero.interfaces.*;
010:
011: import java.util.*;
012:
013: public class ExecutionHistoryApis {
014:
015: static public void main(String[] args) throws Exception {
016:
017: char[] password = { 'b', 's', 'o', 'a' };
018: SimpleCallbackHandler handler = new SimpleCallbackHandler(
019: "bsoa", password);
020: LoginContext lc = new LoginContext("TestClient", handler);
021: lc.login();
022:
023: ProjectSessionHome projectSessionh = ProjectSessionUtil
024: .getHome();
025: ProjectSession pss = projectSessionh.create();
026:
027: // Creates an instance of this process
028: pss.instantiateProject("Approval_workflow");
029:
030: UserSessionHome userSessionh = UserSessionUtil.getHome();
031: UserSession uss = userSessionh.create();
032:
033: // Get Todo list for this user for all running instances
034: Collection activites = uss.getToDoListAllInstances();
035:
036: Iterator acts = activites.iterator();
037: while (acts.hasNext()) {
038: BnNodeValue activity = (BnNodeValue) acts.next();
039: pss.initProject(activity.getBnProject().getName());
040: pss.setNodeProperty("Approval", "decision", "grant");
041: uss.startActivity(activity.getBnProject().getName(),
042: activity.getName());
043: uss.terminateActivity(activity.getBnProject().getName(),
044: activity.getName());
045:
046: activites = uss.getToDoListAllInstances();
047: acts = activites.iterator();
048: }
049:
050: // At this point the workflow instance is finished (all activities are done)
051: // and so the instance related data is saved in a separate repository.
052: // The HistoryAPI allows to retrieve data from finished instances.
053:
054: HistorySessionHome hsh = HistorySessionUtil.getHome();
055: HistorySession hs = hsh.create();
056:
057: Collection pl = hs.getHistoryProjectList();
058: Iterator projects = pl.iterator();
059: while (projects.hasNext()) {
060: // Getting process names having finished instances
061:
062: String projectName = (String) projects.next();
063: System.out.println("Process Name = " + projectName);
064:
065: // Getting finished instances for this process
066: Collection instances = hs
067: .getHistoryInstancesList(projectName);
068: Iterator insts = instances.iterator();
069: while (insts.hasNext()) {
070: String instName = (String) insts.next();
071:
072: int index = instName.indexOf(".xml");
073: instName = instName.substring(0, index);
074:
075: System.out.println("Instance Name = " + instName);
076: ProjectHistoric ph = (ProjectHistoric) hs
077: .getHistoryInstance(instName);
078: System.out.println("Name = " + ph.getName());
079: System.out.println("Version = " + ph.getVersion());
080: System.out.println("Creation Date = "
081: + ph.getCreationDate());
082: System.out.println("End Date = " + ph.getEndDate());
083: System.out.println("Initiator = " + ph.getInitiator()
084: + "\n");
085:
086: // Getting instance properties
087: Collection properties = ph.getProperties();
088:
089: Iterator props = properties.iterator();
090: while (props.hasNext()) {
091: PropertyHistoric propH = (PropertyHistoric) props
092: .next();
093: System.out.println("Property Key = "
094: + propH.getKey());
095: System.out.println("Property Value = "
096: + propH.getValue() + "\n");
097: }
098:
099: // Getting instances activities
100: Collection nodes = ph.getNodes();
101:
102: Iterator nds = nodes.iterator();
103: while (nds.hasNext()) {
104: NodeHistoric nodeH = (NodeHistoric) nds.next();
105: System.out
106: .println("Node name = " + nodeH.getName());
107: System.out.println("Node Description = "
108: + nodeH.getDescription());
109: System.out.println("Node End date = "
110: + nodeH.getEndDate());
111: System.out.println("Node Start date = "
112: + nodeH.getStartDate() + "\n");
113: }
114: }
115:
116: }
117: pss.remove();
118: }
119: }
|