Project

General

Profile

Download (5.53 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
    "nomenclaturalTitleCache",
38
    "collectorTitleCache"
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
    //under construction #4311
50
    @XmlElement(name="CollectorTitleCache")
51
    @Field(index=Index.YES)
52
    @Column(length=800)//see #1592
53
    protected String collectorTitleCache;
54

    
55
    //under construction #9664
56
    @XmlElement(name="NomenclaturalTitleCache")
57
    @Field(index=Index.YES)
58
    @Column(length=800)//see #1592
59
    protected String nomenclaturalTitleCache;
60

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

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

    
71

    
72
    //#9664
73
    @Override
74
    public String getNomenclaturalTitleCache() {
75
        // is title dirty, i.e. equal NULL?
76
        if (nomenclaturalTitleCache == null){
77
            this.nomenclaturalTitleCache = generateNomenclaturalTitleCache();
78
            this.nomenclaturalTitleCache = getTruncatedCache(this.nomenclaturalTitleCache) ;
79
        }
80
        return nomenclaturalTitleCache;
81
    }
82

    
83
    //#4311
84
    public String getCollectorTitleCache() {
85
        // is title dirty, i.e. equal NULL?
86
        if (collectorTitleCache == null){
87
            this.collectorTitleCache = generateCollectorTitleCache();
88
            this.collectorTitleCache = getTruncatedCache(this.collectorTitleCache) ;
89
        }
90
        return collectorTitleCache;
91
    }
92
    public void setCollectorTitleCache(String collectorTitleCache) {
93
        //TODO
94
        this.collectorTitleCache = collectorTitleCache;
95
    }
96

    
97
    @SuppressWarnings("unchecked")
98
    private String generateNomenclaturalTitleCache() {
99
        if (getCacheStrategy() == null){
100
            return this.getClass() + ": " + this.getUuid();
101
        }else{
102
            return getCacheStrategy().getNomenclaturalTitleCache((T)this);
103
        }
104
    }
105

    
106
    @SuppressWarnings("unchecked")
107
    private String generateCollectorTitleCache() {
108
        if (getCacheStrategy() == null){
109
            return this.getClass() + ": " + this.getUuid();
110
        }else{
111
            return getCacheStrategy().getCollectorTitleCache((T)this);
112
        }
113
    }
114

    
115

    
116
    @Override
117
    @Transient
118
    /*
119
        TODO  is the transient annotation still needed, can't we remove this ??
120
        @Transient is an absolutely special case and thus leads to several
121
        special implementations in order to harmonize this exception again
122
        in other parts of the library:
123
         - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
124
         - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
125

    
126
        [a.kohlbecker May 2011]
127
    */
128
    public String getTitleCache() {
129
        isGeneratingTitleCache = true;
130
        String result = super.getTitleCache();
131
        result = replaceEmptyTitleByNomTitle(result);
132
        isGeneratingTitleCache = false;
133
        return result;
134
    }
135

    
136
    @Transient
137
    public String getFullTitle() {
138
        @SuppressWarnings("unchecked")
139
        T agent = (T)this;
140
        if (agent.isProtectedTitleCache()){
141
            return agent.getTitleCache();
142
        }else{
143
            return this.getCacheStrategy().getFullTitle(agent);
144
        }
145
    }
146

    
147
    protected String replaceEmptyTitleByNomTitle(String result) {
148
        if (isBlank(result)){
149
            result = nomenclaturalTitleCache;
150
        }
151
        if (isBlank(result)){
152
            result = super.getTitleCache();
153
        }
154
        return result;
155
    }
156

    
157
    @Override
158
    public TeamOrPersonBase<T> clone() throws CloneNotSupportedException {
159
        TeamOrPersonBase<T> result = (TeamOrPersonBase<T>)super.clone();
160

    
161
        //nothing to do: collectorTitle, nomenclaturalTitle;
162
        return result;
163
    }
164
}
(10-10/12)