01: package client.Java_client;
02:
03: import javax.security.auth.login.LoginContext;
04: import hero.client.test.SimpleCallbackHandler;
05:
06: import hero.interfaces.*;
07:
08: import java.util.*;
09:
10: public class ApprovalIteratingWorkflow {
11:
12: static public void main(String[] args) throws Exception {
13:
14: char[] password = { 't', 'o', 't', 'o' };
15: SimpleCallbackHandler handler = new SimpleCallbackHandler(
16: "admin", password);
17: LoginContext lc = new LoginContext("TestClient", handler);
18: lc.login();
19:
20: ProjectSessionHome projectSessionh = ProjectSessionUtil
21: .getHome();
22: ProjectSession pss = projectSessionh.create();
23:
24: pss.initModel("Approval_iterating_workflow");
25:
26: // Set activities
27: pss.addNode("Request", Constants.Nd.AND_JOIN_NODE);
28: pss.addNode("Approval", Constants.Nd.AND_JOIN_NODE);
29: pss.addNode("Acceptance", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
30: pss.addNode("Reject", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
31: pss.setNodeTraditional("Request");
32: pss.setNodeTraditional("Approval");
33: pss.setNodeTraditional("Acceptance");
34: pss.setNodeTraditional("Reject");
35:
36: // Set node properties
37: pss.setNodeProperty("Request", "User_name", "", true);
38: pss.setNodeProperty("Request", "Phone_number", "", true);
39: pss.setNodeProperty("Request", "Email_address", "", true);
40:
41: Collection applications = new ArrayList();
42: applications.add("application1");
43: applications.add("application2");
44: applications.add("application3");
45: pss.setNodePropertyPossibleValues("Request",
46: "Available_applications", applications);
47: pss.setNodeProperty("Request", "Available_applications",
48: "application1");
49:
50: Collection possible_decision = new ArrayList();
51: possible_decision.add("change_request");
52: possible_decision.add("grant");
53: possible_decision.add("reject");
54: pss.setNodePropertyPossibleValues("Approval", "decision",
55: possible_decision);
56: pss.setNodeProperty("Approval", "decision", "change_request",
57: true);
58:
59: // Set transitions
60: pss.addEdge("Request", "Approval");
61: String approval_acceptance = pss.addEdge("Approval",
62: "Acceptance");
63: String approval_reject = pss.addEdge("Approval", "Reject");
64: pss.setEdgeCondition(approval_acceptance,
65: "decision.equals(\"grant\")");
66: pss.setEdgeCondition(approval_reject,
67: "decision.equals(\"reject\")");
68:
69: // Set iterations
70: pss.addIteration("Approval", "Request",
71: "decision.equals(\"change_request\")");
72:
73: // Set hooks
74: pss.addNodeHook("Acceptance", "hero.hook.MailAccept",
75: hero.interfaces.Constants.Nd.BEFORETERMINATE,
76: Constants.Hook.JAVA);
77: pss.addNodeHook("Reject", "hero.hook.MailReject",
78: hero.interfaces.Constants.Nd.BEFORETERMINATE,
79: Constants.Hook.JAVA);
80:
81: // Set activity roles
82: pss.addRole("Administrator", "The system administator role");
83: pss.setNodeRole("Request", "Administrator");
84: pss.setNodeRole("Approval", "Administrator");
85:
86: // Set role mapper
87: pss.addRoleMapper("Administrator", "AdministratorMapper",
88: Constants.Mapper.PROPERTIES);
89:
90: // Check the defition model
91: pss.checkModelDefinition();
92: }
93: }
|