Project

General

Profile

Download (4.77 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.cdm.model.agent;
10

    
11
import javax.persistence.Column;
12
import javax.persistence.Entity;
13
import javax.persistence.Transient;
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;
19

    
20
import org.apache.log4j.Logger;
21
import org.hibernate.envers.Audited;
22
import org.hibernate.search.annotations.Field;
23
import org.hibernate.search.annotations.Index;
24

    
25
import eu.etaxonomy.cdm.strategy.cache.agent.INomenclaturalAuthorCacheStrategy;
26

    
27

    
28
/**
29
 * The abstract class for such {@link AgentBase agents} ({@link Person persons} or {@link Team teams}) who might also be used
30
 * for authorship of {@link eu.etaxonomy.cdm.model.reference.Reference references} or of {@link eu.etaxonomy.cdm.model.name.TaxonName taxon names}.
31
 *
32
 * @author a.mueller
33
 * @since 17-APR-2008
34
 */
35
@XmlAccessorType(XmlAccessType.FIELD)
36
@XmlType(name = "TeamOrPersonBase", propOrder = {
37
    "nomenclaturalTitle",
38
    "collectorTitle"
39
})
40
@Entity
41
@Audited
42
public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<T>>
43
            extends AgentBase<INomenclaturalAuthorCacheStrategy<T>>
44
            implements INomenclaturalAuthor {
45

    
46
    private static final long serialVersionUID = 5216821307314001961L;
47
    public static final Logger logger = Logger.getLogger(TeamOrPersonBase.class);
48

    
49
    @XmlElement(name="NomenclaturalTitle")
50
    @Field(index=Index.YES)
51
  //TODO Val #3379
52
//    @NullOrNotEmpty
53
    @Column(length=255)
54
    protected String nomenclaturalTitle;
55

    
56
    //under construction #4311
57
    @XmlElement(name="CollectorTitle")
58
    @Field(index=Index.YES)
59
    @Column(length=255)
60
    protected String collectorTitle;
61

    
62
//  from E+M import (still needed?)
63
//    @Column(length=255)
64
//    protected String originalNomenclaturalTitle;
65
//    public String getOriginalNomenclaturalTitle() {return originalNomenclaturalTitle;}
66
//    public void setOriginalNomenclaturalTitle(String originalNomenclaturalTitle) {this.originalNomenclaturalTitle = originalNomenclaturalTitle;}
67

    
68
    @Transient
69
    @XmlTransient
70
    protected boolean isGeneratingTitleCache = false;  //state variable to avoid recursions when generating title cache and nomenclatural title
71

    
72
    /**
73
     * Returns the identification string (nomenclatural abbreviation) used in
74
     * nomenclature for this {@link Person person} or this {@link Team team}.
75
     *
76
     * @see  INomenclaturalAuthor#getNomenclaturalTitle()
77
     */
78
    @Override
79
    @Transient
80
    public String getNomenclaturalTitle() {
81
        String result = nomenclaturalTitle;
82
        if (isBlank(nomenclaturalTitle) && (isGeneratingTitleCache == false)){
83
            result = getTitleCache();
84
        }
85
        return result;
86
    }
87

    
88
    /**
89
     * @see     #getNomenclaturalTitle()
90
     */
91
    @Override
92
    public void setNomenclaturalTitle(String nomenclaturalTitle) {
93
        this.nomenclaturalTitle = isBlank(nomenclaturalTitle) ? null : nomenclaturalTitle;
94
    }
95

    
96

    
97
    @Override
98
    @Transient
99
    /*
100
        TODO  is the transient annotation still needed, can't we remove this ??
101
        @Transient is an absolutely special case and thus leads to several
102
        special implementations in order to harmonize this exception again
103
        in other parts of the library:
104
         - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
105
         - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
106

    
107
        [a.kohlbecker May 2011]
108
    */
109
    public String getTitleCache() {
110
        isGeneratingTitleCache = true;
111
        String result = super.getTitleCache();
112
        result = replaceEmptyTitleByNomTitle(result);
113
        isGeneratingTitleCache = false;
114
        return result;
115
    }
116

    
117
    @Transient
118
    public String getFullTitle() {
119
        @SuppressWarnings("unchecked")
120
        T agent = (T)this;
121
        if (agent.isProtectedTitleCache()){
122
            return agent.getTitleCache();
123
        }else{
124
            return this.getCacheStrategy().getFullTitle(agent);
125
        }
126
    }
127

    
128
    protected String replaceEmptyTitleByNomTitle(String result) {
129
        if (isBlank(result)){
130
            result = nomenclaturalTitle;
131
        }
132
        if (isBlank(result)){
133
            result = super.getTitleCache();
134
        }
135
        return result;
136
    }
137

    
138
    @Override
139
    public TeamOrPersonBase<T> clone() throws CloneNotSupportedException {
140
        TeamOrPersonBase<T> result = (TeamOrPersonBase<T>)super.clone();
141

    
142
        //nothing to do: collectorTitle, nomenclaturalTitle;
143
        return result;
144
    }
145
}
(10-10/12)