KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > UserSessionBean


1 package hero.session;
2 /*
3  * 01/02/2004 - 16:36:12
4  *
5  * UserSessionEJB.java -
6  * Copyright (C) 2004 Ecoo Team
7  * valdes@loria.fr
8  *
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */

24 import hero.interfaces.BnNodeLocal;
25 import hero.interfaces.BnNodeLocalHome;
26 import hero.interfaces.BnNodeUtil;
27 import hero.interfaces.BnNodeValue;
28 import hero.interfaces.BnProjectLocal;
29 import hero.interfaces.BnProjectLightValue;
30 import hero.interfaces.BnProjectLocalHome;
31 import hero.interfaces.BnProjectUtil;
32 import hero.interfaces.BnProjectValue;
33 import hero.interfaces.BnUserLightValue;
34 import hero.interfaces.BnUserLocal;
35 import hero.interfaces.BnUserLocalHome;
36 import hero.interfaces.BnUserPropertyLocal;
37 import hero.interfaces.BnUserPropertyLocalHome;
38 import hero.interfaces.BnUserPropertyUtil;
39 import hero.interfaces.BnUserValue;
40 import hero.interfaces.EngineLocal;
41 import hero.interfaces.EngineLocalHome;
42 import hero.interfaces.InvalidValueException;
43 import hero.interfaces.ProjectSessionLocal;
44 import hero.interfaces.ProjectSessionLocalHome;
45 import hero.interfaces.ProjectSessionUtil;
46 import hero.interfaces.JMSServicesSessionUtil;
47 import hero.interfaces.JMSServicesSessionLocalHome;
48 import hero.interfaces.JMSServicesSessionLocal;
49 import hero.interfaces.UserServiceLocal;
50 import hero.interfaces.UserServiceLocalHome;
51 import hero.util.BonitaConfig;
52 import hero.historic.BonitaTransfer;
53 import hero.util.EngineException;
54 import hero.util.HeroException;
55 import hero.util.EventConstants;
56 import hero.interfaces.Constants;
57
58 import java.util.ArrayList JavaDoc;
59 import java.util.Map JavaDoc;
60 import java.util.Arrays JavaDoc;
61 import java.util.Collection JavaDoc;
62 import java.util.Iterator JavaDoc;
63 import java.util.Hashtable JavaDoc;
64 import java.util.Enumeration JavaDoc;
65
66 import javax.ejb.CreateException JavaDoc;
67 import javax.ejb.EJBException JavaDoc;
68 import javax.ejb.FinderException JavaDoc;
69 import javax.ejb.RemoveException JavaDoc;
70 import javax.ejb.SessionBean JavaDoc;
71 import javax.ejb.SessionContext JavaDoc;
72
73 import org.apache.log4j.Logger;
74
75 /**
76  *
77  * The User Session Bean, is an stateful session bean that provides the user API to get information on
78  * Todo list and started activities and to produce events on activities (start, terminate, cancel).<br>
79  * This Session Bean is based on Engine Session Bean: a recursive implementation that manage the previous execution operations
80  * and propagates the activity state changes to the activities that are connected to this one.
81  *<br><br>
82  * The User Session Bean API provides information about user projects and activites (project list,
83  * todo list and activity list) and also useful information about project instances or user
84  * preferences. With this API users can performs his task/activities by using start, terminate and
85  * cancel methods and also terminates workflow processes.
86  * <br><br>
87  * <strong>The following lines shows a sample code to use this API in your application:<br><br></strong>
88  * <br>
89  * First of all you have to import the User Session files:<br>
90  * <br>
91  * import hero.interfaces.UserSessionLocalHome;<br>
92  * import hero.interfaces.UserSessionLocal;<br>
93  * import hero.interfaces.UserSessionHome;<br>
94  * import hero.interfaces.UserSession;<br>
95  * import hero.interfaces.UserSessionUtil;<br>
96  * <br>
97  * Now, it is time to create the User Session instance:<br>
98  * <br>
99  * Like this if you want to use local interfaces:<br><br>
100  * UserSessionLocalHome userh = (UserSessionLocalHome)hero.interfaces.UserSessionUtil.getLocalHome();<br>
101  * UserSessionLocal usersession = userh.create();<br>
102  * <br>
103  * or like this if you use remote interfaces:<br>
104  * <br>
105  * UserSessionHome userh = (UserSessionHome)hero.interfaces.UserSessionUtil.getHome();<br>
106  * UserSession usersession = userh.create();<br>
107  * <br>
108  * <br>
109  * Now you can call all User Sessions methods...
110  *
111  *
112  * @ejb:bean name="UserSession"
113  * display-name="UserSession Bean"
114  * type="Stateless"
115  * transaction-type="Container"
116  * jndi-name="ejb/hero/UserSession"
117  * local-jndi-name="ejb/hero/UserSession_L"
118  *
119  * @ejb:ejb-ref ejb-name="BnUser"
120  * ref-name="myhero/BnUser"
121  * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
122  *
123  *
124  * @jonas.bean
125  * ejb-name="UserSession"
126  * jndi-name="ejb/hero/UserSession"
127  *
128  *
129  *
130  * @copyright INRIA
131  * @author Miguel Valdes
132  **/

