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 javassist
.compiler
.ast
.Keyword
;
17 import javax
.persistence
.Entity
;
18 import javax
.persistence
.FetchType
;
19 import javax
.persistence
.OneToMany
;
20 import javax
.validation
.constraints
.NotNull
;
21 import javax
.validation
.constraints
.Size
;
22 import javax
.xml
.bind
.annotation
.XmlAccessType
;
23 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
24 import javax
.xml
.bind
.annotation
.XmlElement
;
25 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
26 import javax
.xml
.bind
.annotation
.XmlRootElement
;
27 import javax
.xml
.bind
.annotation
.XmlType
;
29 import org
.apache
.log4j
.Logger
;
30 import org
.hibernate
.annotations
.Cascade
;
31 import org
.hibernate
.annotations
.CascadeType
;
32 import org
.hibernate
.envers
.Audited
;
33 import org
.hibernate
.search
.annotations
.Field
;
34 import org
.hibernate
.search
.annotations
.Indexed
;
35 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
36 import org
.joda
.time
.Partial
;
37 import org
.springframework
.beans
.factory
.annotation
.Configurable
;
39 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
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")
88 private String prefix
;
90 @XmlElement(name
= "FirstName")
95 private String firstname
;
97 @XmlElement(name
= "LastName")
102 private String lastname
;
104 @XmlElement(name
= "Suffix")
109 private String suffix
;
111 @XmlElement(name
= "Lifespan")
113 @Match(value
=MatchMode
.EQUAL_OR_ONE_NULL
)
114 //TODO Val #3379 check carefully what the condition is that lifespan is really null in legacy data
116 private TimePeriod lifespan
= TimePeriod
.NewInstance();
118 @XmlElementWrapper(name
= "InstitutionalMemberships", nillable
= true)
119 @XmlElement(name
= "InstitutionalMembership")
120 @OneToMany(fetch
=FetchType
.LAZY
, mappedBy
= "person")
121 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
122 protected Set
<InstitutionalMembership
> institutionalMemberships
;
125 * Creates a new empty instance for a person whose existence is all what is known.
126 * This can be a provisional solution until more information about <i>this</i> person
127 * can be gathered, for instance in case a member of a nomenclatural author team
128 * is not explicitly mentioned. It also includes the cache strategy defined in
129 * {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
131 public static Person
NewInstance(){
136 * Creates a new instance for a person for whom an "identification" string
137 * is all what is known. This string is generally a short or a complete name.
138 * As this string is kept in the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache}
139 * attribute and should not be overwritten by the {@link #generateTitle() generateTitle} method
140 * the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#isProtectedTitleCache() protectedTitleCache} flag will be turned on.
142 public static Person
NewTitledInstance(String titleCache
){
143 Person result
= new Person();
144 result
.setTitleCache(titleCache
, true);
152 * @see #Person(String, String, String)
156 this.cacheStrategy
= PersonDefaultCacheStrategy
.NewInstance();
161 * Class constructor using a "forenames" string (including initials),
162 * a surname (family name) and an abbreviated name as used in nomenclature.
163 * For the abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
166 * @param firstname the given name
167 * @param lastname the hereditary name
168 * @param nomenclaturalTitel the abbreviated name
170 * @see #NewInstance()
172 public Person(String firstname
, String lastname
, String nomenclaturalTitel
) {
173 this.setFirstname(firstname
);
174 this.setLastname(lastname
);
175 logger
.debug("before - Set nomenclatural Title");
176 this.setNomenclaturalTitle(nomenclaturalTitel
);
177 logger
.debug("after - Set nomenclatural Title");
182 * Returns the set of {@link InstitutionalMembership institution memberships} corresponding to <i>this</i> person.
184 * @see InstitutionalMembership
186 public Set
<InstitutionalMembership
> getInstitutionalMemberships(){
187 if(institutionalMemberships
== null) {
188 this.institutionalMemberships
= new HashSet
<InstitutionalMembership
>();
190 return this.institutionalMemberships
;
193 protected void addInstitutionalMembership(InstitutionalMembership ims
){
194 getInstitutionalMemberships().add(ims
);
195 if (ims
.getPerson() != this){
196 logger
.warn("Institutional membership's person has to be changed for adding it to person: " + this);
197 ims
.getPerson().removeInstitutionalMembership(ims
);
204 * Adds a new {@link InstitutionalMembership membership} of <i>this</i> person in an {@link Institution institution}
205 * to the set of his institution memberships.
206 * This method also creates a new institutional membership instance.
208 * @param institution the institution <i>this</i> person belongs to
209 * @param period the time period for which <i>this</i> person has been a member of the institution
210 * @param department the string label for the department <i>this</i> person belongs to,
211 * within the institution
212 * @param role the string label for the persons's role within the department or institution
213 * @see #getInstitutionalMemberships()
214 * @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
216 public InstitutionalMembership
addInstitutionalMembership(Institution institution
, TimePeriod period
, String department
, String role
){
217 return new InstitutionalMembership(institution
, this, period
, department
, role
);
221 * Removes one element from the set of institutional memberships of <i>this</i> person.
222 * Institute and person attributes of the institutional membership object
225 * @param ims the institutional membership of <i>this</i> person which should be deleted
226 * @see #getInstitutionalMemberships()
228 public void removeInstitutionalMembership(InstitutionalMembership ims
){
229 ims
.setInstitute(null);
231 getInstitutionalMemberships().remove(ims
);
235 * Returns the string representing the prefix (for instance "Prof. Dr.<!-- -->")
236 * to <i>this</i> person's name.
238 public String
getPrefix(){
244 public void setPrefix(String prefix
){
245 this.prefix
= prefix
;
250 * Returns the string representing the given name or forename
251 * (for instance "John") of <i>this</i> person.
252 * This is the part of his name which is not shared with other
253 * family members. Actually it may be just initials (for instance "G. Jr."),
254 * all forenames in full or a combination of expanded names and initials.
256 public String
getFirstname(){
257 return this.firstname
;
260 * @see #getFirstname()
262 public void setFirstname(String firstname
){
263 this.firstname
= firstname
;
268 * Returns the string representing the hereditary name (surname or family name)
269 * (for instance "Smith") of <i>this</i> person.
270 * This is the part of his name which is common to (all) other
271 * members of his family, as distinct from the given name or forename.
273 public String
getLastname(){
274 return this.lastname
;
277 * @see #getLastname()
279 public void setLastname(String lastname
){
280 this.lastname
= lastname
;
285 * Returns the string representing the suffix (for instance "Junior")
286 * of <i>this</i> person's name.
288 public String
getSuffix(){
294 public void setSuffix(String suffix
){
295 this.suffix
= suffix
;
300 * Returns the {@link eu.etaxonomy.cdm.model.common.TimePeriod period of time}
301 * in which <i>this</i> person was alive (life span).
302 * The general form is birth date - death date
303 * (XXXX - YYYY; XXXX - or - YYYY as appropriate),
304 * but a simple flourished date (fl. XXXX) is also possible
305 * if that is all what is known.
307 * @see eu.etaxonomy.cdm.model.common.TimePeriod
309 public TimePeriod
getLifespan(){
310 if(lifespan
== null) {
311 this.lifespan
= TimePeriod
.NewInstance(new Partial(), new Partial());
313 return this.lifespan
;
316 * @see #getLifespan()
318 public void setLifespan(TimePeriod lifespan
){
319 if (lifespan
== null){
320 this.lifespan
= TimePeriod
.NewInstance(new Partial(), new Partial());
322 this.lifespan
= lifespan
;
326 // * Generates the "full" name string of <i>this</i> person according to the strategy
327 // * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
328 // * The used attributes are:
329 // * {@link #getPrefix() prefix}, {@link #getFirstname() firstname}, {@link #getLastname() lastname} and {@link #getSuffix() suffix}.
330 // * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
331 // * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
332 // * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
334 // * @return the string with the full name of <i>this</i> person
337 // public String generateTitle() {
338 // String title = null;
339 // if (cacheStrategy != null) {
340 // title = cacheStrategy.getTitleCache(this);
345 //*********************** CLONE ********************************************************/
348 * Clones <i>this</i> Person. This is a shortcut that enables to create
349 * a new instance that differs only slightly from <i>this</i> Person.
351 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
352 * @see java.lang.Object#clone()
355 public Object
clone() {
357 Person result
= (Person
)super.clone();
358 //no changes to firstname, lastname, lifespan, prefix, suffix
360 } catch (CloneNotSupportedException e
){
361 logger
.warn("Object does not implement cloneable");