001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: Inscription.java,v 1.3 2004/11/10 17:10:50 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.samples;
029:
030: import javax.security.auth.login.LoginContext;
031: import hero.client.test.SimpleCallbackHandler;
032:
033: import hero.interfaces.ProjectSession;
034: import hero.interfaces.ProjectSessionHome;
035: import hero.interfaces.ProjectSessionUtil;
036:
037: import hero.interfaces.UserSession;
038: import hero.interfaces.UserSessionHome;
039: import hero.interfaces.UserSessionUtil;
040:
041: import hero.interfaces.UserRegistration;
042: import hero.interfaces.UserRegistrationHome;
043: import hero.interfaces.UserRegistrationUtil;
044:
045: import java.util.*;
046:
047: public class Inscription {
048:
049: static public void main(String[] args) throws Exception {
050: // Admin login
051: char[] password = { 't', 'o', 't', 'o' };
052: SimpleCallbackHandler handler = new SimpleCallbackHandler(
053: "admin", password);
054: LoginContext lc = new LoginContext("TestClient", handler);
055: lc.login();
056:
057: // Project Session interface instantiation (for admin user)
058: ProjectSessionHome lHome = ProjectSessionUtil.getHome();
059: ProjectSession lProject = lHome.create();
060: String instName = lProject.instantiateProject("e-citizen");
061:
062: // "user1" (e-citizen) creation in Bonita database
063: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
064: UserRegistration userReg = urHome.create();
065: try {
066: userReg.userCreate("user1", "user1",
067: "miguel.valdes-faura@ext.bull.net");
068: } catch (Exception e) {
069: } // Maybe user exists
070: userReg.remove();
071:
072: // "agent1" creation in Bonita database
073: urHome = UserRegistrationUtil.getHome();
074: userReg = urHome.create();
075: try {
076: userReg.userCreate("agent1", "agent1",
077: "miguel.valdes-faura@ext.bull.net");
078: } catch (Exception e) {
079: } // Maybe user exists
080: userReg.remove();
081:
082: // admin user adds "user1" (e-citizen) to this workflow instance
083: lProject.addUser("user1");
084: lProject.addUser("agent1");
085: // admin user adds "InitialRole" to "user1" (e-citizen) for this instance
086: lProject.setUserRole("user1", "InitialRole");
087: // admin user adds "agent" role to "agent1" (Agent) for this instance
088: lProject.setUserRole("agent1", "agent");
089: // admin user adds "user1" process properties
090: lProject.setProperty("userId", "user1");
091: lProject.setProperty("recordId", "1111");
092: lProject.setProperty("orderId", "0001");
093:
094: // "user1" is logged
095: char[] password2 = { 'u', 's', 'e', 'r', '1' };
096: handler = new SimpleCallbackHandler("user1", password2);
097: lc = new LoginContext("TestClient", handler);
098: lc.login();
099:
100: // user1 creates User Session Bean
101: UserSessionHome uHome = UserSessionUtil.getHome();
102: UserSession uSession = uHome.create();
103: Collection nodes = uSession.getToDoList(instName);
104: Iterator i = nodes.iterator();
105: while (i.hasNext()) {
106: String activityName = (String) i.next();
107: uSession.startActivity(instName, activityName);
108: System.out
109: .println("Start application activity... wait for termination");
110: uSession.terminateActivity(instName, activityName);
111: System.out.println("Terminate activity");
112: }
113:
114: // "agent1" is logged
115: char[] password3 = { 'a', 'g', 'e', 'n', 't', '1' };
116: handler = new SimpleCallbackHandler("agent1", password3);
117: lc = new LoginContext("TestClient", handler);
118: lc.login();
119:
120: // agent1 creates User Session Bean
121: uHome = UserSessionUtil.getHome();
122: UserSession aSession = uHome.create();
123: nodes = aSession.getToDoList(instName);
124: i = nodes.iterator();
125: while (i.hasNext()) {
126: String activityName = (String) i.next();
127: // The user data is not correct...
128: ProjectSessionHome lHomeAgent1 = ProjectSessionUtil
129: .getHome();
130: ProjectSession lProjectAgent1 = lHome.create();
131: lProjectAgent1.initProject(instName);
132:
133: lProjectAgent1.setNodeProperty(activityName, "correct",
134: "nok");
135: aSession.startActivity(instName, activityName);
136: System.out
137: .println("Start application activity... wait for termination");
138: aSession.terminateActivity(instName, activityName);
139: System.out.println("Terminate activity");
140: }
141: }
142: }
|