133
134 public class UserSessionBean implements SessionBean JavaDoc, EventConstants {
135     
136     // -------------------------------------------------------------------------
137
// Static
138
// -------------------------------------------------------------------------
139
// Utility variable
140
private static final Logger trace = Logger.getLogger(UserSessionBean.class);
141     
142     // -------------------------------------------------------------------------
143
// Members
144
// -------------------------------------------------------------------------
145

146     private SessionContext JavaDoc mContext;
147     private BonitaConfig bonitaConfig;
148     
149     // -------------------------------------------------------------------------
150
// Methods
151
// -------------------------------------------------------------------------
152

153     /**
154      * Get user project list. Workflow processes associated to this user (models/cooperative/instances)
155      * @return a Collection of BnProjectLightValue objects - the projects list of the user
156      * @throws HeroException
157      * @ejb:interface-method view-type="both"
158      * @ejb:transaction type="Supports"
159      *
160      **/

161     public Collection JavaDoc getProjectList() throws HeroException {
162         Collection JavaDoc pjts = new ArrayList JavaDoc();
163         Collection JavaDoc pva;
164         try{
165             this.synchronizeUser();
166             BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
167             BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
168             trace.info("start by " + mContext.getCallerPrincipal().getName());
169             BnUserValue uv = mUser.getBnUserValue();
170             pva = new ArrayList JavaDoc(Arrays.asList(uv.getBnProjects()));
171         } catch (javax.naming.NamingException JavaDoc ne) {
172             trace.error(ne.getMessage());
173             throw new HeroException(ne.getMessage());
174         } catch (javax.ejb.FinderException JavaDoc fe) {
175             trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
176             throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
177         }
178         return pva;
179     }
180     /**
181      * Get project list names for this user (models/cooperative/instances)
182      * @return a String Collection - the projects list names of the user
183      * @throws HeroException
184      * @ejb:interface-method view-type="both"
185      * @ejb:transaction type="Supports"
186      *
187      **/

188     public Collection JavaDoc getProjectListNames() throws HeroException {
189         trace.info("start by " + mContext.getCallerPrincipal().getName());
190         //Collection projects = null;
191
Collection JavaDoc projectsNames;
192         try{
193             this.synchronizeUser();
194             BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
195             BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
196             //projects = mUser.getBnProjects();
197
BnUserValue uv = mUser.getBnUserValue();
198             Collection JavaDoc pva = new ArrayList JavaDoc(Arrays.asList(uv.getBnProjects()));
199             projectsNames = new ArrayList JavaDoc();
200             Iterator JavaDoc i = pva.iterator();
201             while (i.hasNext())
202                 projectsNames.add(((hero.interfaces.BnProjectLightValue) i.next()).getName());
203         } catch (javax.naming.NamingException JavaDoc ne) {ne.printStackTrace();
204             trace.error(ne.getMessage());
205             throw new HeroException(ne.getMessage());
206         } catch (javax.ejb.FinderException JavaDoc fe) {fe.printStackTrace();
207             trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
208             throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
209         }
210         return projectsNames;
211     }
212     
213     /**
214      * Get user instances list. This method is equivalent to getProjectList but
215      * it only returns the current instances of the user.
216      * @return a Collection of BnProjectLightValue objects - the projects list of the user
217      * @throws HeroException
218      * @ejb:interface-method view-type="both"
219      * @ejb:transaction type="Supports"
220      *
221      **/

222     public Collection JavaDoc getInstancesList() throws HeroException {
223         trace.info("start by " + mContext.getCallerPrincipal().getName());
224         this.synchronizeUser();
225         Collection JavaDoc instances = new ArrayList JavaDoc();
226         Collection JavaDoc pva = this.getProjectList();
227         Iterator JavaDoc ps = pva.iterator();
228         
229         while (ps.hasNext())
230         {
231             BnProjectLightValue pro = (BnProjectLightValue)ps.next();
232             if (pro.getType().equals(Constants.Pj.INSTANCE))
233                 instances.add(pro);
234         }
235         return instances;
236     }
237     
238     /**
239      * Get user model list. This method is equivalent to getProjectList but
240      * it only returns the current models of the user.
241      * @return a Collection of BnProjectLightValue objects - the model list of the user
242      * @throws HeroException
243      * @ejb:interface-method view-type="both"
244      * @ejb:transaction type="Supports"
245      *
246      **/

247     public Collection JavaDoc getModelList() throws HeroException {
248         trace.info("start by " + mContext.getCallerPrincipal().getName());
249         this.synchronizeUser();
250         Collection JavaDoc models = new ArrayList JavaDoc();
251         Collection JavaDoc pva = this.getProjectList();
252         Iterator JavaDoc ps = pva.iterator();
253         
254         while (ps.hasNext())
255         {
256             BnProjectLightValue pro = (BnProjectLightValue)ps.next();
257             if (pro.getType().equals(Constants.Pj.MODEL))
258                 models.add(pro);
259         }
260         return models;
261     }
262     
263     /**
264      * Get available workflow models. This method will be improved with users restrictions
265      * @return a Collection of BnProjectLightValue objects - the model list to be instantiated
266      * @throws HeroException
267      * @ejb:interface-method view-type="both"
268      * @ejb:transaction type="Supports"
269      *
270      **/

271     public Collection JavaDoc getModels() throws HeroException {
272         trace.info("start by " + mContext.getCallerPrincipal().getName());
273         this.synchronizeUser();
274         BnProjectLocalHome projhome;
275         BnProjectLocal project;
276         Collection JavaDoc models = new ArrayList JavaDoc();
277         Collection JavaDoc pva = null;
278         try {
279             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
280         } catch (javax.naming.NamingException JavaDoc be) {
281             throw new HeroException(be.getMessage());
282         }
283         try {
284             pva = projhome.findModels(Constants.Pj.MODEL);
285         } catch (FinderException JavaDoc fe) {
286             throw new HeroException("Error in findByModels: "+fe.getMessage());
287         }
288         Iterator JavaDoc ps = pva.iterator();
289         while (ps.hasNext())
290         {
291             BnProjectLocal pro = (BnProjectLocal)ps.next();
292             models.add(pro.getBnProjectLightValue());
293         }
294         return models;
295     }
296     
297     /**
298      * Get user cooperative projects list. This method is equivalent to getProjectList but
299      * it only returns the current cooperative projects of the user.
300      * @return a Collection of BnProjectLightValue objects - the cooperative projects list of the user
301      * @throws HeroException
302      * @ejb:interface-method view-type="both"
303      * @ejb:transaction type="Supports"
304      *
305      **/

306     public Collection JavaDoc getCooperativeList() throws HeroException {
307         trace.info("start by " + mContext.getCallerPrincipal().getName());
308         this.synchronizeUser();
309         Collection JavaDoc coo = new ArrayList JavaDoc();
310         Collection JavaDoc pva = this.getProjectList();
311         Iterator JavaDoc ps = pva.iterator();
312         
313         while (ps.hasNext())
314         {
315             BnProjectLightValue pro = (BnProjectLightValue)ps.next();
316             if (pro.getType().equals(Constants.Pj.COOPERATIVE))
317                 coo.add(pro);
318         }
319         return coo;
320     }
321     
322     /**
323      * Get instances list names for this user. This method is equivalent to getProjectListNames but
324      * it only returns the current instances of the user.
325      * @return a String Collection - the projects list names of the user
326      * @throws HeroException
327      * @ejb:interface-method view-type="both"
328      * @ejb:transaction type="Supports"
329      *
330      **/

331     public Collection JavaDoc getInstancesListNames() throws HeroException {
332         trace.info("start by " + mContext.getCallerPrincipal().getName());
333         this.synchronizeUser();
334         Collection JavaDoc instances = new ArrayList JavaDoc();
335         Collection JavaDoc pva = this.getProjectList();
336         Iterator JavaDoc ps = pva.iterator();
337         while (ps.hasNext())
338         {
339             BnProjectLightValue pro = (BnProjectLightValue)ps.next();
340             if (pro.getName().matches(".*_instance.*"))
341                 instances.add(pro.getName());
342         }
343         return instances;
344     }
345     
346     /**
347      * Delete a Workflow project
348      * @param projectName the name of the project
349      * @throws HeroException
350      * @ejb:interface-method view-type="both"
351      * @ejb:transaction type="Required"
352      *
353      **/

354     public void removeProject(String JavaDoc projectName) throws HeroException {
355         if (this.getProjectConfigTrace(projectName))
356             trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName());
357         if (this.isAdmin(projectName))
358             this.deleteProject(projectName);
359         else
360             throw new HeroException("Error in delete project: only admin users are allowed to removed it !!");
361     }
362     
363     /**
364      * Obtain all user activities from specific project (ready and anticipable state)
365      * @param projectName the name of the project
366      * @return a String Collection - the list of todo activities of the user for a project
367      * @throws HeroException
368      * @ejb:interface-method view-type="both"
369      * @ejb:transaction type="Supports"
370      *
371      **/

372     public Collection JavaDoc getToDoList(String JavaDoc projectName) throws HeroException {
373         if (this.getProjectConfigTrace(projectName))
374             trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName());
375         BnProjectLocalHome projhome;
376         BnProjectLocal project;
377         BnNodeLocalHome nodehome;
378         Collection JavaDoc ready;
379         this.synchronizeUser();
380         try {
381             projhome = BnProjectUtil.getLocalHome();
382             nodehome = BnNodeUtil.getLocalHome();
383         } catch (javax.naming.NamingException JavaDoc ne) {
384             if (this.getProjectConfigTrace(projectName))
385                 trace.error(ne.getMessage());
386             throw new HeroException(ne.getMessage());
387         }
388         try {
389             project = projhome.findByName(projectName);
390         } catch (FinderException JavaDoc fe) {
391             if (this.getProjectConfigTrace(projectName))
392                 trace.error("BnProject " + projectName + " does not exists " + fe.getMessage());
393             throw new HeroException("BnProject " + projectName + " does not exists");
394         }
395         try {
396             ready = nodehome.findUserReady(project.getId(), mContext.getCallerPrincipal().getName());
397         } catch (FinderException JavaDoc fe) {
398             if (this.getProjectConfigTrace(projectName))
399                 trace.error(fe.getMessage());
400             ready = new ArrayList JavaDoc();
401         }
402         ArrayList JavaDoc result = new ArrayList JavaDoc();
403         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
404             BnNodeLocal nd = (BnNodeLocal) i.next();
405             if (this.getProjectConfigTrace(projectName))
406                 trace.info("NODE NAME=" + nd.getName());
407             result.add(nd.getName());
408         }
409         return result;
410     }
411     
412     /**
413      * Obtain all user activities from specific project (executing and anticipating state)
414      *
415      * @param projectName the name of the project
416      * @return a String Collectio - the list of active activities of the user for a project
417      * @throws HeroException
418      * @ejb:interface-method view-type="both"
419      * @ejb:transaction type="Supports"
420      *
421      **/

