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: Sample1AdminWF.java,v 1.3 2005/03/18 14:50:41 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 Sample1AdminWF {
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: // User registration interface creation
058: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
059: UserRegistration userReg = urHome.create();
060:
061: // User "jack" (customer) creation in Bonita database
062: try {
063: userReg.userCreate("jack", "jack",
064: "miguel.valdes-faura@ext.bull.net");
065: } catch (Exception e) {
066: System.out.println(e);
067: } // Maybe user exists
068:
069: // User "john" (service customer) creation in Bonita database
070: try {
071: userReg.userCreate("john", "john",
072: "miguel.valdes-faura@ext.bull.net");
073: } catch (Exception e) {
074: System.out.println(e);
075: } // Maybe user exists
076:
077: userReg.remove();
078:
079: // Project Session interface instantiation (for admin user)
080: // And user registration in Order Processing Project instance
081: ProjectSessionHome prjSessionHome = ProjectSessionUtil
082: .getHome();
083: ProjectSession prjSession = prjSessionHome.create();
084:
085: try {
086: String instName = prjSession
087: .instantiateProject("Order Processing");
088: } catch (Exception e) {
089: System.out.println(e);
090: } // Maybe project does not exists
091:
092: // User Session interface instanciation (for admin user)
093: // and User registration in "Accept Order" Project instance
094: // For this we need to get the Accpet Order instance
095: UserSessionHome usHome = UserSessionUtil.getHome();
096: UserSession uSession = usHome.create();
097:
098: try {
099: Collection names = uSession
100: .getProjectInstancesNames("Order Processing");
101: Iterator i = names.iterator();
102: prjSession.initProject((String) i.next());
103:
104: // admin user adds "jack" (customer) and "john" (customer service) to this workflow instance
105: prjSession.addUser("jack");
106: prjSession.addUser("john");
107:
108: // admin user sets "customer" role to "miguel" for this instance
109: prjSession.setUserRole("jack", "customer");
110: // admin user sets "agent" role to "john" (Customer Service) for this instance
111: prjSession.setUserRole("john", "agent");
112:
113: //}
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117:
118: prjSession.remove();
119: }
120:
121: }
|