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
.ArrayList
;
13 import java
.util
.List
;
15 import javax
.persistence
.Entity
;
16 import javax
.persistence
.ManyToMany
;
17 import javax
.persistence
.Transient
;
18 import javax
.xml
.bind
.annotation
.XmlAccessType
;
19 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
20 import javax
.xml
.bind
.annotation
.XmlElement
;
21 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
22 import javax
.xml
.bind
.annotation
.XmlIDREF
;
23 import javax
.xml
.bind
.annotation
.XmlRootElement
;
24 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
25 import javax
.xml
.bind
.annotation
.XmlType
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.hibernate
.annotations
.Cascade
;
29 import org
.hibernate
.annotations
.CascadeType
;
31 import eu
.etaxonomy
.cdm
.strategy
.cache
.agent
.TeamDefaultCacheStrategy
;
34 * This class represents teams of {@link Person persons}. A team exists either for itself
35 * or is built with the list of (distinct) persons who belong to it.
36 * In the first case the inherited attribute {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} is to be used.
37 * In the second case at least all abbreviated names
38 * (the inherited attributes {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle})
39 * or all full names (the strings returned by Person.generateTitle)
40 * of the persons must exist. A team is a {@link java.util.List list} of persons.
42 * This class corresponds to: <ul>
43 * <li> Team according to the TDWG ontology
44 * <li> AgentNames (partially) according to the TCS
45 * <li> MicroAgent (partially) according to the ABCD schema
50 * @created 08-Nov-2007 13:06:58
52 @XmlAccessorType(XmlAccessType
.FIELD
)
53 @XmlType(name
= "Team", propOrder
= {
54 "protectedNomenclaturalTitleCache",
60 public class Team
extends TeamOrPersonBase
<Team
> {
61 private static final long serialVersionUID
= 97640416905934622L;
62 public static final Logger logger
= Logger
.getLogger(Team
.class);
64 @XmlElement(name
= "ProtectedNomenclaturalTitleCache")
65 private boolean protectedNomenclaturalTitleCache
;
67 //An abreviated name for the team (e. g. in case of nomenclatural authorteams). A non abreviated name for the team (e. g.
68 //in case of some bibliographical references)
69 @XmlElementWrapper(name
= "TeamMembers")
70 @XmlElement(name
= "TeamMember")
72 @XmlSchemaType(name
= "IDREF")
73 private List
<Person
> teamMembers
= new ArrayList
<Person
>();
77 * Creates a new team instance without any concrete {@link Person members}.
79 static public Team
NewInstance(){
84 * Class constructor (including the cache strategy defined in
85 * {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}).
89 this.cacheStrategy
= TeamDefaultCacheStrategy
.NewInstance();
93 * Returns the list of {@link Person members} belonging to <i>this</i> team.
94 * A person may be a member of several distinct teams.
97 //@IndexColumn(name="sortIndex", base = 0)
98 //@JoinColumn (name = "representation_id", nullable=false)
99 @Cascade({CascadeType
.SAVE_UPDATE
})
100 public List
<Person
> getTeamMembers(){
101 return this.teamMembers
;
104 * @see #getTeamMembers()
106 protected void setTeamMembers(List
<Person
> teamMembers
){
107 this.teamMembers
= teamMembers
;
111 * Adds a new {@link Person person} to <i>this</i> team at the end of the members' list.
113 * @param person the person who should be added to the other team members
114 * @see #getTeamMembers()
117 public void addTeamMember(Person person
){
118 this.teamMembers
.add(person
);
122 * Adds a new {@link Person person} to <i>this</i> team
123 * at the given index place of the members' list. If the person is already
124 * a member of the list he will be moved to the given index place.
125 * The index must be a positive integer. If the index is bigger than
126 * the present number of members the person will be added at the end of the list.
128 * @param person the person who should be added to the other team members
129 * @param index the position at which the new person should be placed within the members' list
130 * @see #getTeamMembers()
133 public void addTeamMember(Person person
, int index
){
134 // TODO is still not fully implemented (range for index!)
135 logger
.warn("not yet fully implemented (range for index!)");
136 int oldIndex
= teamMembers
.indexOf(person
);
137 if (oldIndex
!= -1 ){
138 teamMembers
.remove(person
);
140 this.teamMembers
.add(index
, person
);
144 * Removes one person from the list of members of <i>this</i> team.
146 * @param person the person who should be deleted from <i>this</i> team
147 * @see #getTeamMembers()
149 public void removeTeamMember(Person person
){
150 this.teamMembers
.remove(person
);
154 * Generates an identification string for <i>this</i> team according to the strategy
155 * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}. This string is built
156 * with the full names of all persons belonging to its (ordered) members' list.
157 * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
158 * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
159 * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
161 * @return a string which identifies <i>this</i> team
164 public String
generateTitle() {
165 return cacheStrategy
.getTitleCache(this);
170 * Generates or returns the {@link TeamOrPersonBase#getnomenclaturalTitle() nomenclatural identification} string for <i>this</i> team.
171 * This method overrides {@link TeamOrPersonBase#getNomenclaturalTitle() getNomenclaturalTitle}.
172 * This string is built with the {@link TeamOrPersonBase#getNomenclaturalTitle() abbreviated names}
173 * of all persons belonging to its (ordered) members' list if the flag
174 * {@link #protectedNomenclaturalTitleCache protectedNomenclaturalTitleCache} is not set.
175 * Otherwise this method returns the present nomenclatural abbreviation.
176 * In case the string is generated the cache strategy used is defined in
177 * {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}.
178 * The result might be kept as nomenclatural abbreviation
179 * by using the {@link #setNomenclaturalTitle(String) setNomenclaturalTitle} method.
181 * @return a string which identifies <i>this</i> team for nomenclature
185 public String
getNomenclaturalTitle() {
186 if (protectedNomenclaturalTitleCache
== PROTECTED
){
187 return this.nomenclaturalTitle
;
189 if (nomenclaturalTitle
== null){
190 this.nomenclaturalTitle
= cacheStrategy
.getNomenclaturalTitle(this);
192 return nomenclaturalTitle
;
196 * Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
197 * and protects it from overwriting.
198 * This method overrides {@link TeamOrPersonBase#setNomenclaturalTitle(String) setNomenclaturalTitle}.
200 * @see #getNomenclaturalTitle()
201 * @see #setNomenclaturalTitle(String, boolean)
204 public void setNomenclaturalTitle(String nomenclaturalTitle
) {
205 setNomenclaturalTitle(nomenclaturalTitle
, PROTECTED
);
206 this.nomenclaturalTitle
= nomenclaturalTitle
;
210 * Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
211 * and a protection flag status to this string.
213 * @see #getNomenclaturalTitle()
215 public void setNomenclaturalTitle(String nomenclaturalTitle
, boolean protectedNomenclaturalTitleCache
) {
216 this.nomenclaturalTitle
= nomenclaturalTitle
;
217 this.protectedNomenclaturalTitleCache
= protectedNomenclaturalTitleCache
;