422     public Collection JavaDoc getActivityList(String JavaDoc projectName)
423     throws HeroException {
424         BnProjectLocalHome projhome;
425         BnProjectLocal project;
426         BnNodeLocalHome nodehome;
427         Collection JavaDoc executing;
428         this.synchronizeUser();
429         if (this.getProjectConfigTrace(projectName))
430             trace.info("parameter: -begin projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName());
431         try {
432             projhome = BnProjectUtil.getLocalHome();
433             nodehome = BnNodeUtil.getLocalHome();
434         } catch (javax.naming.NamingException JavaDoc ne) {
435             if (this.getProjectConfigTrace(projectName))
436                 trace.error(ne.getMessage());
437             throw new HeroException(ne.getMessage());
438         }
439         try {
440             project = projhome.findByName(projectName);
441         } catch (FinderException JavaDoc fe) {
442             if (this.getProjectConfigTrace(projectName))
443                 trace.error("BnProject " + projectName + " does not exists " + fe.getMessage());
444             throw new HeroException("BnProject " + projectName + " does not exists");
445         }
446         try {
447             executing =
448                 nodehome.findUserExecuting(project.getId(), mContext.getCallerPrincipal().getName());
449         } catch (FinderException JavaDoc fe) {
450             if (this.getProjectConfigTrace(projectName))
451                 trace.error(fe.getMessage());
452             executing = new ArrayList JavaDoc();
453         }
454         ArrayList JavaDoc result = new ArrayList JavaDoc();
455         for (Iterator JavaDoc i = executing.iterator(); i.hasNext();) {
456             BnNodeLocal nd = (BnNodeLocal) i.next();
457             result.add(nd.getName());
458         }
459         return result;
460     }
461     
462     /**
463      * Obtain todo user activities for all instances/cooperative projects (ready and anticipable state)
464      * @return a BnNodeValue Collection - the list of todo activities of the user for all instances
465      * @throws HeroException
466      * @ejb:interface-method view-type="both"
467      * @ejb:transaction type="Supports"
468      *
469      **/

470     public Collection JavaDoc getToDoListAllInstances() throws HeroException {
471         trace.info(" start by " + mContext.getCallerPrincipal().getName());
472         BnNodeLocalHome nodehome;
473         Collection JavaDoc ready;
474         this.synchronizeUser();
475         try {
476             nodehome = BnNodeUtil.getLocalHome();
477         } catch (javax.naming.NamingException JavaDoc ne) {
478             trace.error(ne.getMessage());
479             throw new HeroException(ne.getMessage());
480         }
481         try {
482             ready = nodehome.findUserReadyAllProjects(mContext.getCallerPrincipal().getName());
483         } catch (FinderException JavaDoc fe) {
484             trace.error(fe.getMessage());
485             ready = new ArrayList JavaDoc();
486         }
487         ArrayList JavaDoc result = new ArrayList JavaDoc();
488         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
489             BnNodeLocal nd = (BnNodeLocal) i.next();
490             if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE))
491                 result.add(nd.getBnNodeValue());
492         }
493         return result;
494     }
495     
496     /**
497      * Obtain executing user activities for all instances/cooperative projects (executing and anticipating state)
498      * @return a BnNodeValue Collection - the list of executing activities ot the user for all instances
499      * @throws HeroException
500      * @ejb:interface-method view-type="both"
501      * @ejb:transaction type="Supports"
502      *
503      **/

504     public Collection JavaDoc getActivityListAllInstances() throws HeroException {
505         trace.info(" start by " + mContext.getCallerPrincipal().getName());
506         BnNodeLocalHome nodehome;
507         Collection JavaDoc executing;
508         this.synchronizeUser();
509         try {
510             nodehome = BnNodeUtil.getLocalHome();
511         } catch (javax.naming.NamingException JavaDoc ne) {
512             trace.error(ne.getMessage());
513             throw new HeroException(ne.getMessage());
514         }
515         try {
516             executing = nodehome.findUserExecutingAllProjects(mContext.getCallerPrincipal().getName());
517         } catch (FinderException JavaDoc fe) {
518             trace.error(fe.getMessage());
519             executing = new ArrayList JavaDoc();
520         }
521         ArrayList JavaDoc result = new ArrayList JavaDoc();
522         for (Iterator JavaDoc i = executing.iterator(); i.hasNext();) {
523             BnNodeLocal nd = (BnNodeLocal) i.next();
524             if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE))
525                 result.add(nd.getBnNodeValue());
526         }
527         return result;
528     }
529     
530     /**
531      * Obtain terminated user activities for all instances/cooperative projects.
532      * @return a BnNodeValue Collection - the list of terminated activities ot the user for all instances
533      * @throws HeroException
534      * @ejb:interface-method view-type="both"
535      * @ejb:transaction type="Supports"
536      *
537      **/

538     public Collection JavaDoc getTerminatedListAllInstances() throws HeroException {
539         trace.info(" start by " + mContext.getCallerPrincipal().getName());
540         BnNodeLocalHome nodehome;
541         Collection JavaDoc executing;
542         this.synchronizeUser();
543         try {
544             nodehome = BnNodeUtil.getLocalHome();
545         } catch (javax.naming.NamingException JavaDoc ne) {
546             trace.error(ne.getMessage());
547             throw new HeroException(ne.getMessage());
548         }
549         try {
550             executing = nodehome.findUserTerminatedAllProjects(mContext.getCallerPrincipal().getName());
551         } catch (FinderException JavaDoc fe) {
552             trace.error(fe.getMessage());
553             executing = new ArrayList JavaDoc();
554         }
555         ArrayList JavaDoc result = new ArrayList JavaDoc();
556         for (Iterator JavaDoc i = executing.iterator(); i.hasNext();) {
557             BnNodeLocal nd = (BnNodeLocal) i.next();
558             if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE))
559                 result.add(nd.getBnNodeValue());
560         }
561         return result;
562     }
563     
564     
565     /**
566      * Obtain todo user activities matching with project property value (ready and anticipable state activities)
567      * @return a BnNodeValue Collection - the list of todo activities matching to project property value
568      * @param key the key of the property
569      * @param value the value of the property
570      *
571      * @throws HeroException
572      * @ejb:interface-method view-type="both"
573      * @ejb:transaction type="Supports"
574      *
575      **/

576     public Collection JavaDoc getToDoListByProperty(String JavaDoc key, String JavaDoc value) throws HeroException {
577         trace.info(" start by " + mContext.getCallerPrincipal().getName());
578         BnNodeLocalHome nodehome;
579         Collection JavaDoc ready;
580         this.synchronizeUser();
581         try {
582             nodehome = BnNodeUtil.getLocalHome();
583         } catch (javax.naming.NamingException JavaDoc ne) {
584             trace.error(ne.getMessage());
585             throw new HeroException(ne.getMessage());
586         }
587         try {
588             ready = nodehome.findUserReadyAllProjectsByProperty(mContext.getCallerPrincipal().getName(),key,value);
589         } catch (FinderException JavaDoc fe) {
590             trace.error(fe.getMessage());
591             ready = new ArrayList JavaDoc();
592         }
593         ArrayList JavaDoc result = new ArrayList JavaDoc();
594         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
595             BnNodeLocal nd = (BnNodeLocal) i.next();
596             if (nd.getBnProject().getName().matches(".*_instance.*"))
597                 result.add(nd.getBnNodeValue());
598         }
599         return result;
600     }
601     
602     /**
603      * Obtain todo user activities matching with project properties (ready and anticipable state activities)
604      * @return a BnNodeValue Collection - the list of todo activities matching to property value. This method
605      * is oriented to administrative workflow (workflow instances) and supports one, two or three properties (key/value pairs).
606      * Operation constants values: hero.interfaces.Constants.AND, hero.interfaces.Constants.OR
607      *
608      * @param operation AND/OR operations are allowed.
609      * @param properties Hashtable containing the key/value elements
610      *
611      * @throws HeroException
612      * @ejb:interface-method view-type="both"
613      * @ejb:transaction type="Supports"
614      *
615      **/

