2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.agent
;
12 import java
.util
.HashSet
;
15 import javax
.persistence
.Entity
;
16 import javax
.persistence
.FetchType
;
17 import javax
.persistence
.OneToMany
;
18 import javax
.validation
.constraints
.NotNull
;
19 import javax
.validation
.constraints
.Size
;
20 import javax
.xml
.bind
.annotation
.XmlAccessType
;
21 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
22 import javax
.xml
.bind
.annotation
.XmlElement
;
23 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
24 import javax
.xml
.bind
.annotation
.XmlRootElement
;
25 import javax
.xml
.bind
.annotation
.XmlType
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.hibernate
.annotations
.Cascade
;
29 import org
.hibernate
.annotations
.CascadeType
;
30 import org
.hibernate
.envers
.Audited
;
31 import org
.hibernate
.search
.annotations
.Field
;
32 import org
.hibernate
.search
.annotations
.Index
;
33 import org
.hibernate
.search
.annotations
.Indexed
;
34 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
35 import org
.joda
.time
.Partial
;
36 import org
.springframework
.beans
.factory
.annotation
.Configurable
;
38 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
39 import eu
.etaxonomy
.cdm
.model
.common
.User
;
40 import eu
.etaxonomy
.cdm
.strategy
.cache
.agent
.PersonDefaultCacheStrategy
;
41 import eu
.etaxonomy
.cdm
.strategy
.match
.Match
;
42 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
43 import eu
.etaxonomy
.cdm
.validation
.annotation
.NullOrNotEmpty
;
46 * This class represents human beings, living or dead.<BR>
47 * It includes name parts, {@link Contact contact} details, {@link InstitutionalMembership institutional membership},
48 * and other possible information such as life {@link TimePeriod time period},
49 * taxonomic and/or geographical {@link Keyword specialization}.
50 * For a short abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
52 * For other alternative (string-)names {@link eu.etaxonomy.cdm.model.common.OriginalSourceBase OriginalSource} instances must be created
53 * and the inherited attribute {@link eu.etaxonomy.cdm.model.common.ReferencedEntityBase#getOriginalNameString() originalNameString} must be used.
55 * This class corresponds to: <ul>
56 * <li> Person according to the TDWG ontology
57 * <li> AgentName (partially) according to the TCS
58 * <li> Person (PersonName partially) according to the ABCD schema
63 * @created 08-Nov-2007 13:06:42
65 @XmlAccessorType(XmlAccessType
.FIELD
)
66 @XmlType(name
= "Person", propOrder
= {
72 "institutionalMemberships"
74 @XmlRootElement(name
= "Person")
76 @Indexed(index
= "eu.etaxonomy.cdm.model.agent.AgentBase")
79 public class Person
extends TeamOrPersonBase
<Person
>{
80 private static final long serialVersionUID
= 4153566493065539763L;
81 public static final Logger logger
= Logger
.getLogger(Person
.class);
83 @XmlElement(name
= "Prefix")
84 @Field(index
=Index
.TOKENIZED
)
87 private String prefix
;
89 @XmlElement(name
= "FirstName")
90 @Field(index
=Index
.TOKENIZED
)
93 private String firstname
;
95 @XmlElement(name
= "LastName")
96 @Field(index
=Index
.TOKENIZED
)
99 private String lastname
;
101 @XmlElement(name
= "Suffix")
102 @Field(index
=Index
.TOKENIZED
)
105 private String suffix
;
107 @XmlElement(name
= "Lifespan")
109 @Match(value
=MatchMode
.EQUAL_OR_ONE_NULL
)
111 private TimePeriod lifespan
= TimePeriod
.NewInstance();
113 @XmlElementWrapper(name
= "InstitutionalMemberships", nillable
= true)
114 @XmlElement(name
= "InstitutionalMembership")
115 @OneToMany(fetch
=FetchType
.LAZY
, mappedBy
= "person")
116 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
117 protected Set
<InstitutionalMembership
> institutionalMemberships
;
120 * Creates a new empty instance for a person whose existence is all what is known.
121 * This can be a provisional solution until more information about <i>this</i> person
122 * can be gathered, for instance in case a member of a nomenclatural author team
123 * is not explicitly mentioned. It also includes the cache strategy defined in
124 * {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
126 public static Person
NewInstance(){
131 * Creates a new instance for a person for whom an "identification" string
132 * is all what is known. This string is generally a short or a complete name.
133 * As this string is kept in the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache}
134 * attribute and should not be overwritten by the {@link #generateTitle() generateTitle} method
135 * the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#isProtectedTitleCache() protectedTitleCache} flag will be turned on.
137 public static Person
NewTitledInstance(String titleCache
){
138 Person result
= new Person();
139 result
.setTitleCache(titleCache
, true);
147 * @see #Person(String, String, String)
151 this.cacheStrategy
= PersonDefaultCacheStrategy
.NewInstance();
156 * Class constructor using a "forenames" string (including initials),
157 * a surname (family name) and an abbreviated name as used in nomenclature.
158 * For the abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
161 * @param firstname the given name
162 * @param lastname the hereditary name
163 * @param nomenclaturalTitel the abbreviated name
165 * @see #NewInstance()
167 public Person(String firstname
, String lastname
, String nomenclaturalTitel
) {
168 this.setFirstname(firstname
);
169 this.setLastname(lastname
);
170 logger
.debug("before - Set nomenclatural Title");
171 this.setNomenclaturalTitle(nomenclaturalTitel
);
172 logger
.debug("after - Set nomenclatural Title");
177 * Returns the set of {@link InstitutionalMembership institution memberships} corresponding to <i>this</i> person.
179 * @see InstitutionalMembership
181 public Set
<InstitutionalMembership
> getInstitutionalMemberships(){
182 if(institutionalMemberships
== null) {
183 this.institutionalMemberships
= new HashSet
<InstitutionalMembership
>();
185 return this.institutionalMemberships
;
188 protected void addInstitutionalMembership(InstitutionalMembership ims
){
189 getInstitutionalMemberships().add(ims
);
190 if (ims
.getPerson() != this){
191 logger
.warn("Institutional membership's person has to be changed for adding it to person: " + this);
192 ims
.getPerson().removeInstitutionalMembership(ims
);
199 * Adds a new {@link InstitutionalMembership membership} of <i>this</i> person in an {@link Institution institution}
200 * to the set of his institution memberships.
201 * This method also creates a new institutional membership instance.
203 * @param institution the institution <i>this</i> person belongs to
204 * @param period the time period for which <i>this</i> person has been a member of the institution
205 * @param department the string label for the department <i>this</i> person belongs to,
206 * within the institution
207 * @param role the string label for the persons's role within the department or institution
208 * @see #getInstitutionalMemberships()
209 * @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
211 public void addInstitutionalMembership(Institution institution
, TimePeriod period
, String department
, String role
){
212 new InstitutionalMembership(institution
, this, period
, department
, role
);
216 * Removes one element from the set of institutional memberships of <i>this</i> person.
217 * Institute and person attributes of the institutional membership object
220 * @param ims the institutional membership of <i>this</i> person which should be deleted
221 * @see #getInstitutionalMemberships()
223 public void removeInstitutionalMembership(InstitutionalMembership ims
){
224 ims
.setInstitute(null);
226 getInstitutionalMemberships().remove(ims
);
230 * Returns the string representing the prefix (for instance "Prof. Dr.<!-- -->")
231 * to <i>this</i> person's name.
233 public String
getPrefix(){
239 public void setPrefix(String prefix
){
240 this.prefix
= prefix
;
245 * Returns the string representing the given name or forename
246 * (for instance "John") of <i>this</i> person.
247 * This is the part of his name which is not shared with other
248 * family members. Actually it may be just initials (for instance "G. Jr."),
249 * all forenames in full or a combination of expanded names and initials.
251 public String
getFirstname(){
252 return this.firstname
;
255 * @see #getFirstname()
257 public void setFirstname(String firstname
){
258 this.firstname
= firstname
;
263 * Returns the string representing the hereditary name (surname or family name)
264 * (for instance "Smith") of <i>this</i> person.
265 * This is the part of his name which is common to (all) other
266 * members of his family, as distinct from the given name or forename.
268 public String
getLastname(){
269 return this.lastname
;
272 * @see #getLastname()
274 public void setLastname(String lastname
){
275 this.lastname
= lastname
;
280 * Returns the string representing the suffix (for instance "Junior")
281 * of <i>this</i> person's name.
283 public String
getSuffix(){
289 public void setSuffix(String suffix
){
290 this.suffix
= suffix
;
295 * Returns the {@link eu.etaxonomy.cdm.model.common.TimePeriod period of time}
296 * in which <i>this</i> person was alive (life span).
297 * The general form is birth date - death date
298 * (XXXX - YYYY; XXXX - or - YYYY as appropriate),
299 * but a simple flourished date (fl. XXXX) is also possible
300 * if that is all what is known.
302 * @see eu.etaxonomy.cdm.model.common.TimePeriod
304 public TimePeriod
getLifespan(){
305 if(lifespan
== null) {
306 this.lifespan
= TimePeriod
.NewInstance(new Partial(), new Partial());
308 return this.lifespan
;
311 * @see #getLifespan()
313 public void setLifespan(TimePeriod lifespan
){
314 this.lifespan
= lifespan
;
318 // * Generates the "full" name string of <i>this</i> person according to the strategy
319 // * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
320 // * The used attributes are:
321 // * {@link #getPrefix() prefix}, {@link #getFirstname() firstname}, {@link #getLastname() lastname} and {@link #getSuffix() suffix}.
322 // * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
323 // * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
324 // * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
326 // * @return the string with the full name of <i>this</i> person
329 // public String generateTitle() {
330 // String title = null;
331 // if (cacheStrategy != null) {
332 // title = cacheStrategy.getTitleCache(this);
337 //*********************** CLONE ********************************************************/
340 * Clones <i>this</i> Person. This is a shortcut that enables to create
341 * a new instance that differs only slightly from <i>this</i> Person.
343 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
344 * @see java.lang.Object#clone()
347 public Object
clone() {
349 Person result
= (Person
)super.clone();
350 //no changes to firstname, lastname, lifespan, prefix, suffix
352 } catch (CloneNotSupportedException e
){
353 logger
.warn("Object does not implement cloneable");