KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > struts > PersonForm


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: PersonForm.java,v $
31  * Revision 1.4 2005/04/29 02:48:14 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:32:02 colinmacleod
36  * Added new themes.
37  * Changed id type to String.
38  * Changed i tag to em and b tag to strong.
39  * Improved PicoContainerFactory with NanoContainer scripts.
40  *
41  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:50:31 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * Revision 1.7 2004/11/12 18:19:14 colinmacleod
49  * Change action and form classes to extend MaskAction, MaskForm respectively.
50  *
51  * Revision 1.6 2004/11/12 15:57:07 colinmacleod
52  * Removed dependencies on SSLEXT.
53  * Moved Persistence classes to ivata masks.
54  *
55  * Revision 1.5 2004/11/03 15:36:01 colinmacleod
56  * Added logging.
57  * Fixed tab handling using keys, rather than ids.
58  *
59  * Revision 1.4 2004/07/13 19:41:14 colinmacleod
60  * Moved project to POJOs from EJBs.
61  * Applied PicoContainer to services layer (replacing session EJBs).
62  * Applied Hibernate to persistence layer (replacing entity EJBs).
63  *
64  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
65  * Shortened name to ivata op.
66  *
67  * Revision 1.2 2004/02/01 22:00:33 colinmacleod
68  * Added full names to author tags
69  *
70  * Revision 1.1.1.1 2004/01/27 20:57:54 colinmacleod
71  * Moved ivata openportal to SourceForge..
72  *
73  * Revision 1.4 2003/11/13 16:03:16 jano
74  * commitng everything to CVS
75  * can deploy and application is ruuning, can login into
76  *
77  * Revision 1.3 2003/10/17 12:36:12 jano
78  * fixing problems with building
79  * converting intranet -> portal
80  * Eclipse building
81  *
82  * Revision 1.2 2003/10/15 13:18:02 colin
83  * fixing for XDoclet
84  *
85  * Revision 1.9 2003/08/21 09:49:32 jano
86  * fixing for new addressBook extension
87  *
88  * Revision 1.8 2003/08/20 16:24:15 jano
89  * fixing addressBook extension
90  *
91  * Revision 1.7 2003/07/25 11:41:04 jano
92  * adding functionality for addressBook extension
93  *
94  * Revision 1.6 2003/06/18 14:22:12 jano
95  * fixing problem with removing user
96  * and spaces in userName
97  * and capitals in userName
98  *
99  * Revision 1.5 2003/04/14 12:21:34 peter
100  * removed helpKey field - it is inherited
101  *
102  * Revision 1.4 2003/04/09 08:53:20 jano
103  * handling data of removing user
104  *
105  * Revision 1.3 2003/02/28 09:36:38 jano
106  * RuntimeException(e) -> IntrnetRuntimeException
107  *
108  * Revision 1.2 2003/02/25 14:38:13 colin
109  * implemented setModified methods on entity beans thro IvataEntityBean superclass
110  *
111  * Revision 1.1 2003/02/24 19:09:21 colin
112  * moved to business
113  *
114  * Revision 1.7 2003/02/21 18:27:56 peter
115  * PersonDO doesn't a formatter - apropriate changes here
116  *
117  * Revision 1.6 2003/02/21 11:00:32 peter
118  * fixed rose model differences and birthDate validation
119  *
120  * Revision 1.5 2003/02/20 20:23:17 colin
121  * improved validation error handling
122  *
123  * Revision 1.4 2003/02/20 07:45:24 colin
124  * fixed bug where name of main group doesnt show in personSummary.jsp
125  *
126  * Revision 1.3 2003/02/18 11:10:27 colin
127  * first release of address book with Struts
128  *
129  * Revision 1.2 2003/02/14 08:59:48 colin
130  * changed findParentGroups... to findGroups...
131  *
132  * Revision 1.1 2003/02/04 17:40:18 colin
133  * first version in CVS
134  * -----------------------------------------------------------------------------
135  */