616     public Collection JavaDoc getToDoListByProperties(int operation, Hashtable JavaDoc properties) throws HeroException {
617         trace.info(" start by " + mContext.getCallerPrincipal().getName());
618         BnNodeLocalHome nodehome;
619         Collection JavaDoc ready = new ArrayList JavaDoc();
620         this.synchronizeUser();
621         try {
622             nodehome = BnNodeUtil.getLocalHome();
623         } catch (javax.naming.NamingException JavaDoc ne) {
624             trace.error(ne.getMessage());
625             throw new HeroException(ne.getMessage());
626         }
627         try {
628             Enumeration JavaDoc keys = properties.keys();
629             Collection JavaDoc vls = properties.values();
630             Iterator JavaDoc values = vls.iterator();
631             if (properties.size() >3)
632             {
633                 throw new HeroException("This method uses EJBQL language to improve queries. These queries are based " +
634                 "on static parameters numbers, so if you want use this method with more than three properties contact us !!");
635             }
636             if (properties.size() == 1)
637                 ready = nodehome.findUserReadyAllProjectsByProperty(mContext.getCallerPrincipal().getName(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next());
638             if (operation == Constants.AND)
639             {
640                 if (properties.size() == 2)
641                     ready = nodehome.findUserReadyAllProjectsByTwoPropertiesAND(mContext.getCallerPrincipal().getName(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next());
642                 else if (properties.size() == 3)
643                     ready = nodehome.findUserReadyAllProjectsByThreePropertiesAND(mContext.getCallerPrincipal().getName(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next());
644             }
645             else if (operation == Constants.OR)
646             {
647                 if (properties.size() == 2)
648                     ready = nodehome.findUserReadyAllProjectsByTwoPropertiesOR(mContext.getCallerPrincipal().getName(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next());
649                 else if (properties.size() == 3)
650                     ready = nodehome.findUserReadyAllProjectsByThreePropertiesOR(mContext.getCallerPrincipal().getName(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next(),(String JavaDoc)keys.nextElement(),(String JavaDoc)values.next());
651             }
652         } catch (FinderException JavaDoc fe) {
653             trace.error(fe.getMessage());
654             ready = new ArrayList JavaDoc();
655         }
656         ArrayList JavaDoc result = new ArrayList JavaDoc();
657         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
658             BnNodeLocal nd = (BnNodeLocal) i.next();
659             if (nd.getBnProject().getName().matches(".*_instance.*"))
660                 result.add(nd.getBnNodeValue());
661         }
662         return result;
663     }
664     
665     /**
666      * Obtain todo user activities matching with activity property value (ready and anticipable state activities)
667      * @return a BnNodeValue Collection - the list of todo activities matching to activity property value
668      * @param key the key of the property
669      * @param value the value of the property
670      *
671      * @throws HeroException
672      * @ejb:interface-method view-type="both"
673      * @ejb:transaction type="Supports"
674      *
675      **/

676     public Collection JavaDoc getToDoListByActivityProperty(String JavaDoc key, String JavaDoc value) throws HeroException {
677         trace.info(" start by " + mContext.getCallerPrincipal().getName());
678         BnNodeLocalHome nodehome;
679         Collection JavaDoc ready;
680         this.synchronizeUser();
681         try {
682             nodehome = BnNodeUtil.getLocalHome();
683         } catch (javax.naming.NamingException JavaDoc ne) {
684             trace.error(ne.getMessage());
685             throw new HeroException(ne.getMessage());
686         }
687         try {
688             ready = nodehome.findUserReadyAllActivitiesByProperty(mContext.getCallerPrincipal().getName(),key,value);
689         } catch (FinderException JavaDoc fe) {
690             trace.error(fe.getMessage());
691             ready = new ArrayList JavaDoc();
692         }
693         ArrayList JavaDoc result = new ArrayList JavaDoc();
694         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
695             BnNodeLocal nd = (BnNodeLocal) i.next();
696             if (nd.getBnProject().getName().matches(".*_instance.*"))
697                 result.add(nd.getBnNodeValue());
698         }
699         return result;
700     }
701     
702     /**
703      * Obtain executing user activities matching with property value (executing and anticipating state activities)
704      * @return a BnNodeValue Collection - the list of executing activities matching to property value
705      * @param key the key of the property
706      * @param value the value of the property
707      *
708      * @throws HeroException
709      * @ejb:interface-method view-type="both"
710      * @ejb:transaction type="Supports"
711      *
712      **/

713     public Collection JavaDoc getActivityListByProperty(String JavaDoc key, String JavaDoc value) throws HeroException {
714         trace.info(" start by " + mContext.getCallerPrincipal().getName());
715         BnNodeLocalHome nodehome;
716         Collection JavaDoc executing;
717         this.synchronizeUser();
718         try {
719             nodehome = BnNodeUtil.getLocalHome();
720         } catch (javax.naming.NamingException JavaDoc ne) {
721             trace.error(ne.getMessage());
722             throw new HeroException(ne.getMessage());
723         }
724         try {
725             executing = nodehome.findUserExecutingAllProjectsByProperty(mContext.getCallerPrincipal().getName(),key,value);
726         } catch (FinderException JavaDoc fe) {
727             trace.error(fe.getMessage());
728             executing = new ArrayList JavaDoc();
729         }
730         ArrayList JavaDoc result = new ArrayList JavaDoc();
731         for (Iterator JavaDoc i = executing.iterator(); i.hasNext();) {
732             BnNodeLocal nd = (BnNodeLocal) i.next();
733             if (nd.getBnProject().getName().matches(".*_instance.*"))
734                 result.add(nd.getBnNodeValue());
735         }
736         return result;
737     }
738     /**
739      * Get workflow instances names of this project
740      *
741      * @param projectName the name of the project
742      * @return a String Collection - the names of project instances
743      * @throws HeroException
744      * @ejb:interface-method view-type="both"
745      * @ejb:transaction type="Supports"
746      *
747      **/

748     public Collection JavaDoc getProjectInstancesNames(String JavaDoc projectName)
749     throws HeroException {
750         if (this.getProjectConfigTrace(projectName))
751             trace.info("parameter: projectName = "+ projectName+ " start by "+ mContext.getCallerPrincipal().getName());
752         ArrayList JavaDoc result = new ArrayList JavaDoc();
753         BnProjectLocalHome projhome;
754         this.synchronizeUser();
755         try {
756             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
757             
758             Collection JavaDoc instances =projhome.findUserInstancesByProject(projectName+"_instance%",this.getUser());
759             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
760                 BnProjectLocal pl = (BnProjectLocal) i.next();
761                 if (!pl.getName().equals(projectName))
762                     result.add(pl.getName());
763             }
764             return (result);
765         } catch (javax.naming.NamingException JavaDoc ne) {
766             if (this.getProjectConfigTrace(projectName))
767                 trace.error(ne.getMessage());
768             throw new HeroException(ne.getMessage());
769         } catch (javax.ejb.FinderException JavaDoc fe) {
770             if (this.getProjectConfigTrace(projectName))
771                 trace.error(fe.getMessage());
772             throw new HeroException(fe.getMessage());
773         }
774     }
775     /**
776      * Get Workflow instances of this project
777      *
778      * @return a BnProjectValue Collection - list of project instances
779      * @param projectName the name of the project
780      * @ejb:interface-method view-type="both"
781      * @ejb:transaction type="Supports"
782      *
783      **/

784     public Collection JavaDoc getProjectInstances(String JavaDoc projectName) throws HeroException {
785         if (this.getProjectConfigTrace(projectName))
786             trace.info("parameter: projectName = "+projectName + " start by " + mContext.getCallerPrincipal().getName());
787         ArrayList JavaDoc result = new ArrayList JavaDoc();
788         BnProjectLocalHome projhome;
789         this.synchronizeUser();
790         try {
791             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
792             Collection JavaDoc instances = projhome.findUserInstancesByProject(projectName+"_instance%",this.getUser());
793             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
794                 BnProjectLocal pl = (BnProjectLocal) i.next();
795                 if (!pl.getName().equals(projectName))
796                     result.add(pl.getBnProjectValue());
797             }
798             return (result);
799         } catch (javax.naming.NamingException JavaDoc ne) {
800             if (this.getProjectConfigTrace(projectName))
801                 trace.error(ne.getMessage());
802             throw new HeroException(ne.getMessage());
803         } catch (javax.ejb.FinderException JavaDoc fe) {
804             if (this.getProjectConfigTrace(projectName))
805                 trace.error(fe.getMessage());
806             throw new HeroException(fe.getMessage());
807         }
808     }
809     
810     /**
811      * Get Workflow instances from a property
812      *
813      * @return a BnProjectValue Collection - list of project instances
814      * @param projectName the name of the project
815      * @ejb:interface-method view-type="both"
816      * @ejb:transaction type="Supports"
817      *
818      **/

819     
820     public Collection JavaDoc getInstancesByProperty(String JavaDoc key, String JavaDoc value)
821     throws HeroException {
822         trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName());
823         ArrayList JavaDoc result = new ArrayList JavaDoc();
824         BnProjectLocalHome projhome;
825         this.synchronizeUser();
826         try {
827             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
828             Collection JavaDoc instances = projhome.findProjectsByProperty(key, value);
829             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
830                 BnProjectLocal pl = (BnProjectLocal) i.next();
831                 if (pl.getName().matches(".*_instance.*"))
832                     result.add(pl.getBnProjectValue());
833             }
834             return (result);
835         } catch (javax.naming.NamingException JavaDoc ne) {
836             trace.error(ne.getMessage());
837             throw new HeroException(ne.getMessage());
838         } catch (javax.ejb.FinderException JavaDoc fe) {
839             trace.error(fe.getMessage());
840             throw new HeroException(fe.getMessage());
841         }
842     }
843     
844     /**
845      * Get Workflow instances from a property
846      *
847      * @return a String Collection - list of project instances
848      * @param projectName the name of the project
849      * @ejb:interface-method view-type="both"
850      * @ejb:transaction type="Supports"
851      *
852      **/

