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

Quick Search    Search Deep

Source code: com/flexstor/common/data/ejb/user/UserData.java


1   /*
2    * UserData.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:48 $ 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.common.data.ejb.user;
12  
13  import java.sql.Timestamp;
14  import java.util.Vector;
15  
16  import com.flexstor.common.data.ejb.Data;
17  import com.flexstor.common.data.ejb.property.PropertyData;
18  import com.flexstor.common.data.ejb.property.PropertyDataBuild;
19  import com.flexstor.common.data.ejb.role.RoleData;
20  import com.flexstor.common.keys.ejb.EmailAddressKey;
21  import com.flexstor.common.keys.ejb.FtpAddressKey;
22  import com.flexstor.common.keys.ejb.GroupCollectionKey;
23  import com.flexstor.common.keys.ejb.RoleKey;
24  import com.flexstor.common.keys.ejb.UserKey;
25  
26  /**
27   * This class supports state data for <code>User</code>.  A Data class holds <br>
28   * all of the state information for a corresponding class and reference <br>
29   * pointers to other classes <br>
30   *
31   * @author  Perry Hoekstra
32   * @version 1.0, 10/19/98
33   *
34   * @since   FLEXSTOR.db 3.0
35   */
36   
37  public class UserData extends Data {
38      
39    // unique id that identifier a user to FLEXSTOR.db
40    protected String userid;
41  
42    // encrypted password that allows a user access to a FLEXSTOR.db system
43    protected String password;
44  
45    // first name of user
46    protected String firstName;
47  
48    // last name of the user
49    protected String lastName;
50  
51    // indicates that when properties of the user's default role and a group role conflict, which properties are used  
52    protected String overrideRole;
53  
54    // timestamp of record in database when the object was retrieved
55    protected Timestamp currentTimestamp;
56  
57    // object reference to this instance in the database  
58    protected UserKey userKey;
59  
60    // reference to the user's role
61    protected RoleData roleData;
62  
63    // reference to a collection of groups that a user belongs to
64    protected GroupCollectionKey groupKey;
65    
66    // reference to a user's email address
67    protected EmailAddressKey emailAddressKey;
68  
69      protected String sFtpAddress = null;
70      protected String sEmailAddress = null;
71      
72    // reference to a user's default ftp server
73    protected FtpAddressKey ftpAddressKey;
74  
75    //reference to a users properties.  These can be "client" specific
76    protected Vector properties = new Vector();
77    
78    // This is a Vector that holds a list of GroupData objects assigned to this user by the Admin Tool
79    protected Vector vAssignedGroups;
80    
81  /** 
82   * Default constructor for the UserData class<p>
83   *
84   * <b>Warning</b> Any objects created with this constructor are not updatable or insertable to the database  
85   */
86   
87  public UserData() {
88    super();
89  }
90  /** 
91   * Constructor for the UserData class<p>
92   *
93   * <b>Warning</b> Any objects created with this constructor are not updatable (insertable, but not updatable) to the database
94   * 
95   * @param java.lang.String  a userid
96   * @param java.lang.String  a password
97   */
98   
99  public UserData(String aUserID, String aPassword) {
100   userid = aUserID;
101   password = aPassword;
102 }
103 
104    /**
105     * Determine if these two objects are equal, i.e. their attributes are equal.  
106     * This method <b>will not</b> test the equality of references to other objects
107     *
108     * @param com.flexstor.common.data.ejb.user.UserData  a data object to compare
109     *
110     * @return boolean <code>true</code> if the objects are equal; <code>false</code> if they are not
111     */
112    public boolean equals(Object o) 
113    {
114       if ( o != null && o instanceof UserData )
115       {
116          String otherUserId = ((UserData)o).getUserID();
117          
118          if ( userid != null && otherUserId != null )
119             return userid.equals(otherUserId);
120       }
121       
122       return false;
123    }
124 
125    public int hashCode()
126    {
127       return getUserID().hashCode();
128    }
129    
130 /**
131  * Return an object reference to user's email address
132  *
133  * @return com.flexstor.common.keys.ejb.EmailAddressKey - an object reference
134  */
135  
136 public EmailAddressKey getEMailAddressKey() {
137   return emailAddressKey;
138 }
139 /**
140  * Return the user's first name
141  *
142  * @return java.lang.String
143  */
144  
145 public java.lang.String getFirstName() {
146   // perform lazy initialization
147   if (firstName == null) {
148     firstName = new String();
149   }
150   
151   return firstName;
152 }
153 /**
154  * Return an object reference to user's default ftp server
155  *
156  * @return com.flexstor.common.keys.ejb.FtpAddressKey - an object reference
157  */
158  
159 public FtpAddressKey getFtpAddressKey() {
160   return ftpAddressKey;
161 }
162 /**
163  * Return an object reference to collection of groups the user is assigned to
164  *
165  * @return com.flexstor.common.keys.ejb.GroupCollectionKey - an object reference to a collection of Groups
166  */
167  
168 public GroupCollectionKey getGroupKey() {
169   return groupKey;
170 }
171 /**
172  * Return the user's last name
173  *
174  * @return java.lang.String
175  */
176  
177 public java.lang.String getLastName() {
178   // perform lazy initialization
179   if (lastName == null) {
180     lastName = new String();
181   }
182   
183   return lastName;
184 }
185 /**
186  * Return the boolean indicator that states whether a user's
187  * individual Role or the Group Role should be used when properties
188  * in those roles conflict.  An example is default language.
189  *
190  * @return boolean
191  */
192  
193 public boolean getOverrideRole() {
194   if (overrideRole.equals("Y")) {
195     return true;
196   }
197   else {
198     return false;
199   }
200 }
201 /**
202  * Return the String indicator that states whether a user's
203  * individual Role or the Group Role should be used.<br>
204  * <p>
205  * "Y" = Yes
206  * "N" = No
207  *
208  * @return java.lang.String
209  */
210  
211 public String getOverrideRoleAsIndicator() {
212   // perform lazy initialization
213   if (overrideRole == null) {
214     overrideRole = "N";
215   }
216     
217   return overrideRole;
218 }
219 /**
220  * Return the user's encrypted password
221  *
222  * @return java.lang.String
223  */
224  
225 public java.lang.String getPassword() {
226   // perform lazy initialization
227   if (password == null) {
228     password = new String();
229   }
230   
231   return password;
232 }
233 /**
234  * Return the reference to this object
235  *
236  * @return com.flexstor.common.keys.ejb.UserKey - an object reference
237  * @deprecated see getKey()
238  */
239  
240 public UserKey getReference() {
241   return userKey;
242 }
243     /**
244     * Return the reference to this object
245     *
246     * @return com.flexstor.common.keys.ejb.UserKey - an object reference
247     */
248      
249     public UserKey getKey() 
250     {
251       return userKey;
252     }
253 
254    /**
255     * Return the user's role data
256     *
257     * @return com.flexstor.common.data.ejb.role.RoleData - the role data for this user
258     */
259    public RoleData getRoleData() 
260    {
261       if ( roleData == null )
262          roleData = new RoleData();
263       return roleData;
264    }
265    
266    /**
267     * Return an object reference to user's default role
268     *
269     * @return com.flexstor.common.keys.ejb.RoleKey - an object reference
270     */
271    public RoleKey getRoleKey() 
272    {
273       if ( roleData != null )
274          return roleData.getKey();
275       else
276          return null;
277    }
278    
279 /**
280  * Return the timestamp of this object in database when the object was retrieved
281  *
282  * @return java.sql.Timestamp
283  */
284  
285 public Timestamp getTimestamp() {
286   return currentTimestamp;
287 }
288 /**
289  * Return the user's id that uniquely identifies the user to the FLEXSTOR system
290  *
291  * @return java.lang.String
292  */
293  
294 public String getUserID() {
295   // perform lazy initialization
296   if (userid == null) {
297     userid = new String();
298   }
299     
300   return userid;
301 }
302 
303 /**
304  * Assign an email address to a user
305  *
306  * @param com.flexstor.common.keys.ejb.EmailAddressKey  an object reference to a user's email address
307  */
308  
309 public void setEMailAddress(EmailAddressKey anEMailAddressKey) {
310   emailAddressKey = anEMailAddressKey;
311 }
312 /**
313  * Assign the primary key to the user's email address
314  *
315  * @param com.flexstor.common.keys.ejb.EmailAddressKey  Primary key to user's email address
316  */
317  
318 public void setEMailAddressKey(EmailAddressKey aKey) {
319   emailAddressKey = aKey;
320 }
321 
322     /**
323     * Set the String email address. For the full email address,
324     * the user should use the EMailPersistBean.
325     */
326     public void setEmailAddress( String addr )
327     {
328         sEmailAddress = addr;
329     }
330     
331     /**
332     * Set the String ftp address. For the full ftp address,
333     * the user should use the FtpPersistBean.
334     */
335     public void setFtpAddress( String addr )
336     {
337         sFtpAddress = addr;
338     }
339     
340     /** 
341     * This will retrieve the String email address.
342     */
343     public String getEmailAddress()
344     {
345         return sEmailAddress;
346     }
347 
348     /** 
349     * This will retrieve the String ftp address.
350     */
351     public String getFtpAddress()
352     {
353         return sFtpAddress;
354     }
355 
356     /** 
357     * This will get the language definition for user
358     */ 
359     public String getLanguage()
360     {
361        if ( roleData != null )
362           return roleData.getLanguage();
363        else
364           return null;
365     }
366     
367     /** 
368     * This will set the language definition for user
369     */ 
370     public void setLanguage( String lang )
371     {
372        if ( roleData == null )
373           roleData = new RoleData();
374           
375        roleData.setLanguage(lang);
376     }
377     
378 /**
379  * Assign the user's first name
380  *
381  * @param java.lang.String   A user's first name
382  */
383  
384 public void setFirstName(java.lang.String aFirstName) {
385   firstName = aFirstName;
386 }
387 /**
388  * Assign an ftp address to auser
389  *
390  * @param com.flexstor.common.keys.ejb.FtpAddressKey  an object reference to a user's ftp address
391  */
392  
393 public void setFtpAddress(FtpAddressKey anFtpAddressKey) {
394   ftpAddressKey = anFtpAddressKey;
395 }
396 /**
397  * Assign the primary key to the user's ftp address
398  *
399  * @param com.flexstor.common.keys.ejb.FtpAddressKey  Primary key to user's ftp address
400  */
401  
402 public void setFtpAddressKey(FtpAddressKey aKey) {
403   ftpAddressKey = aKey;
404 }
405 
406 /**
407  * Assign the primary key to a user's collection of groups
408  *
409  * @param com.flexstor.common.keys.ejb.GroupKey  Primary key to user's groups
410  */
411  
412 public void setGroupKey(GroupCollectionKey aKey) {
413   groupKey = aKey;
414 }
415 /**
416  * Assign the user's last name
417  *
418  * @param java.lang.String   A user's last name
419  */
420  
421 public void setLastName(java.lang.String aLastName) {
422   lastName = aLastName;
423 }
424 /**
425  * Assign the user's override indicator.  This switch states
426  * whether a user's individual Role or the Group Role should be used.
427  *
428  * @param java.lang.String   An override indicator <br>
429  *                           in the form of "Y" or "N"
430  */
431  
432 public void setOverrideRole(String aOverrideIndicator) {
433   overrideRole = aOverrideIndicator;
434 }
435 /**
436  * Assign the user's password
437  *
438  * @param java.lang.String   an encrypted password
439  */
440  
441 public void setPassword(String aPassword) {
442   password = aPassword;  
443 }
444 /**
445  * Assign the reference to this record
446  *
447  * @param com.flexstor.common.keys.ejb.UserKey  Reference to this record
448  * @deprecated see setKey()
449  */
450  
451 public void setReference(UserKey aKey) {
452   userKey = aKey;  
453 }
454 
455     /**
456     * Assign the reference to this record
457     *
458     * @param com.flexstor.common.keys.ejb.UserKey  Reference to this record
459     */
460      
461     public void setKey(UserKey aKey) 
462     {
463       userKey = aKey;  
464     }
465 
466    /**
467     * Assign a role to a user
468     *
469     * @param com.flexstor.common.data.ejb.role.RoleData  an object reference to the user's role
470     */
471    public void setRoleData(RoleData aRoleData) 
472    {
473      roleData = aRoleData;
474    }
475    
476    /**
477     * Assign the primary key to the user's role
478     *
479     * @param com.flexstor.common.keys.ejb.RoleKey  Primary key to user's role
480     */
481    public void setRoleKey(RoleKey aKey) 
482    {
483       if ( roleData == null )
484          roleData = new RoleData();
485          
486      roleData.setKey(aKey);
487    }
488    
489 /**
490  * Assign the current timestamp of the object
491  *
492  * @param java.sql.Timestamp   current timestamp of the database object
493  */
494  
495 public void setTimestamp(Timestamp aTimeStamp) {
496   currentTimestamp = aTimeStamp;
497 }
498 /**
499  * Assign the user's identification
500  *
501  * @param java.lang.String   A userid
502  */
503  
504 public void setUserID(String aUserID) {
505   userid = aUserID;  
506 }
507 /**
508  * Return the contents of the instance as a String.  This method is strictly for use by testing classes
509  * and should not be called by business objects
510  *
511  * @return java.lang.String  String representation of UserData contents
512  * 
513  */
514 
515  
516  /**
517     * This will return a list of properties.
518     *
519     * @return java.util.Vector - A list of PropertyData objects
520     */
521     public Vector getPropertyDataObjects()
522     {
523         properties.trimToSize();
524         return properties;
525     }
526 
527     /**
528     * Get property where it accepts a property String and returns the
529     * value
530     *
531     * @return String - Value
532     */
533 public String getProperty( String key )
534     {
535         if ( properties == null )
536             return null;
537 
538         for ( int i = 0; i < properties.size() ; i++ )
539         {
540             PropertyData _dat = (PropertyData)properties.elementAt( i );
541 
542             if ( _dat.getPropertyKey().compareTo( key ) == 0 )
543                 return _dat.getPropertyValue();
544         }
545 
546         return null;
547     }
548 
549     /**
550     * Set a list of properties.  Vector is a collection of import com.flexstor.common.data.ejb.property.PropertyData objects
551     *
552     * @return void
553     */
554     public void setPropertyDataObjects(Vector props)
555     {
556         props.trimToSize();
557         properties = props;
558     }
559 
560     /**
561     * Set a property where it accepts a property String and value
562     *
563     * @return void
564     *
565     */
566     public void setProperty( String key, String value )
567     {
568 
569       //See if this property exists in the given vector of props
570       int nSize = properties.size();
571       boolean bNew = true;
572       for (int i = 0; i < nSize; i++)
573       {
574         PropertyDataBuild myProp = (PropertyDataBuild)properties.elementAt(i);
575         if (myProp.getPropertyKey().equals(key))
576         {
577            //Update this property
578            bNew = false;
579            myProp.setPropertyValue(value);
580            //stop the loop
581            i = nSize;
582 
583         }
584       }
585 
586       if (bNew)
587       {
588         //create the data object and then add to properties
589         PropertyDataBuild prop = new PropertyDataBuild();
590         prop.setPropertyKey(key);
591         prop.setPropertyValue(value);
592 
593         //Add the data object to the properties vector
594         properties.addElement( (PropertyData)prop );
595       }
596     }
597 
598    /**
599     * Sets the list of GroupData objects for the groups this user has been assigned to 
600     * through the Admin Tool.
601     * This method will be invoked by the Admin Tool prior to calling the UserPersistBean
602     * to update the database.
603     * 
604     * @param vAssignedGroups A Vector of GroupData objects
605     */
606    public void setAssignedGroups( Vector vAssignedGroups ) { this.vAssignedGroups = vAssignedGroups; }
607 
608    /**
609     * Gets the list of GroupData objects for the groups this user has been assigned to
610     * through the Admin Tool.
611     * This method will be invoked by the UserPersistBean to update the database.
612     * 
613     * @return A vector of GroupData objects
614     */
615    public Vector getAssignedGroups() { return vAssignedGroups; }
616 
617 public String toString() {
618   String t_lineSeparator = System.getProperty("line.separator", "\n");
619 
620   StringBuffer t_roUserDataContents = new StringBuffer(t_lineSeparator);
621     
622   t_roUserDataContents.append("Class: UserData\n");
623   t_roUserDataContents.append(t_lineSeparator);
624   
625   t_roUserDataContents.append("UserID: ");
626   t_roUserDataContents.append(getUserID());
627   t_roUserDataContents.append(t_lineSeparator);
628   
629   t_roUserDataContents.append("FirstName: ");
630   t_roUserDataContents.append(getFirstName());
631   t_roUserDataContents.append(t_lineSeparator);
632 
633   t_roUserDataContents.append("LastName: ");
634   t_roUserDataContents.append(getLastName());
635   t_roUserDataContents.append(t_lineSeparator);
636 
637   t_roUserDataContents.append("OverrideRole: ");
638   t_roUserDataContents.append(getOverrideRole());
639   t_roUserDataContents.append(t_lineSeparator);
640   
641   return t_roUserDataContents.toString();  
642 }
643 }