136 package com.ivata.groupware.business.addressbook.struts;
137
138 import java.text.ParseException JavaDoc;
139 import java.util.Arrays JavaDoc;
140 import java.util.HashSet JavaDoc;
141 import java.util.Iterator JavaDoc;
142 import java.util.List JavaDoc;
143 import java.util.Map JavaDoc;
144 import java.util.Set JavaDoc;
145 import java.util.Vector JavaDoc;
146
147 import javax.servlet.http.HttpServletRequest JavaDoc;
148 import javax.servlet.http.HttpSession JavaDoc;
149
150 import org.apache.log4j.Logger;
151 import org.apache.struts.action.ActionMapping;
152
153 import com.ivata.groupware.admin.security.Security;
154 import com.ivata.groupware.admin.security.server.SecuritySession;
155 import com.ivata.groupware.admin.security.user.UserDO;
156 import com.ivata.groupware.admin.setting.SettingsInitializationException;
157 import com.ivata.groupware.business.addressbook.AddressBook;
158 import com.ivata.groupware.business.addressbook.address.AddressDO;
159 import com.ivata.groupware.business.addressbook.address.country.CountryDO;
160 import com.ivata.groupware.business.addressbook.person.PersonDO;
161 import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO;
162 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
163 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressConstants;
164 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO;
165 import com.ivata.groupware.util.SettingDateFormatter;
166 import com.ivata.mask.Mask;
167 import com.ivata.mask.MaskFactory;
168 import com.ivata.mask.util.StringHandling;
169 import com.ivata.mask.util.SystemException;
170 import com.ivata.mask.validation.ValidationError;
171 import com.ivata.mask.validation.ValidationErrors;
172 import com.ivata.mask.web.format.DateFormatterConstants;
173 import com.ivata.mask.web.struts.DialogForm;
174
175
176 /**
177  * <p>This form is wrapper for <code>PersonDO</code>. It is used in
178  * <code>person.jsp</code> and the tabs from that page</p>
179  *
180  * @since 2003-01-31
181  * @author Colin MacLeod
182  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
183  * @version $Revision: 1.4 $
184  */