853     
854     public Collection JavaDoc getInstancesByPropertyNames(String JavaDoc key, String JavaDoc value)
855     throws HeroException {
856         trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName());
857         ArrayList JavaDoc result = new ArrayList JavaDoc();
858         BnProjectLocalHome projhome;
859         this.synchronizeUser();
860         try {
861             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
862             Collection JavaDoc instances = projhome.findProjectsByProperty(key, value);
863             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
864                 BnProjectLocal pl = (BnProjectLocal) i.next();
865                 if (pl.getName().matches(".*_instance.*"))
866                     result.add(pl.getName());
867                 
868             }
869             return (result);
870         } catch (javax.naming.NamingException JavaDoc ne) {
871             trace.error(ne.getMessage());
872             throw new HeroException(ne.getMessage());
873         } catch (javax.ejb.FinderException JavaDoc fe) {
874             trace.error(fe.getMessage());
875             throw new HeroException(fe.getMessage());
876         }
877     }
878     
879     /**
880      * Get Workflow projects from a property
881      *
882      * @return a BnProjectValue Collection - list of projects
883      * @param projectName the name of the project
884      * @ejb:interface-method view-type="both"
885      * @ejb:transaction type="Supports"
886      *
887      **/

888     
889     public Collection JavaDoc getProjectsByProperty(String JavaDoc key, String JavaDoc value)
890     throws HeroException {
891         trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName());
892         ArrayList JavaDoc result = new ArrayList JavaDoc();
893         BnProjectLocalHome projhome;
894         this.synchronizeUser();
895         try {
896             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
897             Collection JavaDoc instances = projhome.findProjectsByProperty(key, value);
898             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
899                 BnProjectLocal pl = (BnProjectLocal) i.next();
900                 if (!pl.getName().matches(".*_instance.*"))
901                     result.add(pl.getBnProjectValue());
902             }
903             return (result);
904         } catch (javax.naming.NamingException JavaDoc ne) {
905             trace.error(ne.getMessage());
906             throw new HeroException(ne.getMessage());
907         } catch (javax.ejb.FinderException JavaDoc fe) {
908             trace.error(fe.getMessage());
909             throw new HeroException(fe.getMessage());
910         }
911     }
912     
913     /**
914      * Get Workflow projects from a property
915      *
916      * @return a String Collection - list of project names
917      * @param projectName the name of the project
918      * @ejb:interface-method view-type="both"
919      * @ejb:transaction type="Supports"
920      *
921      **/

922     
923     public Collection JavaDoc getProjectsByPropertyNames(String JavaDoc key, String JavaDoc value)
924     throws HeroException {
925         trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName());
926         ArrayList JavaDoc result = new ArrayList JavaDoc();
927         BnProjectLocalHome projhome;
928         this.synchronizeUser();
929         try {
930             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
931             Collection JavaDoc instances = projhome.findProjectsByProperty(key, value);
932             for (Iterator JavaDoc i = instances.iterator(); i.hasNext();) {
933                 BnProjectLocal pl = (BnProjectLocal) i.next();
934                 if (!pl.getName().matches(".*_instance.*"))
935                     result.add(pl.getName());
936                 
937             }
938             return (result);
939         } catch (javax.naming.NamingException JavaDoc ne) {
940             trace.error(ne.getMessage());
941             throw new HeroException(ne.getMessage());
942         } catch (javax.ejb.FinderException JavaDoc fe) {
943             trace.error(fe.getMessage());
944             throw new HeroException(fe.getMessage());
945         }
946     }
947     
948     /**
949      * Tries to start an activity (when activity state is ready or anticipable)
950      * @param projectName the name of the project
951      * @param nodeName the name of the node
952      * @ejb:interface-method view-type="both"
953      * @ejb:transaction type="Required"
954      *
955      **/

956     
957     public void startActivity(String JavaDoc projectName, String JavaDoc nodeName)
958     throws HeroException {
959         if (this.getProjectConfigTrace(projectName))
960             trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName());
961         EngineLocalHome enghome;
962         this.synchronizeUser();
963         try {
964             enghome = hero.interfaces.EngineUtil.getLocalHome();
965             EngineLocal engine = enghome.create();
966             engine.startActivity(projectName, nodeName);
967             engine.remove();
968         } catch (javax.naming.NamingException JavaDoc ne) {
969             if (this.getProjectConfigTrace(projectName))
970                 trace.error(ne.getMessage());
971             throw new HeroException(ne.getMessage());
972         } catch (RemoveException JavaDoc r) {
973             if (this.getProjectConfigTrace(projectName))
974                 trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage());
975             throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage());
976         } catch (CreateException JavaDoc c) {
977             if (this.getProjectConfigTrace(projectName))
978                 trace.error("Cannot create Engine bean for "+ projectName+ " " + c.getMessage());
979             throw new HeroException("Cannot create Engine bean for "+ projectName+ " "+ c.getMessage());
980         }
981     }
982     
983     /**
984      * Tries to terminate an activity (when activity state is executing or anticipating)
985      * @param projectName the name of the project
986      * @param nodeName the name of the node
987      * @ejb:interface-method view-type="both"
988      * @ejb:transaction type="Required"
989      **/

990     public void terminateActivity(String JavaDoc projectName, String JavaDoc nodeName)
991     throws HeroException {
992         if (this.getProjectConfigTrace(projectName))
993             trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName());
994         EngineLocalHome enghome;
995         this.synchronizeUser();
996         try {
997             enghome = hero.interfaces.EngineUtil.getLocalHome();
998             EngineLocal engine = enghome.create();
999             engine.terminateActivity(projectName, nodeName);
1000            engine.remove();
1001        } catch (RemoveException JavaDoc r) {
1002            if (this.getProjectConfigTrace(projectName))
1003                trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage());
1004            throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage());
1005        } catch (javax.naming.NamingException JavaDoc ne) {
1006            if (this.getProjectConfigTrace(projectName))
1007                trace.error(ne.getMessage());
1008            throw new HeroException(ne.getMessage());
1009        } catch (CreateException JavaDoc c) {
1010            if (this.getProjectConfigTrace(projectName))
1011                trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage());
1012            throw new HeroException("Cannot create Engine bean for " + projectName);
1013        }
1014    }
1015    
1016    /**
1017     * Tries to cancel an activity (when activity is executing or anticipating)
1018     * @param projectName the name of the project
1019     * @param nodeName the name of the node
1020     * @ejb:interface-method view-type="both"
1021     * @ejb:transaction type="Required"
1022     **/

