0001: /*
0002: * Copyright (c) 2001 - 2005 ivata limited.
0003: * All rights reserved.
0004: * -----------------------------------------------------------------------------
0005: * ivata groupware may be redistributed under the GNU General Public
0006: * License as published by the Free Software Foundation;
0007: * version 2 of the License.
0008: *
0009: * These programs are free software; you can redistribute them and/or
0010: * modify them under the terms of the GNU General Public License
0011: * as published by the Free Software Foundation; version 2 of the License.
0012: *
0013: * These programs are distributed in the hope that they will be useful,
0014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0016: *
0017: * See the GNU General Public License in the file LICENSE.txt for more
0018: * details.
0019: *
0020: * If you would like a copy of the GNU General Public License write to
0021: *
0022: * Free Software Foundation, Inc.
0023: * 59 Temple Place - Suite 330
0024: * Boston, MA 02111-1307, USA.
0025: *
0026: *
0027: * To arrange commercial support and licensing, contact ivata at
0028: * http://www.ivata.com/contact.jsp
0029: * -----------------------------------------------------------------------------
0030: * $Log: PersonForm.java,v $
0031: * Revision 1.8 2005/10/11 18:53:06 colinmacleod
0032: * Fixed some checkstyle and javadoc issues.
0033: *
0034: * Revision 1.7 2005/10/03 10:21:13 colinmacleod
0035: * Fixed some style and javadoc issues.
0036: *
0037: * Revision 1.6 2005/10/02 14:08:55 colinmacleod
0038: * Added/improved log4j logging.
0039: *
0040: * Revision 1.5 2005/09/14 14:49:31 colinmacleod
0041: * Removed unused local and class variables.
0042: * Added serialVersionUID.
0043: *
0044: * Revision 1.4 2005/04/29 02:48:14 colinmacleod
0045: * Data bugfixes.
0046: * Changed primary key back to Integer.
0047: *
0048: * Revision 1.3 2005/04/10 20:32:02 colinmacleod
0049: * Added new themes.
0050: * Changed id type to String.
0051: * Changed i tag to em and b tag to strong.
0052: * Improved PicoContainerFactory with NanoContainer scripts.
0053: *
0054: * Revision 1.2 2005/04/09 17:19:08 colinmacleod
0055: * Changed copyright text to GPL v2 explicitly.
0056: *
0057: * Revision 1.1.1.1 2005/03/10 17:50:31 colinmacleod
0058: * Restructured ivata op around Hibernate/PicoContainer.
0059: * Renamed ivata groupware.
0060: *
0061: * Revision 1.7 2004/11/12 18:19:14 colinmacleod
0062: * Change action and form classes to extend MaskAction, MaskForm respectively.
0063: *
0064: * Revision 1.6 2004/11/12 15:57:07 colinmacleod
0065: * Removed dependencies on SSLEXT.
0066: * Moved Persistence classes to ivata masks.
0067: *
0068: * Revision 1.5 2004/11/03 15:36:01 colinmacleod
0069: * Added logging.
0070: * Fixed tab handling using keys, rather than ids.
0071: *
0072: * Revision 1.4 2004/07/13 19:41:14 colinmacleod
0073: * Moved project to POJOs from EJBs.
0074: * Applied PicoContainer to services layer (replacing session EJBs).
0075: * Applied Hibernate to persistence layer (replacing entity EJBs).
0076: *
0077: * Revision 1.3 2004/03/21 21:16:08 colinmacleod
0078: * Shortened name to ivata op.
0079: *
0080: * Revision 1.2 2004/02/01 22:00:33 colinmacleod
0081: * Added full names to author tags
0082: *
0083: * Revision 1.1.1.1 2004/01/27 20:57:54 colinmacleod
0084: * Moved ivata openportal to SourceForge..
0085: *
0086: * Revision 1.4 2003/11/13 16:03:16 jano
0087: * commitng everything to CVS
0088: * can deploy and application is ruuning, can login into
0089: *
0090: * Revision 1.3 2003/10/17 12:36:12 jano
0091: * fixing problems with building
0092: * converting intranet -> portal
0093: * Eclipse building
0094: *
0095: * Revision 1.2 2003/10/15 13:18:02 colin
0096: * fixing for XDoclet
0097: *
0098: * Revision 1.9 2003/08/21 09:49:32 jano
0099: * fixing for new addressBook extension
0100: *
0101: * Revision 1.8 2003/08/20 16:24:15 jano
0102: * fixing addressBook extension
0103: *
0104: * Revision 1.7 2003/07/25 11:41:04 jano
0105: * adding functionality for addressBook extension
0106: *
0107: * Revision 1.6 2003/06/18 14:22:12 jano
0108: * fixing problem with removing user
0109: * and spaces in userName
0110: * and capitals in userName
0111: *
0112: * Revision 1.5 2003/04/14 12:21:34 peter
0113: * removed helpKey field - it is inherited
0114: *
0115: * Revision 1.4 2003/04/09 08:53:20 jano
0116: * handling data of removing user
0117: *
0118: * Revision 1.3 2003/02/28 09:36:38 jano
0119: * RuntimeException(e) -> IntrnetRuntimeException
0120: *
0121: * Revision 1.2 2003/02/25 14:38:13 colin
0122: * implemented setModified methods on entity beans thro IvataEntityBean
0123: * superclass
0124: *
0125: * Revision 1.1 2003/02/24 19:09:21 colin
0126: * moved to business
0127: *
0128: * Revision 1.7 2003/02/21 18:27:56 peter
0129: * PersonDO doesn't a formatter - apropriate changes here
0130: *
0131: * Revision 1.6 2003/02/21 11:00:32 peter
0132: * fixed rose model differences and birthDate validation
0133: *
0134: * Revision 1.5 2003/02/20 20:23:17 colin
0135: * improved validation error handling
0136: *
0137: * Revision 1.4 2003/02/20 07:45:24 colin
0138: * fixed bug where name of main group doesnt show in personSummary.jsp
0139: *
0140: * Revision 1.3 2003/02/18 11:10:27 colin
0141: * first release of address book with Struts
0142: *
0143: * Revision 1.2 2003/02/14 08:59:48 colin
0144: * changed findParentGroups... to findGroups...
0145: *
0146: * Revision 1.1 2003/02/04 17:40:18 colin
0147: * first version in CVS
0148: * -----------------------------------------------------------------------------
0149: */
0150: package com.ivata.groupware.business.addressbook.struts;
0151:
0152: import org.apache.log4j.Logger;
0153:
0154: import java.text.ParseException;
0155: import java.util.Arrays;
0156: import java.util.HashSet;
0157: import java.util.Iterator;
0158: import java.util.List;
0159: import java.util.Map;
0160: import java.util.Set;
0161: import java.util.Vector;
0162:
0163: import javax.servlet.http.HttpServletRequest;
0164: import javax.servlet.http.HttpSession;
0165:
0166: import org.apache.struts.action.ActionMapping;
0167:
0168: import com.ivata.groupware.admin.security.Security;
0169: import com.ivata.groupware.admin.security.server.SecuritySession;
0170: import com.ivata.groupware.admin.security.user.UserDO;
0171: import com.ivata.groupware.admin.setting.SettingsInitializationException;
0172: import com.ivata.groupware.business.addressbook.AddressBook;
0173: import com.ivata.groupware.business.addressbook.address.AddressDO;
0174: import com.ivata.groupware.business.addressbook.address.country.CountryDO;
0175: import com.ivata.groupware.business.addressbook.person.PersonDO;
0176: import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO;
0177: import com.ivata.groupware.business.addressbook.person.group.GroupDO;
0178: import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressConstants;
0179: import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO;
0180: import com.ivata.groupware.util.SettingDateFormatter;
0181: import com.ivata.mask.Mask;
0182: import com.ivata.mask.MaskFactory;
0183: import com.ivata.mask.util.StringHandling;
0184: import com.ivata.mask.util.SystemException;
0185: import com.ivata.mask.validation.ValidationError;
0186: import com.ivata.mask.validation.ValidationErrors;
0187: import com.ivata.mask.web.format.DateFormatterConstants;
0188: import com.ivata.mask.web.struts.DialogForm;
0189:
0190: /**
0191: * <p>This form is wrapper for <code>PersonDO</code>. It is used in
0192: * <code>person.jsp</code> and the tabs from that page</p>
0193: *
0194: * @since 2003-01-31
0195: * @author Colin MacLeod
0196: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
0197: * @version $Revision: 1.8 $
0198: */
0199: public class PersonForm extends DialogForm {
0200: /**
0201: * Logger for this class.
0202: */
0203: private static final Logger logger = Logger
0204: .getLogger(PersonForm.class);
0205:
0206: /**
0207: * Minimum number of empty telecom addresses to show.
0208: */
0209: public static final int MINIMUM_EMPTY_TELECOM_ADDRESSES = 3;
0210:
0211: /**
0212: * Minimum number of telecom addresses to show overall.
0213: */
0214: public static final int MINIMUM_TELECOM_ADDRESSES = 5;
0215:
0216: /**
0217: * Serialization version (for <code>Serializable</code> interface).
0218: */
0219: private static final long serialVersionUID = 1L;
0220:
0221: /**
0222: * <copyDoc>Refer to {@link PersonForm()}.</copyDoc>
0223: */
0224: private AddressBook addressBook;
0225:
0226: /**
0227: * <p>
0228: * Unique identifier of the address book group. This dictates which groups
0229: * to choose from.
0230: * </p>
0231: */
0232: private Integer addressBookGroupId;
0233:
0234: /**
0235: * <p>
0236: * Name of the address book group. This dictates which groups
0237: * to choose from.
0238: * </p>
0239: */
0240: private String addressBookGroupName;
0241:
0242: /**
0243: * <p>
0244: * Map of all address book names available. This is used to construct a
0245: * combo list for the user to choose from.
0246: * </p>
0247: */
0248: private Map addressBookGroupNames;
0249: /**
0250: * <p>
0251: * Defines the base class of all objects in the value object list.
0252: * </p>
0253: */
0254: private Class baseClass;
0255: /**
0256: *<p><code>true</code> if the current user can remove this person.</p>
0257: */
0258: private boolean canRemove;
0259: /**
0260: * <p><code>true</code> if the address book field has been changed.</p>
0261: */
0262: private String changedAddressBook;
0263: /**
0264: * <copyDoc>Refer to {@link PersonForm()}.</copyDoc>
0265: */
0266: private SettingDateFormatter dateFormatter;
0267:
0268: /**
0269: * <p>Stores the person's date of birth in the format specified by
0270: * setting 'i18nDateInputDisplay'.</p>
0271: */
0272: private String dateOfBirthString;
0273: /**
0274: * <p>Set to <code>true</code> if this person is an employee.
0275: * Otherwise, <code>false</code>.</p>
0276: */
0277: private boolean employee;
0278:
0279: /**
0280: * <p>Users can be enabled and disabled. This lets the system retain
0281: * user information such as comments whilst locking the user out.</p>
0282: */
0283: private boolean enableUser;
0284: /**
0285: * <p>Stores the index of the last telecom address being displayed.
0286: * This is used to increase the list by 3 every time the "show more"
0287: * button is clicked.</p>
0288: */
0289: private Integer lastTelecomAddress;
0290:
0291: /**
0292: * <p>
0293: * Mask containing all the field definitions for this list.
0294: * </p>
0295: */
0296: private Mask mask;
0297: /**
0298: * <p>If non-<code>null</code> and not empty, indicates we should
0299: * display more telecom address fields.</p>
0300: */
0301: private String moreTelecomAddresses;
0302: /**
0303: * <p>Instance of person data object, containing all values
0304: * of person being submitted.</p>
0305: */
0306: private PersonDO person;
0307: /**
0308: * <p>
0309: * Indicates which TAB is active. This name is generated by the tab control
0310: * and depends on the name of the tab control !!!!!
0311: * </p>
0312: */
0313: private Integer personTabActiveTab;
0314: /**
0315: * <p>
0316: * Indicates the localization key of the active tab. This name is generated
0317: * by the tab control and depends on the name of the tab control !!!!!
0318: * </p>
0319: */
0320: private String personTabActiveTabKey;
0321: /**
0322: *<p>
0323: *<code>true</code> if the information in this form cannot be changed.
0324: *</p>
0325: */
0326: private boolean readOnly;
0327:
0328: /**
0329: * <p>If <code>true</code> then the main frame is loaded
0330: * with the address book list when the dialog closes.</p>
0331: */
0332: private boolean refreshOnExit;
0333: /**
0334: * <copyDoc>Refer to {@link PersonForm()}.</copyDoc>
0335: */
0336: private Security security;
0337: /**
0338: * <p>
0339: * Contains the localization key for each of the tabs to be shown.
0340: * </p>
0341: */
0342: private List tabKeys = new Vector();
0343: /**
0344: * <p>Absolute (to application context) location of the page to
0345: * include for the tab body.</p>
0346: */
0347: private String tabPage;
0348: /**
0349: * <p>
0350: * This list representation of the telecom addresses in person are easier
0351: * for <strong>Struts</strong> to manipulate.
0352: * </p>
0353: */
0354: private List telecomAddresses;
0355: /**
0356: * <p>The title we will display depends on the action we're taking -
0357: * add, amend or removed.</p>
0358: */
0359: private String titleKey;
0360: /**
0361: * <p>Stores the new user name of the person. This is done so we can
0362: * compare with before to see if the person is a new user, has had
0363: * his/her user name changed or has lost the right to be a user.</p>
0364: */
0365: private String userName;
0366:
0367: /**
0368: * <p>
0369: * If <code>true</code> then the user tab is shown but cannot be changed.
0370: * </p>
0371: */
0372: private boolean userTabReadOnly;
0373:
0374: /**
0375: * <p>
0376: * Constructor - called by <strong>PicoContainer</strong>.
0377: * </p>
0378: *
0379: * @param addressBookParam Used to validate elements of the form.
0380: * @param dateFormatterParam Parses the date of birth field.
0381: * @param securityParam Checks if the person is a user (to confirm the
0382: * data entry).
0383: * @param maskFactoryParam Used to retrieve the mask for this form (used
0384: * in error reporting).
0385: */
0386: public PersonForm(final AddressBook addressBookParam,
0387: final SettingDateFormatter dateFormatterParam,
0388: final Security securityParam,
0389: final MaskFactory maskFactoryParam) {
0390: this .addressBook = addressBookParam;
0391: this .dateFormatter = dateFormatterParam;
0392: this .security = securityParam;
0393: mask = maskFactoryParam.getMask(PersonDO.class);
0394: }
0395:
0396: /**
0397: * <p>
0398: * Return all form state to initial values.
0399: * </p>
0400: *
0401: * @see com.ivata.mask.web.struts.MaskForm#clear()
0402: */
0403: protected void clear() {
0404: if (logger.isDebugEnabled()) {
0405: logger.debug("clear() - start");
0406: }
0407:
0408: addressBookGroupId = null;
0409: addressBookGroupName = "";
0410: canRemove = false;
0411: changedAddressBook = null;
0412: dateOfBirthString = null;
0413: enableUser = false;
0414: employee = false;
0415: lastTelecomAddress = null;
0416: moreTelecomAddresses = null;
0417: person = new PersonDO();
0418: personTabActiveTab = null;
0419: personTabActiveTabKey = null;
0420: readOnly = false;
0421: refreshOnExit = true;
0422: tabKeys = new Vector();
0423: tabPage = "/addressBook/personDetails.jsp";
0424: telecomAddresses = new Vector();
0425: titleKey = "person.title.new";
0426: userName = null;
0427: userTabReadOnly = false;
0428:
0429: if (logger.isDebugEnabled()) {
0430: logger.debug("clear() - end");
0431: }
0432: }
0433:
0434: /**
0435: * <p>
0436: * Helper to find and set the country on a changed address.
0437: * </p>
0438: *
0439: * @param securitySession Used to validate the current user when looking
0440: * up the country.
0441: */
0442: public void findAndSetCountry(final SecuritySession securitySession) {
0443: if (logger.isDebugEnabled()) {
0444: logger
0445: .debug("findAndSetCountry(SecuritySession securitySession = "
0446: + securitySession + ") - start");
0447: }
0448:
0449: // first update the country in the person's address
0450: AddressDO address = person.getAddress();
0451: CountryDO addressCountry = new CountryDO();
0452: if (address != null) {
0453: if ((address.getCountry() != null)
0454: && !StringHandling.isNullOrEmpty(address
0455: .getCountry().getCode())) {
0456: try {
0457: addressCountry = addressBook.findCountryByCode(
0458: securitySession, address.getCountry()
0459: .getCode());
0460: } catch (SystemException e) {
0461: logger.error("findAndSetCountry(SecuritySession)",
0462: e);
0463:
0464: throw new RuntimeException(e);
0465: }
0466: }
0467: address.setCountry(addressCountry);
0468: }
0469: // now update the country in the person's employee record
0470: EmployeeDO this Employee = person.getEmployee();
0471: if (this Employee != null) {
0472: CountryDO employeeCountry = new CountryDO();
0473: if ((this Employee.getCountry() != null)
0474: && !StringHandling.isNullOrEmpty(this Employee
0475: .getCountry().getCode())) {
0476: try {
0477: employeeCountry = addressBook.findCountryByCode(
0478: securitySession, this Employee.getCountry()
0479: .getCode());
0480: } catch (SystemException e) {
0481: logger.error("findAndSetCountry(SecuritySession)",
0482: e);
0483:
0484: throw new RuntimeException(e);
0485: }
0486: } else {
0487: // if the employee country is empty, default it to the address
0488: // country
0489: employeeCountry = addressCountry;
0490: }
0491: this Employee.setCountry(employeeCountry);
0492: }
0493:
0494: if (logger.isDebugEnabled()) {
0495: logger.debug("findAndSetCountry(SecuritySession) - end");
0496: }
0497: }
0498:
0499: /**
0500: * <p>
0501: * Unique identifier of the address book group. This dictates which groups
0502: * to choose from.
0503: * </p>
0504: *
0505: * @return current value of addressBookId.
0506: */
0507: public final Integer getAddressBookGroupId() {
0508: if (logger.isDebugEnabled()) {
0509: logger.debug("getAddressBookGroupId() - start");
0510: }
0511:
0512: if (logger.isDebugEnabled()) {
0513: logger
0514: .debug("getAddressBookGroupId() - end - return value = "
0515: + addressBookGroupId);
0516: }
0517: return addressBookGroupId;
0518: }
0519:
0520: /**
0521: * <p>
0522: * Name of the address book group. This dictates which groups
0523: * to choose from.
0524: * </p>
0525: *
0526: * @return current value of addressBookGroupName.
0527: */
0528: public final String getAddressBookGroupName() {
0529: if (logger.isDebugEnabled()) {
0530: logger.debug("getAddressBookGroupName() - start");
0531: }
0532:
0533: if (logger.isDebugEnabled()) {
0534: logger
0535: .debug("getAddressBookGroupName() - end - return value = "
0536: + addressBookGroupName);
0537: }
0538: return addressBookGroupName;
0539: }
0540:
0541: /**
0542: * <p>
0543: * Map of all address books available. This is used to construct a combo
0544: * list for the user to choose from.
0545: * </p>
0546: *
0547: * @return current value of addressBookGroups.
0548: */
0549: public final Map getAddressBookGroupNames() {
0550: if (logger.isDebugEnabled()) {
0551: logger.debug("getAddressBookGroupNames() - start");
0552: }
0553:
0554: if (logger.isDebugEnabled()) {
0555: logger
0556: .debug("getAddressBookGroupNames() - end - return value = "
0557: + addressBookGroupNames);
0558: }
0559: return addressBookGroupNames;
0560: }
0561:
0562: /**
0563: * <p>
0564: * Defines the base class of all objects in the value object list.
0565: * </p>
0566: *
0567: * @return base class of all objects in the value object list.
0568: */
0569: public final Class getBaseClass() {
0570: if (logger.isDebugEnabled()) {
0571: logger.debug("getBaseClass() - start");
0572: }
0573:
0574: if (logger.isDebugEnabled()) {
0575: logger.debug("getBaseClass() - end - return value = "
0576: + baseClass);
0577: }
0578: return baseClass;
0579: }
0580:
0581: /**
0582: *<p>Find out whether or not the current user can remove this person.</p>
0583: *
0584: * @return <code>true</code> if the current user can remove.
0585: */
0586: public final boolean getCanRemove() {
0587: if (logger.isDebugEnabled()) {
0588: logger.debug("getCanRemove() - start");
0589: }
0590:
0591: if (logger.isDebugEnabled()) {
0592: logger.debug("getCanRemove() - end - return value = "
0593: + this .canRemove);
0594: }
0595: return this .canRemove;
0596: }
0597:
0598: /**
0599: * <p>Discover whether or not the address book value has changed.</p>
0600: *
0601: * @return <code>true</code> if the address book combo value has changed.
0602: */
0603: public final String getChangedAddressBook() {
0604: if (logger.isDebugEnabled()) {
0605: logger.debug("getChangedAddressBook() - start");
0606: }
0607:
0608: if (logger.isDebugEnabled()) {
0609: logger
0610: .debug("getChangedAddressBook() - end - return value = "
0611: + this .changedAddressBook);
0612: }
0613: return this .changedAddressBook;
0614: }
0615:
0616: /**
0617: * <p>returns the person's date of birth in the format specified by
0618: * setting 'i18nDateInputDisplay'.</p>
0619: * @return the person's date of birth in the format specified by
0620: * setting 'i18nDateInputDisplay'
0621: */
0622: public final String getDateOfBirthString() {
0623: if (logger.isDebugEnabled()) {
0624: logger.debug("getDateOfBirthString() - start");
0625: }
0626:
0627: if (logger.isDebugEnabled()) {
0628: logger
0629: .debug("getDateOfBirthString() - end - return value = "
0630: + dateOfBirthString);
0631: }
0632: return dateOfBirthString;
0633: }
0634:
0635: /**
0636: * <p>Users can be enabled and disabled. This lets the system retain
0637: * user information such as comments whilst locking the user out.</p>
0638: *
0639: * @return the current value of enableUser.
0640: */
0641: public final boolean getEnableUser() {
0642: if (logger.isDebugEnabled()) {
0643: logger.debug("getEnableUser() - start");
0644: }
0645:
0646: if (logger.isDebugEnabled()) {
0647: logger.debug("getEnableUser() - end - return value = "
0648: + enableUser);
0649: }
0650: return enableUser;
0651: }
0652:
0653: /**
0654: * <p>Stores the index of the last telecom address being displayed.
0655: * This is used to increase the list by 3 every time the "show more"
0656: * button is clicked.</p>
0657: *
0658: * @return the current value of lastTelecomAddress.
0659: */
0660: public final Integer getLastTelecomAddress() {
0661: if (logger.isDebugEnabled()) {
0662: logger.debug("getLastTelecomAddress() - start");
0663: }
0664:
0665: if (logger.isDebugEnabled()) {
0666: logger
0667: .debug("getLastTelecomAddress() - end - return value = "
0668: + lastTelecomAddress);
0669: }
0670: return lastTelecomAddress;
0671: }
0672:
0673: /**
0674: * <p>
0675: * Mask containing all the field definitions for this list.
0676: * </p>
0677: *
0678: * @return mask containing all the field definitions for this list.
0679: */
0680: public final Mask getMask() {
0681: if (logger.isDebugEnabled()) {
0682: logger.debug("getMask() - start");
0683: }
0684:
0685: if (logger.isDebugEnabled()) {
0686: logger.debug("getMask() - end - return value = " + mask);
0687: }
0688: return mask;
0689: }
0690:
0691: /**
0692: * <p>If non-<code>null</code> and not empty, indicates we should
0693: * display more telecom address fields.</p>
0694: *
0695: * @return the current value of moreTelecomAddresses.
0696: */
0697: public final String getMoreTelecomAddresses() {
0698: if (logger.isDebugEnabled()) {
0699: logger.debug("getMoreTelecomAddresses() - start");
0700: }
0701:
0702: if (logger.isDebugEnabled()) {
0703: logger
0704: .debug("getMoreTelecomAddresses() - end - return value = "
0705: + moreTelecomAddresses);
0706: }
0707: return moreTelecomAddresses;
0708: }
0709:
0710: /**
0711: * <p>Get the values of the person this form refers to as a dependent
0712: * value object.</p>
0713: *
0714: * @return person values this form refers to.
0715: *
0716: */
0717: public PersonDO getPerson() {
0718: if (logger.isDebugEnabled()) {
0719: logger.debug("getPerson() - start");
0720: }
0721:
0722: if (logger.isDebugEnabled()) {
0723: logger
0724: .debug("getPerson() - end - return value = "
0725: + person);
0726: }
0727: return person;
0728: }
0729:
0730: /**
0731: * <p>
0732: * Indicates which TAB is active. This name is generated by the tab control
0733: * and depends on the name of the form !!!!!
0734: * </p>
0735: *
0736: * @return the current value of personTabActiveTab.
0737:
0738: */
0739: public final Integer getPersonTabActiveTab() {
0740: if (logger.isDebugEnabled()) {
0741: logger.debug("getPersonTabActiveTab() - start");
0742: }
0743:
0744: if (logger.isDebugEnabled()) {
0745: logger
0746: .debug("getPersonTabActiveTab() - end - return value = "
0747: + personTabActiveTab);
0748: }
0749: return personTabActiveTab;
0750: }
0751:
0752: /**
0753: * <p>
0754: * Indicates the localization key of the active tab. This name is generated
0755: * by the tab control and depends on the name of the form !!!!!
0756: * </p>
0757: *
0758: * @return Returns the personTabActiveTabKey.
0759: */
0760: public final String getPersonTabActiveTabKey() {
0761: if (logger.isDebugEnabled()) {
0762: logger.debug("getPersonTabActiveTabKey() - start");
0763: }
0764:
0765: if (logger.isDebugEnabled()) {
0766: logger
0767: .debug("getPersonTabActiveTabKey() - end - return value = "
0768: + personTabActiveTabKey);
0769: }
0770: return personTabActiveTabKey;
0771: }
0772:
0773: /**
0774: *<p>Discover whether this person should be only displayed, or can also
0775: *be amended.</p>
0776: *
0777: * @return <code>true</code> if this person is for display only and should
0778: * not be amended.
0779: */
0780: public final boolean getReadOnly() {
0781: if (logger.isDebugEnabled()) {
0782: logger.debug("getReadOnly() - start");
0783: }
0784:
0785: if (logger.isDebugEnabled()) {
0786: logger.debug("getReadOnly() - end - return value = "
0787: + this .readOnly);
0788: }
0789: return this .readOnly;
0790: }
0791:
0792: /**
0793: * <p>If <code>true</code> then the main frame is loaded
0794: * with the address book list when the dialog closes.</p>
0795: *
0796: * @return the current value of refreshOnExit.
0797: */
0798: public final boolean getRefreshOnExit() {
0799: if (logger.isDebugEnabled()) {
0800: logger.debug("getRefreshOnExit() - start");
0801: }
0802:
0803: if (logger.isDebugEnabled()) {
0804: logger.debug("getRefreshOnExit() - end - return value = "
0805: + refreshOnExit);
0806: }
0807: return refreshOnExit;
0808: }
0809:
0810: /**
0811: * <p>
0812: * Contains the localization key for each of the tabs to be shown.
0813: * </p>
0814: *
0815: * @return Returns the tab keys.
0816: */
0817: public List getTabKeys() {
0818: if (logger.isDebugEnabled()) {
0819: logger.debug("getTabKeys() - start");
0820: }
0821:
0822: if (logger.isDebugEnabled()) {
0823: logger.debug("getTabKeys() - end - return value = "
0824: + tabKeys);
0825: }
0826: return tabKeys;
0827: }
0828:
0829: /**
0830: * <p>Absolute (to application context) location of the page to
0831: * include for the tab body.</p>
0832: *
0833: * @return the current value of tabPage.
0834: */
0835: public final String getTabPage() {
0836: if (logger.isDebugEnabled()) {
0837: logger.debug("getTabPage() - start");
0838: }
0839:
0840: if (logger.isDebugEnabled()) {
0841: logger.debug("getTabPage() - end - return value = "
0842: + tabPage);
0843: }
0844: return tabPage;
0845: }
0846:
0847: /**
0848: * Get the telecom addresses of this user, as a <code>List</code> of
0849: * {@link TelecomAddressDO} instances.
0850: *
0851: * @return Returns the telecom addresses.
0852: */
0853: public List getTelecomAddresses() {
0854: if (logger.isDebugEnabled()) {
0855: logger.debug("getTelecomAddresses() - start");
0856: }
0857:
0858: if (logger.isDebugEnabled()) {
0859: logger
0860: .debug("getTelecomAddresses() - end - return value = "
0861: + telecomAddresses);
0862: }
0863: return telecomAddresses;
0864: }
0865:
0866: /**
0867: * <p>The title we will display depends on the action we're taking -
0868: * add, amend or removed.</p>
0869: *
0870: * @return the current value of titleKey.
0871: */
0872: public final String getTitleKey() {
0873: if (logger.isDebugEnabled()) {
0874: logger.debug("getTitleKey() - start");
0875: }
0876:
0877: if (logger.isDebugEnabled()) {
0878: logger.debug("getTitleKey() - end - return value = "
0879: + titleKey);
0880: }
0881: return titleKey;
0882: }
0883:
0884: /**
0885: * <p>Stores the new user name of the person. This is done so we can
0886: * compare with before to see if the person is a new user, has had
0887: * his/her user name changed or has lost the right to be a user.</p>
0888: *
0889: * @return the current value of userName.
0890: */
0891: public final String getUserName() {
0892: if (logger.isDebugEnabled()) {
0893: logger.debug("getUserName() - start");
0894: }
0895:
0896: if (logger.isDebugEnabled()) {
0897: logger.debug("getUserName() - end - return value = "
0898: + userName);
0899: }
0900: return userName;
0901: }
0902:
0903: /**
0904: * <p>Set to <code>true</code> if this person is an employee.
0905: * Otherwise, <code>false</code>.</p>
0906: *
0907: * @return the current value of employee.
0908: */
0909: public boolean isEmployee() {
0910: if (logger.isDebugEnabled()) {
0911: logger.debug("isEmployee() - start");
0912: }
0913:
0914: if (logger.isDebugEnabled()) {
0915: logger.debug("isEmployee() - end - return value = "
0916: + employee);
0917: }
0918: return employee;
0919: }
0920:
0921: /**
0922: * <p>
0923: * If <code>true</code> then the user tab is shown but cannot be changed.
0924: * </p>
0925: *
0926: * @return current value of userTabReadOnly.
0927: */
0928: public boolean isUserTabReadOnly() {
0929: if (logger.isDebugEnabled()) {
0930: logger.debug("isUserTabReadOnly() - start");
0931: }
0932:
0933: if (logger.isDebugEnabled()) {
0934: logger.debug("isUserTabReadOnly() - end - return value = "
0935: + userTabReadOnly);
0936: }
0937: return userTabReadOnly;
0938: }
0939:
0940: /**
0941: * <p>Reset all bean properties to their default state. This method
0942: * is called before the properties are repopulated by the controller
0943: * servlet.</p>
0944: *
0945: * @param mapping The mapping used to select this instance
0946: * @param request The servlet request we are processing
0947: */
0948: public void reset(final ActionMapping mapping,
0949: final HttpServletRequest request) {
0950: if (logger.isDebugEnabled()) {
0951: logger.debug("reset(ActionMapping mapping = " + mapping
0952: + ", HttpServletRequest request = " + request
0953: + ") - start");
0954: }
0955:
0956: // get the email address host which matches the current user
0957: if (request.getParameter("changedAddressBook") == null) {
0958: this .setChangedAddressBook("false");
0959: }
0960: // find out which tab has just been clicked
0961: if ("/addressBook/address.jsp".equals(tabPage)) {
0962: AddressDO address = new AddressDO();
0963: address.setCountry(new CountryDO());
0964: person.setAddress(address);
0965: } else if ("/addressBook/telecomAddress.jsp".equals(tabPage)) {
0966: moreTelecomAddresses = null;
0967: Iterator telecomAddressIterator = telecomAddresses
0968: .iterator();
0969: while (telecomAddressIterator.hasNext()) {
0970: TelecomAddressDO telecomAddress = (TelecomAddressDO) telecomAddressIterator
0971: .next();
0972: telecomAddress.setAddress("");
0973: }
0974: } else if ("/addressBook/user.jsp".equals(tabPage)) {
0975: enableUser = false;
0976: userName = "";
0977: } else if ("/addressBook/employee.jsp".equals(tabPage)) {
0978: employee = false;
0979: EmployeeDO personEmployee = person.getEmployee();
0980: personEmployee.setCountry(new CountryDO());
0981: personEmployee.setNumber("");
0982: personEmployee.setVacationDays(null);
0983:
0984: } else if (request.getParameter("person.company") != null) {
0985: person.setCompany("");
0986: person.setDateOfBirth(null);
0987: person.setFileAs("");
0988: person.setFirstNames("");
0989: person.setJobTitle("");
0990: person.setLastName("");
0991: person.setSalutation("");
0992: }
0993: personTabActiveTab = null;
0994: personTabActiveTabKey = "";
0995:
0996: super .reset(mapping, request);
0997:
0998: if (logger.isDebugEnabled()) {
0999: logger
1000: .debug("reset(ActionMapping, HttpServletRequest) - end");
1001: }
1002: }
1003:
1004: /**
1005: * <p>
1006: * Unique identifier of the address book group. This dictates which groups
1007: * to choose from.
1008: * </p>
1009: *
1010: * @param addressBookId new value of addressBookId.
1011: */
1012: public final void setAddressBookGroupId(final Integer addressBookId) {
1013: if (logger.isDebugEnabled()) {
1014: logger
1015: .debug("setAddressBookGroupId(Integer addressBookId = "
1016: + addressBookId + ") - start");
1017: }
1018:
1019: this .addressBookGroupId = addressBookId;
1020:
1021: if (logger.isDebugEnabled()) {
1022: logger.debug("setAddressBookGroupId(Integer) - end");
1023: }
1024: }
1025:
1026: /**
1027: * <p>
1028: * Name of the address book group. This dictates which groups
1029: * to choose from.
1030: * </p>
1031: *
1032: * @param addressBookGroupNameParam new value of addressBookGroupName.
1033: */
1034: public final void setAddressBookGroupName(
1035: final String addressBookGroupNameParam) {
1036: if (logger.isDebugEnabled()) {
1037: logger
1038: .debug("setAddressBookGroupName(String addressBookGroupName = "
1039: + addressBookGroupNameParam + ") - start");
1040: }
1041:
1042: this .addressBookGroupName = addressBookGroupNameParam;
1043:
1044: if (logger.isDebugEnabled()) {
1045: logger.debug("setAddressBookGroupName(String) - end");
1046: }
1047: }
1048:
1049: /**
1050: * <p>
1051: * Map of all address books available. This is used to construct a combo
1052: * list for the user to choose from.
1053: * </p>
1054: *
1055: * @param addressBookGroups new value of addressBookGroups.
1056: */
1057: public final void setAddressBookGroupNames(
1058: final Map addressBookGroups) {
1059: if (logger.isDebugEnabled()) {
1060: logger
1061: .debug("setAddressBookGroupNames(Map addressBookGroups = "
1062: + addressBookGroups + ") - start");
1063: }
1064:
1065: this .addressBookGroupNames = addressBookGroups;
1066:
1067: if (logger.isDebugEnabled()) {
1068: logger.debug("setAddressBookGroupNames(Map) - end");
1069: }
1070: }
1071:
1072: /**
1073: *<copyDoc>Refer to {@link #getCanRemove}.</copyDoc>
1074: *
1075: * @param canRemoveParam
1076: * <copyDoc>Refer to {@link #getCanRemove}.</copyDoc>
1077: */
1078: public final void setCanRemove(final boolean canRemoveParam) {
1079: if (logger.isDebugEnabled()) {
1080: logger.debug("setCanRemove(boolean canRemove = "
1081: + canRemoveParam + ") - start");
1082: }
1083:
1084: this .canRemove = canRemoveParam;
1085:
1086: if (logger.isDebugEnabled()) {
1087: logger.debug("setCanRemove(boolean) - end");
1088: }
1089: }
1090:
1091: /**
1092: * <copyDoc>Refer to {@link #getChangedAddressBook()}.</copyDoc>
1093: *
1094: * @param changedAddressBookParam
1095: * <copyDoc>Refer to {@link #getChangedAddressBook()}.</copyDoc>
1096: */
1097: public final void setChangedAddressBook(
1098: final String changedAddressBookParam) {
1099: if (logger.isDebugEnabled()) {
1100: logger
1101: .debug("setChangedAddressBook(String changedAddressBook = "
1102: + changedAddressBookParam + ") - start");
1103: }
1104:
1105: this .changedAddressBook = changedAddressBookParam;
1106:
1107: if (logger.isDebugEnabled()) {
1108: logger.debug("setChangedAddressBook(String) - end");
1109: }
1110: }
1111:
1112: /**
1113: * <p>Set the person's date of birth in the format 'dd.MM.YYYY'.</p>
1114: *
1115: * @param dateOfBirthStringParam the person's date of birth in the format
1116: * 'dd.MM.YYYY'.
1117: *
1118: */
1119: public final void setDateOfBirthString(
1120: final String dateOfBirthStringParam) {
1121: if (logger.isDebugEnabled()) {
1122: logger
1123: .debug("setDateOfBirthString(String dateOfBirthString = "
1124: + dateOfBirthStringParam + ") - start");
1125: }
1126:
1127: this .dateOfBirthString = dateOfBirthStringParam;
1128:
1129: if (logger.isDebugEnabled()) {
1130: logger.debug("setDateOfBirthString(String) - end");
1131: }
1132: }
1133:
1134: /**
1135: * <p>Set to <code>true</code> if this person is an employee.
1136: * Otherwise, <code>false</code>.</p>
1137: *
1138: * @param employeeParam the new value of employee.
1139: */
1140: public final void setEmployee(final boolean employeeParam) {
1141: if (logger.isDebugEnabled()) {
1142: logger.debug("setEmployee(boolean employee = "
1143: + employeeParam + ") - start");
1144: }
1145:
1146: this .employee = employeeParam;
1147:
1148: if (logger.isDebugEnabled()) {
1149: logger.debug("setEmployee(boolean) - end");
1150: }
1151: }
1152:
1153: /**
1154: * <p>Users can be enabled and disabled. This lets the system retain
1155: * user information such as comments whilst locking the user out.</p>
1156: *
1157: * @param enableUserParam the new value of enableUser.
1158: */
1159: public final void setEnableUser(final boolean enableUserParam) {
1160: if (logger.isDebugEnabled()) {
1161: logger.debug("setEnableUser(boolean enableUser = "
1162: + enableUserParam + ") - start");
1163: }
1164:
1165: this .enableUser = enableUserParam;
1166:
1167: if (logger.isDebugEnabled()) {
1168: logger.debug("setEnableUser(boolean) - end");
1169: }
1170: }
1171:
1172: /**
1173: * <p>Stores the index of the last telecom address being displayed.
1174: * This is used to increase the list by 3 every time the "show more"
1175: * button is clicked.</p>
1176: *
1177: * @param lastTelecomAddressParam the new value of lastTelecomAddress.
1178: */
1179: public final void setLastTelecomAddress(
1180: final Integer lastTelecomAddressParam) {
1181: if (logger.isDebugEnabled()) {
1182: logger
1183: .debug("setLastTelecomAddress(Integer lastTelecomAddress = "
1184: + lastTelecomAddressParam + ") - start");
1185: }
1186:
1187: this .lastTelecomAddress = lastTelecomAddressParam;
1188:
1189: if (logger.isDebugEnabled()) {
1190: logger.debug("setLastTelecomAddress(Integer) - end");
1191: }
1192: }
1193:
1194: /**
1195: * <p>If non-<code>null</code> and not empty, indicates we should
1196: * display more telecom address fields.</p>
1197: *
1198: * @param moreTelecomAddressesParam the new value of moreTelecomAddresses.
1199: */
1200: public final void setMoreTelecomAddresses(
1201: final String moreTelecomAddressesParam) {
1202: if (logger.isDebugEnabled()) {
1203: logger
1204: .debug("setMoreTelecomAddresses(String moreTelecomAddresses = "
1205: + moreTelecomAddressesParam + ") - start");
1206: }
1207:
1208: this .moreTelecomAddresses = moreTelecomAddressesParam;
1209:
1210: if (logger.isDebugEnabled()) {
1211: logger.debug("setMoreTelecomAddresses(String) - end");
1212: }
1213: }
1214:
1215: /**
1216: * <p>Get the values of the person this form refers to as a dependent
1217: * value object.</p>
1218: *
1219: * @param personParam person values this form refers to.
1220: *
1221: */
1222: public final void setPerson(final PersonDO personParam) {
1223: if (logger.isDebugEnabled()) {
1224: logger.debug("setPerson(PersonDO person = " + personParam
1225: + ") - start");
1226: }
1227:
1228: this .person = personParam;
1229: // set all the telecom addresses
1230: telecomAddresses = new Vector();
1231: telecomAddresses.addAll(personParam.getTelecomAddresses());
1232: // set the user name
1233: userName = "";
1234: if (personParam.getUser() != null) {
1235: userName = personParam.getUser().getName();
1236: }
1237:
1238: // set the address book name and id
1239: if ((personParam.getGroup() != null)
1240: && (personParam.getGroup().getAddressBook() != null)) {
1241: GroupDO addressBookGroup = personParam.getGroup()
1242: .getAddressBook();
1243: addressBookGroupId = addressBookGroup.getId();
1244: addressBookGroupName = addressBookGroup.getName();
1245: }
1246:
1247: if (logger.isDebugEnabled()) {
1248: logger.debug("setPerson(PersonDO) - end");
1249: }
1250: }
1251:
1252: /**
1253: * <p>
1254: * Update the person to show all the addresses currently in the form.
1255: * </p>
1256: */
1257: public void setPersonFromTelecomAddresses() {
1258: if (logger.isDebugEnabled()) {
1259: logger.debug("setPersonFromTelecomAddresses() - start");
1260: }
1261:
1262: // remove empty telecom addresses
1263: Iterator formTelecomAddressIterator = telecomAddresses
1264: .iterator();
1265: Set personTelecomAddresses = new HashSet();
1266: while (formTelecomAddressIterator.hasNext()) {
1267: TelecomAddressDO this TelecomAddress = (TelecomAddressDO) formTelecomAddressIterator
1268: .next();
1269: if (!StringHandling.isNullOrEmpty(this TelecomAddress
1270: .getAddress())) {
1271: personTelecomAddresses.add(this TelecomAddress);
1272: }
1273: }
1274: person.setTelecomAddresses(personTelecomAddresses);
1275:
1276: if (logger.isDebugEnabled()) {
1277: logger.debug("setPersonFromTelecomAddresses() - end");
1278: }
1279: }
1280:
1281: /**
1282: * <p>
1283: * Indicates which TAB is active. This name is generated by the tab control
1284: * and depends on the name of the form !!!!!
1285: * </p>
1286: *
1287: * @param personTabActiveTabParam the new value of personTabActiveTab.
1288:
1289: */
1290: public final void setPersonTabActiveTab(
1291: final Integer personTabActiveTabParam) {
1292: if (logger.isDebugEnabled()) {
1293: logger
1294: .debug("setPersonTabActiveTab(Integer personTabActiveTab = "
1295: + personTabActiveTabParam + ") - start");
1296: }
1297:
1298: this .personTabActiveTab = personTabActiveTabParam;
1299:
1300: if (logger.isDebugEnabled()) {
1301: logger.debug("setPersonTabActiveTab(Integer) - end");
1302: }
1303: }
1304:
1305: /**
1306: * <p>
1307: * Indicates the localization key of the active tab. This name is generated
1308: * by the tab control and depends on the name of the form !!!!!
1309: * </p>
1310: *
1311: * @param personTabActiveTabKeyParam The personTabActiveTabKey to set.
1312: */
1313: public final void setPersonTabActiveTabKey(
1314: final String personTabActiveTabKeyParam) {
1315: if (logger.isDebugEnabled()) {
1316: logger
1317: .debug("setPersonTabActiveTabKey(String personTabActiveTabKey = "
1318: + personTabActiveTabKeyParam + ") - start");
1319: }
1320:
1321: this .personTabActiveTabKey = personTabActiveTabKeyParam;
1322:
1323: if (logger.isDebugEnabled()) {
1324: logger.debug("setPersonTabActiveTabKey(String) - end");
1325: }
1326: }
1327:
1328: /**
1329: * <copyDoc>Refer to {@link #getReadOnly()}.</copyDoc>
1330: *
1331: * @param readOnlyParam
1332: * <copyDoc>Refer to {@link #getReadOnly()}.</copyDoc>
1333: */
1334: public final void setReadOnly(final boolean readOnlyParam) {
1335: if (logger.isDebugEnabled()) {
1336: logger.debug("setReadOnly(boolean readOnly = "
1337: + readOnlyParam + ") - start");
1338: }
1339:
1340: this .readOnly = readOnlyParam;
1341:
1342: if (logger.isDebugEnabled()) {
1343: logger.debug("setReadOnly(boolean) - end");
1344: }
1345: }
1346:
1347: /**
1348: * <p>If <code>true</code> then the main frame is loaded
1349: * with the address book list when the dialog closes.</p>
1350: *
1351: * @param refreshOnExitParam the new value of refreshOnExit.
1352: */
1353: public final void setRefreshOnExit(final boolean refreshOnExitParam) {
1354: if (logger.isDebugEnabled()) {
1355: logger.debug("setRefreshOnExit(boolean refreshOnExit = "
1356: + refreshOnExitParam + ") - start");
1357: }
1358:
1359: this .refreshOnExit = refreshOnExitParam;
1360:
1361: if (logger.isDebugEnabled()) {
1362: logger.debug("setRefreshOnExit(boolean) - end");
1363: }
1364: }
1365:
1366: /**
1367: * <p>
1368: * Contains the localization key for each of the tabs to be shown.
1369: * </p>
1370: *
1371: * @param tabKeysParam New value of tab keys.
1372: */
1373: public final void setTabKeys(final List tabKeysParam) {
1374: if (logger.isDebugEnabled()) {
1375: logger.debug("setTabKeys(List tabKeys = " + tabKeysParam
1376: + ") - start");
1377: }
1378:
1379: this .tabKeys = tabKeysParam;
1380:
1381: if (logger.isDebugEnabled()) {
1382: logger.debug("setTabKeys(List) - end");
1383: }
1384: }
1385:
1386: /**
1387: * <p>Absolute (to application context) location of the page to
1388: * include for the tab body.</p>
1389: *
1390: * @param tabPageParam the new value of tabPage.
1391: */
1392: public final void setTabPage(final String tabPageParam) {
1393: if (logger.isDebugEnabled()) {
1394: logger.debug("setTabPage(String tabPage = " + tabPageParam
1395: + ") - start");
1396: }
1397:
1398: this .tabPage = tabPageParam;
1399:
1400: if (logger.isDebugEnabled()) {
1401: logger.debug("setTabPage(String) - end");
1402: }
1403: }
1404:
1405: /**
1406: * <copyDoc>Refer to {@link #getTelecomAddresses()}.</copyDoc>
1407: *
1408: * @param telecomAddressesParam
1409: * <copyDoc>Refer to {@link #getTelecomAddresses()}.</copyDoc>
1410: */
1411: public final void setTelecomAddresses(
1412: final List telecomAddressesParam) {
1413: if (logger.isDebugEnabled()) {
1414: logger.debug("setTelecomAddresses(List telecomAddresses = "
1415: + telecomAddressesParam + ") - start");
1416: }
1417:
1418: this .telecomAddresses = telecomAddressesParam;
1419:
1420: if (logger.isDebugEnabled()) {
1421: logger.debug("setTelecomAddresses(List) - end");
1422: }
1423: }
1424:
1425: /**
1426: * <p>
1427: * Initialize the telecom addresses on the form from the person object.
1428: * </p>
1429: */
1430: public final void setTelecomAddressesFromPerson() {
1431: if (logger.isDebugEnabled()) {
1432: logger.debug("setTelecomAddressesFromPerson() - start");
1433: }
1434:
1435: // first remove the blank telecom addresses
1436: Iterator personTelecomAddressIterator = person
1437: .getTelecomAddresses().iterator();
1438: telecomAddresses = new Vector();
1439: while (personTelecomAddressIterator.hasNext()) {
1440: TelecomAddressDO this TelecomAddress = (TelecomAddressDO) personTelecomAddressIterator
1441: .next();
1442: if (!StringHandling.isNullOrEmpty(this TelecomAddress
1443: .getAddress())) {
1444: telecomAddresses.add(this TelecomAddress);
1445: }
1446: }
1447: // show at least 5 telecom addresses in total, at least 3 blank ones
1448: int totalTelecomAddresses = telecomAddresses.size();
1449: int totalToShow = totalTelecomAddresses
1450: + MINIMUM_EMPTY_TELECOM_ADDRESSES;
1451: if (totalToShow < MINIMUM_TELECOM_ADDRESSES) {
1452: totalToShow = MINIMUM_TELECOM_ADDRESSES;
1453: }
1454: // if you wanted more telecom address fields, I'll give you even more
1455: if (!StringHandling.isNullOrEmpty(moreTelecomAddresses)) {
1456: totalToShow += MINIMUM_EMPTY_TELECOM_ADDRESSES;
1457: }
1458: for (int i = totalTelecomAddresses; i < totalToShow; ++i) {
1459: TelecomAddressDO newTelecomAddress = new TelecomAddressDO();
1460: telecomAddresses.add(newTelecomAddress);
1461: // iterate thro' all the types
1462: newTelecomAddress.setType(i
1463: % TelecomAddressConstants.countTypes());
1464: }
1465:
1466: if (logger.isDebugEnabled()) {
1467: logger.debug("setTelecomAddressesFromPerson() - end");
1468: }
1469: }
1470:
1471: /**
1472: * <p>The title we will display depends on the action we're taking -
1473: * add, amend or removed.</p>
1474: *
1475: * @param titleKeyParam the new value of titleKey.
1476: */
1477: public final void setTitleKey(final String titleKeyParam) {
1478: if (logger.isDebugEnabled()) {
1479: logger.debug("setTitleKey(String titleKey = "
1480: + titleKeyParam + ") - start");
1481: }
1482:
1483: this .titleKey = titleKeyParam;
1484:
1485: if (logger.isDebugEnabled()) {
1486: logger.debug("setTitleKey(String) - end");
1487: }
1488: }
1489:
1490: /**
1491: * <p>Stores the new user name of the person. This is done so we can
1492: * compare with before to see if the person is a new user, has had
1493: * his/her user name changed or has lost the right to be a user.</p>
1494: *
1495: * @param userNameParam the new value of userName.
1496: */
1497: public final void setUserName(final String userNameParam) {
1498: if (logger.isDebugEnabled()) {
1499: logger.debug("setUserName(String userName = "
1500: + userNameParam + ") - start");
1501: }
1502:
1503: this .userName = userNameParam;
1504:
1505: if (logger.isDebugEnabled()) {
1506: logger.debug("setUserName(String) - end");
1507: }
1508: }
1509:
1510: /**
1511: * <p>
1512: * If <code>true</code> then the user tab is shown but cannot be changed.
1513: * </p>
1514: *
1515: * @param userTabReadOnlyParam new value of userTabReadOnly.
1516: */
1517: public final void setUserTabReadOnly(
1518: final boolean userTabReadOnlyParam) {
1519: if (logger.isDebugEnabled()) {
1520: logger
1521: .debug("setUserTabReadOnly(boolean userTabReadOnly = "
1522: + userTabReadOnlyParam + ") - start");
1523: }
1524:
1525: this .userTabReadOnly = userTabReadOnlyParam;
1526:
1527: if (logger.isDebugEnabled()) {
1528: logger.debug("setUserTabReadOnly(boolean) - end");
1529: }
1530: }
1531:
1532: /**
1533: * {@inheritDoc}
1534: *
1535: * @param request {@inheritDoc}
1536: * @param session {@inheritDoc}
1537: * @return {@inheritDoc}
1538: */
1539: public ValidationErrors validate(final HttpServletRequest request,
1540: final HttpSession session) {
1541: if (logger.isDebugEnabled()) {
1542: logger.debug("validate(HttpServletRequest request = "
1543: + request + ", HttpSession session = " + session
1544: + ") - start");
1545: }
1546:
1547: ValidationErrors validationErrors = super .validate(request,
1548: session);
1549: SecuritySession securitySession = (SecuritySession) session
1550: .getAttribute("securitySession");
1551:
1552: // if we have userName -> correct
1553: if (!StringHandling.isNullOrEmpty(userName)) {
1554: userName = userName.toLowerCase();
1555: userName = userName.trim();
1556: // remove any spaces
1557: if (userName.indexOf(" ") != -1) {
1558: userName = userName.replaceAll(" ", "");
1559: validationErrors.add(new ValidationError("user",
1560: Security.BUNDLE_PATH, mask.getField("name"),
1561: "errors.addressBook.user.userName"));
1562: }
1563: if ((person.getUser() == null)
1564: || !userName.equals(person.getUser().getName())) {
1565: try {
1566: if (security.isUser(securitySession, userName)) {
1567: validationErrors.add(new ValidationError(
1568: "user", Security.BUNDLE_PATH, mask
1569: .getField("name"),
1570: "errors.unique"));
1571: }
1572: } catch (SystemException e1) {
1573: logger
1574: .error(
1575: "validate(HttpServletRequest, HttpSession)",
1576: e1);
1577:
1578: throw new RuntimeException(e1);
1579: }
1580: }
1581: }
1582: // update the person to reflect the current email addresses
1583: setPersonFromTelecomAddresses();
1584: // now update the form again
1585: setTelecomAddressesFromPerson();
1586:
1587: // find the address country, if an address was specified, or delete the
1588: // address if it is empty
1589: findAndSetCountry(securitySession);
1590: AddressDO address = person.getAddress();
1591: if (StringHandling.isNullOrEmpty(address.getPostCode())
1592: && StringHandling.isNullOrEmpty(address.getRegion())
1593: && StringHandling.isNullOrEmpty(address
1594: .getStreetAddress())
1595: && StringHandling.isNullOrEmpty(address.getTown())) {
1596: // if there is no address, ignore the address elements for
1597: // validation purpses (we'll set it back again at the end of this
1598: // method
1599: person.setAddress(null);
1600: }
1601:
1602: EmployeeDO personEmployee = person.getEmployee();
1603: if (!this .employee) {
1604: // if this is not an employee, ignore the employee elements for
1605: // validation purpses (we'll set it back again at the end of this
1606: // method
1607: person.setEmployee(null);
1608: }
1609:
1610: // store the 'real' user for later
1611: UserDO user = person.getUser();
1612: try {
1613: // if user is going to remove from person
1614: if ((person.getUser() != null)
1615: && StringHandling.isNullOrEmpty(userName)) {
1616: person.setUser(null);
1617: } else {
1618: // this is just to test against server-side validation of user
1619: // name and enabled state
1620: UserDO tmpUser = new UserDO();
1621: tmpUser.setDeleted(user.isDeleted());
1622: tmpUser.setEnabled(enableUser);
1623: tmpUser.setGroups(user.getGroups());
1624: tmpUser.setName(userName);
1625: person.setUser(tmpUser);
1626: }
1627: validationErrors.addAll(addressBook.validate(
1628: securitySession, person));
1629:
1630: // see if there is a date format error setting the date of birth
1631: // note: if dateOfBirth ever becomes mandatory, this will need to
1632: // be set & checked before the validate above
1633: if (StringHandling.isNullOrEmpty(dateOfBirthString)) {
1634: person.setDateOfBirth(null);
1635: } else {
1636: try {
1637: dateFormatter.setUserName((String) session
1638: .getAttribute("userName"));
1639: dateFormatter
1640: .setDateFormat(DateFormatterConstants.DATE_INPUT);
1641: dateFormatter.setDateTimeText("{0}");
1642:
1643: person.setDateOfBirth(dateFormatter
1644: .parse(dateOfBirthString));
1645: } catch (SettingsInitializationException e) {
1646: logger
1647: .error(
1648: "validate(HttpServletRequest, HttpSession)",
1649: e);
1650:
1651: throw new RuntimeException(e);
1652: } catch (ParseException e) {
1653: logger
1654: .error(
1655: "validate(HttpServletRequest, HttpSession)",
1656: e);
1657:
1658: if (validationErrors == null) {
1659: validationErrors = new ValidationErrors();
1660: }
1661: String[] parameters = { dateOfBirthString };
1662:
1663: validationErrors.add(new ValidationError(
1664: "personDetails", AddressBook.BUNDLE_PATH,
1665: mask.getField("dateOfBirthString"),
1666: "errors.date", Arrays.asList(parameters)));
1667: }
1668: }
1669: } catch (SystemException e) {
1670: logger
1671: .error("validate(HttpServletRequest, HttpSession)",
1672: e);
1673:
1674: e.printStackTrace(System.err);
1675: throw new RuntimeException(e);
1676: }
1677: // remove the active tab to return us to the start, if this is ok
1678: if (!StringHandling.isNullOrEmpty(getOk())) {
1679: session.removeAttribute("personTabActiveTab");
1680: }
1681:
1682: // return the address & employee data object to the person, if either
1683: // was set to null
1684: person.setAddress(address);
1685: person.setEmployee(personEmployee);
1686: // likewise, the user
1687: person.setUser(user);
1688:
1689: if (logger.isDebugEnabled()) {
1690: logger.debug("validate - end - return value = "
1691: + validationErrors);
1692: }
1693: return validationErrors;
1694: }
1695: }
|