Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
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 eu.etaxonomy.cdm.model.common.TimePeriod;
13
import eu.etaxonomy.cdm.model.common.Keyword;
14
import eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy;
15

    
16
import org.apache.log4j.Logger;
17
import org.hibernate.annotations.Cascade;
18
import org.hibernate.annotations.CascadeType;
19
import org.hibernate.envers.Audited;
20
import org.springframework.beans.factory.annotation.Configurable;
21

    
22
import java.util.*;
23
import javax.persistence.*;
24
import javax.xml.bind.annotation.XmlAccessType;
25
import javax.xml.bind.annotation.XmlAccessorType;
26
import javax.xml.bind.annotation.XmlElement;
27
import javax.xml.bind.annotation.XmlElementWrapper;
28
import javax.xml.bind.annotation.XmlIDREF;
29
import javax.xml.bind.annotation.XmlRootElement;
30
import javax.xml.bind.annotation.XmlSchemaType;
31
import javax.xml.bind.annotation.XmlType;
32

    
33
/**
34
 * This class represents human beings, living or dead.<BR>
35
 * It includes name parts, {@link Contact contact} details, {@link InstitutionalMembership institutional membership},
36
 * and other possible information such as life {@link TimePeriod time period},
37
 * taxonomic and/or geographical {@link Keyword specialization}.
38
 * For a short abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
39
 * is to be used.<BR>
40
 * For other alternative (string-)names {@link eu.etaxonomy.cdm.model.common.OriginalSource OriginalSource} instances must be created
41
 * and the inherited attribute {@link eu.etaxonomy.cdm.model.common.ReferencedEntityBase#getOriginalNameString() originalNameString} must be used.
42
 * <P>
43
 * This class corresponds to: <ul>
44
 * <li> Person according to the TDWG ontology
45
 * <li> AgentName (partially) according to the TCS
46
 * <li> Person (PersonName partially) according to the ABCD schema
47
 * </ul>
48
 * 
49
 * @author m.doering
50
 * @version 1.0
51
 * @created 08-Nov-2007 13:06:42
52
 */
53
@XmlAccessorType(XmlAccessType.FIELD)
54
@XmlType(name = "Person", propOrder = {
55
	    "prefix",
56
	    "firstname",
57
	    "lastname",
58
	    "suffix",
59
	    "lifespan",
60
	    "institutionalMemberships",
61
	    "keywords"
62
	})