1023    public void cancelActivity(String JavaDoc projectName, String JavaDoc nodeName)
1024    throws HeroException {
1025        if (this.getProjectConfigTrace(projectName))
1026            trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName());
1027        EngineLocalHome enghome;
1028        this.synchronizeUser();
1029        try {
1030            enghome = hero.interfaces.EngineUtil.getLocalHome();
1031            EngineLocal engine = enghome.create();
1032            engine.cancelActivity(projectName, nodeName);
1033            engine.remove();
1034        } catch (RemoveException JavaDoc r) {
1035            if (this.getProjectConfigTrace(projectName))
1036                trace.error("Cannot remove Engine bean for "+ projectName + " " + r.getMessage());
1037            throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage());
1038        } catch (javax.naming.NamingException JavaDoc ne) {
1039            if (this.getProjectConfigTrace(projectName))
1040                trace.error(ne.getMessage());
1041            throw new HeroException(ne.getMessage());
1042        } catch (CreateException JavaDoc c) {
1043            if (this.getProjectConfigTrace(projectName))
1044                trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage());
1045            throw new EJBException JavaDoc("Cannot create Engine bean for " + projectName);
1046        }
1047    }
1048    /**
1049     * Tries to terminate a project (only when all project activities are terminated)
1050     * @param projectName the name of the project
1051     * @throws HeroException
1052     * @ejb:interface-method view-type="both"
1053     * @ejb:transaction type="Required"
1054     **/

1055    public void terminate(String JavaDoc projectName) throws HeroException {
1056        if (this.getProjectConfigTrace(projectName))
1057            trace.info("parameter; projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName());
1058        EngineLocalHome enghome;
1059        this.synchronizeUser();
1060        try {
1061            enghome = hero.interfaces.EngineUtil.getLocalHome();
1062            EngineLocal engine = enghome.create();
1063            engine.terminate(projectName);
1064            engine.remove();
1065            if (this.getProjectConfigHistoric(projectName).equals(Constants.TRANSFER))
1066                BonitaTransfer.TransferFile(projectName);
1067            deleteProject(projectName);
1068        } catch (RemoveException JavaDoc r) {
1069            if (this.getProjectConfigTrace(projectName))
1070                trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage());
1071            throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage());
1072        } catch (javax.naming.NamingException JavaDoc ne) {
1073            if (this.getProjectConfigTrace(projectName))
1074                trace.error(ne.getMessage());
1075            throw new HeroException(ne.getMessage());
1076        } catch (CreateException JavaDoc c) {
1077            if (this.getProjectConfigTrace(projectName))
1078                trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage());
1079            throw new EJBException JavaDoc("Cannot create Engine bean for " + projectName);
1080        } catch (EngineException e) {
1081            if (this.getProjectConfigTrace(projectName))
1082                trace.error("Cannot terminate project " + e.getMessage());
1083            throw new HeroException("Cannot terminate project " + e.getMessage());
1084        }
1085    }
1086    
1087    /**
1088     * Get Node Value from a specific project
1089     * @return a NodeValue object - get node information
1090     * @param projectName the name of the project
1091     * @param nodeName the name of the node
1092     * @ejb:interface-method view-type="both"
1093     * @ejb:transaction type="Supports"
1094     **/

1095    public BnNodeValue getNode(String JavaDoc projectName, String JavaDoc nodeName)
1096    throws HeroException {
1097        if (this.getProjectConfigTrace(projectName))
1098            trace.info("parameters: projectName=" + projectName + " nodeName=" + nodeName + "start by " + mContext.getCallerPrincipal().getName());
1099        this.synchronizeUser();
1100        try {
1101            ProjectSessionLocalHome projectseshome =ProjectSessionUtil.getLocalHome();
1102            ProjectSessionLocal project = projectseshome.create();
1103            project.initProject(projectName);
1104            return project.getNodeValue(nodeName);
1105        } catch (CreateException JavaDoc f) {
1106            if (this.getProjectConfigTrace(projectName))
1107                trace.error("Project does not exists " + projectName + " " + f.getMessage());
1108            throw new HeroException("Project does not exists " + projectName);
1109        } catch (javax.naming.NamingException JavaDoc r) {
1110            if (this.getProjectConfigTrace(projectName))
1111                trace.error("Cannot access to project " + r.getMessage());
1112            throw new HeroException("Cannot access to project " + r.getMessage());
1113        }
1114    }
1115    
1116    /**
1117     * Get the user name
1118     *
1119     * @return a String - get user name
1120     * @ejb:interface-method view-type="both"
1121     * @ejb:transaction type="Supports"
1122     **/

1123    public String JavaDoc getUser() {
1124        trace.info("start by " + mContext.getCallerPrincipal().getName());
1125        return mContext.getCallerPrincipal().getName();
1126    }
1127    
1128    /**
1129     * Get the user light value
1130     *
1131     * @return a BnUserLightValue object - get user information
1132     * @ejb:interface-method view-type="both"
1133     * @ejb:transaction type="Supports"
1134     **/

1135    public BnUserLightValue getUserLightValue() throws HeroException{
1136        try{
1137            trace.info("start by " + mContext.getCallerPrincipal().getName());
1138            this.synchronizeUser();
1139            BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
1140            BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
1141            BnUserLightValue ulv= mUser.getBnUserLightValue();
1142            UserServiceLocalHome ushome = null;
1143            try {
1144                ushome = hero.interfaces.UserServiceUtil.getLocalHome();
1145                UserServiceLocal ul = ushome.create();
1146                Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
1147                ulv.setEmail((String JavaDoc)infos.get("email"));
1148                ulv.setPassword((String JavaDoc)infos.get("password"));
1149                ulv.setJabber((String JavaDoc)infos.get("jabber"));
1150                return ulv;
1151            } catch (Exception JavaDoc ce) {
1152                trace.error(ce.getMessage());
1153                throw new HeroException(ce.getMessage());
1154            }
1155        } catch (javax.naming.NamingException JavaDoc ne) {
1156            trace.error(ne.getMessage());
1157            throw new HeroException(ne.getMessage());
1158        } catch (javax.ejb.FinderException JavaDoc fe) {
1159            trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
1160            throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
1161        }
1162    }
1163    
1164    /**
1165     * Set the mail of this user into Bonita database.
1166     *
1167     * @param userName the name of the user
1168     * @param userName the mail of the user
1169     * @ejb:interface-method view-type="both"
1170     * @ejb:transaction type="Required"
1171     * @throws HeroException
1172     *
1173     **/

1174    public void setUserMail(String JavaDoc userName, String JavaDoc mail) throws HeroException {
1175        trace.info("parameters:: userName = " + userName+" mail = "+mail + " start by " + mContext.getCallerPrincipal().getName());
1176        this.synchronizeUser();
1177        try {
1178            BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
1179            BnUserLocal user = userhome.findByName(userName);
1180            user.setEmail(mail);
1181        } catch (javax.naming.NamingException JavaDoc ne) {
1182            trace.error(ne.getMessage());
1183            throw new HeroException(ne.getMessage());
1184        } catch (FinderException JavaDoc fe) {
1185            trace.error(fe.getMessage());
1186            throw new HeroException(fe.getMessage());
1187        }
1188    }
1189    
1190    /**
1191     * Get the mail of this user from Bonita database.
1192     *
1193     * @param userName the name of the user
1194     * @ejb:interface-method view-type="both"
1195     * @ejb:transaction type="Supports"
1196     * @throws HeroException
1197     *
1198     **/

