KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > UserSoapXMLBean


1 package hero.session;
2 /*
3  * 1Z/01/2004 - 11:58:09
4  *
5  * UserSoapXML.java -
6  * Copyright (C) 2003 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.BnProjectLocal;
28 import hero.interfaces.BnProjectLocalHome;
29 import hero.interfaces.BnProjectUtil;
30 import hero.interfaces.BnUserLightValue;
31 import hero.interfaces.BnUserLocal;
32 import hero.interfaces.BnUserLocalHome;
33 import hero.interfaces.BnUserPropertyLocal;
34 import hero.interfaces.BnUserValue;
35 import hero.interfaces.ProjectSessionLocal;
36 import hero.interfaces.UserServiceLocal;
37 import hero.interfaces.UserServiceLocalHome;
38 import hero.util.BonitaConfig;
39 import hero.util.HeroException;
40 import hero.util.ProjectNodes;
41 import hero.util.Projects;
42 import hero.util.UserProperties;
43 import hero.util.EventConstants;
44
45 import java.io.StringWriter JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.Arrays JavaDoc;
48 import java.util.Collection JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.Map JavaDoc;
51
52 import javax.ejb.CreateException JavaDoc;
53 import javax.ejb.EJBException JavaDoc;
54 import javax.ejb.FinderException JavaDoc;
55 import javax.ejb.SessionBean JavaDoc;
56 import javax.ejb.SessionContext JavaDoc;
57
58
59 import org.apache.log4j.Category;
60 import org.exolab.castor.xml.MarshalException;
61 import org.exolab.castor.xml.Marshaller;
62 import org.exolab.castor.xml.ValidationException;
63
64 /**
65  * UserSessionXML API based on UserSession API but oriented to web services
66  * calls from a non-Java language. Get methods of this API returns
67  * XML.
68  *
69  * @ejb:bean name="UserSoapXML"
70  * display-name="UserSoapXML Bean"
71  * type="Stateless"
72  * transaction-type="Container"
73  * jndi-name="ejb/hero/UserSoapXML"
74  *
75  * @ejb:ejb-ref ejb-name="BnUser"
76  * ref-name="myhero/BnUser"
77  * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
78  *
79  * @jonas.bean
80  * ejb-name="UserSoapXML"
81  * jndi-name="ejb/hero/UserSoapXML"
82  *
83  * @copyright INRIA
84  * @author Miguel Valdes
85  *
86  **/

