clone methods
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / TeamOrPersonBase.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 package eu.etaxonomy.cdm.model.agent;
10
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;
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 import org.hibernate.search.annotations.Indexed;
25
26 import eu.etaxonomy.cdm.common.CdmUtils;
27 import eu.etaxonomy.cdm.strategy.cache.agent.INomenclaturalAuthorCacheStrategy;
28 import 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
46 public 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 //TODO a.kohlbecker remove??
87 public String getTitleCache() {
88 isGeneratingTitleCache = true;
89 String result = super.getTitleCache();
90 result = replaceEmptyTitleByNomTitle(result);
91 isGeneratingTitleCache = false;
92 return result;
93 }
94
95 /**
96 * @param result
97 * @return
98 */
99 protected String replaceEmptyTitleByNomTitle(String result) {
100 if (CdmUtils.isEmpty(result)){
101 result = nomenclaturalTitle;
102 }
103 if (CdmUtils.isEmpty(result)){
104 result = super.getTitleCache();
105 }
106 return result;
107 }
108
109
110 }