1199    public String JavaDoc getUserMail(String JavaDoc userName) throws HeroException {
1200        trace.info("parameter: userName = " + userName + " start by " + mContext.getCallerPrincipal().getName());
1201        UserServiceLocalHome ushome = null;
1202        this.synchronizeUser();
1203        try {
1204            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
1205            UserServiceLocal ul = ushome.create();
1206            Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
1207            return ((String JavaDoc)infos.get("email"));
1208        } catch (Exception JavaDoc ce) {
1209            trace.error(ce.getMessage());
1210            throw new HeroException(ce.getMessage());
1211        }
1212    }
1213    
1214        
1215    /**
1216     * Get the user password
1217     *
1218     * @return a String - get user password
1219     * @ejb:interface-method view-type="both"
1220     * @ejb:transaction type="Supports"
1221     **/

1222    public String JavaDoc getUserPassword() throws HeroException{
1223        UserServiceLocalHome ushome = null;
1224        this.synchronizeUser();
1225        try {
1226            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
1227            UserServiceLocal ul = ushome.create();
1228            Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
1229            return ((String JavaDoc)infos.get("password"));
1230        } catch (Exception JavaDoc ce) {
1231            trace.error(ce.getMessage());
1232            throw new HeroException(ce.getMessage());
1233        }
1234    }
1235    
1236    /**
1237     * Get the user jabber address
1238     *
1239     * @return a String - get user jabber address
1240     * @ejb:interface-method view-type="both"
1241     * @ejb:transaction type="Supports"
1242     **/

1243    public String JavaDoc getUserJabber() throws HeroException{
1244        UserServiceLocalHome ushome = null;
1245        this.synchronizeUser();
1246        try {
1247            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
1248            UserServiceLocal ul = ushome.create();
1249            Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
1250            return ((String JavaDoc)infos.get("jabber"));
1251        } catch (Exception JavaDoc ce) {
1252            trace.error(ce.getMessage());
1253            throw new HeroException(ce.getMessage());
1254        }
1255    }
1256    
1257    /**
1258     * Get User properties
1259     *
1260     * @return a BnUserPropertyValue Collection - list of user properties
1261     * @ejb:interface-method view-type="both"
1262     * @ejb:transaction type="Supports"
1263     *
1264     **/

1265    public Collection JavaDoc getUserProperties() throws HeroException {
1266        Collection JavaDoc prp = new ArrayList JavaDoc();
1267        BnUserPropertyLocal pl;
1268        this.synchronizeUser();
1269        try{
1270            BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
1271            BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
1272            Collection JavaDoc pls = mUser.getBnProperties();
1273            
1274            for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
1275                pl = (BnUserPropertyLocal) i.next();
1276                prp.add(pl.getBnUserPropertyValue());
1277            }
1278            return (prp);
1279        } catch (javax.naming.NamingException JavaDoc ne) {
1280            trace.error(ne.getMessage());
1281            throw new HeroException(ne.getMessage());
1282        } catch (javax.ejb.FinderException JavaDoc fe) {
1283            trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
1284            throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
1285        }
1286    }
1287    
1288    /**
1289     * Set a property of a user
1290     *
1291     * @param key the key of the property
1292     * @param value the name of the property
1293     * @ejb:interface-method view-type="both"
1294     * @ejb:transaction type="Required"
1295     *
1296     **/

1297    
1298    public void setUserProperty(String JavaDoc key, String JavaDoc value)
1299    throws HeroException {
1300        BnUserPropertyLocalHome pHome;
1301        BnUserPropertyLocal propertyLocal = null;
1302        trace.info("parameters: key=" + key + " value=" + value + " start by " + mContext.getCallerPrincipal().getName());
1303        this.synchronizeUser();
1304        
1305        try {
1306            BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
1307            BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
1308            try {
1309                pHome = BnUserPropertyUtil.getLocalHome();
1310            } catch (javax.naming.NamingException JavaDoc ne) {
1311                trace.error(ne.getMessage());
1312                throw new HeroException(ne.getMessage());
1313            }
1314            Collection JavaDoc c = null;
1315            try {
1316                c = pHome.findByTheKey(mUser.getId(), key);
1317            } catch (FinderException JavaDoc fe) {
1318                trace.error(fe.getMessage());
1319                throw new HeroException(fe.getMessage());
1320            }
1321            
1322            if (!c.isEmpty()) {
1323                
1324                propertyLocal = (BnUserPropertyLocal) (c.toArray())[0];
1325                propertyLocal.setTheValue(value);
1326                
1327            } else {
1328                try {
1329                    propertyLocal = pHome.create(key, value);
1330                    propertyLocal.setBnUser(mUser);
1331                    
1332                } catch (InvalidValueException ie) {
1333                    trace.error(ie.getMessage());
1334                    throw new HeroException(ie.getMessage());
1335                } catch (javax.ejb.CreateException JavaDoc ce) {
1336                    trace.error(ce.getMessage());
1337                    throw new HeroException(ce.getMessage());
1338                }
1339                
1340            }
1341        } catch (javax.naming.NamingException JavaDoc ne) {
1342            trace.error(ne.getMessage());
1343            throw new HeroException(ne.getMessage());
1344        } catch (javax.ejb.FinderException JavaDoc fe) {
1345            trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
1346            throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
1347        }
1348    }
1349    
1350    /**
1351     * Delete a property of a user
1352     *
1353     * @param key the key of the property
1354     * @ejb:interface-method view-type="both"
1355     * @ejb:transaction type="Required"
1356     *
1357     **/