63
@XmlRootElement(name = "Person")
64
@Entity
65
@Audited
66
@Configurable
67
public class Person extends TeamOrPersonBase<Person> {
68
	private static final long serialVersionUID = 4153566493065539763L;
69
	public static final Logger logger = Logger.getLogger(Person.class);
70

    
71
    @XmlElement(name = "Prefix")
72
	private String prefix;
73
    
74
    @XmlElement(name = "FirstName")
75
	private String firstname;
76
	
77
    @XmlElement(name = "LastName")
78
	private String lastname;
79
	
80
    @XmlElement(name = "Suffix")
81
	private String suffix;
82
	
83
    @XmlElement(name = "Lifespan")
84
	private TimePeriod lifespan;
85
	
86
    @XmlElementWrapper(name = "InstitutionalMemberships")
87
    @XmlElement(name = "InstitutionalMembership")
88
    @OneToMany(fetch=FetchType.LAZY, mappedBy = "person")
89
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
90
	protected Set<InstitutionalMembership> institutionalMemberships;
91
	
92
    @XmlElementWrapper(name = "Keywords")
93
    @XmlElement(name = "Keyword")
94
    @XmlIDREF
95
    @XmlSchemaType(name="IDREF")
96
    @ManyToMany(fetch=FetchType.LAZY)
97
	@JoinTable(
98
	        name="Person_Keyword",
99
	        joinColumns=@JoinColumn(name="person_fk"),
100
	        inverseJoinColumns=@JoinColumn(name="keyword_fk")
101
	)
102
	private Set<Keyword> keywords = new HashSet<Keyword>();
103

    
104
	/** 
105
	 * Creates a new empty instance for a person whose existence is all what is known.
106
	 * This can be a provisional solution until more information about <i>this</i> person
107
	 * can be gathered, for instance in case a member of a nomenclatural author team
108
	 * is not explicitly mentioned. It also includes the cache strategy defined in
109
	 * {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
110
	 */
111
	public static Person NewInstance(){
112
		return new Person();
113
	}
114
	
115
	/** 
116
	 * Creates a new instance for a person for whom an "identification" string
117
	 * is all what is known. This string is generally a short or a complete name.
118
	 * As this string is kept in the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache}
119
	 * attribute and should not be overwritten by the {@link #generateTitle() generateTitle} method
120
	 * the {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#isProtectedTitleCache() protectedTitleCache} flag will be turned on. 
121
	 */
122
	public static Person NewTitledInstance(String titleCache){
123
		Person result = new Person();
124
		result.setTitleCache(titleCache);
125
		return result;
126
	}
127
	
128
	
129
	/** 
130
	 * Class constructor.
131
	 * 
132
	 * @see #Person(String, String, String)
133
	 */
134
	protected Person() {
135
		super();
136
		this.cacheStrategy = PersonDefaultCacheStrategy.NewInstance();
137

    
138
	}
139
	
140
	/** 
141
	 * Class constructor using a "forenames" string (including initials),
142
	 * a surname (family name) and an abbreviated name as used in nomenclature.
143
	 * For the abbreviated name the inherited attribute {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle}
144
	 * is used.
145
	 *
146
	 * @param  firstname     		the given name
147
	 * @param  lastname      		the hereditary name
148
	 * @param  nomenclaturalTitel 	the abbreviated name
149
	 * @see                  		#Person()
150
	 * @see                  		#NewInstance()
151
	 */
152
	public Person(String firstname, String lastname, String nomenclaturalTitel) {
153
		this.setFirstname(firstname);
154
		this.setLastname(lastname);
155
		this.setNomenclaturalTitle(nomenclaturalTitel);
156
	}
157
	
158
	
159
	/** 
160
	 * Returns the set of {@link InstitutionalMembership institution memberships} corresponding to <i>this</i> person. 
161
	 *
162
	 * @see     InstitutionalMembership
163
	 */
164
	public Set<InstitutionalMembership> getInstitutionalMemberships(){
165
		return this.institutionalMemberships;
166
	}
167

    
168
	
169
	/** 
170
	 * Adds a new {@link InstitutionalMembership membership} of <i>this</i> person in an {@link Institution institution}
171
	 * to the set of his institution memberships.
172
	 * This method also creates a new institutional membership instance.
173
	 *
174
	 * @param  institution  the institution <i>this</i> person belongs to
175
	 * @param  period       the time period for which <i>this</i> person has been a member of the institution
176
	 * @param  department   the string label for the department <i>this</i> person belongs to,
177
	 * 					    within the institution
178
	 * @param  role         the string label for the persons's role within the department or institution
179
	 * @see 			    #getInstitutionalMemberships()
180
	 * @see 			    InstitutionalMembership#InstitutionalMembership(Institution, Person, TimePeriod, String, String)
181
	 */
182
	public void addInstitutionalMembership(Institution institution, TimePeriod period, String department, String role){
183
		//TODO to be implemented?
184
		logger.warn("not yet fully implemented?");
185
		InstitutionalMembership ims = new InstitutionalMembership(institution, this, period, department, role);
186
		institutionalMemberships.add(ims);
187
	}
188
	
189
	/** 
190
	 * Removes one element from the set of institutional memberships of <i>this</i> person.
191
	 * Institute and person attributes of the institutional membership object
192
	 * will be nullified.
193
	 *
194
	 * @param  ims  the institutional membership of <i>this</i> person which should be deleted
195
	 * @see     	#getInstitutionalMemberships()
196
	 */
197
	public void removeInstitutionalMembership(InstitutionalMembership ims){
198
		//TODO to be implemented?
199
		logger.warn("not yet fully implemented?");
200
		ims.setInstitute(null);
201
		ims.setPerson(null);
202
		this.institutionalMemberships.remove(ims);
203
	}
204

    
205

    
206
	/** 
207
	 * Returns the set of {@link eu.etaxonomy.cdm.model.common.Keyword keywords} mostly representing a taxonomic or
208
	 * a geographical specialization of <i>this</i> person.
209
	 * Keywords are items of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}.
210
	 *
211
	 * @see 	Keyword
212
	 */
213
	public Set<Keyword> getKeywords(){
214
		return this.keywords;
215
	}
216

    
217
	/** 
218
	 * Adds a new keyword from the keyword vocabulary to the set of keywords
219
	 * describing or circumscribing <i>this</i> person's activities.
220
	 *
221
	 * @param  keyword  any keyword 
222
	 * @see 			#getKeywords()
223
	 * @see 			eu.etaxonomy.cdm.model.common.Keyword
224
	 */
225
	public void addKeyword(Keyword keyword){
226
		this.keywords.add(keyword);
227
	}
228
	/** 
229
	 * Removes one element from the set of keywords for <i>this</i> person.
230
	 *
231
	 * @param  keyword  the keyword which should be deleted
232
	 * @see             #getKeywords()
233
	 */
234
	public void removeKeyword(Keyword keyword){
235
		this.keywords.remove(keyword);
236
	}
237
	
238
	/**
239
	 * Returns the string representing the prefix (for instance "Prof.&nbsp;Dr.<!-- -->")
240
	 * to <i>this</i> person's name.
241
	 */
242
	public String getPrefix(){
243
		return this.prefix;
244
	}
245
	/**
246
	 * @see  #getPrefix()
247
	 */
248
	public void setPrefix(String prefix){
249
		this.prefix = prefix;
250
	}
251

    
252

    
253
	/**
254
	 * Returns the string representing the given name or forename
255
	 * (for instance "John") of <i>this</i> person. 
256
	 * This is the part of his name which is not shared with other
257
	 * family members. Actually it may be just initials (for instance "G.&nbsp;Jr."),
258
	 * all forenames in full or a combination of expanded names and initials. 
259
	 */
260
	public String getFirstname(){
261
		return this.firstname;
262
	}
263
	/**
264
	 * @see  #getFirstname()
265
	 */
266
	public void setFirstname(String firstname){
267
		this.firstname = firstname;
268
	}
269

    
270
	
271
	/**
272
	 * Returns the string representing the hereditary name (surname or family name)
273
	 * (for instance "Smith") of <i>this</i> person. 
274
	 * This is the part of his name which is common to (all) other
275
	 * members of his family, as distinct from the given name or forename. 
276
	 */
277
	public String getLastname(){
278
		return this.lastname;
279
	}
280
	/**
281
	 * @see  #getLastname()
282
	 */
283
	public void setLastname(String lastname){
284
		this.lastname = lastname;
285
	}
286

    
287

    
288
	/**
289
	 * Returns the string representing the suffix (for instance "Junior")
290
	 * of <i>this</i> person's name.
291
	 */
292
	public String getSuffix(){
293
		return this.suffix;
294
	}
295
	/**
296
	 * @see  #getSuffix()
297
	 */
298
	public void setSuffix(String suffix){
299
		this.suffix = suffix;
300
	}
301

    
302

    
303
	/** 
304
	 * Returns the {@link eu.etaxonomy.cdm.model.common.TimePeriod period of time}
305
	 * in which <i>this</i> person was alive (life span).
306
	 * The general form is birth date - death date
307
	 * (XXXX - YYYY; XXXX - or - YYYY as appropriate),
308
	 * but a simple flourished date (fl. XXXX) is also possible
309
	 * if that is all what is known.
310
	 *
311
	 * @see  eu.etaxonomy.cdm.model.common.TimePeriod
312
	 */
313
	public TimePeriod getLifespan(){
314
		return this.lifespan;
315
	}
316
	/**
317
	 * @see  #getLifespan()
318
	 */
319
	public void setLifespan(TimePeriod lifespan){
320
		this.lifespan = lifespan;
321
	}
322

    
323
//	/**
324
//	 * Generates the "full" name string of <i>this</i> person according to the strategy
325
//	 * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
326
//	 * The used attributes are:
327
//	 * {@link #getPrefix() prefix}, {@link #getFirstname() firstname}, {@link #getLastname() lastname} and {@link #getSuffix() suffix}.
328
//	 * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
329
//	 * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
330
//	 * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
331
//	 * 
332
//	 * @return  the string with the full name of <i>this</i> person
333
//	 */
334
//	@Override
335
//	public String generateTitle() {
336
//		String title = null;
337
//		if (cacheStrategy != null) {
338
//		title = cacheStrategy.getTitleCache(this);
339
//		} 
340
//        return title;
341
//	}
342

    
343
}
(8-8/12)