1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.strategy.cache.taxon;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang.StringUtils;
|
17
|
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
21
|
import eu.etaxonomy.cdm.model.name.ITaxonNameBase;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
23
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
26
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
27
|
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
|
28
|
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
|
29
|
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
|
30
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
31
|
import eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy;
|
32
|
import eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy;
|
33
|
|
34
|
public class TaxonBaseDefaultCacheStrategy<T extends TaxonBase>
|
35
|
extends StrategyBase
|
36
|
implements ITaxonCacheStrategy<T> {
|
37
|
|
38
|
private static final long serialVersionUID = 5769890979070021350L;
|
39
|
final static UUID uuid = UUID.fromString("931e48f0-2033-11de-8c30-0800200c9a66");
|
40
|
|
41
|
@Override
|
42
|
protected UUID getUuid() {
|
43
|
return uuid;
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public String getTitleCache(T taxonBase) {
|
48
|
return getTitleCache(taxonBase, null);
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public List<TaggedText> getTaggedTitle(T taxonBase) {
|
53
|
if (taxonBase == null){
|
54
|
return null;
|
55
|
}
|
56
|
|
57
|
List<TaggedText> tags = new ArrayList<>();
|
58
|
|
59
|
if (taxonBase.isDoubtful()){
|
60
|
tags.add(new TaggedText(TagEnum.separator, "?"));
|
61
|
}
|
62
|
if (taxonBase.isProtectedTitleCache()){
|
63
|
//protected title cache
|
64
|
tags.add(new TaggedText(TagEnum.name, taxonBase.getTitleCache()));
|
65
|
}else{
|
66
|
//name
|
67
|
List<TaggedText> nameTags = getNameTags(taxonBase);
|
68
|
|
69
|
if (nameTags.size() > 0){
|
70
|
tags.addAll(nameTags);
|
71
|
}else{
|
72
|
tags.add(new TaggedText(TagEnum.fullName, "???"));
|
73
|
}
|
74
|
|
75
|
boolean isSynonym = taxonBase.isInstanceOf(Synonym.class);
|
76
|
String secSeparator = (isSynonym? " syn." : "") + " sec. ";
|
77
|
//not used: we currently use a post-separator in the name tags
|
78
|
// if (nameTags.get(nameTags.size() - 1).getType().equals(TagEnum.nomStatus)){
|
79
|
// secSeparator = "," + secSeparator;
|
80
|
// }
|
81
|
|
82
|
//ref.
|
83
|
List<TaggedText> secTags = getSecundumTags(taxonBase);
|
84
|
|
85
|
//sec.
|
86
|
if (!secTags.isEmpty()){
|
87
|
tags.add(new TaggedText(TagEnum.separator, secSeparator));
|
88
|
tags.addAll(secTags);
|
89
|
}
|
90
|
|
91
|
}
|
92
|
return tags;
|
93
|
}
|
94
|
|
95
|
private <X extends ITaxonNameBase> List<TaggedText> getNameTags(T taxonBase) {
|
96
|
List<TaggedText> tags = new ArrayList<>();
|
97
|
TaxonName<?, INameCacheStrategy> name = CdmBase.deproxy(taxonBase.getName());
|
98
|
|
99
|
if (name != null){
|
100
|
INameCacheStrategy<ITaxonNameBase> nameCacheStrategy = name.getCacheStrategy();
|
101
|
if (taxonBase.isUseNameCache() && name.isNonViral() && nameCacheStrategy instanceof INonViralNameCacheStrategy<?>){
|
102
|
INonViralNameCacheStrategy<INonViralName> nvnCacheStrategy = (INonViralNameCacheStrategy)nameCacheStrategy;
|
103
|
List<TaggedText> nameCacheTags = nvnCacheStrategy.getTaggedName(name);
|
104
|
tags.addAll(nameCacheTags);
|
105
|
}else{
|
106
|
List<TaggedText> nameTags = nameCacheStrategy.getTaggedTitle(name);
|
107
|
tags.addAll(nameTags);
|
108
|
List<TaggedText> statusTags = nameCacheStrategy.getNomStatusTags(name, true, true);
|
109
|
tags.addAll(statusTags);
|
110
|
}
|
111
|
if (StringUtils.isNotBlank(taxonBase.getAppendedPhrase())){
|
112
|
tags.add(new TaggedText(TagEnum.appendedPhrase, taxonBase.getAppendedPhrase().trim()));
|
113
|
}
|
114
|
}
|
115
|
|
116
|
return tags;
|
117
|
}
|
118
|
|
119
|
private List<TaggedText> getSecundumTags(T taxonBase) {
|
120
|
List<TaggedText> tags = new ArrayList<>();
|
121
|
|
122
|
Reference ref = taxonBase.getSec();
|
123
|
ref = HibernateProxyHelper.deproxy(ref, Reference.class);
|
124
|
String secRef;
|
125
|
if (ref == null){
|
126
|
//missing sec
|
127
|
if (isBlank(taxonBase.getAppendedPhrase())){
|
128
|
secRef = "???";
|
129
|
}else{
|
130
|
secRef = null;
|
131
|
}
|
132
|
}
|
133
|
else{
|
134
|
//existing sec
|
135
|
if (ref.isProtectedTitleCache() == false &&
|
136
|
ref.getCacheStrategy() != null &&
|
137
|
ref.getAuthorship() != null &&
|
138
|
isNotBlank(ref.getAuthorship().getTitleCache()) &&
|
139
|
isNotBlank(ref.getYear())){
|
140
|
secRef = ref.getCacheStrategy().getCitation(ref);
|
141
|
}else{
|
142
|
secRef = ref.getTitleCache();
|
143
|
}
|
144
|
}
|
145
|
if (secRef != null){
|
146
|
tags.add(new TaggedText(TagEnum.secReference, secRef));
|
147
|
}
|
148
|
//secMicroReference
|
149
|
if (StringUtils.isNotBlank(taxonBase.getSecMicroReference())){
|
150
|
tags.add(new TaggedText(TagEnum.separator, ": "));
|
151
|
tags.add(new TaggedText(TagEnum.secReference, taxonBase.getSecMicroReference()));
|
152
|
|
153
|
}
|
154
|
return tags;
|
155
|
}
|
156
|
|
157
|
|
158
|
@Override
|
159
|
public String getTitleCache(T taxonBase, HTMLTagRules htmlTagRules) {
|
160
|
List<TaggedText> tags = getTaggedTitle(taxonBase);
|
161
|
if (tags == null){
|
162
|
return null;
|
163
|
}else{
|
164
|
String result = TaggedCacheHelper.createString(tags, htmlTagRules);
|
165
|
return result;
|
166
|
}
|
167
|
}
|
168
|
}
|