87
88 public class UserSoapXMLBean implements SessionBean JavaDoc, EventConstants {
89     
90     // -------------------------------------------------------------------------
91
// Static
92
// -------------------------------------------------------------------------
93
// Utility variable
94
private static final Category trace = Category.getInstance(UserSessionBean.class);
95     
96     // -------------------------------------------------------------------------
97
// Members
98
// -------------------------------------------------------------------------
99

100     private SessionContext JavaDoc mContext;
101     private BonitaConfig bonitaConfig;
102     
103     // -------------------------------------------------------------------------
104
// XML Get Methods (Castor Data Binding)
105
// -------------------------------------------------------------------------
106

107     /**
108      * Get user project list. Workflow processes associated to this user
109      * @return a Collection of BnProjectLightValue objects - the projects list of the user
110      * @throws HeroException
111      * @ejb:interface-method view-type="both"
112      * @ejb:transaction type="Supports"
113      *
114      **/

115     public String JavaDoc getProjectList() throws HeroException {
116         trace.info("start by " + mContext.getCallerPrincipal().getName());
117         Collection JavaDoc pjts = new ArrayList JavaDoc();
118         Projects pb = new Projects();
119         Collection JavaDoc pva;
120         try {
121             BnUserLocalHome userhome =
122                 hero.interfaces.BnUserUtil.getLocalHome();
123             BnUserLocal mUser =
124                 userhome.findByName(mContext.getCallerPrincipal().getName());
125             Collection JavaDoc projects = null;
126             projects = mUser.getBnProjects();
127             BnUserValue uv = mUser.getBnUserValue();
128             hero.interfaces.BnProjectLightValue[] pv = uv.getBnProjects();
129             pva = new ArrayList JavaDoc(Arrays.asList(uv.getBnProjects()));
130         } catch (javax.naming.NamingException JavaDoc ne) {
131             throw new HeroException(ne.getMessage());
132         } catch (javax.ejb.FinderException JavaDoc fe) {
133             throw new HeroException(
134                     mContext.getCallerPrincipal().getName() + " does not exists");
135         }
136         
137         try {
138             pb.setProject(pva);
139             StringWriter JavaDoc sw = new StringWriter JavaDoc();
140             Marshaller.marshal(pb, sw);
141             return (sw.toString());
142         } catch (MarshalException ex1) {
143             throw new HeroException(ex1.getMessage());
144         } catch (ValidationException ex2) {
145             throw new HeroException(ex2.getMessage());
146         }
147     }
148     
149     /**
150      * Obtain all user activities from specific project (ready and anticipable state)
151      * @param projectName the name of the project
152      * @return a String Collection - the list of todo activities ot the user for a project
153      * @throws HeroException
154      * @ejb:interface-method view-type="both"
155      * @ejb:transaction type="Supports"
156      *
157      **/

158     public String JavaDoc getToDoList(String JavaDoc projectName) throws HeroException {
159         if (this.getProjectConfigTrace(projectName))
160             trace.info("parameter: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName());
161         ProjectNodes nb = new ProjectNodes();
162         BnProjectLocalHome projhome;
163         BnProjectLocal project;
164         BnNodeLocalHome nodehome;
165         Collection JavaDoc ready;
166         try {
167             projhome = BnProjectUtil.getLocalHome();
168             nodehome = BnNodeUtil.getLocalHome();
169         } catch (javax.naming.NamingException JavaDoc ne) {
170             throw new HeroException(ne.getMessage());
171         }
172         try {
173             project = projhome.findByName(projectName);
174         } catch (FinderException JavaDoc fe) {
175             throw new HeroException(
176                     "BnProject " + projectName + " does not exists");
177         }
178         try {
179             ready =
180                 nodehome.findUserReady(
181                         project.getId(),
182                         mContext.getCallerPrincipal().getName());
183         } catch (FinderException JavaDoc fe) {
184             ready = new ArrayList JavaDoc();
185         }
186         ArrayList JavaDoc result = new ArrayList JavaDoc();
187         for (Iterator JavaDoc i = ready.iterator(); i.hasNext();) {
188             BnNodeLocal nd = (BnNodeLocal) i.next();
189             result.add(nd.getBnNodeLightValue());
190         }
191         try {
192             nb.setNodes(result.toArray());
193             StringWriter JavaDoc sw = new StringWriter JavaDoc();
194             Marshaller.marshal(nb, sw);
195             return (sw.toString());
196         } catch (MarshalException ex1) {
197             throw new HeroException(ex1.getMessage());
198         } catch (ValidationException ex2) {
199             throw new HeroException(ex2.getMessage());
200         }
201     }
202     
203     /**
204      * Obtain all user activities from specific project (executing and anticipating state)
205      *
206      * @param projectName the name of the project
207      * @return a String Collectio - the list of active activities ot the user for a project
208      * @throws HeroException
209      * @ejb:interface-method view-type="both"
210      * @ejb:transaction type="Supports"
211      *
212      **/

213     public String JavaDoc getActivityList(String JavaDoc projectName) throws HeroException {
214         if (this.getProjectConfigTrace(projectName))
215             trace.info("parameter: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName());
216         ProjectNodes nb = new ProjectNodes();
217         BnProjectLocalHome projhome;
218         BnProjectLocal project;
219         BnNodeLocalHome nodehome;
220         Collection JavaDoc executing;
221         try {
222             projhome = BnProjectUtil.getLocalHome();
223             nodehome = BnNodeUtil.getLocalHome();
224         } catch (javax.naming.NamingException JavaDoc ne) {
225             throw new HeroException(ne.getMessage());
226         }
227         try {
228             project = projhome.findByName(projectName);
229         } catch (FinderException JavaDoc fe) {
230             throw new HeroException(
231                     "BnProject " + projectName + " does not exists");
232         }
233         try {
234             executing =
235                 nodehome.findUserExecuting(
236                         project.getId(),
237                         mContext.getCallerPrincipal().getName());
238         } catch (FinderException JavaDoc fe) {
239             executing = new ArrayList JavaDoc();
240         }
241         ArrayList JavaDoc result = new ArrayList JavaDoc();
242         for (Iterator JavaDoc i = executing.iterator(); i.hasNext();) {
243             BnNodeLocal nd = (BnNodeLocal) i.next();
244             result.add(nd.getBnNodeLightValue());
245         }
246         try {
247             nb.setNodes(result.toArray());
248             StringWriter JavaDoc sw = new StringWriter JavaDoc();
249             Marshaller.marshal(nb, sw);
250             return (sw.toString());
251         } catch (MarshalException ex1) {
252             throw new HeroException(ex1.getMessage());
253         } catch (ValidationException ex2) {
254             throw new HeroException(ex2.getMessage());
255         }
256     }
257     
258     /**
259      * Get the user light value
260      *
261      * @return a BnUserLightValue object - get user information
262      * @ejb:interface-method view-type="both"
263      * @ejb:transaction type="Supports"
264      **/

265     public BnUserLightValue getUserLightValue() throws HeroException{
266         try{
267             trace.info("start by " + mContext.getCallerPrincipal().getName());
268             BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome();
269             BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName());
270             BnUserLightValue ulv= mUser.getBnUserLightValue();
271             UserServiceLocalHome ushome = null;
272             try {
273                 ushome = hero.interfaces.UserServiceUtil.getLocalHome();
274                 UserServiceLocal ul = ushome.create();
275                 Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
276                 ulv.setEmail((String JavaDoc)infos.get("email"));
277                 ulv.setPassword((String JavaDoc)infos.get("password"));
278                 ulv.setJabber((String JavaDoc)infos.get("jabber"));
279                 return ulv;
280             } catch (Exception JavaDoc ce) {
281                 trace.error(ce.getMessage());
282                 throw new HeroException(ce.getMessage());
283             }
284         } catch (javax.naming.NamingException JavaDoc ne) {
285             trace.error(ne.getMessage());
286             throw new HeroException(ne.getMessage());
287         } catch (javax.ejb.FinderException JavaDoc fe) {
288             trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage());
289             throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists");
290         }
291     }
292     
293     /**
294      * Get the user name
295      *
296      * @return a String - get user name
297      * @ejb:interface-method view-type="both"
298      * @ejb:transaction type="Supports"
299      **/

300     public String JavaDoc getUser() {
301         trace.info("start by " + mContext.getCallerPrincipal().getName());
302         return mContext.getCallerPrincipal().getName();
303     }
304         
305     /**
306      * Get the mail of this user from Bonita database.
307      *
308      * @param userName the name of the user
309      * @ejb:interface-method view-type="both"
310      * @ejb:transaction type="Supports"
311      * @throws HeroException
312      *
313      **/

314     public String JavaDoc getUserMail(String JavaDoc userName) throws HeroException {
315         trace.info("parameter: userName = " + userName + " start by " + mContext.getCallerPrincipal().getName());
316         UserServiceLocalHome ushome = null;
317         try {
318             ushome = hero.interfaces.UserServiceUtil.getLocalHome();
319             UserServiceLocal ul = ushome.create();
320             Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
321             return ((String JavaDoc)infos.get("email"));
322         } catch (Exception JavaDoc ce) {
323             trace.error(ce.getMessage());
324             throw new HeroException(ce.getMessage());
325         }
326     }
327     
328         
329     /**
330      * Get the user password
331      *
332      * @return a String - get user password
333      * @ejb:interface-method view-type="both"
334      * @ejb:transaction type="Supports"
335      **/

336     public String JavaDoc getUserPassword() throws HeroException{
337         UserServiceLocalHome ushome = null;
338         try {
339             ushome = hero.interfaces.UserServiceUtil.getLocalHome();
340             UserServiceLocal ul = ushome.create();
341             Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
342             return ((String JavaDoc)infos.get("password"));
343         } catch (Exception JavaDoc ce) {
344             trace.error(ce.getMessage());
345             throw new HeroException(ce.getMessage());
346         }
347     }
348     
349     /**
350      * Get the user jabber address
351      *
352      * @return a String - get user jabber address
353      * @ejb:interface-method view-type="both"
354      * @ejb:transaction type="Supports"
355      **/

356     public String JavaDoc getUserJabber() throws HeroException{
357         UserServiceLocalHome ushome = null;
358         try {
359             ushome = hero.interfaces.UserServiceUtil.getLocalHome();
360             UserServiceLocal ul = ushome.create();
361             Map JavaDoc infos = ul.getUserInfos(mContext.getCallerPrincipal().getName());
362             return ((String JavaDoc)infos.get("jabber"));
363         } catch (Exception JavaDoc ce) {
364             trace.error(ce.getMessage());
365             throw new HeroException(ce.getMessage());
366         }
367     }
368     
369     /**
370      * Get User properties
371      *
372      * @return a BnUserPropertyValue Collection - list of user properties
373      * @ejb:interface-method view-type="both"
374      * @ejb:transaction type="Supports"
375      *
376      **/

377     public String JavaDoc getUserProperties() throws HeroException {
378         trace.info("start by " + mContext.getCallerPrincipal().getName());
379         Collection JavaDoc prp = new ArrayList JavaDoc();
380         BnUserPropertyLocal pl;
381         UserProperties ub = new UserProperties();
382         try {
383             BnUserLocalHome userhome =
384                 hero.interfaces.BnUserUtil.getLocalHome();
385             BnUserLocal mUser =
386                 userhome.findByName(mContext.getCallerPrincipal().getName());
387             Collection JavaDoc pls = mUser.getBnProperties();
388             
389             for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
390                 pl = (BnUserPropertyLocal) i.next();
391                 prp.add(pl.getBnUserPropertyValue());
392             }
393             
394             try {
395                 ub.setProperty(prp);
396                 StringWriter JavaDoc sw = new StringWriter JavaDoc();
397                 Marshaller.marshal(ub, sw);
398                 return (sw.toString());
399             } catch (MarshalException ex1) {
400                 throw new HeroException(ex1.getMessage());
401             } catch (ValidationException ex2) {
402                 throw new HeroException(ex2.getMessage());
403             }
404             
405         } catch (javax.naming.NamingException JavaDoc ne) {
406             throw new HeroException(ne.getMessage());
407         } catch (javax.ejb.FinderException JavaDoc fe) {
408             throw new HeroException(
409                     mContext.getCallerPrincipal().getName() + " does not exists");
410         }
411     }
412     
413     private boolean getProjectConfigTrace(String JavaDoc projectName) throws HeroException{
414         return (bonitaConfig.getProcessTrace(projectName));
415     }
416     
417     
418     /**
419      * Create the BnUser Session Bean
420      *
421      * @throws CreateException
422      *
423      * @ejb:create-method view-type="both"
424      **/

425     public void ejbCreate() throws CreateException JavaDoc {
426     }
427     
428     public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
429         mContext = context;
430         try{
431             this.bonitaConfig = new BonitaConfig();
432         }catch(Exception JavaDoc e){throw new EJBException JavaDoc(e.getMessage());}
433     }
434     
435     public void ejbRemove() {
436     }
437     
438     public void ejbActivate() {
439     }
440     
441     public void ejbPassivate() {
442     }
443     
444     // utility methods
445
private boolean checkRights(ProjectSessionLocal ps) throws HeroException {
446         // check that current user is a member of the project
447
return ps.containsUser(mContext.getCallerPrincipal().getName());
448     }
449 }
450
451
452
Popular Tags