KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > person > PersonDO


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: PersonDO.java,v $
31  * Revision 1.3 2005/04/10 18:47:34 colinmacleod
32  * Changed i tag to em and b tag to strong.
33  *
34  * Revision 1.2 2005/04/09 17:19:07 colinmacleod
35  * Changed copyright text to GPL v2 explicitly.
36  *
37  * Revision 1.1.1.1 2005/03/10 17:50:31 colinmacleod
38  * Restructured ivata op around Hibernate/PicoContainer.
39  * Renamed ivata groupware.
40  *
41  * Revision 1.7 2004/11/12 15:57:05 colinmacleod
42  * Removed dependencies on SSLEXT.
43  * Moved Persistence classes to ivata masks.
44  *
45  * Revision 1.6 2004/11/03 15:34:06 colinmacleod
46  * Changed relationship between person and address:
47  * each person for now has exactly one address.
48  *
49  * Revision 1.5 2004/07/18 21:59:10 colinmacleod
50  * Removed Person from User - now you need to use addressbook/persistence manager to find the person (makes the app run faster.)
51  *
52  * Revision 1.4 2004/07/13 19:41:13 colinmacleod
53  * Moved project to POJOs from EJBs.
54  * Applied PicoContainer to services layer (replacing session EJBs).
55  * Applied Hibernate to persistence layer (replacing entity EJBs).
56  *
57  * Revision 1.3 2004/03/21 21:16:06 colinmacleod
58  * Shortened name to ivata op.
59  *
60  * Revision 1.2 2004/02/01 22:00:32 colinmacleod
61  * Added full names to author tags
62  *
63  * Revision 1.1.1.1 2004/01/27 20:57:50 colinmacleod
64  * Moved ivata openportal to SourceForge..
65  *
66  * Revision 1.3 2003/10/17 12:36:12 jano
67  * fixing problems with building
68  * converting intranet -> portal
69  * Eclipse building
70  *
71  * Revision 1.2 2003/10/15 13:18:02 colin
72  * fixing for XDoclet
73  *
74  * Revision 1.7 2003/08/21 09:50:03 jano
75  * we have new field in personDO : memberOfUserGroups
76  *
77  * Revision 1.6 2003/08/20 16:24:27 jano
78  * fixing addressBook extension
79  *
80  * Revision 1.5 2003/08/05 14:57:35 jano
81  * addressBook extension
82  *
83  * Revision 1.4 2003/07/25 11:41:22 jano
84  * adding functionality for addressBook extension
85  *
86  * Revision 1.3 2003/06/02 22:04:29 colin
87  * added comparison method
88  *
89  * Revision 1.2 2003/04/09 08:52:53 jano
90  * handling data of removing user
91  *
92  * Revision 1.1 2003/02/24 19:09:21 colin
93  * moved to business
94  *
95  * Revision 1.12 2003/02/21 16:18:36 peter
96  * dateFormatter and birthDate Strings access taken off
97  *
98  * Revision 1.11 2003/02/18 11:08:54 colin
99  * fixes in setTelecomAddress...(int...
100  *
101  * Revision 1.10 2003/02/04 17:43:44 colin
102  * copyright notice
103  *
104  * Revision 1.9 2003/01/09 13:32:19 jano
105  * we have fiield in Person called : createdBy - its name of user who created that contact
106  *
107  * Revision 1.8 2002/12/19 12:56:02 jano
108  * when contact is read only then showonly name of main group
109  *
110  * Revision 1.7 2002/09/17 08:40:11 colin
111  * addeed checkDO which can be used to check before a new person is added
112  * improved methods for adding telecom addresses to the DO
113  *
114  * Revision 1.6 2002/09/09 08:37:38 colin
115  * improved documentation
116  * finished employee implementation via PersonBean.setDO
117  *
118  * Revision 1.5 2002/08/30 09:49:12 colin
119  * added employee EJB
120  * made country a separate EJB for address
121  *
122  * Revision 1.4 2002/08/29 08:49:21 jano
123  * renamed field department to mainGroup
124  *
125  * Revision 1.3 2002/06/28 13:15:23 colin
126  * first addressbook release
127  *
128  * Revision 1.2 2002/06/17 07:28:49 colin
129  * improved and extended javadoc documentation
130  *
131  * Revision 1.1 2002/06/13 11:21:24 colin
132  * first version with rose model integration.
133  * -----------------------------------------------------------------------------
134  */

135 package com.ivata.groupware.business.addressbook.person;
136
137
138 import java.util.Date JavaDoc;
139 import java.util.HashSet JavaDoc;
140 import java.util.Iterator JavaDoc;
141 import java.util.Set JavaDoc;
142
143 import com.ivata.groupware.admin.security.user.UserDO;
144 import com.ivata.groupware.business.addressbook.address.AddressDO;
145 import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO;
146 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
147 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressConstants;
148 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO;
149 import com.ivata.groupware.container.persistence.NamedDO;
150 import com.ivata.mask.util.StringHandling;
151
152
153 /**
154  * <p>Represents a single person within the intranet system. This person can
155  * be simply within the address book, or can be a user by having a
156  * {@link UserBean user} associated with it.</p>
157  *
158  * <p>This is a dependent value class, used to pass data back from the.</p>
159  * {@link PersonBean PersonBean} to a client application.</p>
160  *
161  * <p><strong>Note:</strong> This class provides data from {@link PersonBean PersonBean}.
162  * This is no local copy of the bean class, however, and changes here
163  * will not be automatically reflected in {@link PersonBean PersonBean}.</p>
164  *
165  * @since 2002-05-12
166  * @author Colin MacLeod
167  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
168  * @version $Revision: 1.3 $
169  *
170  * @hibernate.class
171  * table="person"
172  * @hibernate.cache
173  * usage="read-write"
174  */

175 public class PersonDO extends NamedDO implements Comparable JavaDoc {
176     /**
177      * <p>Store this person's address.</p>
178      */

179     private AddressDO address;
180
181     /**
182      * <p>Store the company the person works for.</p>
183      */

184     private String JavaDoc company;
185
186     /**
187      * <p>Store the person's date of birth.</p>
188      */

189     private Date JavaDoc dateOfBirth;
190
191     /**
192      * <p>
193      * Stores whether or not this person is logically deleted. If a person
194      * is a user and is deleted, then (s)he will only be logically deleted.
195      * </p>
196      */

197     private boolean deleted;
198
199     /**
200      * <p>Stores the employee record for this person as a data object.</p>
201      */

202     private EmployeeDO employee = null;
203
204     /**
205      * <p>Store the string to file the person under in the address book.</p>
206      */

207     private String JavaDoc fileAs;
208
209     /**
210      * <p>Store the person's first names.</p>
211      */

212     private String JavaDoc firstNames;
213
214     /**
215      * <p>Stores the group of this person.</p>
216      */

217     private GroupDO group;
218
219     /**
220      * <p>Store the job title for this person.</p>
221      */

222     private String JavaDoc jobTitle;
223
224     /**
225      * <p>Store the person's last name.</p>
226      */

227     private String JavaDoc lastName;
228
229     /**
230      * <p>Store the salutation with which this person likes to be greeted by
231      * post or email.</p>
232      */

233     private String JavaDoc salutation;
234
235     /**
236      * <p>Store the communication addresses themeselves.</p>
237      */

238     private Set JavaDoc telecomAddresses = new HashSet JavaDoc();
239
240     /**
241      * <p>Stores the user for this person.</p>
242      */

243     private UserDO user;
244
245     /**
246      * Get all the addresses associated with this person.
247      *
248      * @return all addresses associated with this person.
249      *
250      * @hibernate.one-to-one
251      * cascade="all"
252      */

253     public AddressDO getAddress() {
254         return address;
255     }
256
257     /**
258      * <p>Get the company the person works for.</p>
259      *
260      * @return the company the person works for.
261      * @hibernate.property
262      * column="company"
263      */

264     public final String JavaDoc getCompany() {
265         return company;
266     }
267
268     /**
269      * <p>Get the person's date of birth.</p>
270      *
271      * @return the person's date of birth.
272      * @hibernate.property
273      * column="date_of_birth"
274      */

275     public final Date JavaDoc getDateOfBirth() {
276         return dateOfBirth;
277     }
278
279     /**
280      * <p>
281      * Return the first name(s), followed by a space, followed by the last name.
282      * </p>
283      *
284      * @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
285      */

286     public final String JavaDoc getDisplayValue() {
287         StringBuffer JavaDoc displayValue = new StringBuffer JavaDoc();
288         if (!StringHandling.isNullOrEmpty(firstNames)) {
289             displayValue.append(firstNames);
290         }
291         if (!StringHandling.isNullOrEmpty(firstNames)) {
292             if (displayValue.length() > 0) {
293                 displayValue.append(" ");
294             }
295             displayValue.append(lastName);
296         }
297         return displayValue.toString();
298     }
299
300     /**
301      * <p>Get the person's email address, formatted according to <a
302      * HREF='http://www.faqs.org/rfcs/rfc822.HTML'>RFC822</a>.</p>
303      *
304      *
305      * <p>This gives you the form:<br>
306      * <blockquote>&quot;<em>{firstName} {lastName}</em>&quot;&nbsp;&lt;<em>{email}</em>&gt;
307      * </blockquote></p>
308      *
309      * <p>If the person has multiple email addresses, the returned one is the
310      * first one found, as ordered by the address number.</p>
311      *
312      * @return formatted email address, or <code>null</code> if this person does
313      * not have an email address in the system.
314      */

315     public final String JavaDoc getEmailAddress() {
316         String JavaDoc firstEmailAddress = null;
317         for (Iterator JavaDoc telecomAddressIterator = telecomAddresses.iterator(); telecomAddressIterator.hasNext();) {
318             TelecomAddressDO address = (TelecomAddressDO) telecomAddressIterator.next();
319             if (address.getType() == TelecomAddressConstants.TYPE_EMAIL) {
320                 firstEmailAddress = address.getAddress();
321                 break;
322             }
323         }
324         // if no addresses found, return null
325
if (firstEmailAddress == null) {
326             return null;
327         }
328
329         // first prepend the name if there is one for this person
330
StringBuffer JavaDoc formattedEmailAddress = new StringBuffer JavaDoc();
331         if (!StringHandling.isNullOrEmpty(firstNames)) {
332             formattedEmailAddress.append(firstNames);
333         }
334         if (!StringHandling.isNullOrEmpty(lastName)) {
335             if (formattedEmailAddress.length() > 0) {
336                 formattedEmailAddress.append(" ");
337             }
338             formattedEmailAddress.append(lastName);
339         }
340         if (formattedEmailAddress.length() > 0) {
341             formattedEmailAddress.append(" ");
342         }
343         formattedEmailAddress.append("<");
344         formattedEmailAddress.append(firstEmailAddress);
345         formattedEmailAddress.append(">");
346
347         return formattedEmailAddress.toString();
348     }
349
350     /**
351      * <p>Get the employee record for this person as a data object.</p>
352      *
353      * @return employee record, or <code>null</code> if this person is not an
354      * employee.
355      * @hibernate.one-to-one
356      * cascade="all"
357      * property-ref="person"
358      */

359     public final EmployeeDO getEmployee() {
360         return employee;
361     }
362
363     /**
364      * <p>Get the string to file the person under in the address book.</p>
365      *
366      * @return the string to file the person under in the address book.
367      * @hibernate.property
368      * column="file_as"
369      */

370     public final String JavaDoc getFileAs() {
371         return fileAs;
372     }
373
374     /**
375      * <p>Get the person's first names.</p>
376      *
377      * @return the person's first names, separated by a comma.
378      * @hibernate.property
379      * column="first_names"
380      */

381     public final String JavaDoc getFirstNames() {
382         return firstNames;
383     }
384
385     /**
386      * <p>Get the group of this person.</p>
387      *
388      * @return the group this person is in.
389      *
390      * @hibernate.many-to-one
391      * column="person_group"
392      */

393     public final GroupDO getGroup() {
394         return group;
395     }
396     /**
397      * <p>Get the job title for this person.</p>
398      *
399      * @return the job title for this person.
400      * @hibernate.property
401      * column="job_title"
402      */

403     public final String JavaDoc getJobTitle() {
404         return jobTitle;
405     }
406
407     /**
408      * <p>Get the person's last name.</p>
409      *
410      * @return the person's last name.
411      * @hibernate.property
412      * column="last_name"
413      */

414     public final String JavaDoc getLastName() {
415         return lastName;
416     }
417
418     /**
419      * <p>
420      * Get the full name of this person. This is the same as the
421      * <code>fileAs</code> value.
422      * </p>
423      *
424      * @return fileAs value for this person
425      */

426     public final String JavaDoc getName() {
427         return fileAs;
428     }
429
430     /**
431      * <p>Get the saluation with which this person likes to be greeted by mail
432      * or email.</p>
433      *
434      * @return the saluation with which this person likes to be greeted by mail
435      * or email.
436      * @hibernate.property
437      * column="salutation"
438      */

439     public final String JavaDoc getSalutation() {
440         return salutation;
441     }
442
443     /**
444      * <p>Get the communication addresses themeselves.</p>
445      *
446      * @return a set containing the communication addresses themeselves.
447      *
448      * @hibernate.set
449      * cascade="all"
450      * role="telecom-addresses"
451      * @hibernate.collection-key
452      * column="person"
453      * @hibernate.collection-one-to-many
454      * class="com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO"
455      */

456     public final Set JavaDoc getTelecomAddresses() {
457         return telecomAddresses;
458     }
459
460     /**
461      * <p>Get the user for this person.</p>
462      *
463      * @return user name for this person, or <code>null</code> if this person is
464      * not a user.
465      * @hibernate.one-to-one
466      * cascade="all"
467      */

468     public UserDO getUser() {
469         return user;
470     }
471
472     /**
473      * @return Returns the deleted.
474      * @hibernate.property
475      */

476     public boolean isDeleted() {
477         return deleted;
478     }
479
480     /**
481      * @param address The address to set.
482      */

483     public final void setAddress(final AddressDO address) {
484         this.address = address;
485     }
486     /**
487      * <p>Set the company the person works for.</p>
488      *
489      * @param company the company the person works for.
490      */

491     public final void setCompany(final String JavaDoc company) {
492         this.company = company;
493     }
494
495     /**
496      * <p>Set the person's date of birth.</p>
497      *
498      * @param dateOfBirth the new value supplied to person's date of birth.
499      */

500     public final void setDateOfBirth(final java.util.Date JavaDoc dateOfBirth) {
501         this.dateOfBirth = dateOfBirth;
502     }
503     /**
504      * @param deletedParam The deleted to set.
505      */

506     public void setDeleted(boolean deletedParam) {
507         deleted = deletedParam;
508     }
509
510     /**
511      * <p>Get the employee record for this person as a data object.</p>
512      *
513      * @param employee employee record, or <code>null</code> if this person is
514      * not an employee.
515      */

516     public final void setEmployee(final com.ivata.groupware.business.addressbook.person.employee.EmployeeDO employee) {
517         this.employee = employee;
518     }
519
520     /**
521      * <p>Set the string to file the person under in the address book.</p>
522      *
523      * @param fileAs the string to file the person under in the address book.
524      */

525     public final void setFileAs(final String JavaDoc fileAs) {
526         this.fileAs = fileAs;
527     }
528
529     /**
530      * <p>Set the person's first names.</p>
531      *
532      * @param firstNames the person's first names, separated by a comma.
533      */

534     public final void setFirstNames(final String JavaDoc firstNames) {
535         this.firstNames = firstNames;
536     }
537
538     /**
539      * <p>Set the group of this person.</p>
540      *
541      * @param group new value of the group.
542      */

543     public final void setGroup(final GroupDO group) {
544         this.group = group;
545     }
546
547     /**
548      * <p>Set the job title for this person.</p>
549      *
550      * @param jobTitle the job title for this person.
551      */

552     public final void setJobTitle(final String JavaDoc jobTitle) {
553         this.jobTitle = jobTitle;
554     }
555
556     /**
557      * <p>Set the person's last name.</p>
558      *
559      * @param lastName the person's last name.
560      */

561     public final void setLastName(final String JavaDoc lastName) {
562         this.lastName = lastName;
563     }
564
565     /**
566      * <p>Set the saluation with which this person likes to be greeted by mail or
567      * email.</p>
568      *
569      * @param salutation the saluation with which this person likes to be
570      * greeted by mail or email.
571      */

572     public final void setSalutation(final String JavaDoc salutation) {
573         this.salutation = salutation;
574     }
575
576     /**
577      * @param set
578      */

579     public final void setTelecomAddresses(final Set JavaDoc set) {
580         telecomAddresses = set;
581     }
582
583     /**
584      * <p>Set the user for this person.</p>
585      *
586      * @param user new user for this person, or <code>null</code> if
587      * this person is not a user.
588      */

589     public final void setUser(final UserDO user) {
590         this.user = user;
591     }
592 }
593
Popular Tags