001: package hero.session;
002:
003: /*
004: *
005: * ProjectSoapBasicBean.java -
006: * Copyright (C) 2003 Ecoo Team
007: * valdes@loria.fr
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: import hero.interfaces.BnEdgeLocal;
026: import hero.interfaces.BnNodeLocal;
027: import hero.interfaces.BnProjectLocal;
028: import hero.interfaces.BnProjectLocalHome;
029: import hero.interfaces.BnRoleLocal;
030: import hero.interfaces.BnUserLocal;
031: import hero.interfaces.BnUserLocalHome;
032: import hero.interfaces.Constants;
033: import hero.util.EventConstants;
034: import hero.util.HeroException;
035:
036: import java.rmi.RemoteException;
037: import java.util.ArrayList;
038: import java.util.Collection;
039: import java.util.Date;
040:
041: import java.util.Iterator;
042:
043: import javax.ejb.CreateException;
044: import javax.ejb.FinderException;
045: import javax.ejb.SessionBean;
046: import javax.ejb.SessionContext;
047: import javax.naming.Context;
048:
049: import java.util.Vector;
050:
051: import org.apache.log4j.Category;
052:
053: /**
054: * Session Bean Template
055: *
056: * @ejb:bean name="ProjectSoapBasic"
057: * display-name="ProjectSoapBasic Bean"
058: * type="Stateful"
059: * transaction-type="Container"
060: * jndi-name="ejb/hero/ProjectSoapBasic"
061: *
062: * @ejb:ejb-ref ejb-name="ProjectSoapBasic"
063: * view-type="remote"
064: * ref-name="ProjectSoapBasic"
065: *
066: * @ejb:ejb-ref ejb-name="BnProject"
067: * ref-name="myhero/BnProject"
068: *
069: * @ejb:transaction type="Supports"
070: * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
071: * @jonas.bean
072: * ejb-name="ProjectSoapBasic"
073: * jndi-name="ejb/hero/ProjectSoapBasic"
074: *
075: * @jboss.container-configuration name="Standard Stateful SessionBean for Bonita"
076: **/
077:
078: public class ProjectSoapBasicBean implements SessionBean,
079: EventConstants {
080:
081: // -------------------------------------------------------------------------
082: // Static
083: // -------------------------------------------------------------------------
084: // Utility variable
085: private static final Category trace = Category
086: .getInstance(ProjectSessionBean.class);
087:
088: // -------------------------------------------------------------------------
089: // Members
090: // -------------------------------------------------------------------------
091:
092: private SessionContext mContext;
093: private BnProjectLocalHome pHome;
094: private BnProjectLocal mProject;
095: private Collection subProjects = new ArrayList();
096: private ArrayList visited = new ArrayList();
097:
098: // -------------------------------------------------------------------------
099: // Basic Get Methods
100: // -------------------------------------------------------------------------
101:
102: /**
103: * Get ProjectName
104: * @return String
105: *
106: * @ejb:interface-method view-type="both"
107: * @ejb:transaction type="Supports"
108: *
109: **/
110: public String getName() throws HeroException {
111:
112: trace.debug(" process name = " + this .getName()
113: + " started by "
114: + mContext.getCallerPrincipal().getName());
115: return mProject.getName();
116: }
117:
118: /**
119: * Get creator
120: * @return String
121: *
122: * @ejb:interface-method view-type="both"
123: * @ejb:transaction type="Supports"
124: *
125: **/
126: public String getCreator() throws HeroException {
127:
128: trace.debug(" process name = " + this .getName()
129: + " started by "
130: + mContext.getCallerPrincipal().getName());
131: return mProject.getCreator();
132: }
133:
134: /**
135: * Get the node executor
136: *
137: * @param name of the node
138: * @return The user executor
139: * @ejb:interface-method view-type="both"
140: * @ejb:transaction type="Supports"
141: *
142: **/
143: public String getNodeExecutor(String name) throws HeroException {
144:
145: trace.debug("parameter: name=" + name + "process name = "
146: + this .getName() + " started by "
147: + mContext.getCallerPrincipal().getName());
148: BnNodeLocal nd = mProject.getBnNode(name);
149: return nd.getExecutor();
150: }
151:
152: /**
153: * Get Node State
154: *
155: * @param name of the node
156: * @return The state of the node
157: * @ejb:interface-method view-type="both"
158: * @ejb:transaction type="Supports"
159: *
160: **/
161: public int getNodeState(String name) throws HeroException {
162:
163: trace.debug("parameter: name=" + name + "process name = "
164: + this .getName() + " started by "
165: + mContext.getCallerPrincipal().getName());
166: BnNodeLocal nd = mProject.getBnNode(name);
167: int s = nd.getState();
168: return (s);
169: }
170:
171: /**
172: * Get all users of the project
173: * @return Object[]
174: *
175: * @ejb:interface-method view-type="both"
176: * @ejb:transaction type="Supports"
177: *
178: **/
179: public Object[] getUsers() throws HeroException {
180:
181: trace.debug("process name = " + this .getName() + "started by "
182: + mContext.getCallerPrincipal().getName());
183: Collection users = mProject.getBnUsers();
184: ArrayList result = new ArrayList();
185: for (Iterator i = users.iterator(); i.hasNext();) {
186: result.add(((BnUserLocal) i.next()).getName());
187: }
188: return result.toArray();
189: }
190:
191: /**
192: * Return all registered users
193: * @return Object[]
194: *
195: * @ejb:interface-method view-type="both"
196: * @ejb:transaction type="Supports"
197: *
198: **/
199: public Object[] getAllUsers() throws HeroException {
200:
201: trace.debug("process name = " + this .getName() + "started by "
202: + mContext.getCallerPrincipal().getName());
203: BnUserLocalHome uHome;
204: Collection users;
205: try {
206: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
207: .getLocalHome();
208: } catch (javax.naming.NamingException be) {
209: throw new HeroException(be.getMessage());
210: }
211: try {
212: users = uHome.findAll();
213: } catch (FinderException f) {
214: throw new HeroException(
215: "FinderException in findByAll users");
216: }
217: ArrayList result = new ArrayList();
218: for (Iterator i = users.iterator(); i.hasNext();) {
219: result.add(((BnUserLocal) i.next()).getName());
220: }
221: return result.toArray();
222: }
223:
224: /**
225: * Return all registered users
226: * @return Object[]
227: *
228: * @ejb:interface-method view-type="both"
229: * @ejb:transaction type="Supports"
230: *
231: **/
232: public Object[] getAllUsers(int offset, int numrows)
233: throws HeroException {
234:
235: trace.debug("process name = " + this .getName() + "started by "
236: + mContext.getCallerPrincipal().getName());
237: BnUserLocalHome uHome;
238: Collection users;
239: try {
240: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
241: .getLocalHome();
242: } catch (javax.naming.NamingException be) {
243: throw new HeroException(be.getMessage());
244: }
245: try {
246: users = uHome.findAll();
247: } catch (FinderException f) {
248: throw new HeroException(
249: "FinderException in findByAll users");
250: }
251: int cnt = 0;
252: int add = 0;
253: ArrayList result = new ArrayList();
254: for (Iterator i = users.iterator(); i.hasNext();) {
255: BnUserLocal user = (BnUserLocal) i.next();
256: if (cnt >= offset) {
257: result.add(user.getName());
258: add++;
259: if (add == numrows)
260: break;
261: }
262: cnt++;
263: }
264: return result.toArray();
265: }
266:
267: /**
268: * Get number of total entities
269: *
270: * @ejb:interface-method view-type="both"
271: * @ejb:transaction type="Supports"
272: *
273: **/
274: public int getListCnt(String type) throws HeroException {
275: trace.debug("type = " + type + "started by "
276: + mContext.getCallerPrincipal().getName());
277: BnUserLocalHome uHome;
278: Collection list = null;
279: int cnt = 0;
280:
281: if (type.equals(Constants.Pj.GETALLUSERS)) {
282: try {
283: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
284: .getLocalHome();
285: } catch (javax.naming.NamingException be) {
286: throw new HeroException(be.getMessage());
287: }
288: try {
289: list = uHome.findAll();
290: } catch (FinderException f) {
291: throw new HeroException(
292: "FinderException in findByAll users");
293: }
294: }
295: for (Iterator i = list.iterator(); i.hasNext();) {
296: i.next();
297: cnt++;
298: }
299: return cnt;
300: }
301:
302: /**
303: * Get all role names of the project
304: * @return Object[]
305: *
306: * @ejb:interface-method view-type="both
307: * @ejb:transaction type="Supports"
308: *
309: **/
310: public Object[] getRolesNames() throws HeroException {
311:
312: trace.debug("process name = " + this .getName() + "started by "
313: + mContext.getCallerPrincipal().getName());
314: Collection roles = mProject.getBnRoles();
315: ArrayList result = new ArrayList();
316: for (Iterator i = roles.iterator(); i.hasNext();) {
317: result.add(((BnRoleLocal) i.next()).getName());
318: }
319: return result.toArray();
320: }
321:
322: /**
323: * Get all node names of the project
324: *
325: * @return Object[]
326: * @ejb:interface-method view-type="both"
327: * @ejb:transaction type="Supports"
328: *
329: **/
330: public Object[] getNodesNames() throws HeroException {
331:
332: trace.debug("process name = " + this .getName() + "started by "
333: + mContext.getCallerPrincipal().getName());
334:
335: Vector names = new Vector();
336: Collection nodes = mProject.getBnNodes();
337: Iterator i = nodes.iterator();
338: while (i.hasNext()) {
339: BnNodeLocal n = (BnNodeLocal) i.next();
340: names.add(n.getName());
341: }
342: return ((Collection) names).toArray();
343: }
344:
345: /**
346: * Get all node of the project
347: * @return Object[]
348: *
349: * @ejb:interface-method view-type="both"
350: * @ejb:transaction type="Supports"
351: *
352: **/
353: public Object[] getNodes() throws HeroException {
354:
355: trace.debug("process name = " + this .getName() + "started by "
356: + mContext.getCallerPrincipal().getName());
357: Vector nodesDetails = new Vector();
358: Collection nodes = mProject.getBnNodes();
359:
360: Iterator i = nodes.iterator();
361: while (i.hasNext()) {
362: BnNodeLocal n = (BnNodeLocal) i.next();
363: String[] details = new String[5];
364: details[0] = n.getName();
365: details[1] = hero.interfaces.Constants.Nd.nodeStateName[n
366: .getState()];
367: details[2] = ((BnRoleLocal) n.getBnRole()).getName();
368: /* modif MBL
369: if (n.getDeadline()!=null)
370: details[3]=n.getDeadline().toString();
371: */
372: if (n.getDeadlines().size() != 0) {
373: Collection co = n.getDeadlines();
374: Iterator it = co.iterator();
375: Date date = null;
376: while (it.hasNext()) {
377: date = (Date) it.next();
378: }
379: details[3] = date.toString();
380: } else
381: details[3] = "null";
382: details[4] = (new Boolean(n.getAnticipable())).toString();
383: nodesDetails.add(details);
384: }
385: return ((Collection) nodesDetails).toArray();
386: }
387:
388: /**
389: * Get all node information
390: * @return Object[]
391: *
392: * @ejb:interface-method view-type="both"
393: * @ejb:transaction type="Supports"
394: *
395: **/
396:
397: public Object[] getNodeDetails(String node) throws HeroException {
398:
399: trace.debug("parameter: node=" + node + "process name = "
400: + this .getName() + " started by "
401: + mContext.getCallerPrincipal().getName());
402: BnNodeLocal nd = mProject.getBnNode(node);
403: Vector detail = new Vector();
404:
405: detail.add(nd.getName());
406: detail.add(mProject.getName());
407: detail.add(nd.getCreator());
408: detail.add(hero.interfaces.Constants.Nd.nodeStateName[nd
409: .getState()]);
410: detail.add(((BnRoleLocal) nd.getBnRole()).getName());
411: if (nd.getExecutor() != null)
412: detail.add(nd.getExecutor());
413: else
414: detail.add("null");
415: /*
416: if (nd.getDeadline()!=null)
417: detail.add(nd.getDeadline().toString());
418: */
419: if (nd.getDeadlines().size() != 0) {
420: Collection co = nd.getDeadlines();
421: Iterator it = co.iterator();
422: Date date = null;
423: while (it.hasNext()) {
424: date = (Date) it.next();
425: }
426: detail.add(date.toString());
427: }
428:
429: else
430: detail.add("null");
431:
432: detail.add(new Boolean((nd.getAnticipable())).toString());
433:
434: if (nd.getDescription() != null)
435: detail.add(nd.getDescription());
436: else
437: detail.add("null");
438:
439: return (detail.toArray());
440: }
441:
442: /**
443: * Get user roles in project
444: * @return Object[]
445: *
446: * @param userName The name of the user
447: *
448: * @ejb:interface-method view-type="both"
449: * @ejb:transaction type="Supports"
450: *
451: **/
452: public Object[] getUserRolesInProjectNames(String userName)
453: throws HeroException {
454:
455: trace.debug("parameter: userName=" + userName
456: + "process name = " + this .getName() + " started by "
457: + mContext.getCallerPrincipal().getName());
458: BnUserLocalHome uHome;
459: BnUserLocal user;
460: ArrayList result = new ArrayList();
461: try {
462: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
463: .getLocalHome();
464: } catch (javax.naming.NamingException be) {
465: throw new HeroException(be.getMessage());
466: }
467: try {
468: user = uHome.findByName(userName);
469: } catch (FinderException f) {
470: throw new HeroException("FinderException");
471: }
472: Collection userRoles = user.getBnRoles();
473: Collection projectRoles = mProject.getBnRoles();
474: for (Iterator i = userRoles.iterator(); i.hasNext();) {
475: BnRoleLocal ur = (BnRoleLocal) i.next();
476: for (Iterator j = projectRoles.iterator(); j.hasNext();) {
477: BnRoleLocal up = (BnRoleLocal) j.next();
478: if (ur.getId() == up.getId())
479: result.add(ur.getName());
480: }
481: }
482: return result.toArray();
483: }
484:
485: /**
486: * get all in edges of the node
487: * @return Object[]
488: *
489: * @param name the name ot the node
490: *
491: * @ejb:interface-method view-type="both"
492: * @ejb:transaction type="Supports"
493: *
494: **/
495: public Object[] getNodeInEdges(String name) throws HeroException {
496:
497: trace.debug("parameter: name=" + name + "process name = "
498: + this .getName() + " started by "
499: + mContext.getCallerPrincipal().getName());
500: Vector in = new Vector();
501: BnNodeLocal nd = mProject.getBnNode(name);
502:
503: Collection edgesIn = nd.getInBnEdges();
504: Iterator i = edgesIn.iterator();
505: while (i.hasNext()) {
506: BnEdgeLocal e = (BnEdgeLocal) i.next();
507: String[] details = new String[4];
508: details[0] = e.getName();
509: details[1] = hero.interfaces.Constants.Ed.edgeStateName[e
510: .getState()];
511: BnNodeLocal nIn = (BnNodeLocal) e.getInBnNode();
512: details[2] = nIn.getName();
513: BnNodeLocal nOut = (BnNodeLocal) e.getOutBnNode();
514: details[3] = nOut.getName();
515: in.add(details);
516: }
517:
518: return (in.toArray());
519: }
520:
521: /**
522: * Get all BnEdge of the project
523: * @return Object[]
524: *
525: * @ejb:interface-method view-type="both"
526: * @ejb:transaction type="Supports"
527: *
528: **/
529: public Object[] getEdges() throws HeroException {
530:
531: trace.debug("process name = " + this .getName() + " started by "
532: + mContext.getCallerPrincipal().getName());
533: Vector edgesDetails = new Vector();
534: Collection edges = mProject.getBnEdges();
535: Iterator i = edges.iterator();
536: while (i.hasNext()) {
537: BnEdgeLocal e = (BnEdgeLocal) i.next();
538: String[] details = new String[4];
539: details[0] = e.getName();
540: details[1] = hero.interfaces.Constants.Ed.edgeStateName[e
541: .getState()];
542: BnNodeLocal nIn = (BnNodeLocal) e.getInBnNode();
543: details[2] = nIn.getName();
544: BnNodeLocal nOut = (BnNodeLocal) e.getOutBnNode();
545: details[3] = nOut.getName();
546: edgesDetails.add(details);
547: }
548: return (edgesDetails.toArray());
549: }
550:
551: /**
552: * get all out edges of the node
553: * @return Object[]
554: *
555: * @param name the name ot the node
556: *
557: * @ejb:interface-method view-type="both"
558: * @ejb:transaction type="Supports"
559: *
560: **/
561: public Object[] getNodeOutEdges(String name) throws HeroException {
562:
563: trace.debug("parameter: name=" + name + "process name = "
564: + this .getName() + " started by "
565: + mContext.getCallerPrincipal().getName());
566:
567: Vector out = new Vector();
568: BnNodeLocal nd = mProject.getBnNode(name);
569:
570: Collection edgesOut = nd.getOutBnEdges();
571: Iterator i = edgesOut.iterator();
572: while (i.hasNext()) {
573: BnEdgeLocal e = (BnEdgeLocal) i.next();
574: String[] details = new String[4];
575: details[0] = e.getName();
576: details[1] = hero.interfaces.Constants.Ed.edgeStateName[e
577: .getState()];
578: BnNodeLocal nIn = (BnNodeLocal) e.getInBnNode();
579: details[2] = nIn.getName();
580: BnNodeLocal nOut = (BnNodeLocal) e.getOutBnNode();
581: details[3] = nOut.getName();
582: out.add(details);
583: }
584:
585: return (out.toArray());
586: }
587:
588: /**
589: * Get the type of the node
590: *
591: * @param name of the node
592: * @return The type of the node
593: * @ejb:interface-method view-type="both"
594: * @ejb:transaction type="Supports"
595: *
596: **/
597: public int getNodeType(String name) throws HeroException {
598:
599: trace.debug("parameter: name=" + name + "process name = "
600: + this .getName() + " started by "
601: + mContext.getCallerPrincipal().getName());
602: BnNodeLocal nd = mProject.getBnNode(name);
603: return (nd.getType());
604: }
605:
606: // -------------------------------------------------------------------------
607: // ejbCreate and initProject business methods
608: // -------------------------------------------------------------------------
609:
610: /**
611: * Init the Project Session Bean. You have to call this method after "create" call. After that
612: * all methods of ProjectSession API are available.
613: *
614: * @param projectName project name
615: * @ejb:interface-method view-type="both"
616: * @ejb:transaction type="Required"
617: * @throws HeroException
618: **/
619: public void initProject(String projectName) throws HeroException {
620: Context lContext;
621:
622: trace.debug("parameter: projectName=" + projectName
623: + " started by "
624: + mContext.getCallerPrincipal().getName());
625: try {
626: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
627: this .mProject = pHome.findByName(projectName);
628: } catch (javax.naming.NamingException ne) {
629: throw new HeroException(ne.getMessage());
630: } catch (javax.ejb.FinderException fe) {
631: throw new HeroException(fe.getMessage());
632: }
633: }
634:
635: /**
636: * Creates the Project Session Bean. This method is the first one to invoke in order to
637: * use ProjectSession API. If the user is not authorized this method throws an exception.
638: *
639: * @throws CreateException
640: *
641: * @ejb:create-method view-type="both"
642: **/
643: public void ejbCreate() throws CreateException {
644: }
645:
646: /**
647: * Internal Enterprise Java Beans method.
648: **/
649: public void ejbPostCreate(String oldProject, String newProject)
650: throws CreateException, RemoteException {
651: }
652:
653: /**
654: * Internal Enterprise Java Beans method.
655: **/
656: public void setSessionContext(final javax.ejb.SessionContext context) {
657: mContext = context;
658: }
659:
660: /**
661: * Internal Enterprise Java Beans method.
662: **/
663:
664: public void ejbRemove() {
665: }
666:
667: /**
668: * Internal Enterprise Java Beans method.
669: **/
670:
671: public void ejbActivate() {
672: }
673:
674: /**
675: * Internal Enterprise Java Beans method.
676: **/
677:
678: public void ejbPassivate() {
679: }
680: }
|