001: package hero.client.samples;
002:
003: /*
004: *
005: * Inscription.java -
006: * Copyright (C) 2004 Ecoo Team
007: * Anne.Geron@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: import javax.security.auth.login.LoginContext;
026: import hero.client.test.SimpleCallbackHandler;
027:
028: import hero.interfaces.ProjectSessionHome;
029: import hero.interfaces.ProjectSession;
030: import hero.interfaces.ProjectSessionUtil;
031: import hero.interfaces.UserRegistration;
032: import hero.interfaces.UserRegistrationHome;
033: import hero.interfaces.UserRegistrationUtil;
034: import hero.interfaces.BnRoleLocal;
035:
036: import hero.interfaces.Constants;
037:
038: import java.util.*;
039:
040: public class SampleProjectApi {
041:
042: static public void main(String[] args) throws Exception {
043:
044: // User registration interface creation
045: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
046: UserRegistration userReg = urHome.create();
047:
048: try {
049: // User "jack" (customer) creation in Bonita database
050: userReg.userCreate("jack", "jack",
051: "miguel.valdes-faura@ext.bull.net");
052: // User "john" (service customer) creation in Bonita database
053: userReg.userCreate("john", "john",
054: "miguel.valdes-faura@ext.bull.net");
055: } catch (Exception e) {
056: } // Maybe user exists
057:
058: userReg.remove();
059:
060: // User Admin login
061: char[] password = { 't', 'o', 't', 'o' };
062: SimpleCallbackHandler handler = new SimpleCallbackHandler(
063: "admin", password);
064: LoginContext lc = new LoginContext("TestClient", handler);
065: lc.login();
066:
067: // Project Session Bean Creation using Remote Interface
068: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
069: .getHome();
070: ProjectSession prjSession = prjHome.create();
071:
072: //***************************************************************/
073: //************** API Documentation - Sample 1 *******************/
074: //************** Initiating ProjectSessionBean *****************/
075: //***************************************************************/
076:
077: //Process creation by user admin
078:
079: System.out.println("Original Process creation ");
080: prjSession.initModel("Original Process");
081: // if "Original Process" does not exists, it is created.
082: // Process definition : see following sections
083: // adding activities, edges, ...
084: //
085:
086: System.out
087: .println("Original Process cloning into Clone Process ");
088: try {
089: prjSession.initProject("Original Process", "Clone Process");
090: } catch (Exception e) {
091: System.out.println(e);
092: } //Maybe project does not exists
093:
094: System.out.println("Original Process : current Process");
095: prjSession.initModel("Original Process");
096:
097: /***************************************************************/
098: /************** API Documentation - Sample 2 *******************/
099: //************** Project properties *****************/
100: /***************************************************************/
101:
102: String processName = prjSession.getName();
103: System.out.println("Current Process : " + processName);
104:
105: try {
106: String parentName = prjSession.getParent();
107: System.out.println("Parent Process : " + parentName);
108: } catch (Exception e) {
109: System.out.println(e);
110: } //Maybe there is no parent
111:
112: try {
113: String creatorName = prjSession.getCreator();
114: System.out.println("Process Creator : " + creatorName);
115: } catch (Exception e) {
116: System.out.println(e);
117: } //Maybe there is a problem
118:
119: try {
120: prjSession.setProperty("userId", "user1");
121: prjSession.setProperty("recordId", "1111");
122: prjSession.setProperty("orderId", "0001");
123: } catch (Exception e) {
124: System.out.println(e);
125: } //Maybe there is a problem
126:
127: // First way to get properties values
128: System.out.println("First way to access proprerty values : ");
129:
130: Collection properties = prjSession.getProperties();
131: Iterator i = properties.iterator();
132: while (i.hasNext()) {
133: hero.interfaces.BnProjectPropertyValue property = (hero.interfaces.BnProjectPropertyValue) i
134: .next();
135: try {
136: String propertyKeyName = property.getTheKey();
137: String propertyValue = (String) property.getTheValue();
138: System.out.println("Property (Key, Value) : "
139: + propertyKeyName + "/" + propertyValue);
140: } catch (Exception e) {
141: System.out.println(e);
142: } //Maybe there is a problem
143: }
144:
145: // Second way to get properties values
146: System.out.println("Second way to access proprerty values : ");
147: properties = prjSession.getPropertiesKey();
148: i = properties.iterator();
149: while (i.hasNext()) {
150: String propertyKey = (String) i.next();
151: try {
152: hero.interfaces.BnProjectPropertyValue propertyValue = prjSession
153: .getProperty(propertyKey);
154: System.out.println("Property (Key, Value) : " + i + "/"
155: + propertyValue);
156: } catch (Exception e) {
157: System.out.println(e);
158: } //Maybe there is a problem
159: }
160:
161: //Deleting Property
162: try {
163: prjSession.deleteProperty("orderId");
164: } catch (Exception e) {
165: System.out.println(e);
166: } //Maybe there is a problem
167:
168: //Verification
169:
170: System.out.println("Properties after one deletion : ");
171: Collection propertiesLeft = prjSession.getPropertiesKey();
172: Iterator j = properties.iterator();
173: while (j.hasNext()) {
174: String propertyLeftKey = (String) j.next();
175: try {
176: hero.interfaces.BnProjectPropertyValue propertyValue = prjSession
177: .getProperty(propertyLeftKey);
178: System.out.println("Property (Key, Value) : " + i + "/"
179: + propertyValue);
180:
181: } catch (Exception e) {
182: System.out.println(e);
183: } //Maybe there is a problem
184: }
185:
186: /***************************************************************/
187: /************** API Documentation - Sample 3 *******************/
188: //************** Activities in Project *****************/
189: /***************************************************************/
190:
191: System.out.println("Activities creation ... ");
192: try {
193: prjSession
194: .addNode("Activity 1", Constants.Nd.AND_JOIN_NODE);
195: } catch (Exception e) {
196: System.out.println(" --> " + e);
197: } //Maybe something is wrong
198: try {
199: prjSession
200: .addNode("Activity 2", Constants.Nd.AND_JOIN_NODE);
201: } catch (Exception e) {
202: System.out.println(" --> " + e);
203: } //Maybe something is wrong
204: try {
205: prjSession
206: .addNode("Activity 3", Constants.Nd.AND_JOIN_NODE);
207: } catch (Exception e) {
208: System.out.println(" --> " + e);
209: } //Maybe something is wrong
210:
211: System.out.println("Activity 3 definition ... ");
212: try {
213: Date dateLim = new Date(2005, 05, 02);
214: prjSession.setNodeDeadline("Activity 3", dateLim.getTime());
215: prjSession.setNodeDescription("Activity 3",
216: "Activity 3 Description");
217: } catch (Exception e) {
218: System.out.println(" --> " + e);
219: } //Maybe something is wrong
220:
221: System.out.println("Setting Activities types");
222: try {
223: prjSession.setNodeTraditional("Activity 1");
224: prjSession.setNodeAutomatic("Activity 2");
225: prjSession.setNodeTraditional("Activity 3");
226: } catch (Exception e) {
227: System.out.println(" --> " + e);
228: } //Maybe something is wrong
229:
230: System.out
231: .println("Setting node properties which will not be propagated to other nodes");
232: try {
233: prjSession.setNodeProperty("Activity 1", "color", "blue",
234: false);
235: System.out
236: .println("Setting node properties which will be propagated to other nodes");
237: prjSession.setNodeProperty("Activity 1", "price",
238: "expensive", true);
239: prjSession.setNodeProperty("Activity 1", "shape", "square");
240: } catch (Exception e) {
241: System.out.println(" --> " + e);
242: } //Maybe something is wrong
243:
244: System.out.println("Adding edges between activities");
245: try {
246: prjSession.addEdge("Activity 1", "Activity 2");
247: prjSession.addEdge("Activity 2", "Activity 3");
248: } catch (Exception e) {
249: System.out.println(" --> " + e);
250: } //Maybe something is wrong
251:
252: System.out
253: .println("Getting names of all the nodes in the project");
254: Collection nodesNames = prjSession.getNodesNames();
255: j = nodesNames.iterator();
256: while (j.hasNext()) {
257: String nodeName = (String) j.next();
258: System.out.println("Node : " + nodeName
259: + " (anticipable : "
260: + prjSession.getNodeAnticipable(nodeName) + " )");
261: Collection nodeProperties = prjSession
262: .getNodeProperties(nodeName);
263: Iterator k = nodeProperties.iterator();
264: while (k.hasNext()) {
265: hero.interfaces.BnNodePropertyValue nodeProperty = (hero.interfaces.BnNodePropertyValue) k
266: .next();
267: try {
268: String nodePropertyKeyName = nodeProperty
269: .getTheKey();
270: String nodePropertyValue = nodeProperty
271: .getTheValue();
272: System.out.println(" --> Property (Key, Value) : "
273: + nodePropertyKeyName + "/"
274: + nodePropertyValue);
275: } catch (Exception e) {
276: System.out.println(" --> " + e);
277: } //Maybe something is wrong
278: }
279: }
280:
281: System.out.println("Node deletion");
282: try {
283: prjSession.deleteNode("Activity 3");
284: } catch (Exception e) {
285: System.out.println(" --> " + e);
286: } //Maybe something is wrong
287:
288: System.out.println("Node deletion verification");
289: try {
290: nodesNames = prjSession.getNodesNames();
291: j = nodesNames.iterator();
292: while (j.hasNext()) {
293: String nodeName = (String) j.next();
294: System.out.println("Node : " + nodeName);
295: }
296: } catch (Exception e) {
297: System.out.println(" --> " + e);
298: } //Maybe something is wrong
299:
300: System.out
301: .println("Adding a role in the project (before instantiation) ");
302: try {
303: prjSession.addRole("Customer", "customer");
304: } catch (Exception e) {
305: System.out.println(" --> " + e);
306: } //Maybe something is wrong
307:
308: System.out.println(" Getting role names of the project ");
309: try {
310: Collection rolesNames = prjSession.getRolesNames();
311: j = rolesNames.iterator();
312: while (j.hasNext()) {
313: String roleName = (String) j.next();
314: System.out.println("Role : " + roleName);
315: }
316: } catch (Exception e) {
317: System.out.println(" --> " + e);
318: } //Maybe something is wrong
319:
320: /***************************************************************/
321: /* "Original Process" instantiation */
322: /***************************************************************/
323: System.out.println("Creating project new intance");
324: try {
325: prjSession.instantiateProject("Original Process");
326: } catch (Exception e) {
327: System.out.println(" --> " + e);
328: } //Maybe project does not exists
329: // The new instance becomes the current project
330:
331: processName = prjSession.getName();
332: System.out.println("Current Process : " + processName);
333:
334: System.out.println(" Getting role names of the instance ");
335: try {
336: Collection rolesNames = prjSession.getRolesNames();
337: j = rolesNames.iterator();
338: while (j.hasNext()) {
339: String roleName = (String) j.next();
340: System.out.println("Role : " + roleName);
341: }
342: } catch (Exception e) {
343: System.out.println(" --> " + e);
344: } //Maybe something is wrong
345:
346: /***************************************************************/
347: /************** API Documentation - Sample 4 *******************/
348: //************** Users in Project *****************/
349: /***************************************************************/
350:
351: System.out.println(" Getting users names of the project ");
352: try {
353: Collection usersNames = prjSession.getUsers();
354: j = usersNames.iterator();
355: while (j.hasNext()) {
356: String userName = (String) j.next();
357: System.out.println("User : " + userName);
358: }
359: } catch (Exception e) {
360: System.out.println(" --> " + e);
361: } //Maybe something is wrong
362:
363: System.out.println(" Adding John in the project ");
364: try {
365: prjSession.addUser("john");
366: } catch (Exception e) {
367: System.out.println(" --> " + e);
368: } //Maybe something is wrong
369:
370: processName = prjSession.getName();
371: System.out.println(" --> Current Process : " + processName
372: + " contains john :" + prjSession.containsUser("john"));
373:
374: /***************************************************************/
375: /************** API Documentation - Sample 5 *******************/
376: //************** Roles in Project *****************/
377: /***************************************************************/
378:
379: System.out
380: .println("Adding a Custumer role for john in the current project ");
381: try {
382: prjSession.setUserRole("john", "Customer");
383: } catch (Exception e) {
384: System.out.println(" --> " + e);
385: } //Maybe something is wrong
386:
387: System.out.println(" Getting role names of the project ");
388: try {
389: Collection rolesNames = prjSession.getRolesNames();
390: j = rolesNames.iterator();
391: while (j.hasNext()) {
392: String roleName = (String) j.next();
393: System.out.println("Role : " + roleName);
394: }
395: } catch (Exception e) {
396: System.out.println(" --> " + e);
397: } //Maybe something is wrong
398:
399: System.out
400: .println(" Getting role names for john user in this project ");
401: try {
402: Collection johnRolesNames = prjSession.getRolesNames();
403: j = johnRolesNames.iterator();
404: while (j.hasNext()) {
405: String johnRoleName = (String) j.next();
406: System.out.println("John role : " + johnRoleName);
407: }
408: } catch (Exception e) {
409: System.out.println(" --> " + e);
410: } //Maybe something is wrong
411:
412: System.out
413: .println(" Setting role names for an activites of this project ");
414: try {
415: Collection prjNodesNames = prjSession.getNodesNames();
416: j = prjNodesNames.iterator();
417: while (j.hasNext()) {
418: String prjNodeName = (String) j.next();
419: System.out.println("Node --> " + prjNodeName);
420: System.out
421: .println(" --> Getting the actuel role names for Activities ");
422: try {
423: System.out.println(" Activity role : "
424: + prjSession.getNodeRoleName(prjNodeName));
425: } catch (Exception e) {
426: System.out.println(" --> " + e);
427: } //Maybe something is wrong
428:
429: System.out
430: .println(" --> Setting activities new roles ");
431: try {
432: prjSession.setNodeRole(prjNodeName, "admin");
433: // prjSession.setNodeRole("Activity 2","Customer") ;
434: } catch (Exception e) {
435: System.out.println(" --> " + e);
436: } //Maybe something is wrong
437:
438: System.out
439: .println(" --> Getting the new role names for Activities ");
440: try {
441: System.out.println(" Activity role : "
442: + prjSession.getNodeRoleName(prjNodeName));
443: } catch (Exception e) {
444: System.out.println(" --> " + e);
445: } //Maybe something is wrong
446:
447: }
448: } catch (Exception e) {
449: System.out.println(" --> " + e);
450: } //Maybe something is wrong
451:
452: } //End Main
453:
454: } // End SampleProjectApi Class
|