1358    public void deleteUserProperty(String JavaDoc key) throws HeroException {
1359        trace.info("parameter key=" + key + " start by " + mContext.getCallerPrincipal().getName());
1360        
1361        BnUserPropertyLocalHome pHome;
1362        BnUserPropertyLocal propertyLocal = null;
1363        this.synchronizeUser();
1364        try {
1365            BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
1366            BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
1367            try {
1368                pHome = BnUserPropertyUtil.getLocalHome();
1369            } catch (javax.naming.NamingException JavaDoc ne) {
1370                trace.error(ne.getMessage());
1371                throw new HeroException(ne.getMessage());
1372            }
1373            Collection JavaDoc c = null;
1374            try {
1375                c = pHome.findByTheKey(mUser.getId(), key);
1376            } catch (FinderException JavaDoc fe) {
1377                trace.error(fe.getMessage());
1378                throw new HeroException(fe.getMessage());
1379            }
1380            
1381            if (!c.isEmpty()) {
1382                try {
1383                    propertyLocal = (BnUserPropertyLocal) (c.toArray())[0];
1384                    propertyLocal.remove();
1385                } catch (RemoveException JavaDoc rm) {
1386                    trace.error(rm.getMessage());
1387                    throw new HeroException(rm.getMessage());
1388                }
1389            } else {
1390                throw new HeroException("Property not found :" + key);
1391            }
1392            
1393        } catch (javax.naming.NamingException JavaDoc ne) {
1394            trace.error(ne.getMessage());
1395            throw new HeroException(ne.getMessage());
1396        } catch (javax.ejb.FinderException JavaDoc fe) {
1397            trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
1398            throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
1399        }
1400    }
1401    
1402    private void deleteInstances(Collection JavaDoc instances) throws HeroException{
1403        Iterator JavaDoc inst = instances.iterator();
1404        JMSServicesSessionLocal jms;
1405        this.synchronizeUser();
1406        try{
1407            JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
1408            jms=home.create();
1409        }catch(Exception JavaDoc e){
1410            trace.error(e.getMessage());
1411            throw new EngineException(e.getMessage());
1412        }
1413        try{
1414            while (inst.hasNext())
1415            {
1416                BnProjectLocal ins = (BnProjectLocal)inst.next();
1417                if (ins.getName().matches(".*_instance.*"))
1418                {
1419                    ins.remove();
1420                    jms.sendProjectEvent(DELETEPROJECT, ins.getName());
1421                }
1422            }
1423        } catch (RemoveException JavaDoc re) {
1424            trace.error("Error in delete instance " + re.getMessage());
1425            throw new HeroException("Error in delete project");
1426        }
1427    }
1428    
1429    private void deleteSubProcesses(String JavaDoc projectName) throws HeroException{
1430        BnProjectLocalHome pHome;
1431        JMSServicesSessionLocal jms;
1432        this.synchronizeUser();
1433        try{
1434            JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
1435            jms=home.create();
1436        }catch(Exception JavaDoc e){
1437            if (this.getProjectConfigTrace(projectName))
1438                trace.error(e.getMessage());
1439            throw new EngineException(e.getMessage());
1440        }
1441        try {
1442            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
1443        } catch (javax.naming.NamingException JavaDoc be) {
1444            if (this.getProjectConfigTrace(projectName))
1445                trace.error(be.getMessage());
1446            throw new HeroException(be.getMessage());
1447        }
1448        try {
1449            BnProjectLocal pl = pHome.findByName(projectName);
1450            String JavaDoc userName = mContext.getCallerPrincipal().getName();
1451            Collection JavaDoc nodes = pl.getBnNodes();
1452            Iterator JavaDoc nds = nodes.iterator();
1453            while (nds.hasNext()) // Verifies if the project has any subProcesses
1454
{
1455                BnNodeLocal nd = (BnNodeLocal)nds.next();
1456                if (nd.getType()==Constants.Nd.SUB_PROCESS_NODE)
1457                    this.deleteSubProcesses(nd.getName());
1458            }
1459            pl.remove();
1460            jms.sendProjectEvent(DELETEPROJECT, projectName);
1461        } catch (Exception JavaDoc re) {
1462            trace.error("Error in delete subProcess " + re.getMessage());
1463            throw new HeroException("Error in delete subProcess");
1464        }
1465    }
1466    
1467    private boolean getProjectConfigTrace(String JavaDoc projectName) throws HeroException{
1468        return (bonitaConfig.getProcessTrace(projectName));
1469    }
1470    
1471    private String JavaDoc getProjectConfigHistoric(String JavaDoc projectName) throws HeroException{
1472        return (bonitaConfig.getPocessHistoric(projectName));
1473    }
1474    
1475    /**
1476     * Creates the User Session Bean. This method is the first one to invoke in order to
1477     * use UserSession API. If the user is not authorized this method throws an exception.
1478     *
1479     * @throws CreateException
1480     *
1481     * @ejb:create-method view-type="both"
1482     **/

1483    public void ejbCreate() throws CreateException JavaDoc {
1484    }
1485    
1486    private void synchronizeUser() throws HeroException{
1487        UserServiceLocalHome ushome = null;
1488        try {
1489            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
1490            UserServiceLocal ul = ushome.create();
1491            ul.findUserLocal(mContext.getCallerPrincipal().getName());
1492        } catch (Exception JavaDoc ce) {ce.printStackTrace();
1493            trace.error("Error in findUserLocal " + ce.getMessage());
1494            throw new HeroException("Error in findUserLocal: "+ce.getMessage());
1495        }
1496    }
1497    
1498    private boolean isAdmin(String JavaDoc projectName)
1499    throws HeroException {
1500        if (this.getProjectConfigTrace(projectName))
1501            trace.info("parameters: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName());
1502        this.synchronizeUser();
1503        try {
1504            ProjectSessionLocalHome projectseshome =ProjectSessionUtil.getLocalHome();
1505            ProjectSessionLocal project = projectseshome.create();
1506            project.initProject(projectName);
1507            return(project.isAdminOfProject(projectName));
1508
1509        } catch (CreateException JavaDoc f) {
1510            if (this.getProjectConfigTrace(projectName))
1511                trace.error("Project does not exists " + projectName + " " + f.getMessage());
1512            throw new HeroException("Project does not exists " + projectName);
1513        } catch (javax.naming.NamingException JavaDoc r) {
1514            if (this.getProjectConfigTrace(projectName))
1515                trace.error("Cannot access to project " + r.getMessage());
1516            throw new HeroException("Cannot access to project " + r.getMessage());
1517        }
1518    }
1519    
1520    private void deleteProject(String JavaDoc projectName) throws HeroException {
1521        if (this.getProjectConfigTrace(projectName))
1522            trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName());
1523        BnProjectLocalHome pHome;
1524        JMSServicesSessionLocal jms;
1525        this.synchronizeUser();
1526        try{
1527            JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
1528            jms=home.create();
1529        }catch(Exception JavaDoc e){
1530            if (this.getProjectConfigTrace(projectName))
1531                trace.error(e.getMessage());
1532            throw new EngineException(e.getMessage());
1533        }
1534        try {
1535            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
1536        } catch (javax.naming.NamingException JavaDoc be) {
1537            if (this.getProjectConfigTrace(projectName))
1538                trace.error(be.getMessage());
1539            throw new HeroException(be.getMessage());
1540        }
1541        try {
1542            BnProjectLocal pl = pHome.findByName(projectName);
1543            String JavaDoc userName = mContext.getCallerPrincipal().getName();
1544            if (this.isAdmin(projectName))
1545            {
1546                if (pl.getParent().equals(pl.getName()))
1547                {
1548                    Collection JavaDoc ins = new ArrayList JavaDoc();
1549                    if (pl.getModel().getName().equals(pl.getName())) // is a projectModel
1550
{
1551                        ins = this.getProjectInstances(pl.getName());
1552                        Iterator JavaDoc instances = ins.iterator();
1553                        while (instances.hasNext())
1554                        {
1555                            BnProjectValue pr = (BnProjectValue)instances.next();
1556                            if (!pr.getName().equals(pl.getName()) && pr.getState() != Constants.Pj.TERMINATED)
1557                                throw new HeroException("Error in delete project: This Workflow model has running instances !!");
1558                        }
1559                    }
1560                    
1561                    Collection JavaDoc nodes = pl.getBnNodes();
1562                    Iterator JavaDoc nds = nodes.iterator();
1563                    while (nds.hasNext()) // Verifies if the project has any subProcesses
1564
{
1565                        BnNodeLocal nd = (BnNodeLocal)nds.next();
1566                        if (nd.getType()==Constants.Nd.SUB_PROCESS_NODE)
1567                            this.deleteSubProcesses(nd.getName());
1568                    }
1569                    
1570                    if (!ins.isEmpty())
1571                        this.deleteInstances(ins);
1572                    pl.remove();
1573                    jms.sendProjectEvent(DELETEPROJECT, projectName);
1574                }
1575                else
1576                    throw new HeroException("Error in delete project: You have to delete subProcess activity of this project !!");
1577            }
1578            else
1579                throw new HeroException("Error in delete project: only admin users are allowed to removed it !!");
1580        } catch (javax.ejb.FinderException JavaDoc fe) {
1581            if (this.getProjectConfigTrace(projectName))
1582                trace.error("User does not exist " + fe.getMessage());
1583            throw new HeroException("User does not exist");
1584        } catch (RemoveException JavaDoc re) {
1585            if (this.getProjectConfigTrace(projectName))
1586                trace.error("Error in delete project " + re.getMessage());
1587            throw new HeroException("Error in delete project");
1588        }
1589    }
1590    
1591    /**
1592     * Internal Enterprise Java Beans method.
1593     **/

1594    
1595    public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
1596        mContext = context;
1597        try{
1598            this.bonitaConfig = new BonitaConfig();
1599        }catch(Exception JavaDoc e){throw new EJBException JavaDoc(e.getMessage());}
1600    }
1601    
1602    /**
1603     * Internal Enterprise Java Beans method.
1604     **/

1605    public void ejbRemove() {
1606    }
1607    
1608    /**
1609     * Internal Enterprise Java Beans method.
1610     **/

1611    public void ejbActivate() {
1612    }
1613    
1614    /**
1615     * Internal Enterprise Java Beans method.
1616     **/

1617    public void ejbPassivate() {
1618    }
1619    
1620}
1621
Popular Tags