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
.FetchType
;
17 import javax
.persistence
.ManyToMany
;
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
.envers
.Audited
;
30 import eu
.etaxonomy
.cdm
.strategy
.cache
.agent
.TeamDefaultCacheStrategy
;
33 * This class represents teams of {@link Person persons}. A team exists either for itself
34 * or is built with the list of (distinct) persons who belong to it.
35 * In the first case the inherited attribute {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} is to be used.
36 * In the second case at least all abbreviated names
37 * (the inherited attributes {@link TeamOrPersonBase#getNomenclaturalTitle() nomenclaturalTitle})
38 * or all full names (the strings returned by Person.generateTitle)
39 * of the persons must exist. A team is a {@link java.util.List list} of persons.
41 * This class corresponds to: <ul>
42 * <li> Team according to the TDWG ontology
43 * <li> AgentNames (partially) according to the TCS
44 * <li> MicroAgent (partially) according to the ABCD schema
49 * @created 08-Nov-2007 13:06:58
51 @XmlAccessorType(XmlAccessType
.FIELD
)
52 @XmlType(name
= "Team", propOrder
= {
53 "protectedNomenclaturalTitleCache",
59 public class Team
extends TeamOrPersonBase
<Team
> {
60 private static final long serialVersionUID
= 97640416905934622L;
61 public static final Logger logger
= Logger
.getLogger(Team
.class);
63 @XmlElement(name
= "ProtectedNomenclaturalTitleCache")
64 private boolean protectedNomenclaturalTitleCache
;
66 //An abreviated name for the team (e. g. in case of nomenclatural authorteams). A non abreviated name for the team (e. g.
67 //in case of some bibliographical references)
68 @XmlElementWrapper(name
= "TeamMembers")
69 @XmlElement(name
= "TeamMember")
71 @XmlSchemaType(name
= "IDREF")
72 @ManyToMany(fetch
= FetchType
.LAZY
)
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.
96 public List
<Person
> getTeamMembers(){
97 return this.teamMembers
;
101 * Adds a new {@link Person person} to <i>this</i> team at the end of the members' list.
103 * @param person the person who should be added to the other team members
104 * @see #getTeamMembers()
107 public void addTeamMember(Person person
){
108 this.teamMembers
.add(person
);
112 * Adds a new {@link Person person} to <i>this</i> team
113 * at the given index place of the members' list. If the person is already
114 * a member of the list he will be moved to the given index place.
115 * The index must be a positive integer. If the index is bigger than
116 * the present number of members the person will be added at the end of the list.
118 * @param person the person who should be added to the other team members
119 * @param index the position at which the new person should be placed within the members' list
120 * @see #getTeamMembers()
123 public void addTeamMember(Person person
, int index
){
124 // TODO is still not fully implemented (range for index!)
125 logger
.warn("not yet fully implemented (range for index!)");
126 int oldIndex
= teamMembers
.indexOf(person
);
127 if (oldIndex
!= -1 ){
128 teamMembers
.remove(person
);
130 this.teamMembers
.add(index
, person
);
134 * Removes one person from the list of members of <i>this</i> team.
136 * @param person the person who should be deleted from <i>this</i> team
137 * @see #getTeamMembers()
139 public void removeTeamMember(Person person
){
140 this.teamMembers
.remove(person
);
144 * Generates an identification string for <i>this</i> team according to the strategy
145 * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}. This string is built
146 * with the full names of all persons belonging to its (ordered) members' list.
147 * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
148 * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
149 * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
151 * @return a string which identifies <i>this</i> team
154 public String
generateTitle() {
155 return cacheStrategy
.getTitleCache(this);
160 * Generates or returns the {@link TeamOrPersonBase#getnomenclaturalTitle() nomenclatural identification} string for <i>this</i> team.
161 * This method overrides {@link TeamOrPersonBase#getNomenclaturalTitle() getNomenclaturalTitle}.
162 * This string is built with the {@link TeamOrPersonBase#getNomenclaturalTitle() abbreviated names}
163 * of all persons belonging to its (ordered) members' list if the flag
164 * {@link #protectedNomenclaturalTitleCache protectedNomenclaturalTitleCache} is not set.
165 * Otherwise this method returns the present nomenclatural abbreviation.
166 * In case the string is generated the cache strategy used is defined in
167 * {@link eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy TeamDefaultCacheStrategy}.
168 * The result might be kept as nomenclatural abbreviation
169 * by using the {@link #setNomenclaturalTitle(String) setNomenclaturalTitle} method.
171 * @return a string which identifies <i>this</i> team for nomenclature
174 public String
getNomenclaturalTitle() {
175 if (protectedNomenclaturalTitleCache
== PROTECTED
){
176 return this.nomenclaturalTitle
;
178 if (nomenclaturalTitle
== null){
179 this.nomenclaturalTitle
= cacheStrategy
.getNomenclaturalTitle(this);
181 return nomenclaturalTitle
;
185 * Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
186 * and protects it from overwriting.
187 * This method overrides {@link TeamOrPersonBase#setNomenclaturalTitle(String) setNomenclaturalTitle}.
189 * @see #getNomenclaturalTitle()
190 * @see #setNomenclaturalTitle(String, boolean)
193 public void setNomenclaturalTitle(String nomenclaturalTitle
) {
194 setNomenclaturalTitle(nomenclaturalTitle
, PROTECTED
);
195 this.nomenclaturalTitle
= nomenclaturalTitle
;
199 * Assigns a {@link TeamOrPersonBase#nomenclaturalTitle nomenclatural identification} string to <i>this</i> team
200 * and a protection flag status to this string.
202 * @see #getNomenclaturalTitle()
204 public void setNomenclaturalTitle(String nomenclaturalTitle
, boolean protectedNomenclaturalTitleCache
) {
205 this.nomenclaturalTitle
= nomenclaturalTitle
;
206 this.protectedNomenclaturalTitleCache
= protectedNomenclaturalTitleCache
;