(no commit message)
[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 implements INomenclaturalAgent {
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 /**
61 * Class constructor using a "forenames" string (including initials),
62 * a surname (family name) and an abbreviated name.
63 *
64 * @param firstname the given name of this person
65 * @param lastname the hereditary name of this person
66 * @param abbreviation a standardised or abbreviated name of this person
67 * @see #Person()
68 */
69 public Person(String firstname, String lastname, String abbreviation) {
70 this.setFirstname(firstname);
71 this.setLastname(lastname);
72 this.setTitleCache(abbreviation);
73 }
74
75
76 @OneToMany
77 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
78 public Set<InstitutionalMembership> getInstitutionalMemberships(){
79 return this.institutionalMemberships;
80 }
81 protected void setInstitutionalMemberships(Set<InstitutionalMembership> institutionalMemberships){
82 this.institutionalMemberships = institutionalMemberships;
83 }
84
85 /**
86 * Adds a new membership of this person in an institution.
87 * This method also creates a new institutional membership instance.
88 *
89 * @param institution the institution this person belongs to
90 * @param period the time period for which this person has been a member of the institution
91 * @param department the string label for the department this person belongs to,
92 * within the institution
93 * @param role the string label for the persons's role within the department or institution
94 * @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
95 */
96 public void addInstitutionalMembership(Institution institution, TimePeriod period, String department, String role){
97 InstitutionalMembership ims = new InstitutionalMembership(institution, this, period, department, role);
98 }
99
100 /**
101 * Removes one element from the set of institutional memberships of this person.
102 *
103 * @param ims the institutional membership of this person which should be deleted
104 * @see #addInstitutionalMembership(Institution, TimePeriod, String, String)
105 */
106 public void removeInstitutionalMembership(InstitutionalMembership ims){
107 //TODO to be implemented?
108 logger.warn("not yet fully implemented?");
109 ims.setInstitute(null);
110 ims.setPerson(null);
111 this.institutionalMemberships.remove(ims);
112 }
113
114
115 @OneToMany
116 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
117 public Set<Keyword> getKeywords(){
118 return this.keywords;
119 }
120 public void setKeywords(Set<Keyword> keywords){
121 this.keywords = keywords;
122 }
123 /**
124 * Adds a new keyword from the keyword vocabulary to describe better this person
125 * or circumscribe his activities.
126 *
127 * @param keyword any keyword relevant for this person or for his activities
128 * @see common.Keyword
129 */
130 public void addKeyword(Keyword keyword){
131 this.keywords.add(keyword);
132 }
133 /**
134 * Removes one element from the set of keywords for this person.
135 *
136 * @param keyword the keyword describing this person or his activities which should be deleted
137 * @see #addKeyword(Keyword)
138 */
139 public void removeKeyword(Keyword keyword){
140 this.keywords.remove(keyword);
141 }
142
143
144
145 @ManyToOne
146 @Cascade({CascadeType.SAVE_UPDATE})
147 public Contact getContact(){
148 return this.contact;
149 }
150 /**
151 * Assigns a {@link Contact contact} to this person.
152 *
153 * @param contact the contact which should be assigned to this person
154 */
155 public void setContact(Contact contact){
156 this.contact = contact;
157 }
158
159
160 public String getPrefix(){
161 return this.prefix;
162 }
163 /**
164 * Assigns a prefix (for instance "Prof.&nbsp;Dr.<!-- -->") to this person's name.
165 *
166 * @param prefix the string which should be assigned as a prefix to this person's name
167 */
168 public void setPrefix(String prefix){
169 this.prefix = prefix;
170 }
171
172
173 public String getFirstname(){
174 return this.firstname;
175 }
176 /**
177 * Assigns a given name or forename (for instance "John") to this person.
178 * This is the part of his name which is not shared with other
179 * family members. Actually it may be just initials (for instance "G. Jr."),
180 * all forenames in full or a combination of expanded names and initials.
181 *
182 * @param firstname the string which should be assigned as a given name to this person
183 */
184 public void setFirstname(String firstname){
185 this.firstname = firstname;
186 }
187
188
189 public String getLastname(){
190 return this.lastname;
191 }
192 /**
193 * Assigns a hereditary name (surname or family name)
194 * to this person (for instance "Smith").
195 * This is the part of his name which is common to (all) other
196 * members of his family, as distinct from the given name or forename.
197 *
198 * @param lastname the string which should be assigned as a hereditary name to this person
199 */
200 public void setLastname(String lastname){
201 this.lastname = lastname;
202 }
203
204
205 public String getSuffix(){
206 return this.suffix;
207 }
208 /**
209 * Assigns a suffix (for instance "Junior") to this person's name.
210 *
211 * @param suffix the string which should be assigned as a suffix to this person's name
212 */
213 public void setSuffix(String suffix){
214 this.suffix = suffix;
215 }
216
217
218 public TimePeriod getLifespan(){
219 return this.lifespan;
220 }
221 /**
222 * Assigns to this person a period of time in which he was alive.
223 * The form birthdate - deathdate (XXXX - YYYY; XXXX - or - YYYY as appropriate) is
224 * preferred, but a simple flourished date (fl. XXXX) may be given
225 * if that is all what is known.
226 *
227 * @param lifespan the time period to be assigned as life time to this person
228 * @see common.TimePeriod
229 */
230 public void setLifespan(TimePeriod lifespan){
231 this.lifespan = lifespan;
232 }
233
234 @Override
235 /**
236 * Generates the "full" name string of this person. The used attributes are:
237 * {@link #prefix prefix}, {@link #firstname firstname}, {@link #lastname lastname} and {@link #suffix suffix}.
238 * This method overrides {@link common.IdentifiableEntity#generateTitle() generateTitle}.
239 * The result might be kept as {@link common.IdentifiableEntity#setTitleCache(String) titleCache} if the
240 * flag {@link common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
241 *
242 * @return the string with the full name of this person
243 */
244 public String generateTitle(){
245 return "";
246 }
247
248
249 public String getNomenclaturalTitle() {
250 // TODO Auto-generated method stub
251 return null;
252 }
253
254 }