Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/ejb/user/FlexGroupBean.java


1   /*
2    * FlexGroupBean.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:37 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.ejb.user;
12  
13  import java.rmi.RemoteException;
14  import java.util.Enumeration;
15  import java.util.Hashtable;
16  import java.util.Vector;
17  
18  import javax.ejb.CreateException;
19  
20  import com.flexstor.common.constants.EjbHomeInterfacesI;
21  import com.flexstor.common.data.ejb.role.RoleData;
22  import com.flexstor.common.data.ejb.user.GroupData;
23  import com.flexstor.common.exceptions.ejb.EjbException;
24  import com.flexstor.common.exceptions.ejb.NotFoundException;
25  import com.flexstor.common.keys.ejb.CollectionKey;
26  import com.flexstor.common.keys.ejb.DisguiseCollectionKey;
27  import com.flexstor.common.keys.ejb.EmailAddressCollectionKey;
28  import com.flexstor.common.keys.ejb.FlexKey;
29  import com.flexstor.common.keys.ejb.FtpAddressCollectionKey;
30  import com.flexstor.common.keys.ejb.GroupCollectionKey;
31  import com.flexstor.common.keys.ejb.GroupKey;
32  import com.flexstor.common.keys.ejb.ImportSettingCollectionKey;
33  import com.flexstor.common.keys.ejb.PrivAssetCollectionKey;
34  import com.flexstor.common.keys.ejb.ReportTemplateCollectionKey;
35  import com.flexstor.common.keys.ejb.RoleKey;
36  import com.flexstor.common.keys.ejb.SaveSearchCollectionKey;
37  import com.flexstor.common.keys.ejb.SendSettingCollectionKey;
38  import com.flexstor.common.keys.ejb.ServerCollectionKey;
39  import com.flexstor.common.keys.ejb.WhereCollectionKey;
40  import com.flexstor.ejb.role.persist.RolePersist;
41  import com.flexstor.ejb.role.persist.RolePersistHome;
42  import com.flexstor.ejb.trace.BeanTrace;
43  import com.flexstor.ejb.user.persist.GroupPersist;
44  import com.flexstor.ejb.user.persist.GroupPersistHome;
45  
46  /**
47   *
48   * <P>
49   * FlexGroup <BR>
50   * <BLOCKQUOTE>
51   *    FlexGroup is a role defined for several users.  Several users can be placed in a FlexGroup, and then <BR>
52   *    the preferences can be defined once. A FlexGroup must have a Role in order to define itself. <BR>
53   *    A user can belong to one or more groups. <BR>
54   * </BLOCKQUOTE>
55   * </P>
56   *
57   * <P>
58   * Uses cache: no
59   *
60   * State Management Type: Stateful
61   * </P>
62   *
63   * Configurable properties in flexdm.properties: <BR>
64   * <BLOCKQUOTE>
65   * <P>
66   *    NONE <BR>
67   * </P>
68   * </BLOCKQUOTE>
69   *
70   */
71  public class FlexGroupBean
72      extends com.flexstor.ejb.BusinessObjectSessionBean
73  {
74    // MKS macro expander
75    public final static String IDENTIFIER = "$Id: FlexGroupBean.java,v 1.4 2003/08/11 02:22:37 aleric Exp $";
76  
77    private  transient  GroupPersist groupPersist         = null;
78    private transient  RolePersist  rolePersist          = null;
79    private            GroupData    groupData            = null;
80    private transient  Vector         importSettings       = null;
81    private transient  Vector         sendSettings         = null;
82    private transient  Vector         securityRights       = null;
83    private transient  Vector         emailAddresses       = null;
84    private transient  Vector         ftpAddresses         = null;
85    private transient  Vector         servers              = null;
86    private transient  Vector         disguises            = null;
87    private transient  Vector         saveSearches         = null;
88    private transient  Vector         privileges           = null;
89      private transient  Hashtable      preferences          = null;
90    private transient  Vector         reportTemplates      = null;
91      private transient  Vector         wheres               = null;
92    private transient  RoleKey      userRoleKey          = null;
93      private            int            userRoleId           = -1;
94  
95      /** 
96      * Default constructor for the FlexGroupBean class
97      */
98       
99      public FlexGroupBean() 
100     {
101       super();
102     }
103 
104 
105     /**
106     * Add a Vector of security rights to the combined collection of security rights
107     *
108     * @param java.util.Hashtable  a collection of security rights from a particular group's role
109     */
110 
111     private void addSecurityRights(int[] aSecurityRightsCollection)
112     {
113 
114       int t_arraySize = aSecurityRightsCollection.length;
115 
116       for (int idx = 0; idx < t_arraySize; idx++)
117         securityRights.addElement(new Integer(aSecurityRightsCollection[idx]));
118     }
119    /**
120     * Add a Vector of prefernces to the combined collection of security rights
121     *
122     * @param java.util.Hashtable  a collection of security rights from a particular group's role
123     */
124 
125     private void addPreferences( Hashtable aPrefs )
126     {
127         if ( aPrefs != null )
128         {
129           Enumeration enum = aPrefs.keys();
130           String key       = null;
131 
132         while ( enum.hasMoreElements () )
133           {
134             key = ( String ) enum.nextElement();
135             preferences.put ( key, ( String ) aPrefs.get ( key ) );
136           }
137         }  
138     }
139 
140 
141 
142     /**
143     * Combine all the role's collections of data to a single collection
144     *
145     * @param java.util.Hashtable       - collection of RoleData
146     */
147      
148     private void buildRoleUnion( Vector aRoleCollection, int roleId )
149     {
150       RoleData t_roleData = null;
151 
152         BeanTrace.println ("[ DEBUG ] Total number of roles "+aRoleCollection.size(), BeanTrace.DEBUG);
153 
154       for ( int i=0; i<aRoleCollection.size(); i++ )
155       {
156         t_roleData = (RoleData)aRoleCollection.elementAt ( i );
157 
158         if ( t_roleData.getId() == roleId )
159         {
160             userRoleKey = t_roleData.getKey();
161             userRoleId  = roleId;
162         }
163 
164         addSecurityRights ( t_roleData.getSecurityRights() );
165 
166             addPreferences    ( t_roleData.getPreferences() );
167 
168 
169         // should only be one in the collections
170         if (t_roleData.getEMailAddresses() != null)
171         {
172           if (t_roleData.getEMailAddresses().size() > 0)
173             emailAddresses.addElement(t_roleData.getEMailAddresses().elementAt(0));
174         }
175 
176         if (t_roleData.getFtpAddresses() != null)
177         {
178           if (t_roleData.getFtpAddresses().size() > 0)
179             ftpAddresses.addElement(t_roleData.getFtpAddresses().elementAt(0));
180         }
181 
182         if (t_roleData.getServers() != null) 
183         {
184           if (t_roleData.getServers().size() > 0)
185             servers.addElement(t_roleData.getServers().elementAt(0));
186         }
187           if (t_roleData.getWheres() != null)
188         {
189           if (t_roleData.getWheres().size() > 0)
190             wheres.addElement(t_roleData.getWheres().elementAt(0));
191         }
192 
193 
194         if (t_roleData.getDisguises() != null)
195         {
196           if (t_roleData.getDisguises().size() > 0)
197             disguises.addElement(t_roleData.getDisguises().elementAt(0));
198         }
199 
200         if (t_roleData.getReportTemplates() != null)
201         {
202           if (t_roleData.getReportTemplates().size() > 0)
203             reportTemplates.addElement(t_roleData.getReportTemplates().elementAt(0));
204         }
205 
206         if (t_roleData.getSaveSearches() != null)
207         {
208           if (t_roleData.getSaveSearches().size() > 0)
209             saveSearches.addElement(t_roleData.getSaveSearches().elementAt(0));
210         }
211 
212         if (t_roleData.getImportSettings() != null)
213         {
214           if (t_roleData.getImportSettings().size() > 0)
215             importSettings.addElement(t_roleData.getImportSettings().elementAt(0));
216         }
217 
218         if (t_roleData.getPrivileges() != null)
219         {
220                 if (t_roleData.getPrivileges().size() > 0)
221          privileges.addElement(t_roleData.getPrivileges().elementAt(0));
222 
223         }
224 
225         if (t_roleData.getSendSettings() != null)
226         {
227           if (t_roleData.getSendSettings().size() > 0)
228             sendSettings.addElement(t_roleData.getSendSettings().elementAt(0));
229         }
230       }
231         // > 1 .. because if its just one collection key in the vector, it cannt contain
232         // duplicate keys ( Based on the present code of CollectionKey beacause
233         // CollectionKey.addKey always checks for already containment: Praveen )
234         if ( emailAddresses.size() >  1 )
235         {
236           BeanTrace.println ("\n[ DEBUG ] Removing duplicate emails.... ", BeanTrace.DEBUG);
237           EmailAddressCollectionKey eCollKey = new EmailAddressCollectionKey ( removeDuplicates ( emailAddresses ) );
238           emailAddresses.removeAllElements();
239           emailAddresses.addElement ( eCollKey );
240         }
241 
242         if ( ftpAddresses.size() >  1 )
243         {
244           BeanTrace.println ("\n[ DEBUG ] Removing duplicate ftps.... ", BeanTrace.DEBUG);
245           FtpAddressCollectionKey fCollKey = new FtpAddressCollectionKey ( removeDuplicates ( ftpAddresses ) );
246           ftpAddresses.removeAllElements();
247           ftpAddresses.addElement ( fCollKey );
248         }
249 
250         if ( wheres.size() >  1 )
251         {
252           BeanTrace.println ("\n[ DEBUG ] Removing duplicate wheres.... ", BeanTrace.DEBUG);
253           WhereCollectionKey wCollKey = new WhereCollectionKey ( removeDuplicates ( wheres ) );
254           wheres.removeAllElements();
255           wheres.addElement ( wCollKey );
256         }
257 
258 
259         if ( servers.size() > 1 )
260         {
261           BeanTrace.println ("\n[ DEBUG ] Removing duplicate servers.... ", BeanTrace.DEBUG);
262           ServerCollectionKey sCollKey  = new ServerCollectionKey ( removeDuplicates ( servers ) );
263           servers.removeAllElements();
264           servers.addElement ( sCollKey );
265         }
266 
267         if ( disguises.size() > 1 )
268         {
269           BeanTrace.println ("\n[ DEBUG ] Removing duplicate disguises.... ", BeanTrace.DEBUG);
270           DisguiseCollectionKey dCollKey  = new DisguiseCollectionKey ( removeDuplicates ( disguises ) );
271           disguises.removeAllElements();
272           disguises.addElement ( dCollKey );
273         }
274 
275         if ( reportTemplates.size() > 1 )
276         {
277           BeanTrace.println ("\n[ DEBUG ] Removing duplicate Report Templates.... ", BeanTrace.DEBUG);
278           ReportTemplateCollectionKey rCollKey  = new ReportTemplateCollectionKey ( removeDuplicates ( reportTemplates ) );
279           reportTemplates.removeAllElements();
280           reportTemplates.addElement ( rCollKey );
281         }
282 
283         if ( saveSearches.size() > 1 )
284         {
285           BeanTrace.println ("\n[ DEBUG ] Removing duplicate save searches.... ", BeanTrace.DEBUG);
286           SaveSearchCollectionKey ssCollKey = new SaveSearchCollectionKey ( removeDuplicates ( saveSearches ) );
287           saveSearches.removeAllElements();
288           saveSearches.addElement ( ssCollKey );
289         }
290 
291         if ( importSettings.size() > 1 )
292         {
293           BeanTrace.println ("\n[ DEBUG ] Removing duplicate Import Settings.... ", BeanTrace.DEBUG);
294           ImportSettingCollectionKey  isCollKey = new ImportSettingCollectionKey  ( removeDuplicates ( importSettings ) );
295           importSettings.removeAllElements();
296           importSettings.addElement ( isCollKey );
297         }
298 
299         if ( sendSettings.size() > 1 )
300         {
301           BeanTrace.println ("\n[ DEBUG ] Removing duplicate Send Settings.... ", BeanTrace.DEBUG);
302           SendSettingCollectionKey    stCollKey = new SendSettingCollectionKey ( removeDuplicates ( sendSettings ) );
303           sendSettings.removeAllElements();
304           sendSettings.addElement ( stCollKey );
305         }
306 
307         if ( privileges.size() > 1 )
308         {
309           BeanTrace.println ("\n[ DEBUG ] Removing duplicate privileges.... ", BeanTrace.DEBUG);
310           PrivAssetCollectionKey pCollKey  = new PrivAssetCollectionKey ( removeDuplicates ( privileges ) );
311           privileges.removeAllElements();
312           privileges.addElement ( pCollKey );
313         }  
314      }
315 
316 
317     /**
318     * Convert a hashtable of Integer keys to an int array
319     *
320     * @param java.util.Hashtable  an array of Integer keys stored as a Hashtable
321     *
322     * @return int[]
323     */
324 
325     private int[] convertToArray(Vector vec)
326     {
327 
328         if ( vec == null || vec.size() == 0)
329             return new int[0];
330 
331       int t_arraySize = vec.size();
332 
333       int[] t_convertedHashtable = new int[ t_arraySize ];
334 
335       for ( int i = 0; i < t_arraySize; i++ )
336       {
337         Integer t_key = (Integer)vec.elementAt( i );
338         t_convertedHashtable[ i ] = t_key.intValue();
339       }
340 
341       return t_convertedHashtable;
342     }
343    /**
344     * Convert a hashtable to vector.
345     *
346     * @param java.util.Hashtable
347     *
348     * @return Vector
349     */
350 
351     private Vector convertHashtableToVector( Hashtable hash )
352     {
353 
354         if ( hash == null || hash.size() == 0)
355             return new Vector();
356 
357       Vector vector = new Vector( hash.size() );
358 
359         Enumeration enum = hash.elements();
360 
361       while ( enum.hasMoreElements() )
362       {
363        vector.addElement ( enum.nextElement() );
364       }
365       return vector;
366     }
367 
368 
369     /**
370     * EJB container calls ejbCreate in order to create an instance of the object. ejbCreate initalizes the state of <br>
371     * the EJB object. <br>
372     *
373     * This method corresponds to the create method in the home interface <code>FlexGroupHome</code>.<br>
374     *
375     * @exception javax.ejb.CreateException  - EJB Server could not create instance of this bean 
376     * @exception java.rmi.RemoteException   - Some problem occured with the EJB persistent server
377     *
378     * @see com.flexstor.ejb.user.FlexGroup
379     * @see com.flexstor.ejb.user.FlexGroupHome
380     */
381      
382     public void ejbCreate() 
383         throws EjbException, CreateException, RemoteException 
384     {
385         super.ejbCreate();
386       // create an initial Context object
387       buildInitialContext("FlexGroup");
388     }
389 
390     /**
391     * EJB container calls ejbCreate in order to create an instance of the object. ejbCreate initalizes the state of <br>
392     * the EJB object. <br>
393     *
394     * This method corresponds to the create method in the home interface <code>FlexGroupHome</code>.<br>
395     *
396     * @param java.lang.String                                       a groupName Of the Group for this Bean
397     *
398     * @exception com.flexstor.common.exceptions.ejb.EjbException     - Unable to query the database for a group
399     * @exception javax.ejb.CreateException                          - EJB Server could not create instance of this bean 
400     * @exception java.rmi.RemoteException                           - Some problem occured with the EJB server
401     */
402      
403     public void ejbCreate(String aGroupName) 
404         throws CreateException, EjbException, NotFoundException, RemoteException
405     {
406       ejbCreate();
407         groupData = getGroup( aGroupName );
408     }
409 
410     /**
411     * EJB container calls ejbCreate in order to create an instance of the object. ejbCreate initalizes the state of <br>
412     * the EJB object. <br>
413     *
414     * This method corresponds to the create method in the home interface <code>FlexGroupHome</code>.<br>
415     *
416     * @param com.flexstor.common.keys.ejb.GroupKey - Primary Key for this Object
417     *
418     * @exception com.flexstor.common.exceptions.ejb.EjbException     - Unable to query the database for a group
419     * @exception javax.ejb.CreateException                          - EJB Server could not create instance of this bean 
420     * @exception java.rmi.RemoteException                           - Some problem occured with the EJB server
421     */
422      
423     public void ejbCreate(GroupKey key) 
424         throws CreateException, EjbException, NotFoundException, RemoteException
425     {
426       ejbCreate();
427         groupData = getGroup( key );
428     }
429 
430     /**
431     * A notification that signals the intent of the EJB container to remove (destroy) the <br>
432     * entity representation in the EJB server database.  This call may be in response to the client <br>
433     * removing the associated session object or the container will also call ejbRemove when the session <br>
434     * object expires.
435     *
436     * Calls a remove on all of the EJB objects it is holding references to.
437     */
438      
439     public void ejbRemove() 
440     {
441       try 
442       {
443           super.ejbRemove();
444           
445         if (groupPersist != null) 
446         {
447             try
448             {
449               groupPersist.remove();
450           }
451           catch(Exception e)
452           {
453               BeanTrace.println("Exception: " + e, BeanTrace.WARNING );
454               e.printStackTrace();
455           }
456       }
457           
458         if (rolePersist != null) 
459         {
460             try
461             {
462               rolePersist.remove();
463           }
464           catch(Exception e)
465           {
466               BeanTrace.println("Exception: " + e, BeanTrace.WARNING );
467               e.printStackTrace();
468           }
469       }
470       }
471       catch ( Exception e ) 
472       {
473       }
474     }
475 
476     /**
477     * A notification that signals the intent of the EJB container to remove (destroy) the <br>
478     * entity representation in the EJB server database.  This call may be in response to the client <br>
479     * removing the associated session object or the container will also call ejbRemove when the session <br>
480     * object expires.
481     *
482     * Calls a remove on all of the EJB objects it is holding references to.
483     */
484      
485     public void ejbPassivate() 
486     {
487       try 
488       {
489           super.ejbPassivate();
490           
491         if (groupPersist != null) 
492         {
493             try
494             {
495               groupPersist.remove();
496           }
497           catch(Exception e)
498           {
499               BeanTrace.println("Exception: " + e, BeanTrace.WARNING );
500               e.printStackTrace();
501           }
502       }
503           
504         if (rolePersist != null) 
505         {
506             try
507             {
508               rolePersist.remove();
509           }
510           catch(Exception e)
511           {
512               BeanTrace.println("Exception: " + e, BeanTrace.WARNING );
513               e.printStackTrace();
514           }
515       }
516       }
517       catch ( Exception e ) 
518       {
519       }
520     }
521 
522    /**
523     * Retrieve a FlexGroup data object
524     * Transaction Attribute: Not Supported
525     *
526     * @param aGroupKey a group object reference
527     * @return - a FlexGroup data object
528     *
529     * @exception EjbException - an error occured obtaining an group
530     * @exception RemoteException - Some problem occured with the EJB server
531     */
532     public GroupData getGroup(GroupKey aGroupKey)
533         throws EjbException, RemoteException, NotFoundException 
534     {
535       if ( aGroupKey == null || aGroupKey.getRef() == null ) 
536         throw new NotFoundException("Null Group Key or Ref");
537       
538       groupData = getGroupPersist().getGroup(aGroupKey);
539       return groupData;
540     }
541 
542    /**
543     * Retrieve an FlexGroup data object
544     * Transaction Attribute: Not Supported
545     *
546     * @param aGroupName a group name
547     * @return - FlexGroup data object
548     *
549     * @exception EjbException - an error occured obtaining an group
550     * @exception NotFoundException - Group not found in the database
551     * @exception RemoteException - Some problem occured with the EJB server
552     */
553     public GroupData getGroup(String aGroupName)
554         throws EjbException, RemoteException, NotFoundException
555     {
556       //check to see that the name is not null or empty
557       if (assertNull(aGroupName)) 
558         throw new NotFoundException("Null Group Name");
559 
560       groupData = getGroupPersist().getGroup(aGroupName);
561       return groupData;  
562     }
563 
564     /**
565     * Retrieve the GroupPersist bean associated with this object
566     *
567     * @return com.flexstor.ejb.user.persist.GroupPersist
568     *
569     * @exception com.flexstor.common.exceptions.ejb.EjbException     - Unable to obtain a persist bean 
570     * @exception java.rmi.RemoteException                           - Some problem occured with the EJB server  
571     */
572      
573     private GroupPersist getGroupPersist() 
574         throws EjbException, RemoteException 
575     {
576       if (groupPersist == null) 
577       {
578         try 
579         {
580           GroupPersistHome t_roGroupPersistHome = (GroupPersistHome) getBeanHome(EjbHomeInterfacesI.GROUP_PERSIST_HOME, GroupPersistHome.class);
581           groupPersist = t_roGroupPersistHome.create();        
582         }
583         catch (javax.ejb.CreateException aCreateException) 
584         {
585           throw new EjbException("FlexGroupBean", "getGroupPersist", aCreateException.getMessage(), 5417);
586         }
587         catch (RemoteException aRemoteException)
588         {
589           throw new EjbException("FlexGroupBean", "getGroupPersist", aRemoteException.getMessage(), 5419);    
590         }
591       }
592 
593       return groupPersist;
594     }
595 
596    /**
597     * Retrieve a collection of GroupData
598     * Transaction Attribute: Not Supported
599     *
600     * @param aKey object reference to a collection of groups
601     * @return - GroupData collection with the GroupData name(String) as its key
602     *
603     * @exception EjbException - Unable to query the database for a group collection
604     * @exception RemoteException - Some problem occured with the EJB server
605     *
606     * @see com.flexstor.common.data.ejb.user.GroupData
607     */
608     public Vector getGroups(GroupCollectionKey aKey)
609         throws EjbException, RemoteException, NotFoundException 
610     {
611       //check to see that the key is not null  
612       if ( aKey == null || aKey.getKeys() == null ) 
613             return null;
614             
615       return getGroupPersist().getGroups(aKey);
616     }
617 
618    /**
619     * A user can be assigned to multiple groups, each with a role. This method iterates through
620     * the roles (including the user's default role) and creates a role which is a union of all
621     * the group roles assigned to a user.
622     * Transaction Attribute: Not Supported
623     *
624     * @param aKey object reference to a collection of groups
625     * @param aRoleKey object reference to user's default role
626     * @param anOverrideIndicator override role indicator
627     * @return - a union of all roles
628     *
629     * @exception EjbException - an error occured obtaining an group
630     * @exception RemoteException - Some problem occured with the EJB server
631     */
632     public RoleData getRoleUnion(GroupCollectionKey aGroupCollectionKey, RoleKey aRoleKey )
633         throws EjbException, RemoteException, NotFoundException
634     {
635         int userRoleId = -1;
636 
637       //check to see that the key is not null
638       if (assertNull(aGroupCollectionKey))
639         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey, RoleKey, boolean)", 5410);
640 
641       //check to see that the data object is not null
642       if (assertNull(aRoleKey))
643         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey, RoleKey, boolean)", 5410);
644 
645       RoleData t_roleDataUnion = new RoleData();
646 
647       importSettings   = new Vector();
648       sendSettings     = new Vector();
649       securityRights   = new Vector();
650       emailAddresses   = new Vector();
651       ftpAddresses     = new Vector();
652       servers          = new Vector();
653       disguises        = new Vector();
654       saveSearches     = new Vector();
655       privileges       = new Vector();
656       reportTemplates  = new Vector();
657         preferences      = new Hashtable();
658         wheres           = new Vector();
659 
660       // first, obtain the groups and build a collection of roles
661       Vector t_roleCollection = convertHashtableToVector ( getRoles( aGroupCollectionKey ) );
662 
663     RoleData t_roleData = getRolePersistBean().getRole(aRoleKey);
664     userRoleId = t_roleData.getId();
665     t_roleCollection.addElement( t_roleData );
666 
667     // override set to true, use the user's default role first
668     t_roleDataUnion.setLanguage(t_roleData.getLanguage());
669 
670     //prime all the various collections that need to be tracked
671 //    t_roleDataUnion.setPreference(t_roleData.getPreferences());
672     t_roleDataUnion.setTrackingData(t_roleData.getTrackingData());
673 
674       // iterate across the collection and get the roles associated with each group
675       buildRoleUnion(t_roleCollection, userRoleId);
676 
677       // put the combined values in the new role data object
678       t_roleDataUnion.setUnionSet( true );
679       t_roleDataUnion.setSecurityRights(convertToArray(securityRights));
680       t_roleDataUnion.setEMailAddresses(emailAddresses);
681       t_roleDataUnion.setFtpAddresses(ftpAddresses);
682       t_roleDataUnion.setServers( servers );
683       t_roleDataUnion.setDisguises( disguises );
684       t_roleDataUnion.setPrivileges( privileges );
685         t_roleDataUnion.setSaveSearches( saveSearches );
686         t_roleDataUnion.setImportSettings( importSettings );
687         t_roleDataUnion.setSendSettings( sendSettings );
688         t_roleDataUnion.setReportTemplates( reportTemplates );
689         t_roleDataUnion.setKey(userRoleKey);
690         t_roleDataUnion.setId(userRoleId);
691         t_roleDataUnion.setPreference ( preferences );
692         t_roleDataUnion.setWheres ( wheres );
693 
694       return t_roleDataUnion;
695     }
696 
697    /**
698     * A user can be assigned to multiple groups, each with a role. This method iterates through the roles
699     * of the groups ( whole collection keys are sent as parameter ) and creates a role which is a union of all
700     * those groups. NOTE : the roleKey parameter represents the rolekey  of the user, but this function DOES NOT
701     * user's role into the union. If you want the user's role as wel, use getRoleUnion function.
702     * Transaction Attribute: Not Supported
703     *
704     * @param aGroupCollectionKey object reference to a collection of groups
705     * @param aRoleKey role key of the user
706     * @param anOverrideIndicator override role indicator
707     * @return - a union of all roles
708     *
709     * @exception EjbException - an error occured obtaining an group
710     * @exception RemoteException - Some problem occured with the EJB server
711     */
712     public RoleData getGroupRoleUnion(GroupCollectionKey aGroupCollectionKey, RoleKey aRoleKey )
713         throws EjbException, RemoteException, NotFoundException
714     {
715 
716       //check to see that the key is not null
717       if (assertNull(aGroupCollectionKey))
718         throw new EjbException("FlexGroupBean", "getRoleUnion(GroupCollectionKey)", 5410);
719 
720          //check to see that the data object is not null
721       if (assertNull(aRoleKey))
722         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey, RoleKey, boolean)", 5410);
723 
724 
725       RoleData t_roleDataUnion = new RoleData();
726 
727       importSettings   = new Vector();
728       sendSettings     = new Vector();
729       securityRights   = new Vector();
730       emailAddresses   = new Vector();
731       ftpAddresses     = new Vector();
732       servers          = new Vector();
733       disguises        = new Vector();
734       saveSearches     = new Vector();
735       privileges       = new Vector();
736       reportTemplates  = new Vector();
737         preferences      = new Hashtable();
738         wheres           = new Vector();
739 
740       // first, obtain the groups and build a collection of roles
741       Vector t_roleCollection = convertHashtableToVector ( getRoles( aGroupCollectionKey ) );
742 
743     RoleData t_roleData = getRolePersistBean().getRole(aRoleKey);
744     userRoleId = t_roleData.getId();
745 //    t_roleCollection.put( new Integer( t_roleData.getId()), t_roleData );
746 
747     // override set to true, use the user's default role first
748         t_roleDataUnion.setKey ( aRoleKey );
749     t_roleDataUnion.setLanguage(t_roleData.getLanguage());
750 
751     //prime all the various collections that need to be tracked
752     t_roleDataUnion.setTrackingData(t_roleData.getTrackingData());
753 
754       // iterate across the collection and get the roles associated with each group
755       buildRoleUnion(t_roleCollection, userRoleId);
756 
757       // put the combined values in the new role data object
758       t_roleDataUnion.setUnionSet( true );
759       t_roleDataUnion.setSecurityRights(convertToArray(securityRights));
760       t_roleDataUnion.setEMailAddresses(emailAddresses);
761       t_roleDataUnion.setFtpAddresses(ftpAddresses);
762       t_roleDataUnion.setServers( servers );
763       t_roleDataUnion.setDisguises( disguises );
764       t_roleDataUnion.setPrivileges( privileges );
765         t_roleDataUnion.setSaveSearches( saveSearches );
766         t_roleDataUnion.setImportSettings( importSettings );
767         t_roleDataUnion.setSendSettings( sendSettings );
768         t_roleDataUnion.setReportTemplates( reportTemplates );
769 //        t_roleDataUnion.setKey(userRoleKey);
770         t_roleDataUnion.setId(userRoleId);
771         // for preferences
772       t_roleDataUnion.setPreference( preferences );
773         t_roleDataUnion.setWheres    ( wheres );
774       return t_roleDataUnion;
775     }
776 
777 
778     /**
779     * Obtain a reference to a RolePersist bean
780     *
781     * @return com.flexstor.ejb.user.persist.RolePersist               - an RolePersist bean
782     *
783     * @exception com.flexstor.common.exceptions.ejb.EjbException      - Could not create RolePersist bean
784     * @exception java.rmi.RemoteException                            - Some problem occured with the EJB server  
785     */
786      
787     private RolePersist getRolePersistBean() throws EjbException, RemoteException 
788     {
789       if (rolePersist == null) 
790       {
791         try 
792         {
793           RolePersistHome t_roleHome = (RolePersistHome) getBeanHome(EjbHomeInterfacesI.ROLE_HOME, RolePersistHome.class);
794           rolePersist = t_roleHome.create();
795         }
796         catch (javax.ejb.CreateException aCreateException) 
797         {
798           throw new EjbException("FlexGroupBean", "getRolePersist", aCreateException.getMessage(), 5417);
799         }
800         catch (RemoteException aRemoteException) 
801         {
802           throw new EjbException("FlexGroupBean", "getRolePersist", aRemoteException.getMessage(), 5419);    
803         }
804       }
805       
806       return rolePersist;
807     }
808 
809    /**
810     * Retrieve all roles associated with the groups identified by this object reference
811     * Transaction Attribute: Not Supported
812     *
813     * @param aGroupCollectionKey a group object reference
814     * @return - collection of Role data objects
815     *
816     * @exception EjbException - Could not obtain a RolePersist bean
817     * @exception RemoteException - Some problem occured with the EJB server
818     *
819     * @see com.flexstor.common.data.ejb.role.RoleData
820     */
821     public Hashtable getRoles(GroupCollectionKey aGroupCollectionKey)
822         throws EjbException, RemoteException, NotFoundException
823     {
824       //check to see that the key is not null  
825       if (assertNull(aGroupCollectionKey)) 
826         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey)", 5410);    
827 
828         Vector vec = getGroupPersist().getGroups(aGroupCollectionKey);
829 
830         if ( vec == null )
831             return new Hashtable();
832             
833       Hashtable t_roleCollection = null;
834       
835       if (vec.size() > 0) 
836       {
837         t_roleCollection = new Hashtable( vec.size() );
838 
839         GroupData t_groupData = null;
840         RoleData t_roleData = null;
841         
842             for ( int i = 0; i < vec.size() ; i++ )
843         {
844           t_groupData = (GroupData)vec.elementAt( i );
845           t_roleData = getRolePersistBean().getRole(t_groupData.getRoleKey());
846 
847           t_roleCollection.put(new Integer(t_roleData.getId()), t_roleData);
848         }
849       }
850       else 
851         t_roleCollection = new Hashtable();
852 
853       return t_roleCollection;
854     }
855 
856    /**
857     * Retrieve all roles associated with the groups identified by the object references
858     * Transaction Attribute: Not Supported
859     *
860     * @param aGroupCollectionKey object reference to a collection of groups
861     * @param aRoleKey object reference to user's default role
862     * @return - a collection of all roles
863     *
864     * @exception EjbException - an error occured obtaining an group
865     * @exception RemoteException - Some problem occured with the EJB server
866     */
867     public Hashtable getRoles(GroupCollectionKey aGroupCollectionKey, RoleKey aRoleKey)
868         throws EjbException, RemoteException , NotFoundException
869     {
870       //check to see that the key is not null  
871       if (assertNull(aGroupCollectionKey)) 
872         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey, RoleKey)", 5410);    
873 
874       //check to see that the data object is not null  
875       if (assertNull(aRoleKey)) 
876         throw new EjbException("FlexGroupBean", "getRoles(GroupCollectionKey, RoleKey)", 5410);    
877         
878       Hashtable t_roleCollection = getRoles(aGroupCollectionKey);
879       RoleData t_roleData = getRolePersistBean().getRole(aRoleKey);
880       t_roleCollection.put(new Integer(t_roleData.getId()), t_roleData);
881         
882       return t_roleCollection;
883     }
884 
885    /**
886     * Retrieve the role associated with the cached group
887     * Transaction Attribute: Not Supported
888     *
889     * @return a RoleData object
890     *
891     * @exception EjbException - an error occured obtaining an group
892     * @exception RemoteException - Some problem occured with the EJB server
893     */
894     public RoleData getRole()
895         throws EjbException, RemoteException, NotFoundException
896     {
897       //check to see that the key is not null  
898       if ( groupData == null ) 
899         throw new RemoteException("Cached Group Is Null: need to use create(group) or getGroup()");    
900 
901       return getRolePersistBean().getRole( groupData.getRoleKey() );
902     }
903     // removes duplicate keys and creates a vector of unique atomic keys !
904     private Vector removeDuplicates ( Vector collectionKeys )
905     {
906         if ( collectionKeys == null )
907           return null;
908 
909         Vector          uniqueKeysColl = new Vector();
910         Vector          superKeys      = null;
911         CollectionKey collKeys       = null;
912         FlexKey           key            = null;
913 
914         for ( int i=0; i<collectionKeys.size(); i++ )
915         {
916            collKeys = ( CollectionKey ) collectionKeys.elementAt ( i );
917            
918            if ( collKeys != null )
919            {
920              superKeys = collKeys.getSuperKeys();
921              if ( superKeys != null )
922              {
923                  BeanTrace.println ("[ DEBUG ] removeDuplicates: No of keys From Role : "+i+" : "+superKeys.size(), BeanTrace.DEBUG);
924                  for ( int k=0; k<superKeys.size(); k++ )
925                  {
926                     key = ( FlexKey ) superKeys.elementAt( k );
927                     if ( key != null )
928                     {
929                       if ( !( uniqueKeysColl.contains ( key ) ) )
930                       {
931                         uniqueKeysColl.addElement ( key );
932                       }
933                     }
934                  }
935               }
936             }
937          }
938          BeanTrace.println ("[ DEBUG ]Number of unique keys now "+uniqueKeysColl.size(), BeanTrace.DEBUG);
939          return  uniqueKeysColl;
940     }
941 }