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
.Size
;
21 import javax
.xml
.bind
.annotation
.XmlAccessType
;
22 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
23 import javax
.xml
.bind
.annotation
.XmlElement
;
24 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
25 import javax
.xml
.bind
.annotation
.XmlRootElement
;
26 import javax
.xml
.bind
.annotation
.XmlType
;
28 import org
.apache
.commons
.lang
.StringUtils
;
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
;
45 * This class represents human beings, living or dead.<BR>
46 * It includes name parts, {@link Contact contact} details, {@link InstitutionalMembership institutional membership},
47 * and other possible information such as life {@link TimePeriod time period},
48 * taxonomic and/or geographical {@link Keyword specialization}.
49 * For a short abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
51 * For other alternative (string-)names {@link eu.etaxonomy.cdm.model.common.OriginalSourceBase OriginalSource} instances must be created
52 * and the inherited attribute {@link eu.etaxonomy.cdm.model.common.ReferencedEntityBase#getOriginalNameString() originalNameString} must be used.
54 * This class corresponds to: <ul>
55 * <li> Person according to the TDWG ontology
56 * <li> AgentName (partially) according to the TCS
57 * <li> Person (PersonName partially) according to the ABCD schema
62 * @created 08-Nov-2007 13:06:42
64 @XmlAccessorType(XmlAccessType
.FIELD
)
65 @XmlType(name
= "Person", propOrder
= {
71 "institutionalMemberships"
73 @XmlRootElement(name
= "Person")
75 @Indexed(index
= "eu.etaxonomy.cdm.model.agent.AgentBase")
78 public class Person
extends TeamOrPersonBase
<Person
>{
79 private static final long serialVersionUID
= 4153566493065539763L;
80 public static final Logger logger
= Logger
.getLogger(Person
.class);
82 @XmlElement(name
= "Prefix")
87 private String prefix
;
89 @XmlElement(name
= "FirstName")
94 private String firstname
;
96 @XmlElement(name
= "LastName")
101 private String lastname
;
103 @XmlElement(name
= "Suffix")
108 private String suffix
;
110 @XmlElement(name
= "Lifespan")
112 @Match(value
=MatchMode
.EQUAL_OR_ONE_NULL
)
113 //TODO Val #3379 check carefully what the condition is that lifespan is really null in legacy data
115 private TimePeriod lifespan
= TimePeriod
.NewInstance();
117 @XmlElementWrapper(name
= "InstitutionalMemberships", nillable
= true)
118 @XmlElement(name
= "InstitutionalMembership")
119 @OneToMany(fetch
=FetchType
.LAZY
, mappedBy
= "person")
120 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
121 protected Set
<InstitutionalMembership
> institutionalMemberships
;
124 * Creates a new empty instance for a person whose existence is all what is known.
125 * This can be a provisional solution until more information about <i>this</i> person
126 * can be gathered, for instance in case a member of a nomenclatural author team
127 * is not explicitly mentioned. It also includes the cache strategy defined in
128 * {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
130 public static Person
NewInstance(){
135 * Creates a new instance for a person for whom an "identification" string
136 * is all what is known. This string is generally a short or a complete name.
137 * As this string is kept in the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache}
138 * attribute and should not be overwritten by the {@link #generateTitle() generateTitle} method
139 * the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#isProtectedTitleCache() protectedTitleCache} flag will be turned on.
141 public static Person
NewTitledInstance(String titleCache
){
142 Person result
= new Person();
143 result
.setTitleCache(titleCache
, true);
151 * @see #Person(String, String, String)
155 this.cacheStrategy
= PersonDefaultCacheStrategy
.NewInstance();
160 * Class constructor using a "forenames" string (including initials),
161 * a surname (family name) and an abbreviated name as used in nomenclature.
162 * For the abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
165 * @param firstname the given name
166 * @param lastname the hereditary name
167 * @param nomenclaturalTitel the abbreviated name
169 * @see #NewInstance()
171 public Person(String firstname
, String lastname
, String nomenclaturalTitel
) {
172 this.setFirstname(firstname
);
173 this.setLastname(lastname
);
174 logger
.debug("before - Set nomenclatural Title");
175 this.setNomenclaturalTitle(nomenclaturalTitel
);
176 logger
.debug("after - Set nomenclatural Title");
181 * Returns the set of {@link InstitutionalMembership institution memberships} corresponding to <i>this</i> person.
183 * @see InstitutionalMembership
185 public Set
<InstitutionalMembership
> getInstitutionalMemberships(){
186 if(institutionalMemberships
== null) {
187 this.institutionalMemberships
= new HashSet
<InstitutionalMembership
>();
189 return this.institutionalMemberships
;
192 protected void addInstitutionalMembership(InstitutionalMembership ims
){
193 getInstitutionalMemberships().add(ims
);
194 if (ims
.getPerson() != this){
195 logger
.warn("Institutional membership's person has to be changed for adding it to person: " + this);
196 ims
.getPerson().removeInstitutionalMembership(ims
);
203 * Adds a new {@link InstitutionalMembership membership} of <i>this</i> person in an {@link Institution institution}
204 * to the set of his institution memberships.
205 * This method also creates a new institutional membership instance.
207 * @param institution the institution <i>this</i> person belongs to
208 * @param period the time period for which <i>this</i> person has been a member of the institution
209 * @param department the string label for the department <i>this</i> person belongs to,
210 * within the institution
211 * @param role the string label for the persons's role within the department or institution
212 * @see #getInstitutionalMemberships()
213 * @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
215 public InstitutionalMembership
addInstitutionalMembership(Institution institution
, TimePeriod period
, String department
, String role
){
216 return new InstitutionalMembership(institution
, this, period
, department
, role
);
220 * Removes one element from the set of institutional memberships of <i>this</i> person.
221 * Institute and person attributes of the institutional membership object
224 * @param ims the institutional membership of <i>this</i> person which should be deleted
225 * @see #getInstitutionalMemberships()
227 public void removeInstitutionalMembership(InstitutionalMembership ims
){
228 ims
.setInstitute(null);
230 getInstitutionalMemberships().remove(ims
);
234 * Returns the string representing the prefix (for instance "Prof. Dr.<!-- -->")
235 * to <i>this</i> person's name.
237 public String
getPrefix(){
243 public void setPrefix(String prefix
){
244 this.prefix
= StringUtils
.isBlank(prefix
) ?
null : prefix
;
249 * Returns the string representing the given name or forename
250 * (for instance "John") of <i>this</i> person.
251 * This is the part of his name which is not shared with other
252 * family members. Actually it may be just initials (for instance "G. Jr."),
253 * all forenames in full or a combination of expanded names and initials.
255 public String
getFirstname(){
256 return this.firstname
;
259 * @see #getFirstname()
261 public void setFirstname(String firstname
){
262 this.firstname
= StringUtils
.isBlank(firstname
) ?
null : firstname
;
267 * Returns the string representing the hereditary name (surname or family name)
268 * (for instance "Smith") of <i>this</i> person.
269 * This is the part of his name which is common to (all) other
270 * members of his family, as distinct from the given name or forename.
272 public String
getLastname(){
273 return this.lastname
;
276 * @see #getLastname()
278 public void setLastname(String lastname
){
279 this.lastname
= StringUtils
.isBlank(lastname
) ?
null : lastname
;
284 * Returns the string representing the suffix (for instance "Junior")
285 * of <i>this</i> person's name.
287 public String
getSuffix(){
293 public void setSuffix(String suffix
){
294 this.suffix
= StringUtils
.isBlank(suffix
) ?
null: suffix
;
299 * Returns the {@link eu.etaxonomy.cdm.model.common.TimePeriod period of time}
300 * in which <i>this</i> person was alive (life span).
301 * The general form is birth date - death date
302 * (XXXX - YYYY; XXXX - or - YYYY as appropriate),
303 * but a simple flourished date (fl. XXXX) is also possible
304 * if that is all what is known.
306 * @see eu.etaxonomy.cdm.model.common.TimePeriod
308 public TimePeriod
getLifespan(){
309 if(lifespan
== null) {
310 this.lifespan
= TimePeriod
.NewInstance(new Partial(), new Partial());
312 return this.lifespan
;
315 * @see #getLifespan()
317 public void setLifespan(TimePeriod lifespan
){
318 if (lifespan
== null){
319 this.lifespan
= TimePeriod
.NewInstance(new Partial(), new Partial());
321 this.lifespan
= lifespan
;
325 // * Generates the "full" name string of <i>this</i> person according to the strategy
326 // * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
327 // * The used attributes are:
328 // * {@link #getPrefix() prefix}, {@link #getFirstname() firstname}, {@link #getLastname() lastname} and {@link #getSuffix() suffix}.
329 // * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
330 // * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
331 // * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
333 // * @return the string with the full name of <i>this</i> person
336 // public String generateTitle() {
337 // String title = null;
338 // if (cacheStrategy != null) {
339 // title = cacheStrategy.getTitleCache(this);
344 //*********************** CLONE ********************************************************/
347 * Clones <i>this</i> Person. This is a shortcut that enables to create
348 * a new instance that differs only slightly from <i>this</i> Person.
350 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
351 * @see java.lang.Object#clone()
354 public Object
clone() {
356 Person result
= (Person
)super.clone();
357 //no changes to firstname, lastname, lifespan, prefix, suffix
359 } catch (CloneNotSupportedException e
){
360 logger
.warn("Object does not implement cloneable");