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.
9 package eu
.etaxonomy
.cdm
.model
.agent
;
11 import javax
.persistence
.Entity
;
12 import javax
.persistence
.Transient
;
13 import javax
.validation
.constraints
.Size
;
14 import javax
.xml
.bind
.annotation
.XmlAccessType
;
15 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
16 import javax
.xml
.bind
.annotation
.XmlElement
;
17 import javax
.xml
.bind
.annotation
.XmlTransient
;
18 import javax
.xml
.bind
.annotation
.XmlType
;
20 import org
.apache
.commons
.lang
.StringUtils
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.hibernate
.envers
.Audited
;
23 import org
.hibernate
.search
.annotations
.Field
;
24 import org
.hibernate
.search
.annotations
.Index
;
25 import org
.hibernate
.search
.annotations
.Indexed
;
27 import eu
.etaxonomy
.cdm
.strategy
.cache
.agent
.INomenclaturalAuthorCacheStrategy
;
28 import eu
.etaxonomy
.cdm
.validation
.annotation
.NullOrNotEmpty
;
32 * The abstract class for such {@link AgentBase agents} ({@link Person persons} or {@link Team teams}) who might also be used
33 * for authorship of {@link eu.etaxonomy.cdm.model.reference.Reference references} or of {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon names}.
37 * @created 17-APR-2008
39 @XmlAccessorType(XmlAccessType
.FIELD
)
40 @XmlType(name
= "TeamOrPersonBase", propOrder
= {
45 // even if hibernate complains "Abstract classes can never insert index documents. Remove @Indexed."
46 // this is needed, otherwise the fields of the also abstract super class are missed during indexing
47 @Indexed(index
= "eu.etaxonomy.cdm.model.agent.AgentBase")
48 public abstract class TeamOrPersonBase
<T
extends TeamOrPersonBase
<?
>> extends AgentBase
<INomenclaturalAuthorCacheStrategy
<T
>> implements INomenclaturalAuthor
{
49 private static final long serialVersionUID
= 5216821307314001961L;
50 public static final Logger logger
= Logger
.getLogger(TeamOrPersonBase
.class);
52 @XmlElement(name
="NomenclaturalTitle")
53 @Field(index
=Index
.YES
)
57 protected String nomenclaturalTitle
;
61 protected boolean isGeneratingTitleCache
= false; //state variable to avoid recursions when generating title cache and nomenclatural title
64 * Returns the identification string (nomenclatural abbreviation) used in
65 * nomenclature for this {@link Person person} or this {@link Team team}.
67 * @see INomenclaturalAuthor#getNomenclaturalTitle()
71 public String
getNomenclaturalTitle() {
72 String result
= nomenclaturalTitle
;
73 if (StringUtils
.isBlank(nomenclaturalTitle
) && (isGeneratingTitleCache
== false)){
74 result
= getTitleCache();
80 * @see #getNomenclaturalTitle()
83 public void setNomenclaturalTitle(String nomenclaturalTitle
) {
84 this.nomenclaturalTitle
= nomenclaturalTitle
;
88 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
92 TODO is the transient annotation still needed, can't we remove this ??
93 @Transient is an absolutely special case and thus leads to several
94 special implementations in order to harmonize this exception again
95 in other parts of the library:
96 - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
97 - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
99 [a.kohlbecker May 2011]
101 public String
getTitleCache() {
102 isGeneratingTitleCache
= true;
103 String result
= super.getTitleCache();
104 result
= replaceEmptyTitleByNomTitle(result
);
105 isGeneratingTitleCache
= false;
113 protected String
replaceEmptyTitleByNomTitle(String result
) {
114 if (StringUtils
.isBlank(result
)){
115 result
= nomenclaturalTitle
;
117 if (StringUtils
.isBlank(result
)){
118 result
= super.getTitleCache();