185 public class PersonForm extends DialogForm {
186     /**
187      * <p>This log provides tracing and debugging information.</p>
188      */

189     private static Logger log = Logger.getLogger(PersonForm.class);
190
191     /**
192      * <p>
193      * Implementation of the address book services layer.
194      * </p>
195      */

196     private AddressBook addressBook;
197
198     /**
199      * <p>
200      * Unique identifier of the address book group. This dictates which groups
201      * to choose from.
202      * </p>
203      */

204     private Integer JavaDoc addressBookGroupId;
205
206     /**
207      * <p>
208      * Name of the address book group. This dictates which groups
209      * to choose from.
210      * </p>
211      */

212     private String JavaDoc addressBookGroupName;
213
214     /**
215      * <p>
216      * Map of all address book names available. This is used to construct a combo
217      * list for the user to choose from.
218      * </p>
219      */

220     private Map JavaDoc addressBookGroupNames;
221
222     /**
223      * <p>
224      * Defines the base class of all objects in the value object list.
225      * </p>
226      */

227     private Class JavaDoc baseClass;
228
229     /**
230      *<p>in case that userName can remove this contact it's true</p>
231      */

232     private boolean canRemove;
233     /**
234      * <p>if user chenged addressBook combo box it's true othrewise it's false.</p>
235      */

236     private String JavaDoc changedAddressBook;
237     private SettingDateFormatter dateFormatter;
238     /**
239      * <p>Stores the person's date of birth in the format specified by
240      * setting 'i18nDateInputDisplay'.</p>
241      */

242     private String JavaDoc dateOfBirthString;
243     /**
244      * <p>Set to <code>true</code> if this person is an employee.
245      * Otherwise, <code>false</code>.</p>
246      */

247     private boolean employee;
248
249     /**
250      * <p>Users can be enabled and disabled. This lets the system retain
251      * user information such as comments whilst locking the user out.</p>
252      */

253     private boolean enableUser;
254     /**
255      * <p>Stores the index of the last telecom address being displayed.
256      * This is used to increase the list by 3 every time the "show more"
257      * button is clicked.</p>
258      */

259     private Integer JavaDoc lastTelecomAddress;
260
261     /**
262      * <p>
263      * Mask containing all the field definitions for this list.
264      * </p>
265      */

266     private Mask mask;
267     /**
268      * <p>If non-<code>null</code> and not empty, indicates we should
269      * display more telecom address fields.</p>
270      */

271     private String JavaDoc moreTelecomAddresses;
272
273     /**
274      * <p>Instance of person data object, containing all values
275      * of person being submitted.</p>
276      */

277     private PersonDO person;
278     /**
279      * <p>
280      * Indicates which TAB is active. This name is generated by the tab control
281      * and depends on the name of the form !!!!!
282      * </p>
283      */

284     private Integer JavaDoc personTab_activeTab;
285     /**
286      * <p>
287      * Indicates the localization key of the active tab. This name is generated
288      * by the tab control and depends on the name of the form !!!!!
289      * </p>
290      */

291     private String JavaDoc personTab_activeTabKey;
292     /**
293      *<p>if contact is readOnly it's true</p>
294      */

295     private boolean readOnly;
296     /**
297      * <p>If <code>true</code> then the main frame is loaded
298      * with the address book list when the dialog closes.</p>
299      */

300     private boolean refreshOnExit;
301     /**
302      * <p>Button for restoring removed user.</p>
303      */

304     private String JavaDoc restoreUser;
305     private Security security;
306
307     /**
308      * <p>
309      * Contains the localization key for each of the tabs to be shown.
310      * </p>
311      */

312     private List JavaDoc tabKeys = new Vector JavaDoc();
313     /**
314      * <p>Absolute (to application context) location of the page to
315      * include for the tab body.</p>
316      */

317     private String JavaDoc tabPage;
318     /**
319      * <p>
320      * This list representation of the telecom addresses in person are easier
321      * for <strong>Struts</strong> to manipulate.
322      * </p>
323      */

324     private List JavaDoc telecomAddresses;
325     /**
326      * <p>The title we will display depends on the action we're taking -
327      * add, amend or removed.</p>
328      */

329     private String JavaDoc titleKey;
330     /**
331      * <p>
332      * Map of all user group names available. This is used to construct a
333      * list to choose groups the user is a member of.
334      * </p>
335      */

336     private List JavaDoc userGroups;
337     /**
338      * <p>Stores the new user name of the person. This is done so we can
339      * compare with before to see if the person is a new user, has had
340      * his/her user name changed or has lost the right to be a user.</p>
341      */

342     private String JavaDoc userName;
343     /**
344      * <p>
345      * If <code>true</code> then the user tab is shown but cannot be changed.
346      * </p>
347      */

348     private boolean userTabReadOnly;
349     /**
350      * <p>
351      * Constructor - called by <strong>PicoContainer</strong>.
352      * </p>
353      *
354      * @param addressBook addresss book implementation.
355      * @param dateFormatter date formatter for the current session.
356      * @param maskParam Refer to {@link DialogForm#DialogForm}.
357      * @param baseClassParam Refer to {@link DialogForm#DialogForm}.
358      */

359     public PersonForm(final AddressBook addressBook,
360             final SettingDateFormatter dateFormatter,
361             final Security security,
362             final MaskFactory maskFactory) {
363         this.addressBook = addressBook;
364         this.dateFormatter = dateFormatter;
365         this.security = security;
366         mask = maskFactory.getMask(PersonDO.class);
367     }
368
369     /**
370      * <p>
371      * Return all form state to initial values.
372      * </p>
373      *
374      * @see com.ivata.mask.web.struts.MaskForm#clear()
375      */

376     protected void clear() {
377         addressBookGroupId = null;
378         addressBookGroupName = "";
379         canRemove = false;
380         changedAddressBook = null;
381         dateOfBirthString = null;
382         enableUser = false;
383         employee = false;
384         lastTelecomAddress = null;
385         moreTelecomAddresses = null;
386         person = new PersonDO();
387         personTab_activeTab = null;
388         personTab_activeTabKey = null;
389         readOnly = false;
390         refreshOnExit = true;
391         restoreUser = null;
392         tabKeys = new Vector JavaDoc();
393         tabPage = "/addressBook/personDetails.jsp";
394         telecomAddresses = new Vector JavaDoc();
395         titleKey = "person.title.new";
396         userName = null;
397         userGroups = null;
398         userTabReadOnly = false;
399     }
400
401     /**
402      * <p>
403      * Helper to find and set the country on a changed address.
404      * </p>
405      *
406      * @param securitySession valid security sesion, used to look up the country.
407      * @param address the address for which to find the country. The country
408      * code should be set.
409      */

410     public void findAndSetCountry(final SecuritySession securitySession) {
411         // first update the country in the person's address
412
AddressDO address = person.getAddress();
413         CountryDO addressCountry = new CountryDO();
414         if (address != null) {
415             if ((address.getCountry() != null)
416                     && !StringHandling.isNullOrEmpty(address.getCountry().getCode())) {
417                 try {
418                     addressCountry = addressBook.findCountryByCode(securitySession, address.getCountry().getCode());
419                 } catch (SystemException e) {
420                     throw new RuntimeException JavaDoc(e);
421                 }
422             }
423             address.setCountry(addressCountry);
424         }
425         // now update the country in the person's employee record
426
EmployeeDO employee = person.getEmployee();
427         if (employee != null) {
428             CountryDO employeeCountry = new CountryDO();
429             if ((employee.getCountry() != null)
430                     && !StringHandling.isNullOrEmpty(employee.getCountry().getCode())) {
431                 try {
432                     employeeCountry = addressBook.findCountryByCode(securitySession, employee.getCountry().getCode());
433                 } catch (SystemException e) {
434                     throw new RuntimeException JavaDoc(e);
435                 }
436             } else {
437                 // if the employee country is empty, default it to the address
438
// country
439
employeeCountry = addressCountry;
440             }
441             employee.setCountry(employeeCountry);
442         }
443     }
444     /**
445      * <p>
446      * Unique identifier of the address book group. This dictates which groups
447      * to choose from.
448      * </p>
449      *
450      * @return current value of addressBookId.
451      */

452     public final Integer JavaDoc getAddressBookGroupId() {
453         return addressBookGroupId;
454     }
455     /**
456      * <p>
457      * Name of the address book group. This dictates which groups
458      * to choose from.
459      * </p>
460      *
461      * @return current value of addressBookGroupName.
462      */

463     public final String JavaDoc getAddressBookGroupName() {
464         return addressBookGroupName;
465     }
466     /**
467      * <p>
468      * Map of all address books available. This is used to construct a combo
469      * list for the user to choose from.
470      * </p>
471      *
472      * @return current value of addressBookGroups.
473      */

474     public final Map JavaDoc getAddressBookGroupNames() {
475         return addressBookGroupNames;
476     }
477
478     /**
479      * <p>
480      * Defines the base class of all objects in the value object list.
481      * </p>
482      *
483      * @return base class of all objects in the value object list.
484      */

485     public final Class JavaDoc getBaseClass() {
486         return baseClass;
487     }
488
489     /**
490      *<p>in case that userName can remove this contact it's true</p>
491      *
492      * @return the current value of canRemove.
493      */

494     public final boolean getCanRemove() {
495         return this.canRemove;
496     }
497
498     /**
499      * <p>if user chenged addressBook combo box it's true othrewise it's false.</p>
500      *
501      * @return the current value of changedAddressBook.
502      */

503     public final String JavaDoc getChangedAddressBook() {
504         return this.changedAddressBook;
505     }
506
507     /**
508      * <p>returns the person's date of birth in the format specified by
509      * setting 'i18nDateInputDisplay'.</p>
510      * @return the person's date of birth in the format specified by
511      * setting 'i18nDateInputDisplay'
512      */

513     public final String JavaDoc getDateOfBirthString() {
514         return dateOfBirthString;
515     }
516
517     /**
518      * <p>Users can be enabled and disabled. This lets the system retain
519      * user information such as comments whilst locking the user out.</p>
520      *
521      * @return the current value of enableUser.
522      */

523     public final boolean getEnableUser() {
524         return enableUser;
525     }
526
527     /**
528      * <p>Stores the index of the last telecom address being displayed.
529      * This is used to increase the list by 3 every time the "show more"
530      * button is clicked.</p>
531      *
532      * @return the current value of lastTelecomAddress.
533      */

534     public final Integer JavaDoc getLastTelecomAddress() {
535         return lastTelecomAddress;
536     }
537
538     /**
539      * <p>
540      * Mask containing all the field definitions for this list.
541      * </p>
542      *
543      * @return mask containing all the field definitions for this list.
544      */

545     public final Mask getMask() {
546         return mask;
547     }
548
549     /**
550      * <p>If non-<code>null</code> and not empty, indicates we should
551      * display more telecom address fields.</p>
552      *
553      * @return the current value of moreTelecomAddresses.
554      */

555     public final String JavaDoc getMoreTelecomAddresses() {
556         return moreTelecomAddresses;
557     }
558
559     /**
560      * <p>Get the values of the person this form refers to as a dependent
561      * value object.</p>
562      *
563      * @return person values this form refers to.
564      *
565      */

566     public PersonDO getPerson() {
567         return person;
568     }
569
570     /**
571      * <p>
572      * Indicates which TAB is active. This name is generated by the tab control
573      * and depends on the name of the form !!!!!
574      * </p>
575      *
576      * @return the current value of personTab_activeTab.
577
578      */

579     public final Integer JavaDoc getPersonTab_activeTab() {
580         return personTab_activeTab;
581     }
582     /**
583      * <p>
584      * Indicates the localization key of the active tab. This name is generated
585      * by the tab control and depends on the name of the form !!!!!
586      * </p>
587      *
588      * @return Returns the personTab_activeTabKey.
589      */

590     public final String JavaDoc getPersonTab_activeTabKey() {
591         return personTab_activeTabKey;
592     }
593
594     /**
595      *<p>if contact is readOnly it's true</p>
596      *
597      * @return the current value of readOnly.
598      */

599     public final boolean getReadOnly() {
600         return this.readOnly;
601     }
602
603     /**
604      * <p>If <code>true</code> then the main frame is loaded
605      * with the address book list when the dialog closes.</p>
606      *
607      * @return the current value of refreshOnExit.
608      */

609     public final boolean getRefreshOnExit() {
610         return refreshOnExit;
611     }
612
613     /**
614      * <p>Button for restoring removed user.</p>
615      *
616      * @return the current value of restoreUser.
617      */

618     public final String JavaDoc getRestoreUser() {
619         return this.restoreUser;
620     }
621     /**
622      * <p>
623      * Contains the localization key for each of the tabs to be shown.
624      * </p>
625      *
626      * @return Returns the tab keys.
627      */

628     public List JavaDoc getTabKeys() {
629         return tabKeys;
630     }
631
632     /**
633      * <p>Absolute (to application context) location of the page to
634      * include for the tab body.</p>
635      *
636      * @return the current value of tabPage.
637      */

638     public final String JavaDoc getTabPage() {
639         return tabPage;
640     }
641     /**
642      * @return Returns the telecomAddresses.
643      */

644     public List JavaDoc getTelecomAddresses() {
645         return telecomAddresses;
646     }
647     /**
648      * <p>The title we will display depends on the action we're taking -
649      * add, amend or removed.</p>
650      *
651      * @return the current value of titleKey.
652      */

653     public final String JavaDoc getTitleKey() {
654         return titleKey;
655     }
656
657     /**
658      * <p>
659      * List of all user groups available.
660      * </p>
661      *
662      * @return current value of userGroups.
663      */

664     public List JavaDoc getUserGroups() {
665         return userGroups;
666     }
667
668     /**
669      * <p>Stores the new user name of the person. This is done so we can
670      * compare with before to see if the person is a new user, has had
671      * his/her user name changed or has lost the right to be a user.</p>
672      *
673      * @return the current value of userName.
674      */

675     public final String JavaDoc getUserName() {
676         return userName;
677     }
678
679     /**
680      * <p>Set to <code>true</code> if this person is an employee.
681      * Otherwise, <code>false</code>.</p>
682      *
683      * @return the current value of employee.
684      */

685     public boolean isEmployee() {
686         return employee;
687     }
688     /**
689      * <p>
690      * If <code>true</code> then the user tab is shown but cannot be changed.
691      * </p>
692      *
693      * @return current value of userTabReadOnly.
694      */

695     public boolean isUserTabReadOnly() {
696         return userTabReadOnly;
697     }
698
699     /**
700      * <p>Reset all bean properties to their default state. This method
701      * is called before the properties are repopulated by the controller
702      * servlet.</p>
703      *
704      * @param mapping The mapping used to select this instance
705      * @param request The servlet request we are processing
706      */

707     public void reset(final ActionMapping mapping,
708             final HttpServletRequest JavaDoc request) {
709         // get the email address host which matches the current user
710
if (request.getParameter("changedAddressBook")==null) {
711             this.setChangedAddressBook("false");
712         }
713         // find out which tab has just been clicked
714
if ("/addressBook/address.jsp".equals(tabPage)) {
715             AddressDO address = new AddressDO();
716             address.setCountry(new CountryDO());
717             person.setAddress(address);
718         } else if ("/addressBook/telecomAddress.jsp".equals(tabPage)) {
719             moreTelecomAddresses = null;
720             Iterator JavaDoc telecomAddressIterator = telecomAddresses.iterator();
721             while (telecomAddressIterator.hasNext()) {
722                 TelecomAddressDO telecomAddress = (TelecomAddressDO) telecomAddressIterator.next();
723                 telecomAddress.setAddress("");
724             }
725         } else if ("/addressBook/member.jsp".equals(tabPage)) {
726             // no nothing
727
} else if ("/addressBook/user.jsp".equals(tabPage)) {
728             enableUser = false;
729             userName = "";
730         } else if ("/addressBook/restoreUser.jsp".equals(tabPage)) {
731             // do nothing
732
int i = 0;
733         } else if ("/addressBook/employee.jsp".equals(tabPage)) {
734             employee = false;
735             EmployeeDO employee = person.getEmployee();
736             employee.setCountry(new CountryDO());
737             employee.setNumber("");
738             employee.setVacationDays(null);
739
740         } else if (request.getParameter("person.company") != null) {
741             person.setCompany("");
742             person.setDateOfBirth(null);
743             person.setFileAs("");
744             person.setFirstNames("");
745             person.setJobTitle("");
746             person.setLastName("");
747             person.setSalutation("");
748         }
749         personTab_activeTab = null;
750         personTab_activeTabKey = "";
751
752         super.reset(mapping, request);
753     }
754     /**
755      * <p>
756      * Unique identifier of the address book group. This dictates which groups
757      * to choose from.
758      * </p>
759      *
760      * @param addressBookId new value of addressBookId.
761      */

762     public final void setAddressBookGroupId(final Integer JavaDoc addressBookId) {
763         this.addressBookGroupId = addressBookId;
764     }
765     /**
766      * <p>
767      * Name of the address book group. This dictates which groups
768      * to choose from.
769      * </p>
770      *
771      * @param addressBookGroupName new value of addressBookGroupName.
772      */

773     public final void setAddressBookGroupName(final String JavaDoc addressBookGroupName) {
774         this.addressBookGroupName = addressBookGroupName;
775     }
776     /**
777      * <p>
778      * Map of all address books available. This is used to construct a combo
779      * list for the user to choose from.
780      * </p>
781      *
782      * @param addressBookGroups new value of addressBookGroups.
783      */

784     public final void setAddressBookGroupNames(final Map JavaDoc addressBookGroups) {
785         this.addressBookGroupNames = addressBookGroups;
786     }
787
788     /**
789      *<p>in case that userName can remove this contact it's true</p>
790      *
791      * @param canRemove the new value of canRemove.
792      */

793     public final void setCanRemove(final boolean canRemove) {
794         this.canRemove = canRemove;
795     }
796
797     /**
798      * <p>if user chenged addressBook combo box it's true othrewise it's false.</p>
799      *
800      * @param changedAddressBook the new value of changedAddressBook.
801      */

802     public final void setChangedAddressBook(final String JavaDoc changedAddressBook) {
803         this.changedAddressBook = changedAddressBook;
804     }
805
806     /**
807      * <p>Set the person's date of birth in the format 'dd.MM.YYYY'.</p>
808      *
809      * @param dateOfBirthString the person's date of birth in the format
810      * 'dd.MM.YYYY'.
811      *
812      */

813     public final void setDateOfBirthString(final String JavaDoc dateOfBirthString) {
814         this.dateOfBirthString = dateOfBirthString;
815     }
816     /**
817      * <p>Set to <code>true</code> if this person is an employee.
818      * Otherwise, <code>false</code>.</p>
819      *
820      * @param employee the new value of employee.
821      */

822     public final void setEmployee(final boolean employee) {
823         this.employee = employee;
824     }
825
826     /**
827      * <p>Users can be enabled and disabled. This lets the system retain
828      * user information such as comments whilst locking the user out.</p>
829      *
830      * @param enableUser the new value of enableUser.
831      */

832     public final void setEnableUser(final boolean enableUser) {
833         this.enableUser = enableUser;
834     }
835
836     /**
837      * <p>Stores the index of the last telecom address being displayed.
838      * This is used to increase the list by 3 every time the "show more"
839      * button is clicked.</p>
840      *
841      * @param lastTelecomAddress the new value of lastTelecomAddress.
842      */

843     public final void setLastTelecomAddress(final Integer JavaDoc lastTelecomAddress) {
844         this.lastTelecomAddress = lastTelecomAddress;
845     }
846
847     /**
848      * <p>If non-<code>null</code> and not empty, indicates we should
849      * display more telecom address fields.</p>
850      *
851      * @param moreTelecomAddresses the new value of moreTelecomAddresses.
852      */

853     public final void setMoreTelecomAddresses(final String JavaDoc moreTelecomAddresses) {
854         this.moreTelecomAddresses = moreTelecomAddresses;
855     }
856
857     /**
858      * <p>Get the values of the person this form refers to as a dependent
859      * value object.</p>
860      *
861      * @param person person values this form refers to.
862      *
863      */

864     public final void setPerson(final PersonDO person) {
865         this.person = person;
866         // set all the telecom addresses
867
telecomAddresses = new Vector JavaDoc();
868         telecomAddresses.addAll(person.getTelecomAddresses());
869         // set the user name
870
userName = "";
871         if (person.getUser() != null) {
872             userName = person.getUser().getName();
873         }
874
875         // set the address book name and id
876
if ((person.getGroup() != null)
877                 && (person.getGroup().getAddressBook() != null)) {
878             GroupDO addressBook = person.getGroup().getAddressBook();
879             addressBookGroupId = addressBook.getId();
880             addressBookGroupName = addressBook.getName();
881         }
882     }
883     /**
884      * <p>
885      * Update the person to show all the addresses currently in the form.
886      * </p>
887      */

888     public void setPersonFromTelecomAddresses() {
889         // remove empty telecom addresses
890
Iterator JavaDoc formTelecomAddressIterator = telecomAddresses.iterator();
891         Set JavaDoc personTelecomAddresses = new HashSet JavaDoc();
892         UserDO user = person.getUser();
893
894         // remove empty addresses and find out if person has any email address
895
Iterator JavaDoc telecomAddressIterator = personTelecomAddresses.iterator();
896         while (formTelecomAddressIterator.hasNext()) {
897             TelecomAddressDO thisTelecomAddress = (TelecomAddressDO)
898                 formTelecomAddressIterator.next();
899             if (!StringHandling.isNullOrEmpty(thisTelecomAddress.getAddress())) {
900                 personTelecomAddresses.add(thisTelecomAddress);
901             }
902         }
903         person.setTelecomAddresses(personTelecomAddresses);
904     }
905
906     /**
907      * <p>
908      * Indicates which TAB is active. This name is generated by the tab control
909      * and depends on the name of the form !!!!!
910      * </p>
911      *
912      * @param personTab_activeTab the new value of personTab_activeTab.
913
914      */

915     public final void setPersonTab_activeTab(final Integer JavaDoc personTab_activeTab) {
916         this.personTab_activeTab = personTab_activeTab;
917     }
918     /**
919      * <p>
920      * Indicates the localization key of the active tab. This name is generated
921      * by the tab control and depends on the name of the form !!!!!
922      * </p>
923      *
924      * @param personTab_activeTabKey The personTab_activeTabKey to set.
925      */

926     public final void setPersonTab_activeTabKey(final String JavaDoc personTab_activeTabKey) {
927         this.personTab_activeTabKey = personTab_activeTabKey;
928     }
929
930     /**
931      *<p>if contact is readOnly it's true</p>
932      *
933      * @param readOnly the new value of readOnly.
934      */

935     public final void setReadOnly(final boolean readOnly) {
936         this.readOnly = readOnly;
937     }
938
939     /**
940      * <p>If <code>true</code> then the main frame is loaded
941      * with the address book list when the dialog closes.</p>
942      *
943      * @param refreshOnExit the new value of refreshOnExit.
944      */

945     public final void setRefreshOnExit(final boolean refreshOnExit) {
946         this.refreshOnExit = refreshOnExit;
947     }
948
949     /**
950      * <p>Button for restoring removed user.</p>
951      *
952      * @param restoreUser the new value of restoreUser.
953      */

954     public final void setRestoreUser(final String JavaDoc restoreUser) {
955         this.restoreUser = restoreUser;
956     }
957     /**
958      * <p>
959      * Contains the localization key for each of the tabs to be shown.
960      * </p>
961      *
962      * @param tabKeys New value of tab keys.
963      */

964     public final void setTabKeys(final List JavaDoc tabKeys) {
965         this.tabKeys = tabKeys;
966     }
967
968     /**
969      * <p>Absolute (to application context) location of the page to
970      * include for the tab body.</p>
971      *
972      * @param tabPage the new value of tabPage.
973      */

974     public final void setTabPage(final String JavaDoc tabPage) {
975         this.tabPage = tabPage;
976     }
977     /**
978      * @param telecomAddresses The telecomAddresses to set.
979      */

980     public final void setTelecomAddresses(final List JavaDoc telecomAddresses) {
981         this.telecomAddresses = telecomAddresses;
982     }
983
984     /**
985      * <p>
986      * Initialize the telecom addresses on the form from the person object.
987      * </p>
988      */

989     public final void setTelecomAddressesFromPerson() {
990         // first remove the blank telecom addresses
991
Iterator JavaDoc personTelecomAddressIterator = person.getTelecomAddresses().iterator();
992         telecomAddresses = new Vector JavaDoc();
993         while (personTelecomAddressIterator.hasNext()) {
994             TelecomAddressDO thisTelecomAddress = (TelecomAddressDO)
995                 personTelecomAddressIterator.next();
996             if (!StringHandling.isNullOrEmpty(thisTelecomAddress.getAddress())) {
997                 telecomAddresses.add(thisTelecomAddress);
998             }
999         }
1000        // show at least 5 telecom addresses in total, at least 3 blank ones
1001
int totalTelecomAddresses = telecomAddresses.size();
1002        int totalToShow = totalTelecomAddresses < 3 ? 5 : totalTelecomAddresses + 3;
1003        // if you wanted more telecom address fields, I'll give you even more
1004
if (!StringHandling.isNullOrEmpty(moreTelecomAddresses)) {
1005            totalToShow += 3;
1006        }
1007        for(int i=totalTelecomAddresses; i<totalToShow; ++i) {
1008            TelecomAddressDO newTelecomAddress = new TelecomAddressDO();
1009            telecomAddresses.add(newTelecomAddress);
1010            // iterate thro' all the types
1011
newTelecomAddress.setType(i % TelecomAddressConstants.countTypes());
1012        }
1013    }
1014
1015    /**
1016     * <p>The title we will display depends on the action we're taking -
1017     * add, amend or removed.</p>
1018     *
1019     * @param titleKey the new value of titleKey.
1020     */

1021    public final void setTitleKey(final String JavaDoc titleKey) {
1022        this.titleKey = titleKey;
1023    }
1024
1025    /**
1026     * <p>
1027     * List of all user groups available.
1028     * </p>
1029     *
1030     * @param userGroupNames new value of userGroupNames.
1031     */

1032    public final void setUserGroups(final List JavaDoc userGroups) {
1033        this.userGroups = userGroups;
1034    }
1035
1036    /**
1037     * <p>Stores the new user name of the person. This is done so we can
1038     * compare with before to see if the person is a new user, has had
1039     * his/her user name changed or has lost the right to be a user.</p>
1040     *
1041     * @param userName the new value of userName.
1042     */

1043    public final void setUserName(final String JavaDoc userName) {
1044        this.userName = userName;
1045    }
1046    /**
1047     * <p>
1048     * If <code>true</code> then the user tab is shown but cannot be changed.
1049     * </p>
1050     *
1051     * @param userTabReadOnly new value of userTabReadOnly.
1052     */

1053    public final void setUserTabReadOnly(final boolean userTabReadOnly) {
1054        this.userTabReadOnly = userTabReadOnly;
1055    }
1056
1057    /**
1058     * <p>Validates the form contents.</p>
1059     */

1060    public ValidationErrors validate(final HttpServletRequest JavaDoc request,
1061            final HttpSession JavaDoc session) {
1062        ValidationErrors validationErrors = super.validate(request, session);
1063        SecuritySession securitySession = (SecuritySession)
1064            session.getAttribute("securitySession");
1065
1066        // if we have userName -> correct
1067
if (!StringHandling.isNullOrEmpty(userName)) {
1068            userName = userName.toLowerCase();
1069            userName = userName.trim();
1070            // remove any spaces
1071
if (userName.indexOf(" ")!=-1) {
1072                userName = userName.replaceAll(" ","");
1073                validationErrors.add(new ValidationError(
1074                        "user",
1075                        Security.BUNDLE_PATH,
1076                        mask.getField("name"),
1077                        "errors.addressBook.user.userName"));
1078            }
1079            if ((person.getUser() == null)
1080                    || !userName.equals(person.getUser().getName())) {
1081                try {
1082                    if (security.isUser(securitySession, userName)) {
1083                        validationErrors.add(new ValidationError(
1084                                "user",
1085                                Security.BUNDLE_PATH,
1086                                mask.getField("name"),
1087                                "errors.unique"));
1088                    }
1089                } catch (SystemException e1) {
1090                    throw new RuntimeException JavaDoc(e1);
1091                }
1092            }
1093        }
1094        // update the person to reflect the current email addresses
1095
setPersonFromTelecomAddresses();
1096        // now update the form again
1097
setTelecomAddressesFromPerson();
1098
1099        // find the address country, if an address was specified, or delete the
1100
// address if it is empty
1101
findAndSetCountry(securitySession);
1102        AddressDO address = person.getAddress();
1103        if (StringHandling.isNullOrEmpty(address.getPostCode())
1104                && StringHandling.isNullOrEmpty(address.getRegion())
1105                && StringHandling.isNullOrEmpty(address.getStreetAddress())
1106                && StringHandling.isNullOrEmpty(address.getTown())) {
1107            // if there is no address, ignore the address elements for
1108
// validation purpses (we'll set it back again at the end of this
1109
// method
1110
person.setAddress(null);
1111        }
1112
1113        EmployeeDO employee = person.getEmployee();
1114        if (!this.employee) {
1115            // if this is not an employee, ignore the employee elements for
1116
// validation purpses (we'll set it back again at the end of this
1117
// method
1118
person.setEmployee(null);
1119        }
1120
1121
1122        // store the 'real' user for later
1123
UserDO user = person.getUser();
1124        try {
1125            // if user is going to remove from person
1126
if ((person.getUser()!= null)
1127                    && StringHandling.isNullOrEmpty(userName)) {
1128                person.setUser(null);
1129            } else {
1130                // this is just to test against server-side validation of user
1131
// name and enabled state
1132
UserDO tmpUser = new UserDO();
1133                tmpUser.setDeleted(user.isDeleted());
1134                tmpUser.setEnabled(enableUser);
1135                tmpUser.setGroups(user.getGroups());
1136                tmpUser.setName(userName);
1137                person.setUser(tmpUser);
1138            }
1139            validationErrors.addAll(addressBook.validate(securitySession,
1140                    person));
1141
1142            // see if there is a date format error setting the date of birth
1143
// note: if dateOfBirth ever becomes mandatory, this will need to
1144
// be set & checked before the validate above
1145
if (StringHandling.isNullOrEmpty(dateOfBirthString)) {
1146                person.setDateOfBirth(null);
1147            } else {
1148                try {
1149                    dateFormatter.setUserName((String JavaDoc) session.getAttribute("userName"));
1150                    dateFormatter.setDateFormat(DateFormatterConstants.DATE_INPUT);
1151                    dateFormatter.setDateTimeText("{0}");
1152
1153                    person.setDateOfBirth(dateFormatter.parse(dateOfBirthString));
1154                } catch (SettingsInitializationException e) {
1155                    throw new RuntimeException JavaDoc(e);
1156                } catch (ParseException JavaDoc e) {
1157                    if (validationErrors == null) {
1158                        validationErrors = new ValidationErrors();
1159                    }
1160                    String JavaDoc[] parameters = {dateOfBirthString};
1161
1162                    validationErrors.add(new ValidationError(
1163                            "personDetails",
1164                            AddressBook.BUNDLE_PATH,
1165                            mask.getField("dateOfBirthString"),
1166                            "errors.date",
1167                            Arrays.asList(parameters)));
1168                }
1169            }
1170        } catch (SystemException e) {
1171            e.printStackTrace(System.err);
1172            throw new RuntimeException JavaDoc(e);
1173        }
1174        // remove the active tab to return us to the start, if this is ok
1175
if (!StringHandling.isNullOrEmpty(getOk())) {
1176            session.removeAttribute("personTab_activeTab");
1177        }
1178
1179        // return the address & employee data object to the person, if either
1180
// was set to null
1181
person.setAddress(address);
1182        person.setEmployee(employee);
1183        // likewise, the user
1184
person.setUser(user);
1185        return validationErrors;
1186    }
1187}
Popular Tags