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
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import javax.persistence.Column;
|
16
|
import javax.persistence.Entity;
|
17
|
import javax.persistence.FetchType;
|
18
|
import javax.persistence.OneToMany;
|
19
|
import javax.xml.bind.annotation.XmlAccessType;
|
20
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21
|
import javax.xml.bind.annotation.XmlElement;
|
22
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
23
|
import javax.xml.bind.annotation.XmlRootElement;
|
24
|
import javax.xml.bind.annotation.XmlType;
|
25
|
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.hibernate.annotations.Cascade;
|
28
|
import org.hibernate.annotations.CascadeType;
|
29
|
import org.hibernate.annotations.Type;
|
30
|
import org.hibernate.envers.Audited;
|
31
|
import org.hibernate.search.annotations.Field;
|
32
|
import org.hibernate.search.annotations.FieldBridge;
|
33
|
import org.hibernate.search.annotations.Index;
|
34
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
35
|
import org.springframework.beans.factory.annotation.Configurable;
|
36
|
|
37
|
import eu.etaxonomy.cdm.hibernate.search.OrcidBridge;
|
38
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
39
|
import eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy;
|
40
|
import eu.etaxonomy.cdm.strategy.match.Match;
|
41
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
42
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
43
|
import javassist.compiler.ast.Keyword;
|
44
|
|
45
|
/**
|
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}
|
51
|
* is to be used.<BR>
|
52
|
* For other alternative (string-)names {@link eu.etaxonomy.cdm.model.reference.OriginalSourceBase OriginalSource} instances must be created
|
53
|
* and the attribute {@link eu.etaxonomy.cdm.model.common.OriginalSourceBase#getOriginalNameString() originalNameString} must be used.
|
54
|
* <P>
|
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
|
59
|
* </ul>
|
60
|
*
|
61
|
* @author m.doering
|
62
|
* @since 08-Nov-2007 13:06:42
|
63
|
*/
|
64
|
@XmlAccessorType(XmlAccessType.FIELD)
|
65
|
@XmlType(name = "Person", propOrder = {
|
66
|
"prefix",
|
67
|
"familyName",
|
68
|
"givenName",
|
69
|
"initials",
|
70
|
"suffix",
|
71
|
"collectorTitle",
|
72
|
"lifespan",
|
73
|
"orcid",
|
74
|
"institutionalMemberships"
|
75
|
})
|
76
|
@XmlRootElement(name = "Person")
|
77
|
@Entity
|
78
|
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
|
79
|
//@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
|
80
|
@Audited
|
81
|
@Configurable
|
82
|
public class Person extends TeamOrPersonBase<Person>{
|
83
|
|
84
|
private static final long serialVersionUID = 4153566493065539763L;
|
85
|
public static final Logger logger = Logger.getLogger(Person.class);
|
86
|
|
87
|
//under construction #4311
|
88
|
@XmlElement(name="CollectorTitle")
|
89
|
@Field(index=Index.YES)
|
90
|
@Column(length=255)
|
91
|
private String collectorTitle;
|
92
|
|
93
|
@XmlElement(name = "Prefix")
|
94
|
@Field
|
95
|
//TODO Val #3379
|
96
|
// @NullOrNotEmpty
|
97
|
@Column(length=255)
|
98
|
private String prefix;
|
99
|
|
100
|
@XmlElement(name = "GivenName")
|
101
|
@Field
|
102
|
//TODO Val #3379
|
103
|
// @NullOrNotEmpty
|
104
|
@Column(length=255)
|
105
|
private String givenName;
|
106
|
|
107
|
@XmlElement(name = "Initials")
|
108
|
@Field
|
109
|
@NullOrNotEmpty
|
110
|
@Column(length=80)
|
111
|
private String initials;
|
112
|
|
113
|
@XmlElement(name = "FamilyName")
|
114
|
@Field
|
115
|
//TODO Val #3379
|
116
|
// @NullOrNotEmpty
|
117
|
@Column(length=255)
|
118
|
private String familyName;
|
119
|
|
120
|
@XmlElement(name = "Suffix")
|
121
|
@Field
|
122
|
//TODO Val #3379
|
123
|
// @NullOrNotEmpty
|
124
|
@Column(length=255)
|
125
|
private String suffix;
|
126
|
|
127
|
@XmlElement(name = "Lifespan")
|
128
|
@IndexedEmbedded
|
129
|
@Match(value=MatchMode.EQUAL_OR_ONE_NULL)
|
130
|
//TODO Val #3379 check carefully what the condition is that lifespan is really null in legacy data
|
131
|
// @NotNull
|
132
|
private TimePeriod lifespan = TimePeriod.NewInstance();
|
133
|
|
134
|
@XmlElement(name = "Orcid")
|
135
|
@Field
|
136
|
@FieldBridge(impl = OrcidBridge.class)
|
137
|
@Type(type="orcidUserType")
|
138
|
@Column(length=16)
|
139
|
private ORCID orcid;
|
140
|
|
141
|
@XmlElementWrapper(name = "InstitutionalMemberships", nillable = true)
|
142
|
@XmlElement(name = "InstitutionalMembership")
|
143
|
@OneToMany(fetch=FetchType.LAZY, mappedBy = "person")
|
144
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
|
145
|
protected Set<InstitutionalMembership> institutionalMemberships;
|
146
|
|
147
|
// *********************** FACTORY **********************************/
|
148
|
|
149
|
/**
|
150
|
* Creates a new empty instance for a person whose existence is all what is known.
|
151
|
* This can be a provisional solution until more information about <i>this</i> person
|
152
|
* can be gathered, for instance in case a member of a nomenclatural author team
|
153
|
* is not explicitly mentioned. It also includes the cache strategy defined in
|
154
|
* {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
|
155
|
*/
|
156
|
public static Person NewInstance(){
|
157
|
return new Person();
|
158
|
}
|
159
|
|
160
|
/**
|
161
|
* Creates a new instance for a person for whom an "identification" string
|
162
|
* is all what is known. This string is generally a short or a complete name.
|
163
|
* As this string is kept in the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache}
|
164
|
* attribute and should not be overwritten by the {@link #generateTitle() generateTitle} method
|
165
|
* the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#isProtectedTitleCache() protectedTitleCache} flag will be turned on.
|
166
|
*/
|
167
|
public static Person NewTitledInstance(String titleCache){
|
168
|
Person result = new Person();
|
169
|
result.setTitleCache(titleCache, true);
|
170
|
return result;
|
171
|
}
|
172
|
|
173
|
public static Person NewInstance(String nomRefTitle, String familyName, String initials, String givenName){
|
174
|
Person result = new Person();
|
175
|
result.setNomenclaturalTitle(nomRefTitle);
|
176
|
result.setFamilyName(familyName);
|
177
|
result.setInitials(initials);
|
178
|
result.setGivenName(givenName);
|
179
|
return result;
|
180
|
}
|
181
|
|
182
|
|
183
|
// *********************** CONSTRUCTOR **********************************/
|
184
|
|
185
|
/**
|
186
|
* Class constructor.
|
187
|
*
|
188
|
* @see #Person(String, String, String)
|
189
|
*/
|
190
|
protected Person() {
|
191
|
super();
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* Class constructor using a "forenames" string (including initials),
|
196
|
* a surname (family name) and an abbreviated name as used in nomenclature.
|
197
|
* For the abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
|
198
|
* is used.
|
199
|
*
|
200
|
* @param givenname the given name
|
201
|
* @param familyname the hereditary name
|
202
|
* @param nomenclaturalTitel the abbreviated name
|
203
|
* @see #Person()
|
204
|
* @see #NewInstance()
|
205
|
*/
|
206
|
public Person(String givenname, String familyname, String nomenclaturalTitel) {
|
207
|
this.setGivenName(givenname);
|
208
|
this.setFamilyName(familyname);
|
209
|
logger.debug("before - Set nomenclatural Title");
|
210
|
this.setNomenclaturalTitle(nomenclaturalTitel);
|
211
|
logger.debug("after - Set nomenclatural Title");
|
212
|
}
|
213
|
|
214
|
@Override
|
215
|
protected void initDefaultCacheStrategy() {
|
216
|
this.cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
|
217
|
}
|
218
|
|
219
|
// *********************** GETTER SETTER ADDER **********************************/
|
220
|
|
221
|
|
222
|
/**
|
223
|
* Returns the set of {@link InstitutionalMembership institution memberships} corresponding to <i>this</i> person.
|
224
|
*
|
225
|
* @see InstitutionalMembership
|
226
|
*/
|
227
|
public Set<InstitutionalMembership> getInstitutionalMemberships(){
|
228
|
if(institutionalMemberships == null) {
|
229
|
this.institutionalMemberships = new HashSet<>();
|
230
|
}
|
231
|
return this.institutionalMemberships;
|
232
|
}
|
233
|
|
234
|
protected void addInstitutionalMembership(InstitutionalMembership ims){
|
235
|
getInstitutionalMemberships().add(ims);
|
236
|
if (ims.getPerson() != this){
|
237
|
logger.warn("Institutional membership's person has to be changed for adding it to person: " + this);
|
238
|
ims.getPerson().removeInstitutionalMembership(ims);
|
239
|
ims.setPerson(this);
|
240
|
}
|
241
|
}
|
242
|
|
243
|
/**
|
244
|
* Adds a new {@link InstitutionalMembership membership} of <i>this</i> person in an {@link Institution institution}
|
245
|
* to the set of his institution memberships.
|
246
|
* This method also creates a new institutional membership instance.
|
247
|
*
|
248
|
* @param institution the institution <i>this</i> person belongs to
|
249
|
* @param period the time period for which <i>this</i> person has been a member of the institution
|
250
|
* @param department the string label for the department <i>this</i> person belongs to,
|
251
|
* within the institution
|
252
|
* @param role the string label for the persons's role within the department or institution
|
253
|
* @see #getInstitutionalMemberships()
|
254
|
* @see InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
|
255
|
*/
|
256
|
public InstitutionalMembership addInstitutionalMembership(Institution institution, TimePeriod period, String department, String role){
|
257
|
return new InstitutionalMembership(institution, this, period, department, role);
|
258
|
}
|
259
|
|
260
|
/**
|
261
|
* Removes one element from the set of institutional memberships of <i>this</i> person.
|
262
|
* Institute and person attributes of the institutional membership object
|
263
|
* will be nullified.
|
264
|
*
|
265
|
* @param ims the institutional membership of <i>this</i> person which should be deleted
|
266
|
* @see #getInstitutionalMemberships()
|
267
|
*/
|
268
|
public void removeInstitutionalMembership(InstitutionalMembership ims){
|
269
|
ims.setInstitute(null);
|
270
|
ims.setPerson(null);
|
271
|
getInstitutionalMemberships().remove(ims);
|
272
|
}
|
273
|
|
274
|
/**
|
275
|
* Returns the string representing the prefix (for instance "Prof. Dr.<!-- -->")
|
276
|
* to <i>this</i> person's name.
|
277
|
*/
|
278
|
public String getPrefix(){
|
279
|
return this.prefix;
|
280
|
}
|
281
|
/**
|
282
|
* @see #getPrefix()
|
283
|
*/
|
284
|
public void setPrefix(String prefix){
|
285
|
this.prefix = isBlank(prefix) ? null : prefix;
|
286
|
}
|
287
|
|
288
|
|
289
|
/**
|
290
|
* Returns the string representing the given name or forename
|
291
|
* (for instance "John") of <i>this</i> person.
|
292
|
* This is the part of his name which is not shared with other
|
293
|
* family members. <BR>
|
294
|
* Pure initials should be stored in {@link #getInitials() initials}
|
295
|
* A combination of expanded names and initials maybe stored here.
|
296
|
* <BR> In user interfaces (UI) this field should better be called
|
297
|
* "Other/given names" according to {@link https://www.w3.org/International/questions/qa-personal-names.en#fielddesign }.
|
298
|
*
|
299
|
* @see #getInitials()
|
300
|
* @see #getFamilyName()
|
301
|
* @see https://www.w3.org/International/questions/qa-personal-names.en#fielddesign
|
302
|
*/
|
303
|
public String getGivenName(){
|
304
|
return this.givenName;
|
305
|
}
|
306
|
/**
|
307
|
* @see #getGivenName()
|
308
|
*/
|
309
|
public void setGivenName(String givenName){
|
310
|
this.givenName = isBlank(givenName) ? null : givenName;
|
311
|
}
|
312
|
|
313
|
//#4311
|
314
|
public String getCollectorTitle() {
|
315
|
return collectorTitle;
|
316
|
}
|
317
|
public void setCollectorTitle(String collectorTitle) {
|
318
|
this.collectorTitle = collectorTitle;
|
319
|
}
|
320
|
|
321
|
/**
|
322
|
* Returns the initials of this person as used in bibliographic
|
323
|
* references. Usually these are the first letters of each givenname
|
324
|
* followed by "." per givenname. For East Asian names it may
|
325
|
* be the first 2 letters. Also dashes are kept.
|
326
|
* @return the initials
|
327
|
*/
|
328
|
public String getInitials(){
|
329
|
return this.initials;
|
330
|
}
|
331
|
/**
|
332
|
* @see #getInitals()
|
333
|
*/
|
334
|
public void setInitials(String initials){
|
335
|
this.initials = isBlank(initials) ? null : initials;
|
336
|
}
|
337
|
|
338
|
|
339
|
/**
|
340
|
* Returns the string representing the hereditary name (surname or family name)
|
341
|
* (for instance "Smith") of <i>this</i> person.
|
342
|
* This is the part of his name which is common to (all) other
|
343
|
* members of his family, as distinct from the given name or forename.
|
344
|
*
|
345
|
* <BR> In user interfaces (UI) this field should better be called
|
346
|
* "Family name" according to {@link https://www.w3.org/International/questions/qa-personal-names.en#fielddesign }.
|
347
|
*
|
348
|
* @see #getInitials()
|
349
|
* @see #getGivenName()
|
350
|
* @see https://www.w3.org/International/questions/qa-personal-names.en#fielddesign
|
351
|
*/
|
352
|
public String getFamilyName(){
|
353
|
return this.familyName;
|
354
|
}
|
355
|
/**
|
356
|
* @see #getfamilyName()
|
357
|
*/
|
358
|
public void setFamilyName(String familyName){
|
359
|
this.familyName = isBlank(familyName) ? null : familyName;
|
360
|
}
|
361
|
|
362
|
|
363
|
/**
|
364
|
* Returns the string representing the suffix (for instance "Junior")
|
365
|
* of <i>this</i> person's name.
|
366
|
*/
|
367
|
public String getSuffix(){
|
368
|
return this.suffix;
|
369
|
}
|
370
|
/**
|
371
|
* @see #getSuffix()
|
372
|
*/
|
373
|
public void setSuffix(String suffix){
|
374
|
this.suffix = isBlank(suffix) ? null: suffix;
|
375
|
}
|
376
|
|
377
|
|
378
|
/**
|
379
|
* Returns the {@link eu.etaxonomy.cdm.model.common.TimePeriod period of time}
|
380
|
* in which <i>this</i> person was alive (life span).
|
381
|
* The general form is birth date - death date
|
382
|
* (XXXX - YYYY; XXXX - or - YYYY as appropriate),
|
383
|
* but a simple flourished date (fl. XXXX) is also possible
|
384
|
* if that is all what is known.
|
385
|
*
|
386
|
* @see eu.etaxonomy.cdm.model.common.TimePeriod
|
387
|
*/
|
388
|
public TimePeriod getLifespan(){
|
389
|
if(lifespan == null) {
|
390
|
this.lifespan = TimePeriod.NewInstance();
|
391
|
}
|
392
|
return this.lifespan;
|
393
|
}
|
394
|
/**
|
395
|
* @see #getLifespan()
|
396
|
*/
|
397
|
public void setLifespan(TimePeriod lifespan){
|
398
|
this.lifespan = lifespan != null? lifespan : TimePeriod.NewInstance();
|
399
|
}
|
400
|
|
401
|
|
402
|
/**
|
403
|
* The {@link ORCID ORCiD} of this person.<BR>
|
404
|
* See https://orcid.org/ for information on ORCiD.
|
405
|
* @return the ORCiD
|
406
|
*/
|
407
|
public ORCID getOrcid() {
|
408
|
return orcid;
|
409
|
}
|
410
|
/**
|
411
|
* @see #getOrcid()
|
412
|
*/
|
413
|
public void setOrcid(ORCID orcid) {
|
414
|
this.orcid = orcid;
|
415
|
}
|
416
|
|
417
|
@Override
|
418
|
public boolean updateCaches(){
|
419
|
boolean result = false;
|
420
|
result |= super.updateCaches();
|
421
|
if (this.nomenclaturalTitle == null){
|
422
|
this.nomenclaturalTitle = this.getTitleCache();
|
423
|
if ( this.nomenclaturalTitle != null ){
|
424
|
result = true;
|
425
|
}
|
426
|
}
|
427
|
|
428
|
return result;
|
429
|
}
|
430
|
|
431
|
//*********************** CLONE ********************************************************/
|
432
|
|
433
|
/**
|
434
|
* Clones <i>this</i> Person. This is a shortcut that enables to create
|
435
|
* a new instance that differs only slightly from <i>this</i> Person.
|
436
|
*
|
437
|
* @see java.lang.Object#clone()
|
438
|
*/
|
439
|
@Override
|
440
|
public Person clone() {
|
441
|
try{
|
442
|
Person result = (Person)super.clone();
|
443
|
//no changes to givenname, familyname, lifespan, prefix, suffix
|
444
|
return result;
|
445
|
} catch (CloneNotSupportedException e){
|
446
|
logger.warn("Object does not implement cloneable");
|
447
|
e.printStackTrace();
|
448
|
return null;
|
449
|
}
|
450
|
}
|
451
|
}
|