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

Quick Search    Search Deep

Source code: com/clra/web/MemberInfoForm.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: MemberInfoForm.java,v $
5    * $Date: 2003/03/02 15:32:06 $
6    * $Revision: 1.16 $
7    */
8   
9   package com.clra.web;
10  
11  import com.clra.member.AccountType;
12  import com.clra.member.Address;
13  import com.clra.member.Email;
14  import com.clra.member.MemberName;
15  import com.clra.member.MemberRole;
16  import com.clra.member.Telephone;
17  import com.clra.util.ValidationException;
18  
19  import java.text.SimpleDateFormat;
20  import java.io.IOException;
21  import java.util.Calendar;
22  import java.util.Date;
23  import java.util.HashSet;
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.Set;
27  import javax.servlet.http.HttpServletRequest;
28  import org.apache.log4j.Category;
29  import org.apache.struts.action.ActionError;
30  import org.apache.struts.action.ActionErrors;
31  import org.apache.struts.action.ActionForm;
32  import org.apache.struts.action.ActionMapping;
33  
34  /**
35   * Form bean for the user profile page.
36   * 
37   * @author <a href="mailto:jmstone@nerc.com">Jan Stone</a>
38   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
39   */
40  public class MemberInfoForm extends ActionForm  {
41  
42    private final  static String base = MemberInfoForm.class.getName();
43    private final  static Category theLog = Category.getInstance( base );
44  
45    /**
46     * Indicates the purpose of this workflow is to edit an
47     * existing member with restrictions (by a member of the club)
48     */
49    public final static String FUNCTION_MEMBEREDIT = "MemberEdit";
50  
51    /**
52     * Indicates the purpose of this workflow is to create
53     * a new member.
54     */
55    public final static String FUNCTION_ADMINCREATE = "AdminCreate";
56  
57    /**
58     * Indicates the purpose of this workflow is to edit an
59     * existing member without restriction (by an admin of the club)
60     */
61    public final static String FUNCTION_ADMINEDIT = "AdminEdit";
62  
63    public static String[] validFunctions() {
64      return new String[] {
65        FUNCTION_MEMBEREDIT, FUNCTION_ADMINCREATE, FUNCTION_ADMINEDIT
66      };
67    }
68  
69    private String function = null; // required
70  
71    private String first  = null; // required
72    private String middle = null; // optional
73    private String last   = null; // required
74    private String suffix = null; // optional
75  
76    private Integer id = null;                 // optional during creation
77    private String accountName = null;         // required
78    private String accountNameOriginal = null; // workflow flag
79    private String accountPassword = null;     // required
80    private String confirmPassword = null;     // required
81  
82    private Calendar birthDate  = null; // optional
83  
84    private int accountYear = -1;        // required
85    private String strAccountType = null; // required
86  
87    private Set accountRoles = new HashSet(); // optional (but typical)
88  
89    private String emailAddr = null;  // optional
90  
91    private String phoneEveningAreaCode = null; // required
92    private String phoneEveningExchange = null; // required
93    private String phoneEveningLocal    = null; // required
94    private String phoneEveningExt      = null; // optional
95  
96    private String phoneDayAreaCode = null; // optional
97    private String phoneDayExchange = null; // optional
98    private String phoneDayLocal    = null; // optional
99    private String phoneDayExt      = null; // optional
100 
101   private String phoneOtherAreaCode = null; // optional
102   private String phoneOtherExchange = null; // optional
103   private String phoneOtherLocal    = null; // optional
104   private String phoneOtherExt      = null; // optional
105 
106   private String street1 = null; // required
107   private String street2 = null; // optional
108   private String city    = null; // required
109   private String state   = null; // required
110   private String zip     = null; // required
111 
112   public String getFunction() {
113     return this.function;
114   }
115 
116   public void setFunction(String f) {
117     this.function = f == null ? null : f ;
118   }
119 
120   public boolean isAdminCreate() {
121     return FUNCTION_ADMINCREATE.equalsIgnoreCase( this.function ) ;
122   }
123 
124   public boolean isAdminEdit() {
125     return FUNCTION_ADMINEDIT.equalsIgnoreCase( this.function ) ;
126   }
127 
128   public boolean isMemberEdit() {
129     return FUNCTION_MEMBEREDIT.equalsIgnoreCase( this.function ) ;
130   }
131 
132   public boolean isRestricted() {
133     return !( this.isAdminCreate() || this.isAdminEdit() );
134   }
135 
136   public String getFirstName() {
137     return this.first;
138   }
139 
140   public void setFirstName(String nm) {
141     this.first = nm == null ? null : nm.trim() ;
142   }
143 
144   public boolean hasMiddleName() {
145     return this.middle != null;
146   }
147 
148   public String getMiddleName() {
149     return this.middle;
150   }
151 
152   public void setMiddleName(String nm ) {
153     this.middle = nm == null ? null : nm.trim() ;
154   }
155 
156   public String getLastName() {
157     return this.last;
158   }
159 
160   public void setLastName(String nm) {
161     this.last = nm == null ? null : nm.trim() ;
162   }
163 
164   public boolean hasSuffix() {
165     return this.suffix != null;
166   }
167 
168   public String getSuffix() {
169     return this.suffix;
170   }
171 
172   public void setSuffix(String s) {
173     this.suffix = s == null ? null : s.trim() ;
174   }
175 
176   public String getFullName() {
177 
178     StringBuffer sb = new StringBuffer();
179     sb.append( getFirstName() );
180     sb.append( " " );
181     if ( hasMiddleName() ) {
182       sb.append( getMiddleName() );
183       sb.append( " " );
184     }
185     sb.append( getLastName() );
186     if ( hasSuffix() ) {
187       sb.append( " " );
188       sb.append( getSuffix() );
189     }
190 
191     String retVal = new String(sb);
192 
193     return retVal;
194   } // getFullName()
195 
196   public Integer getId() {
197     if ( this.id == null
198           && !getFunction().equalsIgnoreCase(FUNCTION_ADMINCREATE) ) {
199       throw new IllegalStateException( "null id && function != ADMINCREATE" );
200     }
201     return this.id;
202   }
203 
204   public void setId( Integer I ) {
205     this.id = I;
206   }
207 
208   public String getAccountNameOriginal() {
209     return this.accountNameOriginal;
210   }
211 
212   public void setAccountNameOriginal( String str ) {
213     this.accountNameOriginal = str == null ? null : str.trim() ;
214   } 
215 
216   public String getAccountName() {
217     return this.accountName;
218   }
219 
220   public void setAccountName( String str ) {
221     this.accountName = str == null ? null : str.trim() ;
222   } 
223 
224   public String getAccountPassword() {
225     return this.accountPassword;
226   }
227 
228   public void setAccountPassword( String str ) {
229     this.accountPassword = str == null ? null : str.trim() ;
230   } 
231 
232   public String getConfirmPassword() {
233     return this.confirmPassword;
234   }
235 
236   public void setConfirmPassword( String str ) {
237     this.confirmPassword = str == null ? null : str.trim() ;
238   }
239 
240   public boolean getHasKnownBirthDate() {
241     return birthDate != null;
242   }
243 
244   public void setBirthDate( Date d ) {
245     if ( d == null ) {
246       this.birthDate = null;
247     } else {
248       if ( this.birthDate == null ) {
249         this.birthDate = Calendar.getInstance();
250       }
251       this.birthDate.setTime( d );
252     }
253   }
254 
255   public int getBirthMonthInt() {
256     int retVal = -1;
257     if ( this.getHasKnownBirthDate() ) {
258       retVal = this.birthDate.get(Calendar.MONTH) + 1;
259     }
260     return retVal;
261   }
262 
263   public int getBirthDayInt() {
264     int retVal = -1;
265     if ( this.getHasKnownBirthDate() ) {
266       retVal = this.birthDate.get(Calendar.DAY_OF_MONTH);
267     }
268     return retVal;
269   }
270 
271   public int getBirthYearInt() {
272     int retVal = -1;
273     if ( this.getHasKnownBirthDate() ) {
274       retVal = this.birthDate.get(Calendar.YEAR);
275     }
276     return retVal;
277   }
278 
279   public String getBirthMonth() {
280     String retVal = "";
281     if ( this.getHasKnownBirthDate() ) {
282       retVal = "" + this.getBirthMonthInt();
283     }
284     return retVal;
285   }
286 
287   public String getBirthDay() {
288     String retVal = "";
289     if ( this.getHasKnownBirthDate() ) {
290       retVal = "" + getBirthDayInt();
291     }
292     return retVal;
293   }
294 
295   public String getBirthYear() {
296     String retVal = "";
297     if ( this.getHasKnownBirthDate() ) {
298       retVal = "" + getBirthYearInt();
299     }
300     return retVal;
301   }
302 
303   public void setBirthMonth( String s )  {
304     if ( s != null && s.trim().length() > 0 ) {
305       final int m = Integer.parseInt(s.trim()) - 1;
306       if ( 0 < m && m < 13 ) {
307         if ( this.birthDate == null ) {
308           this.birthDate = Calendar.getInstance();
309         }
310         this.birthDate.set(Calendar.MONTH,m);
311       }
312     }
313   }
314 
315   public void setBirthDay( String s ) {
316     if ( s != null && s.trim().length() > 0 ) {
317       final int d = Integer.parseInt(s.trim());
318       if ( 0 < d && d < 32 ) {
319         if ( this.birthDate == null ) {
320           this.birthDate = Calendar.getInstance();
321         }
322         this.birthDate.set(Calendar.DAY_OF_MONTH,d);
323       }
324     }
325   }
326 
327   public void setBirthYear( String s ) {
328     if ( s != null && s.trim().length() > 0 ) {
329       final int y = Integer.parseInt(s.trim());
330       if ( 1900 < y && y < 2032 ) {
331         if ( this.birthDate == null ) {
332           this.birthDate = Calendar.getInstance();
333         }
334         this.birthDate.set(Calendar.YEAR,y);
335       }
336     }
337   }
338 
339   public int getAccountYear() {
340     return this.accountYear;
341   }
342 
343   public void setAccountYear( int s ) {
344     this.accountYear = s;
345   } 
346   
347   public String getAccountTypeStr() {
348     return this.strAccountType;
349   }
350 
351   public void setAccountTypeStr( String str ) {
352     this.strAccountType = str == null ? null : str.trim() ;
353   }
354 
355   public MemberRole[] getMemberRoles() {
356     MemberRole[] retVal =
357       (MemberRole[]) accountRoles.toArray(new MemberRole[0]);
358     return retVal;
359   }
360 
361   public void setMemberRoles( MemberRole[] roles ) {
362     if ( roles == null ) {
363       throw new IllegalArgumentException( "null role array" );
364     }
365     accountRoles = new HashSet();
366     for ( int i=0; i<roles.length; i++ ) {
367       if ( roles[i] == null ) {
368         throw new IllegalArgumentException( "null role" );
369       }
370       accountRoles.add( roles[i] );
371     }
372     return;
373   } // setMemberRoles(MemberRole[])
374 
375   public boolean isCaptain() {
376     return accountRoles.contains( MemberRole.CAPTAIN );
377   }
378 
379   public void setCaptain( boolean isCaptain ) {
380     if ( isCaptain ) {
381       accountRoles.add( MemberRole.CAPTAIN );
382     } else {
383       accountRoles.remove( MemberRole.CAPTAIN );
384     }
385     return;
386   } // setCaptain(boolean)
387 
388   public boolean isCoach() {
389     return accountRoles.contains( MemberRole.COACH );
390   }
391 
392   public void setCoach( boolean isCoach ) {
393     if ( isCoach ) {
394       accountRoles.add( MemberRole.COACH );
395     } else {
396       accountRoles.remove( MemberRole.COACH );
397     }
398     return;
399   } // setCoach(boolean)
400 
401   public boolean isMember() {
402     return accountRoles.contains( MemberRole.MEMBER );
403   }
404 
405   public void setMember( boolean isMember ) {
406     if ( isMember ) {
407       accountRoles.add( MemberRole.MEMBER );
408     } else {
409       accountRoles.remove( MemberRole.MEMBER );
410     }
411     return;
412   } // setMember(boolean)
413 
414   public boolean isMemberManager() {
415     return accountRoles.contains( MemberRole.MEMBERMGR );
416   }
417 
418   public void setMemberManager( boolean isMemberManager ) {
419     if ( isMemberManager ) {
420       accountRoles.add( MemberRole.MEMBERMGR );
421     } else {
422       accountRoles.remove( MemberRole.MEMBERMGR );
423     }
424     return;
425   } // setMemberManager(boolean)
426 
427   public boolean isSessionManager() {
428     return accountRoles.contains( MemberRole.SESSIONMGR );
429   }
430 
431   public void setSessionManager( boolean isSessionManager ) {
432     if ( isSessionManager ) {
433       accountRoles.add( MemberRole.SESSIONMGR );
434     } else {
435       accountRoles.remove( MemberRole.SESSIONMGR );
436     }
437     return;
438   } // setSessionManager(boolean)
439 
440   public boolean isTreasurer() {
441     return accountRoles.contains( MemberRole.TREASURER );
442   }
443 
444   public void setTreasurer( boolean isTreasurer ) {
445     if ( isTreasurer ) {
446       accountRoles.add( MemberRole.TREASURER );
447     } else {
448       accountRoles.remove( MemberRole.TREASURER );
449     }
450     return;
451   } // setTreasurer(boolean)
452 
453   public boolean hasEmail() {
454     return (this.emailAddr != null);
455   }
456 
457   public String getEmail() {
458     return this.emailAddr;
459   }
460 
461   public void setEmail( String str) {
462     this.emailAddr = str == null ? null : str.trim() ;
463     if ( this.emailAddr != null
464       && this.emailAddr.trim().length() == 0 ) {
465         this.emailAddr = null;
466     }
467   } 
468 
469   public String getPhoneEveningAreaCode() {
470     return this.phoneEveningAreaCode;
471   }
472 
473   public String getPhoneEveningExchange() {
474     return this.phoneEveningExchange;
475   }
476 
477   public String getPhoneEveningLocal() {
478     return this.phoneEveningLocal;
479   }
480 
481   public String getPhoneEveningExt() {
482     return this.phoneEveningExt;
483   }
484 
485   public String getPhoneDayAreaCode() {
486     return this.phoneDayAreaCode;
487   }    
488 
489   public String getPhoneDayExchange() {
490     return this.phoneDayExchange;
491   }    
492 
493   public String getPhoneDayLocal() {
494     return this.phoneDayLocal;
495   }    
496 
497   public String getPhoneDayExt() {
498     return this.phoneDayExt;
499   }    
500 
501   public String getPhoneOtherAreaCode() {
502     return this.phoneOtherAreaCode;
503   } 
504 
505   public String getPhoneOtherExchange() {
506     return this.phoneOtherExchange;
507   } 
508 
509   public String getPhoneOtherLocal() {
510     return this.phoneOtherLocal;
511   } 
512 
513   public String getPhoneOtherExt() {
514     return this.phoneOtherExt;
515   } 
516 
517   public void setPhoneEveningAreaCode( String s ) {
518     this.phoneEveningAreaCode = s == null ? null : s.trim() ;
519   }
520 
521   public void setPhoneEveningExchange( String s ) {
522     this.phoneEveningExchange = s == null ? null : s.trim() ;
523   }
524 
525   public void setPhoneEveningLocal( String s ) {
526     this.phoneEveningLocal = s == null ? null : s.trim() ;
527   }
528 
529   public void setPhoneEveningExt( String s ) {
530     this.phoneEveningExt = s == null ? null : s.trim() ;
531     if ( this.phoneEveningExt != null
532       && this.phoneEveningExt.trim().length() == 0 ) {
533         this.phoneEveningExt = null;
534     }
535   }
536 
537   public void setPhoneDayAreaCode( String s ) {
538     this.phoneDayAreaCode = s == null ? null : s.trim() ;
539   } 
540 
541   public void setPhoneDayExchange( String s ) {
542     this.phoneDayExchange = s == null ? null : s.trim() ;
543   } 
544 
545   public void setPhoneDayLocal( String s ) {
546     this.phoneDayLocal = s == null ? null : s.trim() ;
547   } 
548 
549   public void setPhoneDayExt( String s ) {
550     this.phoneDayExt = s == null ? null : s.trim() ;
551     if ( this.phoneDayExt != null
552       && this.phoneDayExt.trim().length() == 0 ) {
553         this.phoneDayExt = null;
554     }
555   } 
556 
557   public void setPhoneOtherAreaCode( String s ) {
558     this.phoneOtherAreaCode = s == null ? null : s.trim() ;
559   }
560 
561   public void setPhoneOtherExchange( String s ) {
562     this.phoneOtherExchange = s == null ? null : s.trim() ;
563   }
564 
565   public void setPhoneOtherLocal( String s ) {
566     this.phoneOtherLocal = s == null ? null : s.trim() ;
567   }
568 
569   public void setPhoneOtherExt( String s ) {
570     this.phoneOtherExt = s == null ? null : s.trim() ;
571     if ( this.phoneOtherExt != null
572       && this.phoneOtherExt.trim().length() == 0 ) {
573         this.phoneOtherExt = null;
574     }
575   }
576 
577   public String getStreet1() {
578     return this.street1;
579   }
580 
581   public String getStreet2() {
582     return this.street2;
583   }
584 
585   public String getCity() {
586     return this.city;
587   }
588 
589   public String getState() {
590     return this.state;
591   }
592 
593   public String getZip() {
594     return this.zip;
595   }
596 
597   public void setAddress( Address address ) {
598     this.street1 = address.getStreet1();
599     this.street2 = address.getStreet2();
600     this.city = address.getCity();
601     this.state = address.getState();
602     this.zip = address.getZip();
603   }
604 
605   public void setStreet1( String s ) {
606     this.street1 = s == null ? null : s.trim() ;
607   }
608 
609   public void setStreet2( String s ) {
610     this.street2 = s == null ? null : s.trim() ;
611   }
612 
613   public void setCity( String s ) {
614     this.city = s == null ? null : s.trim() ;
615   }
616 
617   public void setState( String s ) {
618     this.state = s == null ? null : s.trim() ;
619   }
620 
621   public void setZip( String s ) {
622     this.zip = s == null ? null : s.trim() ;
623   }
624 
625   // Validate
626   public ActionErrors validate(ActionMapping mapping,
627     HttpServletRequest request) {
628 
629     ActionErrors errors = new ActionErrors();
630 
631     new ValidateMemberName(this).validate(errors);
632     new ValidateMemberMailingAddress(this).validate(errors);
633     new ValidateMemberPhoneNumbers(this).validate(errors);
634     new ValidateMemberEmail(this).validate(errors);
635     new ValidateMemberAccountName(this).validate(errors);
636     new ValidateMemberOptionalInfo(this).validate(errors);
637 
638     if ( !isRestricted() ) {
639 
640       new ValidateMemberPassword(this).validate(errors);
641       new ValidateMemberAccountYear(this).validate(errors);
642       new ValidateMemberRoleAndStatus(this).validate(errors);
643 
644     }
645 
646     return errors;
647   } // validate
648 
649 } // MemberInfoForm
650 
651 /*
652  * $Log: MemberInfoForm.java,v $
653  * Revision 1.16  2003/03/02 15:32:06  rphall
654  * Removed unused fields and operations
655  *
656  * Revision 1.15  2003/02/26 03:38:46  rphall
657  * Added copyright and GPL license
658  *
659  * Revision 1.14  2003/02/24 13:29:54  rphall
660  * Added handling for when accountName changes
661  *
662  * Revision 1.13  2003/02/24 12:09:47  rphall
663  * Fixed bug in setEmail(String)
664  *
665  * Revision 1.12  2003/02/21 19:14:26  rphall
666  * Added validation of user name during AdminEdit
667  *
668  * Revision 1.11  2003/02/21 15:09:16  rphall
669  * More fixes to blank extension bug
670  *
671  * Revision 1.10  2003/02/20 16:29:29  rphall
672  * Fixed bug with null birthdate
673  *
674  * Revision 1.9  2003/02/20 04:51:27  rphall
675  * Added properties for Roles
676  *
677  * Revision 1.8  2003/02/19 03:20:34  rphall
678  * Added isAdminCreate(), isAdminEdit() and isMemberEdit() tests
679  *
680  * Revision 1.7  2003/02/18 04:29:59  rphall
681  * Major revision; working for MEMBEREDIT, ADMINEDIT, ADMINCREATE
682  *
683  */
684