001: package hero.client.samples;
002:
003: /*
004: *
005: * Inscription.java -
006: * Copyright (C) 2004 Ecoo Team
007: * miguel.valdes-faura@ext.bull.net
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: /* This class implements the third part of the Business Process example described in the
026: * "BONITA workflow cooperative System Users's Guide
027: * jack : Custumer
028: * john : Custumer Service employee
029: */
030:
031: import javax.security.auth.login.LoginContext;
032: import hero.client.test.SimpleCallbackHandler;
033:
034: import hero.interfaces.ProjectSession;
035: import hero.interfaces.ProjectSessionHome;
036: import hero.interfaces.ProjectSessionUtil;
037:
038: import hero.interfaces.UserSession;
039: import hero.interfaces.UserSessionHome;
040: import hero.interfaces.UserSessionUtil;
041:
042: import hero.interfaces.UserRegistration;
043: import hero.interfaces.UserRegistrationHome;
044: import hero.interfaces.UserRegistrationUtil;
045:
046: import java.util.*;
047:
048: public class Sample1RunningSession {
049:
050: static public void main(String[] args) throws Exception {
051:
052: // jackOrderProcessing
053: // "jack" is logged
054: char[] passwordJack = { 'j', 'a', 'c', 'k' };
055: SimpleCallbackHandler handlerJack = new SimpleCallbackHandler(
056: "jack", passwordJack);
057: LoginContext lcJack = new LoginContext("TestClient",
058: handlerJack);
059: lcJack.login();
060:
061: // jack creates User Session Bean (Activity running)
062: UserSessionHome userHome = UserSessionUtil.getHome();
063: UserSession userSession = userHome.create();
064:
065: Collection names = userSession
066: .getProjectInstancesNames("Order Processing");
067: Iterator i = names.iterator();
068: String instNameOP = (String) i.next();
069:
070: // ProjectSessionBean needed (Activity properties setting )
071: ProjectSessionHome prjHome = ProjectSessionUtil.getHome();
072: ProjectSession prjSession = prjHome.create();
073:
074: System.out.println("SessionBean created");
075:
076: // Verifying roles
077: try {
078: prjSession.initProject(instNameOP);
079: } catch (Exception e) {
080: System.out.println("initProject : exception raised");
081: }
082:
083: try {
084: Collection roleNames = prjSession
085: .getUserRolesInProject("jack");
086: Iterator j = roleNames.iterator();
087: while (j.hasNext()) {
088: System.out.println("user jack : rôle : " + j.next());
089: }
090: } catch (Exception e) {
091: System.out
092: .println("getUserRolesInProject : exception raised : "
093: + e);
094: }
095:
096: // Activity to be started :
097: String activityName = "Receive Order";
098:
099: // etat de l'activité avant lancement
100: int state = 0;
101: try {
102: state = prjSession.getNodeState(activityName);
103: } catch (Exception e) {
104: System.out.println("getNodeState : exception raised");
105: }
106:
107: System.out.println("Verification : Node State : " + state);
108:
109: try {
110: userSession.startActivity(instNameOP, activityName);
111: System.out.println("(Jack) Activity started : "
112: + activityName);
113: } catch (Exception e) {
114: System.out.println("startActivity : exception raised : "
115: + e);
116: } // Maybe instance or activity does not exists
117:
118: try {
119: state = prjSession.getNodeState(activityName);
120: } catch (Exception e) {
121: System.out.println("getNodeState : exception raised");
122: }
123:
124: System.out.println("Verification : Node State : " + state);
125:
126: // Now He has to set the Order Data : setting the values for the properties associated to this activities
127: try {
128: prjSession.setNodeProperty(activityName, "customer_name",
129: "jack", true);
130: prjSession.setNodeProperty(activityName, "product_name",
131: "tv", true);
132: prjSession
133: .setNodeProperty(activityName, "items", "1", true);
134: } catch (Exception e) {
135: System.out.println("setNodeProperty : exception raised : "
136: + e);
137: } // maybe it raises some exception
138:
139: System.out.println("properties set");
140:
141: try {
142: Collection Properties = prjSession
143: .getNodeProperties(activityName);
144: Iterator k = Properties.iterator();
145: while (k.hasNext()) {
146: System.out.println("Activity " + activityName
147: + " property : " + k.next());
148: }
149: } catch (Exception e) {
150: System.out
151: .println("getNodeProperties : exception raised : "
152: + e);
153: }
154:
155: try {
156: userSession.terminateActivity(instNameOP, activityName);
157: System.out.println("(Jack) Activity terminated : "
158: + activityName);
159: } catch (Exception e) {
160: System.out
161: .println("terminateActivity : exception raised : "
162: + e);
163: } // Maybe instance or activity does not exists
164:
165: // johnStartAcceptOrder
166: // "john" is logged
167: char[] passwordJohn = { 'j', 'o', 'h', 'n' };
168: SimpleCallbackHandler handlerJohn = new SimpleCallbackHandler(
169: "john", passwordJohn);
170: LoginContext lcJohn = new LoginContext("TestClient",
171: handlerJohn);
172: lcJohn.login();
173:
174: names = userSession.getProjectInstancesNames("Accept Order");
175: i = names.iterator();
176: String instNameAO = (String) i.next();
177: ;
178:
179: // jackStartAskCustomer
180: // Jack context
181: lcJack.login();
182:
183: // Session bean already created
184: // Activity to be started :
185: activityName = "Ask Customer";
186:
187: try {
188: userSession.startActivity(instNameAO, activityName);
189: System.out.println("(Jack) Activity started : "
190: + activityName);
191: } catch (Exception e) {
192: System.out.println("startActivity : exception raised : "
193: + e);
194: } // Maybe instance or activity does not exists
195:
196: try {
197: userSession.terminateActivity(instNameAO, activityName);
198: System.out.println("(Jack) Activity terminated : "
199: + activityName);
200: } catch (Exception e) {
201: System.out
202: .println("terminateActivity : exception raised : "
203: + e);
204: } // Maybe instance or activity does not exists
205:
206: //johnTermAcceptOrder
207: // John context
208: lcJohn.login();
209:
210: // Session bean already created
211:
212: // John starts and terminates "Notify Sales"
213: activityName = "Notify Sales";
214: try {
215: userSession.startActivity(instNameAO, activityName);
216: System.out.println("(John) Activity started : "
217: + activityName);
218: } catch (Exception e) {
219: System.out.println("startActivity : exception raised : "
220: + e);
221: } // Maybe instance or activity does not exists
222:
223: try {
224: userSession.terminateActivity(instNameAO, activityName);
225: System.out.println("(John) Activity terminated : "
226: + activityName);
227: } catch (Exception e) {
228: System.out
229: .println("terminateActivity : exception raised : "
230: + e);
231: } // Maybe instance or activity does not exists
232:
233: System.out.println(" ");
234: System.out
235: .println(" ------------------------------------------");
236: System.out.println(" First Iteration terminated");
237: System.out
238: .println(" Play other iterations with Bonita manager tool (jack and john users)");
239: System.out
240: .println(" To stop : just use Bonita Web admin page (admin user) and ");
241: System.out
242: .println(" position the once_more property to KO for the Accept Order_Instance1 SUB PROJECT ");
243: System.out
244: .println("(and not activity) before terminating the Notify Sales activity ");
245: System.out
246: .println(" ------------------------------------------");
247:
248: }
249:
250: }
|