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.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import javax.persistence.Entity;
|
16
|
import javax.persistence.FetchType;
|
17
|
import javax.persistence.ManyToMany;
|
18
|
import javax.persistence.Transient;
|
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.XmlIDREF;
|
24
|
import javax.xml.bind.annotation.XmlRootElement;
|
25
|
import javax.xml.bind.annotation.XmlSchemaType;
|
26
|
import javax.xml.bind.annotation.XmlType;
|
27
|
|
28
|
import org.apache.log4j.Logger;
|
29
|
import org.hibernate.annotations.Cascade;
|
30
|
import org.hibernate.annotations.CascadeType;
|
31
|
import org.hibernate.annotations.IndexColumn;
|
32
|
import org.hibernate.envers.Audited;
|
33
|
import org.hibernate.search.annotations.Indexed;
|
34
|
import org.springframework.beans.factory.annotation.Configurable;
|
35
|
|
36
|
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
|
37
|
import eu.etaxonomy.cdm.strategy.match.IMatchable;
|
38
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
39
|
import eu.etaxonomy.cdm.strategy.match.Match;
|
40
|
import eu.etaxonomy.cdm.strategy.merge.IMergable;
|
41
|
|
42
|
/**
|
43
|
* This class represents teams of {@link Person persons}. A team exists either for itself
|
44
|
* or is built with the list of (distinct) persons who belong to it.
|
45
|
* In the first case the inherited attribute {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} is to be used.
|
46
|
* In the second case at least all abbreviated names
|
47
|
* (the inherited attributes {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle})
|
48
|
* or all full names (the strings returned by Person.generateTitle)
|
49
|
* of the persons must exist. A team is a {@link java.util.List list} of persons.
|
50
|
* <P>
|
51
|
* This class corresponds to: <ul>
|
52
|
* <li> Team according to the TDWG ontology
|
53
|
* <li> AgentNames (partially) according to the TCS
|
54
|
* <li> MicroAgent (partially) according to the ABCD schema
|
55
|
* </ul>
|
56
|
*
|
57
|
* @author m.doering
|
58
|
* @version 1.0
|
59
|
* @created 08-Nov-2007 13:06:58
|
60
|
*/
|
61
|
@XmlAccessorType(XmlAccessType.FIELD)
|
62
|
@XmlType(name = "Team", propOrder = {
|
63
|
"protectedNomenclaturalTitleCache",
|
64
|
"teamMembers"
|
65
|
})
|
66
|
@XmlRootElement
|
67
|
@Entity
|
68
|
@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
|
69
|
@Audited
|
70
|
@Configurable
|
71
|
public class Team extends TeamOrPersonBase<Team> {
|
72
|
private static final long serialVersionUID = 97640416905934622L;
|
73
|
public static final Logger logger = Logger.getLogger(Team.class);
|
74
|
|
75
|
@XmlElement(name = "ProtectedNomenclaturalTitleCache")
|
76
|
private boolean protectedNomenclaturalTitleCache;
|
77
|
|
78
|
//An abreviated name for the team (e. g. in case of nomenclatural authorteams). A non abreviated name for the team (e. g.
|
79
|
//in case of some bibliographical references)
|
80
|
@XmlElementWrapper(name = "TeamMembers")
|
81
|
@XmlElement(name = "TeamMember")
|
82
|
@XmlIDREF
|
83
|
@XmlSchemaType(name = "IDREF")
|
84
|
@IndexColumn(name="sortIndex", base = 0)
|
85
|
@ManyToMany(fetch = FetchType.LAZY)
|
86
|
@Cascade(CascadeType.SAVE_UPDATE)
|
87
|
@Match(MatchMode.MATCH)
|
88
|
private List<Person> teamMembers = new ArrayList<Person>();
|
89
|
|
90
|
|
91
|
/**
|
92
|
* Creates a new team instance without any concrete {@link Person members}.
|
93
|
*/
|
94
|
static public Team NewInstance(){
|
95
|
return new Team();
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Class constructor (including the cache strategy defined in
|
100
|
* {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}).
|
101
|
*/
|
102
|
public Team() {
|
103
|
super();
|
104
|
this.cacheStrategy = TeamDefaultCacheStrategy.NewInstance();
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Returns the list of {@link Person members} belonging to <i>this</i> team.
|
109
|
* A person may be a member of several distinct teams.
|
110
|
*/
|
111
|
public List<Person> getTeamMembers(){
|
112
|
return this.teamMembers;
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Adds a new {@link Person person} to <i>this</i> team at the end of the members' list.
|
117
|
*
|
118
|
* @param person the person who should be added to the other team members
|
119
|
* @see #getTeamMembers()
|
120
|
* @see Person
|
121
|
*/
|
122
|
public void addTeamMember(Person person){
|
123
|
this.teamMembers.add(person);
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Adds a new {@link Person person} to <i>this</i> team
|
128
|
* at the given index place of the members' list. If the person is already
|
129
|
* a member of the list he will be moved to the given index place.
|
130
|
* The index must be a positive integer. If the index is bigger than
|
131
|
* the present number of members the person will be added at the end of the list.
|
132
|
*
|
133
|
* @param person the person who should be added to the other team members
|
134
|
* @param index the position at which the new person should be placed within the members' list
|
135
|
* @see #getTeamMembers()
|
136
|
* @see Person
|
137
|
*/
|
138
|
public void addTeamMember(Person person, int index){
|
139
|
// TODO is still not fully implemented (range for index!)
|
140
|
logger.warn("not yet fully implemented (range for index!)");
|
141
|
int oldIndex = teamMembers.indexOf(person);
|
142
|
if (oldIndex != -1 ){
|
143
|
teamMembers.remove(person);
|
144
|
}
|
145
|
this.teamMembers.add(index, person);
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* Removes one person from the list of members of <i>this</i> team.
|
150
|
*
|
151
|
* @param person the person who should be deleted from <i>this</i> team
|
152
|
* @see #getTeamMembers()
|
153
|
*/
|
154
|
public void removeTeamMember(Person person){
|
155
|
this.teamMembers.remove(person);
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* Generates an identification string for <i>this</i> team according to the strategy
|
160
|
* defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}. This string is built
|
161
|
* with the full names of all persons belonging to its (ordered) members' list.
|
162
|
* This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
|
163
|
* The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
|
164
|
* flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
|
165
|
*
|
166
|
* @return a string which identifies <i>this</i> team
|
167
|
*/
|
168
|
// @Override
|
169
|
// public String generateTitle() {
|
170
|
// return cacheStrategy.getTitleCache(this);
|
171
|
// }
|
172
|
|
173
|
|
174
|
/**
|
175
|
* Generates or returns the {@link TeamOrPersonBase#getnomenclaturalTitle() nomenclatural identification} string for <i>this</i> team.
|
176
|
* This method overrides {@link TeamOrPersonBase#getNomenclaturalTitle() getNomenclaturalTitle}.
|
177
|
* This string is built with the {@link TeamOrPersonBase#getNomenclaturalTitle() abbreviated names}
|
178
|
* of all persons belonging to its (ordered) members' list if the flag
|
179
|
* {@link #protectedNomenclaturalTitleCache protectedNomenclaturalTitleCache} is not set.
|
180
|
* Otherwise this method returns the present nomenclatural abbreviation.
|
181
|
* In case the string is generated the cache strategy used is defined in
|
182
|
* {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}.
|
183
|
* The result might be kept as nomenclatural abbreviation
|
184
|
* by using the {@link #setNomenclaturalTitle(String) setNomenclaturalTitle} method.
|
185
|
*
|
186
|
* @return a string which identifies <i>this</i> team for nomenclature
|
187
|
*/
|
188
|
@Override
|
189
|
@Transient
|
190
|
public String getNomenclaturalTitle() {
|
191
|
if (protectedNomenclaturalTitleCache == PROTECTED){
|
192
|
return this.nomenclaturalTitle;
|
193
|
}
|
194
|
if (nomenclaturalTitle == null){
|
195
|
this.nomenclaturalTitle = cacheStrategy.getNomenclaturalTitle(this);
|
196
|
}
|
197
|
return nomenclaturalTitle;
|
198
|
}
|
199
|
|
200
|
/**
|
201
|
* Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
|
202
|
* and protects it from overwriting.
|
203
|
* This method overrides {@link TeamOrPersonBase#setNomenclaturalTitle(String) setNomenclaturalTitle}.
|
204
|
*
|
205
|
* @see #getNomenclaturalTitle()
|
206
|
* @see #setNomenclaturalTitle(String, boolean)
|
207
|
*/
|
208
|
@Override
|
209
|
public void setNomenclaturalTitle(String nomenclaturalTitle) {
|
210
|
setNomenclaturalTitle(nomenclaturalTitle, PROTECTED);
|
211
|
this.nomenclaturalTitle = nomenclaturalTitle;
|
212
|
}
|
213
|
|
214
|
/**
|
215
|
* Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
|
216
|
* and a protection flag status to this string.
|
217
|
*
|
218
|
* @see #getNomenclaturalTitle()
|
219
|
*/
|
220
|
public void setNomenclaturalTitle(String nomenclaturalTitle, boolean protectedNomenclaturalTitleCache) {
|
221
|
this.nomenclaturalTitle = nomenclaturalTitle;
|
222
|
this.protectedNomenclaturalTitleCache = protectedNomenclaturalTitleCache;
|
223
|
}
|
224
|
}
|