5c04118987e1e5f10a6da8ef15feb198f251586d
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / Person.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.model.agent;
11
12
13 import eu.etaxonomy.cdm.model.common.TimePeriod;
14 import eu.etaxonomy.cdm.model.common.Keyword;
15 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
16 import org.apache.log4j.Logger;
17 import org.hibernate.annotations.Cascade;
18 import org.hibernate.annotations.CascadeType;
19
20 import java.util.*;
21
22 import javax.persistence.*;
23
24 /**
25 * A representation of a human being, living or dead.
26 * It includes name parts, contact details, institutional membership,
27 * and other possible information such as life period,
28 * taxonomic and/or geographical specialization. For a short name
29 * the inherited attribute {@link common.IdentifiableEntity#setTitleCache(String) titleCache} is to be used.
30 * For other alternative (string-)names {@link common.OriginalSource OriginalSource} instances must be created.
31 * and the inherited attribute {@link common.ReferencedEntityBase#setOriginalNameString(String) originalNameString} must be used.
32 * <p>
33 * See also the <a href="http://rs.tdwg.org/ontology/voc/Person.rdf">TDWG Ontology</a>
34 *
35 * @author m.doering
36 * @version 1.0
37 * @created 08-Nov-2007 13:06:42
38 */
39 @Entity
40 public class Person extends Agent {
41 static Logger logger = Logger.getLogger(Person.class);
42
43 private String prefix;
44 private String firstname;
45 private String lastname;
46 private String suffix;
47 private TimePeriod lifespan;
48 protected Set<InstitutionalMembership> institutionalMemberships;
49 private Contact contact;
50 private Set<Keyword> keywords = new HashSet();
51
52 /**
53 * Class constructor.
54 *
55 * @see #Person(String, String, String)
56 */
57 public Person() {
58 }
59 /**
60 * Class constructor using a "forenames" string (including initials),
61 * a surname (family name) and an abbreviated name.
62 *
63 * @param firstname the given name of this person
64 * @param lastname the hereditary name of this person
65 * @param abbreviation a standardised or abbreviated name of this person
66 * @see #Person()
67 */
68 public Person(String firstname, String lastname, String abbreviation) {
69 this.setFirstname(firstname);
70 this.setLastname(lastname);
71 this.setTitleCache(abbreviation);
72 }
73
74
75 @OneToMany
76 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
77 public Set<InstitutionalMembership> getInstitutionalMemberships(){
78 return this.institutionalMemberships;
79 }
80 protected void setInstitutionalMemberships(Set<InstitutionalMembership> institutionalMemberships){
81 this.institutionalMemberships = institutionalMemberships;
82 }
83 /**
84 * Adds a new membership of this person in an institution.
85 *
86 * @param institution the institution this person belongs to
87 * @param period the time period for which this person has been a member of the institution
88 * @param department the string label for the department this person belongs to,
89 * within the institution
90 * @param role the string label for the persons's role within the department or institution
91 * @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
92 */
93 public void addInstitutionalMembership(Institution institution, TimePeriod period, String department, String role){
94 InstitutionalMembership ims = new InstitutionalMembership(institution, this, period, department, role);
95 }
96 /**
97 * Removes one element of the set of institutional memberships of this person.
98 *
99 * @param ims the institutional membership of this person which should be deleted
100 * @see #addInstitutionalMembership(Institution, TimePeriod, String, String)
101 */
102 public void removeInstitutionalMembership(InstitutionalMembership ims){
103 ims.setInstitute(null);
104 ims.setPerson(null);
105 //this.institutionalMemberships.remove(ims);
106 }
107
108
109 @OneToMany
110 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
111 public Set<Keyword> getKeywords(){
112 return this.keywords;
113 }
114 public void setKeywords(Set<Keyword> keywords){
115 this.keywords = keywords;
116 }
117 /**
118 * Adds a new keyword to describe better this person or circumscribe his activities.
119 *
120 * @param keyword any relevant keyword for this person or for his activities
121 * @see common.Keyword
122 */
123 public void addKeyword(Keyword keyword){
124 this.keywords.add(keyword);
125 }
126 /**
127 * Removes one element of the set of keywords for this person.
128 *
129 * @param keyword the keyword describing this person or his activities which should be deleted
130 * @see #addKeyword(Keyword)
131 */
132 public void removeKeyword(Keyword keyword){
133 this.keywords.remove(keyword);
134 }
135
136
137
138 @ManyToOne
139 @Cascade({CascadeType.SAVE_UPDATE})
140 public Contact getContact(){
141 return this.contact;
142 }
143 /**
144 * Assigns a {@link Contact contact} to this person.
145 *
146 * @param contact the contact which should be assigned to this person
147 */
148 public void setContact(Contact contact){
149 this.contact = contact;
150 }
151
152
153 public String getPrefix(){
154 return this.prefix;
155 }
156 /**
157 * Assigns a prefix (for instance "Prof.&nbsp;Dr.<!-- -->") to this person's name.
158 *
159 * @param prefix the string which should be assigned as a prefix to this person's name
160 */
161 public void setPrefix(String prefix){
162 this.prefix = prefix;
163 }
164
165
166 public String getFirstname(){
167 return this.firstname;
168 }
169 /**
170 * Assigns a given name or forename (for instance "John") to this person.
171 * This is the part of his name which is not shared with other
172 * family members. Actually it may be just initials (for instance "G. Jr."),
173 * all forenames in full or a combination of expanded names and initials.
174 *
175 * @param firstname the string which should be assigned as a given name to this person
176 */
177 public void setFirstname(String firstname){
178 this.firstname = firstname;
179 }
180
181
182 public String getLastname(){
183 return this.lastname;
184 }
185 /**
186 * Assigns a hereditary name (surname or family name)
187 * to this person (for instance "Smith").
188 * This is the part of his name which is common to (all) other
189 * members of his family, as distinct from the given name or forename.
190 *
191 * @param lastname the string which should be assigned as a hereditary name to this person
192 */
193 public void setLastname(String lastname){
194 this.lastname = lastname;
195 }
196
197
198 public String getSuffix(){
199 return this.suffix;
200 }
201 /**
202 * Assigns a suffix (for instance "Junior") to this person's name.
203 *
204 * @param suffix the string which should be assigned as a suffix to this person's name
205 */
206 public void setSuffix(String suffix){
207 this.suffix = suffix;
208 }
209
210
211 public TimePeriod getLifespan(){
212 return this.lifespan;
213 }
214 /**
215 * Assigns to this person a period of time in which he was alive.
216 * The form birthdate - deathdate (XXXX - YYYY; XXXX - or - YYYY as appropriate) is
217 * preferred, but a simple flourished date (fl. XXXX) may be given
218 * if that is all what is known.
219 *
220 * @param lifespan the time period to be assigned as life time to this person
221 * @see common.TimePeriod
222 */
223 public void setLifespan(TimePeriod lifespan){
224 this.lifespan = lifespan;
225 }
226
227 @Override
228 /**
229 * Generates the "full" name string of this person on the basis of the attributes:
230 * {@link #prefix prefix}, {@link #firstname firstname}, {@link #lastname lastname} and {@link #suffix suffix}.
231 * This method overrides {@link common.IdentifiableEntity#generateTitle() generateTitle}
232 * The result might be kept as {@link common.IdentifiableEntity#setTitleCache(String) titleCache} if the
233 * flag {@link common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
234 *
235 * @return the full name string of this person
236 */
237 public String generateTitle(){
238 return "";
239 }
240
241 }