root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/TeamOrPersonBase.java

Revision 13571, 4.1 kB (checked in by a.kohlbecker, 5 months ago)

harmonising whitespace tab->space

  • Property svn:keywords set to Id
Line 
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*/
9package eu.etaxonomy.cdm.model.agent;
10
11import javax.persistence.Entity;
12import javax.persistence.Transient;
13import javax.validation.constraints.Size;
14import javax.xml.bind.annotation.XmlAccessType;
15import javax.xml.bind.annotation.XmlAccessorType;
16import javax.xml.bind.annotation.XmlElement;
17import javax.xml.bind.annotation.XmlTransient;
18import javax.xml.bind.annotation.XmlType;
19
20import org.apache.log4j.Logger;
21import org.hibernate.envers.Audited;
22import org.hibernate.search.annotations.Field;
23import org.hibernate.search.annotations.Index;
24import org.hibernate.search.annotations.Indexed;
25
26import eu.etaxonomy.cdm.common.CdmUtils;
27import eu.etaxonomy.cdm.strategy.cache.agent.INomenclaturalAuthorCacheStrategy;
28import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
29
30
31/**
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}.
34 *
35 * @author a.mueller
36 * @version 1.0
37 * @created 17-APR-2008
38 */
39@XmlAccessorType(XmlAccessType.FIELD)
40@XmlType(name = "TeamOrPersonBase", propOrder = {
41    "nomenclaturalTitle"
42})
43@Entity
44@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
45@Audited
46public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends AgentBase<INomenclaturalAuthorCacheStrategy<T>> implements INomenclaturalAuthor {
47    private static final long serialVersionUID = 5216821307314001961L;
48    public static final Logger logger = Logger.getLogger(TeamOrPersonBase.class);
49
50    @XmlElement(name="NomenclaturalTitle")
51    @Field(index=Index.TOKENIZED)
52    @NullOrNotEmpty
53    @Size(max = 255)
54    protected String nomenclaturalTitle;
55
56    @Transient
57    @XmlTransient
58    protected boolean isGeneratingTitleCache = false;
59
60    /**
61     * Returns the identification string (nomenclatural abbreviation) used in
62     * nomenclature for this {@link Person person} or this {@link Team team}.
63     *
64     * @see  INomenclaturalAuthor#getNomenclaturalTitle()
65     */
66    @Transient
67    public String getNomenclaturalTitle() {
68        String result = nomenclaturalTitle;
69        if (CdmUtils.isEmpty(nomenclaturalTitle) && (isGeneratingTitleCache == false)){
70            result = getTitleCache();
71        }
72        return result;
73    }
74
75    /**
76     * @see     #getNomenclaturalTitle()
77     */
78    public void setNomenclaturalTitle(String nomenclaturalTitle) {
79        this.nomenclaturalTitle = nomenclaturalTitle;
80    }
81
82    /* (non-Javadoc)
83     * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
84     */
85    @Override
86    @Transient /*
87                TODO  is this still needed, can't we remove this ??
88                @Transient is an absolutely special case and thus leads to several
89                special implementations in order to harmonize this exception again
90                in other parts of the library:
91                 - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
92                 - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
93
94                [a.kohlbecker May 2011]
95         */
96    public String getTitleCache() {
97        isGeneratingTitleCache = true;
98        String result = super.getTitleCache();
99        result = replaceEmptyTitleByNomTitle(result);
100        isGeneratingTitleCache = false;
101        return result;
102    }
103
104    /**
105     * @param result
106     * @return
107     */
108    protected String replaceEmptyTitleByNomTitle(String result) {
109        if (CdmUtils.isEmpty(result)){
110            result = nomenclaturalTitle;
111        }
112        if (CdmUtils.isEmpty(result)){
113            result = super.getTitleCache();
114        }
115        return result;
116    }
117
118
119}
Note: See TracBrowser for help on using the browser.