Major Update to cdmlib-3.3
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / NonViralName.java
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.name;
11
12
13 import java.beans.PropertyChangeEvent;
14 import java.beans.PropertyChangeListener;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.HashSet;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Set;
21
22 import javax.persistence.Entity;
23 import javax.persistence.FetchType;
24 import javax.persistence.ManyToOne;
25 import javax.persistence.OneToMany;
26 import javax.persistence.Transient;
27 import javax.validation.constraints.NotNull;
28 import javax.validation.constraints.Pattern;
29 import javax.validation.constraints.Size;
30 import javax.xml.bind.annotation.XmlAccessType;
31 import javax.xml.bind.annotation.XmlAccessorType;
32 import javax.xml.bind.annotation.XmlElement;
33 import javax.xml.bind.annotation.XmlElementWrapper;
34 import javax.xml.bind.annotation.XmlIDREF;
35 import javax.xml.bind.annotation.XmlRootElement;
36 import javax.xml.bind.annotation.XmlSchemaType;
37 import javax.xml.bind.annotation.XmlType;
38
39 import org.apache.log4j.Logger;
40 import org.hibernate.annotations.Cascade;
41 import org.hibernate.annotations.CascadeType;
42 import org.hibernate.annotations.Target;
43 import org.hibernate.envers.Audited;
44 import org.hibernate.search.annotations.Analyze;
45 import org.hibernate.search.annotations.Analyzer;
46 import org.hibernate.search.annotations.Field;
47 import org.hibernate.search.annotations.Fields;
48 import org.hibernate.search.annotations.Index;
49 import org.hibernate.search.annotations.Indexed;
50 import org.hibernate.search.annotations.IndexedEmbedded;
51 import org.hibernate.search.annotations.Store;
52 import org.hibernate.validator.constraints.NotEmpty;
53 import org.springframework.beans.factory.annotation.Configurable;
54
55 import eu.etaxonomy.cdm.common.CdmUtils;
56 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
57 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
58 import eu.etaxonomy.cdm.model.common.CdmBase;
59 import eu.etaxonomy.cdm.model.common.RelationshipBase;
60 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
61 import eu.etaxonomy.cdm.model.reference.Reference;
62 import eu.etaxonomy.cdm.strategy.cache.name.CacheUpdate;
63 import eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy;
64 import eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy;
65 import eu.etaxonomy.cdm.strategy.match.Match;
66 import eu.etaxonomy.cdm.strategy.match.Match.ReplaceMode;
67 import eu.etaxonomy.cdm.strategy.match.MatchMode;
68 import eu.etaxonomy.cdm.strategy.merge.Merge;
69 import eu.etaxonomy.cdm.strategy.merge.MergeMode;
70 import eu.etaxonomy.cdm.validation.Level2;
71 import eu.etaxonomy.cdm.validation.Level3;
72 import eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank;
73 import eu.etaxonomy.cdm.validation.annotation.MustHaveAuthority;
74 import eu.etaxonomy.cdm.validation.annotation.NoDuplicateNames;
75 import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
76
77 /**
78 * The taxon name class for all non viral taxa. Parenthetical authorship is derived
79 * from basionym relationship. The scientific name including author strings and
80 * maybe year can be stored as a string in the inherited {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
81 * The year itself is an information obtained from the {@link eu.etaxonomy.cdm.model.reference.Reference#getYear() nomenclatural reference}.
82 * The scientific name string without author strings and year can be stored in the {@link #getNameCache() nameCache} attribute.
83 * <P>
84 * This class corresponds partially to: <ul>
85 * <li> TaxonName according to the TDWG ontology
86 * <li> ScientificName and CanonicalName according to the TCS
87 * <li> ScientificName according to the ABCD schema
88 * </ul>
89 *
90 * @author m.doering
91 * @version 1.0
92 * @created 08-Nov-2007 13:06:39
93 */
94 @XmlAccessorType(XmlAccessType.FIELD)
95 @XmlType(name = "NonViralName", propOrder = {
96 "nameCache",
97 "genusOrUninomial",
98 "infraGenericEpithet",
99 "specificEpithet",
100 "infraSpecificEpithet",
101 "combinationAuthorTeam",
102 "exCombinationAuthorTeam",
103 "basionymAuthorTeam",
104 "exBasionymAuthorTeam",
105 "authorshipCache",
106 "protectedAuthorshipCache",
107 "protectedNameCache",
108 "hybridParentRelations",
109 "hybridChildRelations",
110 "hybridFormula",
111 "monomHybrid",
112 "binomHybrid",
113 "trinomHybrid"
114 })
115 @XmlRootElement(name = "NonViralName")
116 @Entity
117 @Indexed(index = "eu.etaxonomy.cdm.model.name.TaxonNameBase")
118 @Audited
119 @Configurable
120 @CorrectEpithetsForRank(groups = Level2.class)
121 @MustHaveAuthority(groups = Level2.class)
122 @NoDuplicateNames(groups = Level3.class)
123 public class NonViralName<T extends NonViralName> extends TaxonNameBase<T, INonViralNameCacheStrategy> implements Cloneable{
124 private static final long serialVersionUID = 4441110073881088033L;
125 private static final Logger logger = Logger.getLogger(NonViralName.class);
126
127 @XmlElement(name = "NameCache")
128 @Fields({
129 @Field(name = "nameCache_tokenized"),
130 @Field(store = Store.YES, index = Index.YES, analyze = Analyze.YES)
131 })
132 @Analyzer (impl = org.apache.lucene.analysis.KeywordAnalyzer.class)
133 @Match(value=MatchMode.CACHE, cacheReplaceMode=ReplaceMode.DEFINED,
134 cacheReplacedProperties={"genusOrUninomial", "infraGenericEpithet", "specificEpithet", "infraSpecificEpithet"} )
135 @NotEmpty(groups = Level2.class) // implicitly NotNull
136 @Size(max = 255)
137 private String nameCache;
138
139 @XmlElement(name = "ProtectedNameCache")
140 @CacheUpdate(value="nameCache")
141 protected boolean protectedNameCache;
142
143 @XmlElement(name = "GenusOrUninomial")
144 @Field(analyze = Analyze.YES,indexNullAs=Field.DEFAULT_NULL_TOKEN)
145 @Match(MatchMode.EQUAL_REQUIRED)
146 @CacheUpdate("nameCache")
147 @Size(max = 255)
148 @Pattern(regexp = "[A-Z][a-z\\u00E4\\u00EB\\u00EF\\u00F6\\u00FC\\-]+", groups=Level2.class, message="{eu.etaxonomy.cdm.model.name.NonViralName.allowedCharactersForUninomial.message}")
149 @NullOrNotEmpty
150 @NotEmpty(groups = Level3.class) //TODO shouldn't this be only @NotNull as @NullOrNotEmpty already checks for not being empty.
151 private String genusOrUninomial;
152
153 @XmlElement(name = "InfraGenericEpithet")
154 @Field(analyze = Analyze.YES,indexNullAs=Field.DEFAULT_NULL_TOKEN)
155 @CacheUpdate("nameCache")
156 //TODO Val #3379
157 // @NullOrNotEmpty
158 @Size(max = 255)
159 @Pattern(regexp = "[a-z\\u00E4\\u00EB\\u00EF\\u00F6\\u00FC\\-]+", groups=Level2.class,message="{eu.etaxonomy.cdm.model.name.NonViralName.allowedCharactersForEpithet.message}")
160 private String infraGenericEpithet;
161
162 @XmlElement(name = "SpecificEpithet")
163 @Field(analyze = Analyze.YES,indexNullAs=Field.DEFAULT_NULL_TOKEN)
164 @CacheUpdate("nameCache")
165 //TODO Val #3379
166 // @NullOrNotEmpty
167 @Size(max = 255)
168 @Pattern(regexp = "[a-z\\u00E4\\u00EB\\u00EF\\u00F6\\u00FC\\-]+", groups=Level2.class, message = "{eu.etaxonomy.cdm.model.name.NonViralName.allowedCharactersForEpithet.message}")
169 private String specificEpithet;
170
171 @XmlElement(name = "InfraSpecificEpithet")
172 @Field(analyze = Analyze.YES,indexNullAs=Field.DEFAULT_NULL_TOKEN)
173 @CacheUpdate("nameCache")
174 //TODO Val #3379
175 // @NullOrNotEmpty
176 @Size(max = 255)
177 @Pattern(regexp = "[a-z\\u00E4\\u00EB\\u00EF\\u00F6\\u00FC\\-]+", groups=Level2.class, message = "{eu.etaxonomy.cdm.model.name.NonViralName.allowedCharactersForEpithet.message}")
178 private String infraSpecificEpithet;
179
180 @XmlElement(name = "CombinationAuthorTeam", type = TeamOrPersonBase.class)
181 @XmlIDREF
182 @XmlSchemaType(name = "IDREF")
183 @ManyToOne(fetch = FetchType.LAZY)
184 @Target(TeamOrPersonBase.class)
185 @Cascade(CascadeType.SAVE_UPDATE)
186 @CacheUpdate("authorshipCache")
187 @IndexedEmbedded
188 private INomenclaturalAuthor combinationAuthorTeam;
189
190 @XmlElement(name = "ExCombinationAuthorTeam", type = TeamOrPersonBase.class)
191 @XmlIDREF
192 @XmlSchemaType(name = "IDREF")
193 @ManyToOne(fetch = FetchType.LAZY)
194 @Target(TeamOrPersonBase.class)
195 @Cascade(CascadeType.SAVE_UPDATE)
196 @CacheUpdate("authorshipCache")
197 @IndexedEmbedded
198 private INomenclaturalAuthor exCombinationAuthorTeam;
199
200 @XmlElement(name = "BasionymAuthorTeam", type = TeamOrPersonBase.class)
201 @XmlIDREF
202 @XmlSchemaType(name = "IDREF")
203 @ManyToOne(fetch = FetchType.LAZY)
204 @Target(TeamOrPersonBase.class)
205 @Cascade(CascadeType.SAVE_UPDATE)
206 @CacheUpdate("authorshipCache")
207 @IndexedEmbedded
208 private INomenclaturalAuthor basionymAuthorTeam;
209
210 @XmlElement(name = "ExBasionymAuthorTeam", type = TeamOrPersonBase.class)
211 @XmlIDREF
212 @XmlSchemaType(name = "IDREF")
213 @ManyToOne(fetch = FetchType.LAZY)
214 @Target(TeamOrPersonBase.class)
215 @Cascade(CascadeType.SAVE_UPDATE)
216 @CacheUpdate("authorshipCache")
217 @IndexedEmbedded
218 private INomenclaturalAuthor exBasionymAuthorTeam;
219
220 @XmlElement(name = "AuthorshipCache")
221 @Fields({
222 @Field(name = "authorshipCache_tokenized"),
223 @Field(analyze = Analyze.NO)
224 })
225 @Match(value=MatchMode.CACHE, cacheReplaceMode=ReplaceMode.DEFINED,
226 cacheReplacedProperties={"combinationAuthorTeam", "basionymAuthorTeam", "exCombinationAuthorTeam", "exBasionymAuthorTeam"} )
227 //TODO Val #3379
228 // @NotNull
229 @Size(max = 255)
230 @Pattern(regexp = "[A-Za-z0-9 \\u00E4\\u00EB\\u00EF\\u00F6\\u00FC\\-\\&\\,\\(\\)\\.]+", groups=Level2.class, message = "{eu.etaxonomy.cdm.model.name.NonViralName.allowedCharactersForAuthority.message}")
231 private String authorshipCache;
232
233 @XmlElement(name = "ProtectedAuthorshipCache")
234 @CacheUpdate("authorshipCache")
235 protected boolean protectedAuthorshipCache;
236
237 @XmlElementWrapper(name = "HybridRelationsFromThisName")
238 @XmlElement(name = "HybridRelationsFromThisName")
239 @OneToMany(mappedBy="relatedFrom", fetch = FetchType.LAZY, orphanRemoval=true)
240 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
241 @Merge(MergeMode.RELATION)
242 @NotNull
243 private Set<HybridRelationship> hybridParentRelations = new HashSet<HybridRelationship>();
244
245 @XmlElementWrapper(name = "HybridRelationsToThisName")
246 @XmlElement(name = "HybridRelationsToThisName")
247 @OneToMany(mappedBy="relatedTo", fetch = FetchType.LAZY, orphanRemoval=true) //a hybrid relation can be deleted automatically if the child is deleted.
248 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
249 @Merge(MergeMode.RELATION)
250 @NotNull
251 private Set<HybridRelationship> hybridChildRelations = new HashSet<HybridRelationship>();
252
253 //if set: this name is a hybrid formula (a hybrid that does not have an own name) and no other hybrid flags may be set. A
254 //hybrid name may not have either an authorteam nor other name components.
255 @XmlElement(name ="IsHybridFormula")
256 @CacheUpdate("nameCache")
257 private boolean hybridFormula = false;
258
259 @XmlElement(name ="IsMonomHybrid")
260 @CacheUpdate("nameCache")
261 private boolean monomHybrid = false;
262
263 @XmlElement(name ="IsBinomHybrid")
264 @CacheUpdate("nameCache")
265 private boolean binomHybrid = false;
266
267 @XmlElement(name ="IsTrinomHybrid")
268 @CacheUpdate("nameCache")
269 private boolean trinomHybrid = false;
270
271 /**
272 * Creates a new non viral taxon name instance
273 * only containing its {@link common.Rank rank} and
274 * the {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy default cache strategy}.
275 *
276 * @param rank the rank to be assigned to <i>this</i> non viral taxon name
277 * @see #NewInstance(Rank, HomotypicalGroup)
278 * @see #NonViralName(Rank, HomotypicalGroup)
279 * @see #NonViralName()
280 * @see #NonViralName(Rank, String, String, String, String, TeamOrPersonBase, Reference, String, HomotypicalGroup)
281 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
282 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
283 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
284 */
285 public static NonViralName NewInstance(Rank rank){
286 return new NonViralName(rank, null);
287 }
288
289 /**
290 * Creates a new non viral taxon name instance
291 * only containing its {@link common.Rank rank},
292 * its {@link HomotypicalGroup homotypical group} and
293 * the {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy default cache strategy}.
294 * The new non viral taxon name instance will be also added to the set of
295 * non viral taxon names belonging to this homotypical group.
296 *
297 * @param rank the rank to be assigned to <i>this</i> non viral taxon name
298 * @param homotypicalGroup the homotypical group to which <i>this</i> non viral taxon name belongs
299 * @see #NewInstance(Rank)
300 * @see #NonViralName(Rank, HomotypicalGroup)
301 * @see #NonViralName()
302 * @see #NonViralName(Rank, String, String, String, String, TeamOrPersonBase, Reference, String, HomotypicalGroup)
303 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
304 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
305 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
306 */
307 public static NonViralName NewInstance(Rank rank, HomotypicalGroup homotypicalGroup){
308 return new NonViralName(rank, homotypicalGroup);
309 }
310
311 // ************************** CONSTRUCTORS *************/
312
313 //needed by hibernate
314 /**
315 * Class constructor: creates a new non viral taxon name instance
316 * only containing the {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy default cache strategy}.
317 *
318 * @see #NonViralName(Rank, HomotypicalGroup)
319 * @see #NonViralName(Rank, String, String, String, String, TeamOrPersonBase, Reference, String, HomotypicalGroup)
320 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
321 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
322 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
323 */
324 protected NonViralName(){
325 super();
326 setNameCacheStrategy();
327 }
328
329 /**
330 * Class constructor: creates a new non viral taxon name instance
331 * only containing its {@link Rank rank},
332 * its {@link HomotypicalGroup homotypical group} and
333 * the {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy default cache strategy}.
334 * The new non viral taxon name instance will be also added to the set of
335 * non viral taxon names belonging to this homotypical group.
336 *
337 * @param rank the rank to be assigned to <i>this</i> non viral taxon name
338 * @param homotypicalGroup the homotypical group to which <i>this</i> non viral taxon name belongs
339 * @see #NonViralName()
340 * @see #NonViralName(Rank, String, String, String, String, TeamOrPersonBase, Reference, String, HomotypicalGroup)
341 * @see #NewInstance(Rank, HomotypicalGroup)
342 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
343 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
344 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
345 */
346 protected NonViralName(Rank rank, HomotypicalGroup homotypicalGroup) {
347 super(rank, homotypicalGroup);
348 setNameCacheStrategy();
349 }
350 /**
351 * Class constructor: creates a new non viral taxon name instance
352 * containing its {@link Rank rank},
353 * its {@link HomotypicalGroup homotypical group},
354 * its scientific name components, its {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase author(team)},
355 * its {@link eu.etaxonomy.cdm.model.reference.Reference nomenclatural reference} and
356 * the {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy default cache strategy}.
357 * The new non viral taxon name instance will be also added to the set of
358 * non viral taxon names belonging to this homotypical group.
359 *
360 * @param rank the rank to be assigned to <i>this</i> non viral taxon name
361 * @param genusOrUninomial the string for <i>this</i> non viral taxon name
362 * if its rank is genus or higher or for the genus part
363 * if its rank is lower than genus
364 * @param infraGenericEpithet the string for the first epithet of
365 * <i>this</i> non viral taxon name if its rank is lower than genus
366 * and higher than species aggregate
367 * @param specificEpithet the string for the first epithet of
368 * <i>this</i> non viral taxon name if its rank is species aggregate or lower
369 * @param infraSpecificEpithet the string for the second epithet of
370 * <i>this</i> non viral taxon name if its rank is lower than species
371 * @param combinationAuthorTeam the author or the team who published <i>this</i> non viral taxon name
372 * @param nomenclaturalReference the nomenclatural reference where <i>this</i> non viral taxon name was published
373 * @param nomenclMicroRef the string with the details for precise location within the nomenclatural reference
374 * @param homotypicalGroup the homotypical group to which <i>this</i> non viral taxon name belongs
375 * @see #NonViralName()
376 * @see #NonViralName(Rank, HomotypicalGroup)
377 * @see #NewInstance(Rank, HomotypicalGroup)
378 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
379 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
380 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
381 */
382 protected NonViralName(Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
383 super(rank, homotypicalGroup);
384 setNameCacheStrategy();
385 setGenusOrUninomial(genusOrUninomial);
386 setInfraGenericEpithet (infraGenericEpithet);
387 setSpecificEpithet(specificEpithet);
388 setInfraSpecificEpithet(infraSpecificEpithet);
389 setCombinationAuthorTeam(combinationAuthorTeam);
390 setNomenclaturalReference(nomenclaturalReference);
391 this.setNomenclaturalMicroReference(nomenclMicroRef);
392 }
393
394
395
396 //**************************** METHODS **************************************/
397
398
399 private void setNameCacheStrategy(){
400 if (getClass() == NonViralName.class){
401 this.cacheStrategy = NonViralNameDefaultCacheStrategy.NewInstance();
402 }
403 }
404
405 @Override
406 protected void initListener(){
407 PropertyChangeListener listener = new PropertyChangeListener() {
408 @Override
409 public void propertyChange(PropertyChangeEvent e) {
410 boolean protectedByLowerCache = false;
411 //authorship cache
412 if (fieldHasCacheUpdateProperty(e.getPropertyName(), "authorshipCache")){
413 if (protectedAuthorshipCache){
414 protectedByLowerCache = true;
415 }else{
416 authorshipCache = null;
417 }
418 }
419
420 //nameCache
421 if (fieldHasCacheUpdateProperty(e.getPropertyName(), "nameCache")){
422 if (protectedNameCache){
423 protectedByLowerCache = true;
424 }else{
425 nameCache = null;
426 }
427 }
428 //title cache
429 if (! fieldHasNoUpdateProperty(e.getPropertyName(), "titleCache")){
430 if (isProtectedTitleCache()|| protectedByLowerCache == true ){
431 protectedByLowerCache = true;
432 }else{
433 titleCache = null;
434 }
435 }
436 //full title cache
437 if (! fieldHasNoUpdateProperty(e.getPropertyName(), "fullTitleCache")){
438 if (isProtectedFullTitleCache()|| protectedByLowerCache == true ){
439 protectedByLowerCache = true;
440 }else{
441 fullTitleCache = null;
442 }
443 }
444 }
445 };
446 addPropertyChangeListener(listener); //didn't use this.addXXX to make lsid.AssemblerTest run in cdmlib-remote
447 }
448
449 private static Map<String, java.lang.reflect.Field> allFields = null;
450 @Override
451 protected Map<String, java.lang.reflect.Field> getAllFields(){
452 if (allFields == null){
453 allFields = CdmUtils.getAllFields(this.getClass(), CdmBase.class, false, false, false, true);
454 }
455 return allFields;
456 }
457
458 /**
459 * @param propertyName
460 * @param string
461 * @return
462 */
463 private boolean fieldHasCacheUpdateProperty(String propertyName, String cacheName) {
464 java.lang.reflect.Field field;
465 try {
466 field = getAllFields().get(propertyName);
467 if (field != null){
468 CacheUpdate updateAnnotation = field.getAnnotation(CacheUpdate.class);
469 if (updateAnnotation != null){
470 for (String value : updateAnnotation.value()){
471 if (cacheName.equals(value)){
472 return true;
473 }
474 }
475 }
476 }
477 return false;
478 } catch (SecurityException e1) {
479 throw e1;
480 }
481 }
482
483 private boolean fieldHasNoUpdateProperty(String propertyName, String cacheName) {
484 java.lang.reflect.Field field;
485 //do not update fields with the same name
486 if (cacheName.equals(propertyName)){
487 return true;
488 }
489 //evaluate annotation
490 try {
491 field = getAllFields().get(propertyName);
492 if (field != null){
493 CacheUpdate updateAnnotation = field.getAnnotation(CacheUpdate.class);
494 if (updateAnnotation != null){
495 for (String value : updateAnnotation.noUpdate()){
496 if (cacheName.equals(value)){
497 return true;
498 }
499 }
500 }
501 }
502 return false;
503 } catch (SecurityException e1) {
504 throw e1;
505 }
506 }
507
508
509 /**
510 * Returns the {@link eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor author (team)} that published <i>this</i> non viral
511 * taxon name.
512 *
513 * @return the nomenclatural author (team) of <i>this</i> non viral taxon name
514 * @see eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor
515 * @see eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getNomenclaturalTitle()
516 */
517 public INomenclaturalAuthor getCombinationAuthorTeam(){
518 return this.combinationAuthorTeam;
519 }
520
521 /**
522 * @see #getCombinationAuthorTeam()
523 */
524 public void setCombinationAuthorTeam(INomenclaturalAuthor combinationAuthorTeam){
525 this.combinationAuthorTeam = combinationAuthorTeam;
526 }
527
528 /**
529 * Returns the {@link eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor author (team)} that contributed to
530 * the publication of <i>this</i> non viral taxon name as generally stated by
531 * the {@link #getCombinationAuthorTeam() combination author (team)} itself.<BR>
532 * An ex-author(-team) is an author(-team) to whom a taxon name was ascribed
533 * although it is not the author(-team) of a valid publication (for instance
534 * without the validating description or diagnosis in case of a name for a
535 * new taxon). The name of this ascribed authorship, followed by "ex", may
536 * be inserted before the name(s) of the publishing author(s) of the validly
537 * published name:<BR>
538 * <i>Lilium tianschanicum</i> was described by Grubov (1977) as a new species and
539 * its name was ascribed to Ivanova; since there is no indication that
540 * Ivanova provided the validating description, the name may be cited as
541 * <i>Lilium tianschanicum</i> N. A. Ivanova ex Grubov or <i>Lilium tianschanicum</i> Grubov.
542 * <P>
543 * The presence of an author (team) of <i>this</i> non viral taxon name is a
544 * condition for the existence of an ex author (team) for <i>this</i> same name.
545 *
546 * @return the nomenclatural ex author (team) of <i>this</i> non viral taxon name
547 * @see #getCombinationAuthorTeam()
548 * @see eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor
549 * @see eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getNomenclaturalTitle()
550 */
551 public INomenclaturalAuthor getExCombinationAuthorTeam(){
552 return this.exCombinationAuthorTeam;
553 }
554
555 /**
556 * @see #getExCombinationAuthorTeam()
557 */
558 public void setExCombinationAuthorTeam(INomenclaturalAuthor exCombinationAuthorTeam){
559 this.exCombinationAuthorTeam = exCombinationAuthorTeam;
560 }
561
562 /**
563 * Returns the {@link eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor author (team)} that published the original combination
564 * on which <i>this</i> non viral taxon name is nomenclaturally based. Such an
565 * author (team) can only exist if <i>this</i> non viral taxon name is a new
566 * combination due to a taxonomical revision.
567 *
568 * @return the nomenclatural basionym author (team) of <i>this</i> non viral taxon name
569 * @see #getCombinationAuthorTeam()
570 * @see eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor
571 * @see eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getNomenclaturalTitle()
572 */
573 public INomenclaturalAuthor getBasionymAuthorTeam(){
574 return basionymAuthorTeam;
575 }
576
577 /**
578 * @see #getBasionymAuthorTeam()
579 */
580 public void setBasionymAuthorTeam(INomenclaturalAuthor basionymAuthorTeam) {
581 this.basionymAuthorTeam = basionymAuthorTeam;
582 }
583
584 /**
585 * Returns the {@link eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor author (team)} that contributed to
586 * the publication of the original combination <i>this</i> non viral taxon name is
587 * based on. This should have been generally stated by
588 * the {@link #getBasionymAuthorTeam() basionym author (team)} itself.
589 * The presence of a basionym author (team) of <i>this</i> non viral taxon name is a
590 * condition for the existence of an ex basionym author (team)
591 * for <i>this</i> same name.
592 *
593 * @return the nomenclatural ex basionym author (team) of <i>this</i> non viral taxon name
594 * @see #getBasionymAuthorTeam()
595 * @see #getExCombinationAuthorTeam()
596 * @see #getCombinationAuthorTeam()
597 * @see eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor
598 * @see eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getNomenclaturalTitle()
599 */
600 public INomenclaturalAuthor getExBasionymAuthorTeam(){
601 return exBasionymAuthorTeam;
602 }
603
604 /**
605 * @see #getExBasionymAuthorTeam()
606 */
607 public void setExBasionymAuthorTeam(INomenclaturalAuthor exBasionymAuthorTeam) {
608 this.exBasionymAuthorTeam = exBasionymAuthorTeam;
609 }
610 /**
611 * Returns either the scientific name string (without authorship) for <i>this</i>
612 * non viral taxon name if its rank is genus or higher (monomial) or the string for
613 * the genus part of it if its {@link Rank rank} is lower than genus (bi- or trinomial).
614 * Genus or uninomial strings begin with an upper case letter.
615 *
616 * @return the string containing the suprageneric name, the genus name or the genus part of <i>this</i> non viral taxon name
617 * @see #getNameCache()
618 */
619 public String getGenusOrUninomial() {
620 return genusOrUninomial;
621 }
622
623 /**
624 * @see #getGenusOrUninomial()
625 */
626 public void setGenusOrUninomial(String genusOrUninomial) {
627 this.genusOrUninomial = genusOrUninomial;
628 }
629
630 /**
631 * Returns the genus subdivision epithet string (infrageneric part) for
632 * <i>this</i> non viral taxon name if its {@link Rank rank} is infrageneric (lower than genus and
633 * higher than species aggregate: binomial). Genus subdivision epithet
634 * strings begin with an upper case letter.
635 *
636 * @return the string containing the infrageneric part of <i>this</i> non viral taxon name
637 * @see #getNameCache()
638 */
639 public String getInfraGenericEpithet(){
640 return this.infraGenericEpithet;
641 }
642
643 /**
644 * @see #getInfraGenericEpithet()
645 */
646 public void setInfraGenericEpithet(String infraGenericEpithet){
647 this.infraGenericEpithet = infraGenericEpithet;
648 }
649
650 /**
651 * Returns the species epithet string for <i>this</i> non viral taxon name if its {@link Rank rank} is
652 * species aggregate or lower (bi- or trinomial). Species epithet strings
653 * begin with a lower case letter.
654 *
655 * @return the string containing the species epithet of <i>this</i> non viral taxon name
656 * @see #getNameCache()
657 */
658 public String getSpecificEpithet(){
659 return this.specificEpithet;
660 }
661
662 /**
663 * @see #getSpecificEpithet()
664 */
665 public void setSpecificEpithet(String specificEpithet){
666 this.specificEpithet = specificEpithet;
667 }
668
669 /**
670 * Returns the species subdivision epithet string (infraspecific part) for
671 * <i>this</i> non viral taxon name if its {@link Rank rank} is infraspecific
672 * (lower than species: trinomial). Species subdivision epithet strings
673 * begin with a lower case letter.
674 *
675 * @return the string containing the infraspecific part of <i>this</i> non viral taxon name
676 * @see #getNameCache()
677 */
678 public String getInfraSpecificEpithet(){
679 return this.infraSpecificEpithet;
680 }
681
682 /**
683 * @see #getInfraSpecificEpithet()
684 */
685 public void setInfraSpecificEpithet(String infraSpecificEpithet){
686 this.infraSpecificEpithet = infraSpecificEpithet;
687 }
688
689 /**
690 * Generates and returns the string with the scientific name of <i>this</i>
691 * non viral taxon name including author strings and maybe year according to
692 * the strategy defined in
693 * {@link eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy INonViralNameCacheStrategy}.
694 * This string may be stored in the inherited
695 * {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
696 * This method overrides the generic and inherited
697 * TaxonNameBase#generateTitle() method.
698 *
699 * @return the string with the composed name of <i>this</i> non viral taxon name with authorship (and maybe year)
700 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
701 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
702 * @see TaxonNameBase#generateTitle()
703 */
704 // @Override
705 // public String generateTitle(){
706 // if (cacheStrategy == null){
707 // logger.warn("No CacheStrategy defined for nonViralName: " + this.getUuid());
708 // return null;
709 // }else{
710 // return cacheStrategy.getTitleCache(this);
711 // }
712 // }
713
714 @Override
715 public String generateFullTitle(){
716 if (cacheStrategy == null){
717 logger.warn("No CacheStrategy defined for nonViralName: " + this.getUuid());
718 return null;
719 }else{
720 return cacheStrategy.getFullTitleCache(this);
721 }
722 }
723
724 /**
725 * Generates the composed name string of <i>this</i> non viral taxon name without author
726 * strings or year according to the strategy defined in
727 * {@link eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy INonViralNameCacheStrategy}.
728 * The result might be stored in {@link #getNameCache() nameCache} if the
729 * flag {@link #isProtectedNameCache() protectedNameCache} is not set.
730 *
731 * @return the string with the composed name of <i>this</i> non viral taxon name without authors or year
732 * @see #getNameCache()
733 */
734 protected String generateNameCache(){
735 if (cacheStrategy == null){
736 logger.warn("No CacheStrategy defined for taxonName: " + this.toString());
737 return null;
738 }else{
739 return cacheStrategy.getNameCache(this);
740 }
741 }
742
743 /**
744 * Returns or generates the nameCache (scientific name
745 * without author strings and year) string for <i>this</i> non viral taxon name. If the
746 * {@link #isProtectedNameCache() protectedNameCache} flag is not set (False)
747 * the string will be generated according to a defined strategy,
748 * otherwise the value of the actual nameCache string will be returned.
749 *
750 * @return the string which identifies <i>this</i> non viral taxon name (without authors or year)
751 * @see #generateNameCache()
752 */
753 @Transient
754 public String getNameCache() {
755 if (protectedNameCache){
756 return this.nameCache;
757 }
758 // is title dirty, i.e. equal NULL?
759 if (nameCache == null){
760 this.nameCache = generateNameCache();
761 }
762 return nameCache;
763 }
764
765 /**
766 * Assigns a nameCache string to <i>this</i> non viral taxon name and protects it from being overwritten.
767 * Sets the protectedNameCache flag to <code>true</code>.
768 *
769 * @param nameCache the string which identifies <i>this</i> non viral taxon name (without authors or year)
770 * @see #getNameCache()
771 */
772 public void setNameCache(String nameCache){
773 setNameCache(nameCache, true);
774 }
775
776 /**
777 * Assigns a nameCache string to <i>this</i> non viral taxon name and protects it from being overwritten.
778 * Sets the protectedNameCache flag to <code>true</code>.
779 *
780 * @param nameCache the string which identifies <i>this</i> non viral taxon name (without authors or year)
781 * @param protectedNameCache if true teh protectedNameCache is set to <code>true</code> or otherwise set to
782 * <code>false</code>
783 * @see #getNameCache()
784 */
785 public void setNameCache(String nameCache, boolean protectedNameCache){
786 this.nameCache = nameCache;
787 this.setProtectedNameCache(protectedNameCache);
788 }
789
790 /**
791 * Returns the boolean value of the flag intended to protect (true)
792 * or not (false) the {@link #getNameCache() nameCache} (scientific name without author strings and year)
793 * string of <i>this</i> non viral taxon name.
794 *
795 * @return the boolean value of the protectedNameCache flag
796 * @see #getNameCache()
797 */
798 public boolean isProtectedNameCache() {
799 return protectedNameCache;
800 }
801
802 /**
803 * @see #isProtectedNameCache()
804 */
805 public void setProtectedNameCache(boolean protectedNameCache) {
806 this.protectedNameCache = protectedNameCache;
807 }
808
809
810 /**
811 * Generates and returns a concatenated and formated authorteams string
812 * including basionym and combination authors of <i>this</i> non viral taxon name
813 * according to the strategy defined in
814 * {@link eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy#getAuthorshipCache(NonViralName) INonViralNameCacheStrategy}.
815 *
816 * @return the string with the concatenated and formated authorteams for <i>this</i> non viral taxon name
817 * @see eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy#getAuthorshipCache(NonViralName)
818 */
819 public String generateAuthorship(){
820 if (cacheStrategy == null){
821 logger.warn("No CacheStrategy defined for nonViralName: " + this.getUuid());
822 return null;
823 }else{
824 return ((INonViralNameCacheStrategy<T>)cacheStrategy).getAuthorshipCache((T)this);
825 }
826 }
827
828 /**
829 * Returns the concatenated and formated authorteams string including
830 * basionym and combination authors of <i>this</i> non viral taxon name.
831 * If the protectedAuthorshipCache flag is set this method returns the
832 * string stored in the the authorshipCache attribute, otherwise it
833 * generates the complete authorship string, returns it and stores it in
834 * the authorshipCache attribute.
835 *
836 * @return the string with the concatenated and formated authorteams for <i>this</i> non viral taxon name
837 * @see #generateAuthorship()
838 */
839 @Transient
840 public String getAuthorshipCache() {
841 if (protectedAuthorshipCache){
842 return this.authorshipCache;
843 }
844 if (this.authorshipCache == null ){
845 this.authorshipCache = generateAuthorship();
846 }else{
847 //TODO get is Dirty of authors, make better if possible
848 this.setAuthorshipCache(generateAuthorship(), protectedAuthorshipCache); //throw change event to inform higher caches
849
850 }
851 return authorshipCache;
852 }
853
854
855 /**
856 * Updates the authorship cache if any changes appeared in the authors nomenclatural caches.
857 * Deletes the titleCache and the fullTitleCache if not protected and if any change has happened
858 * @return
859 */
860 private void updateAuthorshipCache() {
861 //updates the authorship cache if necessary and via the listener updates all higher caches
862 if (protectedAuthorshipCache == false){
863 String oldCache = this.authorshipCache;
864 String newCache = this.getAuthorshipCache();
865 if ( (oldCache == null && newCache != null) || CdmUtils.nullSafeEqual(oldCache,newCache)){
866 this.setAuthorshipCache(this.getAuthorshipCache(), false);
867 }
868 }
869 }
870
871 /**
872 * Assigns an authorshipCache string to <i>this</i> non viral taxon name. Sets the isProtectedAuthorshipCache
873 * flag to <code>true</code>.
874 *
875 * @param authorshipCache the string which identifies the complete authorship of <i>this</i> non viral taxon name
876 * @see #getAuthorshipCache()
877 */
878 public void setAuthorshipCache(String authorshipCache) {
879 setAuthorshipCache(authorshipCache, true);
880 }
881
882 @Override
883 @Transient
884 public String getFullTitleCache(){
885 updateAuthorshipCache();
886 return super.getFullTitleCache();
887 }
888
889 @Override
890 public String getTitleCache(){
891 if(!protectedTitleCache) {
892 updateAuthorshipCache();
893 }
894
895 return super.getTitleCache();
896 }
897
898
899 /**
900 * Assigns an authorshipCache string to <i>this</i> non viral taxon name.
901 *
902 * @param authorshipCache the string which identifies the complete authorship of <i>this</i> non viral taxon name
903 * @param protectedAuthorshipCache if true the isProtectedAuthorshipCache flag is set to <code>true</code>, otherwise
904 * the flag is set to <code>false</code>.
905 * @see #getAuthorshipCache()
906 */
907 public void setAuthorshipCache(String authorshipCache, boolean protectedAuthorshipCache) {
908 this.authorshipCache = authorshipCache;
909 this.setProtectedAuthorshipCache(protectedAuthorshipCache);
910 }
911
912 @Override
913 public void setTitleCache(String titleCache, boolean protectCache){
914 super.setTitleCache(titleCache, protectCache);
915 }
916
917 /**
918 * Returns the boolean value "false" since the components of <i>this</i> taxon name
919 * cannot follow the rules of a corresponding {@link NomenclaturalCode nomenclatural code}
920 * which is not defined for this class. The nomenclature code depends on
921 * the concrete name subclass ({@link BacterialName BacterialName},
922 * {@link BotanicalName BotanicalName}, {@link CultivarPlantName CultivarPlantName} or
923 * {@link ZoologicalName ZoologicalName} to which <i>this</i> non viral taxon name belongs.
924 * This method overrides the isCodeCompliant method from the abstract
925 * {@link TaxonNameBase#isCodeCompliant() TaxonNameBase} class.
926 *
927 * @return false
928 * @see TaxonNameBase#isCodeCompliant()
929 */
930 @Override
931 @Transient
932 public boolean isCodeCompliant() {
933 //FIXME
934 logger.warn("is CodeCompliant not yet implemented");
935 return false;
936 }
937
938 /* (non-Javadoc)
939 * @see eu.etaxonomy.cdm.model.name.TaxonNameBase#getNomeclaturalCode()
940 */
941 /**
942 * Returns null as {@link NomenclaturalCode nomenclatural code} that governs
943 * the construction of <i>this</i> non viral taxon name since there is no specific
944 * nomenclatural code defined. The real implementention takes place in the
945 * subclasses {@link BacterialName BacterialName},
946 * {@link BotanicalName BotanicalName}, {@link CultivarPlantName CultivarPlantName} and
947 * {@link ZoologicalName ZoologicalName}.
948 * This method overrides the getNomeclaturalCode method from {@link TaxonNameBase TaxonNameBase}.
949 *
950 * @return null
951 * @see #isCodeCompliant()
952 * @see TaxonNameBase#getHasProblem()
953 */
954 @Override
955 @Transient
956 public NomenclaturalCode getNomenclaturalCode() {
957 logger.warn("Non Viral Name has no specific Code defined. Use subclasses");
958 return null;
959 }
960
961 /**
962 * Returns the boolean value of the flag intended to protect (true)
963 * or not (false) the {@link #getAuthorshipCache() authorshipCache} (complete authorship string)
964 * of <i>this</i> non viral taxon name.
965 *
966 * @return the boolean value of the protectedAuthorshipCache flag
967 * @see #getAuthorshipCache()
968 */
969 public boolean isProtectedAuthorshipCache() {
970 return protectedAuthorshipCache;
971 }
972
973 /**
974 * @see #isProtectedAuthorshipCache()
975 * @see #getAuthorshipCache()
976 */
977 public void setProtectedAuthorshipCache(boolean protectedAuthorshipCache) {
978 this.protectedAuthorshipCache = protectedAuthorshipCache;
979 }
980
981
982 /**
983 * Returns the boolean value of the flag indicating whether the name of <i>this</i>
984 * botanical taxon name is a hybrid formula (true) or not (false). A hybrid
985 * named by a hybrid formula (composed with its parent names by placing the
986 * multiplication sign between them) does not have an own published name
987 * and therefore has neither an {@link NonViralName#getAuthorshipCache() autorship}
988 * nor other name components. If this flag is set no other hybrid flags may
989 * be set.
990 *
991 * @return the boolean value of the isHybridFormula flag
992 * @see #isMonomHybrid()
993 * @see #isBinomHybrid()
994 * @see #isTrinomHybrid()
995 */
996 public boolean isHybridFormula(){
997 return this.hybridFormula;
998 }
999
1000 /**
1001 * @see #isHybridFormula()
1002 */
1003 public void setHybridFormula(boolean hybridFormula){
1004 this.hybridFormula = hybridFormula;
1005 }
1006
1007 /**
1008 * Returns the boolean value of the flag indicating whether <i>this</i> botanical
1009 * taxon name is the name of an intergeneric hybrid (true) or not (false).
1010 * In this case the multiplication sign is placed before the scientific
1011 * name. If this flag is set no other hybrid flags may be set.
1012 *
1013 * @return the boolean value of the isMonomHybrid flag
1014 * @see #isHybridFormula()
1015 * @see #isBinomHybrid()
1016 * @see #isTrinomHybrid()
1017 */
1018 public boolean isMonomHybrid(){
1019 return this.monomHybrid;
1020 }
1021
1022 /**
1023 * @see #isMonomHybrid()
1024 * @see #isBinomHybrid()
1025 * @see #isTrinomHybrid()
1026 */
1027 public void setMonomHybrid(boolean monomHybrid){
1028 this.monomHybrid = monomHybrid;
1029 }
1030
1031 /**
1032 * Returns the boolean value of the flag indicating whether <i>this</i> botanical
1033 * taxon name is the name of an interspecific hybrid (true) or not (false).
1034 * In this case the multiplication sign is placed before the species
1035 * epithet. If this flag is set no other hybrid flags may be set.
1036 *
1037 * @return the boolean value of the isBinomHybrid flag
1038 * @see #isHybridFormula()
1039 * @see #isMonomHybrid()
1040 * @see #isTrinomHybrid()
1041 */
1042 public boolean isBinomHybrid(){
1043 return this.binomHybrid;
1044 }
1045
1046 /**
1047 * @see #isBinomHybrid()
1048 * @see #isMonomHybrid()
1049 * @see #isTrinomHybrid()
1050 */
1051 public void setBinomHybrid(boolean binomHybrid){
1052 this.binomHybrid = binomHybrid;
1053 }
1054
1055 /**
1056 * Returns the boolean value of the flag indicating whether <i>this</i> botanical
1057 * taxon name is the name of an infraspecific hybrid (true) or not (false).
1058 * In this case the term "notho-" (optionally abbreviated "n-") is used as
1059 * a prefix to the term denoting the infraspecific rank of <i>this</i> botanical
1060 * taxon name. If this flag is set no other hybrid flags may be set.
1061 *
1062 * @return the boolean value of the isTrinomHybrid flag
1063 * @see #isHybridFormula()
1064 * @see #isMonomHybrid()
1065 * @see #isBinomHybrid()
1066 */
1067 public boolean isTrinomHybrid(){
1068 return this.trinomHybrid;
1069 }
1070
1071 /**
1072 * @see #isTrinomHybrid()
1073 * @see #isBinomHybrid()
1074 * @see #isMonomHybrid()
1075 */
1076 public void setTrinomHybrid(boolean trinomHybrid){
1077 this.trinomHybrid = trinomHybrid;
1078 }
1079
1080
1081 /**
1082 * Returns the set of all {@link HybridRelationship hybrid relationships}
1083 * in which <i>this</i> taxon name is involved as a {@link common.RelationshipBase#getRelatedFrom() parent}.
1084 *
1085 * @see #getHybridRelationships()
1086 * @see #getChildRelationships()
1087 * @see HybridRelationshipType
1088 */
1089 public Set<HybridRelationship> getHybridParentRelations() {
1090 if(hybridParentRelations == null) {
1091 this.hybridParentRelations = new HashSet<HybridRelationship>();
1092 }
1093 return hybridParentRelations;
1094 }
1095
1096 private void setHybridParentRelations(Set<HybridRelationship> hybridParentRelations) {
1097 this.hybridParentRelations = hybridParentRelations;
1098 }
1099
1100
1101 /**
1102 * Returns the set of all {@link HybridRelationship hybrid relationships}
1103 * in which <i>this</i> taxon name is involved as a {@link common.RelationshipBase#getRelatedTo() child}.
1104 *
1105 * @see #getHybridRelationships()
1106 * @see #getParentRelationships()
1107 * @see HybridRelationshipType
1108 */
1109 public Set<HybridRelationship> getHybridChildRelations() {
1110 if(hybridChildRelations == null) {
1111 this.hybridChildRelations = new HashSet<HybridRelationship>();
1112 }
1113 return hybridChildRelations;
1114 }
1115
1116 private void setHybridChildRelations(Set<HybridRelationship> hybridChildRelations) {
1117 this.hybridChildRelations = hybridChildRelations;
1118 }
1119
1120 /**
1121 * Returns the set of all {@link HybridRelationship hybrid relationships}
1122 * in which <i>this</i> taxon name is involved as a {@link common.RelationshipBase#getRelatedFrom() parent}.
1123 * @see #getHybridParentRelations()
1124 * @see #getHybridRelationships()
1125 * @see #getChildRelationships()
1126 * @see HybridRelationshipType
1127 * @deprecated use {@link #getHybridParentRelations()} instead. Will be removed in higher versions.
1128 */
1129 @Deprecated
1130 @Transient
1131 public Set<HybridRelationship> getParentRelationships() {
1132 return getHybridParentRelations();
1133 }
1134
1135 /**
1136 * Returns the hybrid child relationships ordered by relationship type, or if equal
1137 * by title cache of the related names.
1138 * @see #getHybridParentRelations()
1139 */
1140 @Transient
1141 public List<HybridRelationship> getOrderedChildRelationships(){
1142 List<HybridRelationship> result = new ArrayList<HybridRelationship>();
1143 result.addAll(this.hybridChildRelations);
1144 Collections.sort(result);
1145 Collections.reverse(result);
1146 return result;
1147
1148 }
1149
1150
1151 /**
1152 * @see #getHybridChildRelations()
1153 * @deprecated use {@link #getHybridChildRelations()} instead. Will be removed in higher versions.
1154 */
1155 @Transient
1156 @Deprecated
1157 public Set<HybridRelationship> getChildRelationships() {
1158 return this.getHybridChildRelations();
1159 }
1160
1161 /**
1162 * Adds the given {@link HybridRelationship hybrid relationship} to the set
1163 * of {@link #getHybridRelationships() hybrid relationships} of both non-viral names
1164 * involved in this hybrid relationship. One of both non-viral names
1165 * must be <i>this</i> non-viral name otherwise no addition will be carried
1166 * out. The {@link eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo() child
1167 * non viral taxon name} must be a hybrid, which means that one of its four hybrid flags must be set.
1168 *
1169 * @param relationship the hybrid relationship to be added
1170 * @see #isHybridFormula()
1171 * @see #isMonomHybrid()
1172 * @see #isBinomHybrid()
1173 * @see #isTrinomHybrid()
1174 * @see #getHybridRelationships()
1175 * @see #getParentRelationships()
1176 * @see #getChildRelationships()
1177 * @see #addRelationship(RelationshipBase)
1178 * @throws IllegalArgumentException
1179 */
1180 protected void addHybridRelationship(HybridRelationship rel) {
1181 if (rel!=null && rel.getHybridName().equals(this)){
1182 this.hybridChildRelations.add(rel);
1183 }else if(rel!=null && rel.getParentName().equals(this)){
1184 this.hybridParentRelations.add(rel);
1185 }else{
1186 throw new IllegalArgumentException("Hybrid relationship is either null or the relationship does not reference this name");
1187 }
1188 }
1189
1190
1191
1192 /**
1193 * Does the same as the addHybridRelationship method if the given
1194 * {@link common.RelationshipBase relation} is also a {@link HybridRelationship hybrid relationship}.
1195 * Otherwise this method does the same as the overwritten {@link TaxonNameBase#addRelationship(RelationshipBase) addRelationship}
1196 * method from TaxonNameBase.
1197 *
1198 * @param relation the relationship to be added to some of <i>this</i> taxon name's relationships sets
1199 * @see #addHybridRelationship(HybridRelationship)
1200 * @see TaxonNameBase#addRelationship(RelationshipBase)
1201 * @see TaxonNameBase#addNameRelationship(NameRelationship)
1202 * @deprecated to be used by RelationshipBase only
1203 */
1204 @Override
1205 @Deprecated //to be used by RelationshipBase only
1206 public void addRelationship(RelationshipBase relation) {
1207 if (relation instanceof HybridRelationship){
1208 addHybridRelationship((HybridRelationship)relation);
1209 }else {
1210 super.addRelationship(relation);
1211 }
1212 }
1213
1214 /**
1215 * Creates a new {@link HybridRelationship#HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String) hybrid relationship}
1216 * to <i>this</i> botanical name. A HybridRelationship may be of type
1217 * "is first/second parent" or "is male/female parent". By invoking this
1218 * method <i>this</i> botanical name becomes a hybrid child of the parent
1219 * botanical name.
1220 *
1221 * @param parentName the botanical name of the parent for this new hybrid name relationship
1222 * @param type the type of this new name relationship
1223 * @param ruleConsidered the string which specifies the rule on which this name relationship is based
1224 * @return
1225 * @see #addHybridChild(BotanicalName, HybridRelationshipType,String )
1226 * @see #getRelationsToThisName()
1227 * @see #getNameRelations()
1228 * @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
1229 * @see #addNameRelationship(NameRelationship)
1230 */
1231 public HybridRelationship addHybridParent(NonViralName parentName, HybridRelationshipType type, String ruleConsidered){
1232 return new HybridRelationship(this, parentName, type, ruleConsidered);
1233 }
1234
1235 /**
1236 * Creates a new {@link HybridRelationship#HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String) hybrid relationship}
1237 * to <i>this</i> botanical name. A HybridRelationship may be of type
1238 * "is first/second parent" or "is male/female parent". By invoking this
1239 * method <i>this</i> botanical name becomes a parent of the hybrid child
1240 * botanical name.
1241 *
1242 * @param childName the botanical name of the child for this new hybrid name relationship
1243 * @param type the type of this new name relationship
1244 * @param ruleConsidered the string which specifies the rule on which this name relationship is based
1245 * @return
1246 * @see #addHybridParent(BotanicalName, HybridRelationshipType,String )
1247 * @see #getRelationsToThisName()
1248 * @see #getNameRelations()
1249 * @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
1250 * @see #addNameRelationship(NameRelationship)
1251 */
1252 public HybridRelationship addHybridChild(NonViralName childName, HybridRelationshipType type, String ruleConsidered){
1253 return new HybridRelationship(childName, this, type, ruleConsidered);
1254 }
1255
1256
1257 /**
1258 * Removes one {@link HybridRelationship hybrid relationship} from the set of
1259 * {@link #getHybridRelationships() hybrid relationships} in which <i>this</i> botanical taxon name
1260 * is involved. The hybrid relationship will also be removed from the set
1261 * belonging to the second botanical taxon name involved.
1262 *
1263 * @param relationship the hybrid relationship which should be deleted from the corresponding sets
1264 * @see #getHybridRelationships()
1265 */
1266 public void removeHybridRelationship(HybridRelationship hybridRelation) {
1267 if (hybridRelation == null) {
1268 return;
1269 }
1270
1271 NonViralName parent = hybridRelation.getParentName();
1272 NonViralName child = hybridRelation.getHybridName();
1273
1274 hybridRelation.setHybridName(null);
1275 hybridRelation.setParentName(null);
1276
1277 if (parent != null) {
1278 parent.removeHybridRelationship(hybridRelation);
1279 }
1280
1281 if (child != null) {
1282 child.removeHybridRelationship(hybridRelation);
1283 }
1284
1285 this.hybridChildRelations.remove(hybridRelation);
1286 this.hybridParentRelations.remove(hybridRelation);
1287 }
1288
1289
1290 public void removeHybridChild(NonViralName child) {
1291 Set<HybridRelationship> hybridRelationships = new HashSet<HybridRelationship>();
1292 hybridRelationships.addAll(this.getChildRelationships());
1293 hybridRelationships.addAll(this.getParentRelationships());
1294 for(HybridRelationship hybridRelationship : hybridRelationships) {
1295 // remove name relationship from this side
1296 if (hybridRelationship.getParentName().equals(this) && hybridRelationship.getHybridName().equals(child)) {
1297 this.removeHybridRelationship(hybridRelationship);
1298 }
1299 }
1300 }
1301
1302 public void removeHybridParent(NonViralName parent) {
1303 Set<HybridRelationship> hybridRelationships = new HashSet<HybridRelationship>();
1304 hybridRelationships.addAll(this.getChildRelationships());
1305 hybridRelationships.addAll(this.getParentRelationships());
1306 for(HybridRelationship hybridRelationship : hybridRelationships) {
1307 // remove name relationship from this side
1308 if (hybridRelationship.getParentName().equals(parent) && hybridRelationship.getHybridName().equals(this)) {
1309 this.removeHybridRelationship(hybridRelationship);
1310 }
1311 }
1312 }
1313
1314 /**
1315 * Needs to be implemented by those classes that handle autonyms (e.g. botanical names).
1316 **/
1317 @Transient
1318 public boolean isAutonym(){
1319 return false;
1320 }
1321
1322
1323 // /**
1324 // * Returns the boolean value indicating whether <i>this</i> names rank is Rank "unranked"
1325 // * (uuid = 'a965befb-70a9-4747-a18f-624456c65223') but most likely it is an infrageneric rank
1326 // * due to existing atomized data for the genus epithet and the infrageneric epithet but missing
1327 // * specific epithet.
1328 // * Returns false if <i>this</i> names rank is null.
1329 // *
1330 // * @see #isSupraGeneric()
1331 // * @see #isGenus()
1332 // * @see #isSpeciesAggregate()
1333 // * @see #isSpecies()
1334 // * @see #isInfraSpecific()
1335 // */
1336 // @Transient
1337 // public boolean isInfragenericUnranked() {
1338 // Rank rank = this.getRank();
1339 // if (rank == null || ! rank.equals(Rank.UNRANKED())){
1340 // return false;
1341 // }
1342 // if (StringUtils.isBlank(this.getSpecificEpithet()) && StringUtils.isBlank(this.getInfraSpecificEpithet()) ){
1343 // return true;
1344 // }else{
1345 // return false;
1346 // }
1347 // }
1348
1349
1350 /**
1351 * Tests if the given name has any authors.
1352 * @return false if no author ((ex)combination or (ex)basionym) exists, true otherwise
1353 */
1354 public boolean hasAuthors() {
1355 return (this.getCombinationAuthorTeam() != null ||
1356 this.getExCombinationAuthorTeam() != null ||
1357 this.getBasionymAuthorTeam() != null ||
1358 this.getExBasionymAuthorTeam() != null);
1359 }
1360
1361 /**
1362 * Shortcut. Returns the combination authors title cache. Returns null if no combination author exists.
1363 * @return
1364 */
1365 public String computeCombinationAuthorNomenclaturalTitle() {
1366 return computeNomenclaturalTitle(this.getCombinationAuthorTeam());
1367 }
1368
1369 /**
1370 * Shortcut. Returns the basionym authors title cache. Returns null if no basionym author exists.
1371 * @return
1372 */
1373 public String computeBasionymAuthorNomenclaturalTitle() {
1374 return computeNomenclaturalTitle(this.getBasionymAuthorTeam());
1375 }
1376
1377
1378 /**
1379 * Shortcut. Returns the ex-combination authors title cache. Returns null if no ex-combination author exists.
1380 * @return
1381 */
1382 public String computeExCombinationAuthorNomenclaturalTitle() {
1383 return computeNomenclaturalTitle(this.getExCombinationAuthorTeam());
1384 }
1385
1386 /**
1387 * Shortcut. Returns the ex-basionym authors title cache. Returns null if no exbasionym author exists.
1388 * @return
1389 */
1390 public String computeExBasionymAuthorNomenclaturalTitle() {
1391 return computeNomenclaturalTitle(this.getExBasionymAuthorTeam());
1392 }
1393
1394 private String computeNomenclaturalTitle(INomenclaturalAuthor author){
1395 if (author == null){
1396 return null;
1397 }else{
1398 return author.getNomenclaturalTitle();
1399 }
1400 }
1401
1402 //*********************** CLONE ********************************************************/
1403
1404 /**
1405 * Clones <i>this</i> non-viral name. This is a shortcut that enables to create
1406 * a new instance that differs only slightly from <i>this</i> non-viral name by
1407 * modifying only some of the attributes.
1408 *
1409 * @see eu.etaxonomy.cdm.model.name.TaxonNameBase#clone()
1410 * @see java.lang.Object#clone()
1411 */
1412 @Override
1413 public Object clone() {
1414 NonViralName result = (NonViralName)super.clone();
1415
1416 //HybridChildRelations
1417 result.hybridChildRelations = new HashSet<HybridRelationship>();
1418 for (HybridRelationship hybridRelationship : getHybridChildRelations()){
1419 HybridRelationship newChildRelationship = (HybridRelationship)hybridRelationship.clone();
1420 newChildRelationship.setRelatedTo(result);
1421 result.hybridChildRelations.add(newChildRelationship);
1422 }
1423
1424 //HybridParentRelations
1425 result.hybridParentRelations = new HashSet<HybridRelationship>();
1426 for (HybridRelationship hybridRelationship : getHybridParentRelations()){
1427 HybridRelationship newParentRelationship = (HybridRelationship)hybridRelationship.clone();
1428 newParentRelationship.setRelatedFrom(result);
1429 result.hybridParentRelations.add(newParentRelationship);
1430 }
1431
1432 //empty caches
1433 if (! protectedNameCache){
1434 result.nameCache = null;
1435 }
1436
1437 //empty caches
1438 if (! protectedAuthorshipCache){
1439 result.authorshipCache = null;
1440 }
1441
1442 //no changes to: basionamyAuthorTeam, combinationAuthorTeam, exBasionymAuthorTeam, exCombinationAuthorTeam
1443 //genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet,
1444 //protectedAuthorshipCache, protectedNameCache
1445 //binomHybrid, monomHybrid, trinomHybrid, hybridFormula,
1446 return result;
1447 }
1448 }