4 package eu
.etaxonomy
.cdm
.strategy
.cache
.name
;
6 import java
.util
.ArrayList
;
10 import org
.apache
.log4j
.Logger
;
12 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
13 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
14 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
16 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
17 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
22 * This class is a default implementation for the INonViralNameCacheStrategy<T extends NonViralName> interface.
23 * The method actually implements a cache strategy for botanical names so no method has to be overwritten by
24 * a subclass for botanic names.
25 * Where differing from this Default BotanicNameCacheStrategy other subclasses should overwrite the existing methods
26 * e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor
34 public class NonViralNameDefaultCacheStrategy
<T
extends NonViralName
> extends NameCacheStrategyBase
<T
> implements INonViralNameCacheStrategy
<T
> {
35 private static final Logger logger
= Logger
.getLogger(NonViralNameDefaultCacheStrategy
.class);
37 final static UUID uuid
= UUID
.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
39 protected String NameAuthorSeperator
= " ";
40 protected String BasionymStart
= "(";
41 protected String BasionymEnd
= ")";
42 protected String ExAuthorSeperator
= " ex ";
43 protected CharSequence BasionymAuthorCombinationAuthorSeperator
= " ";
45 public UUID
getUuid(){
52 * @return NonViralNameDefaultCacheStrategy A new instance of NonViralNameDefaultCacheStrategy
54 public static NonViralNameDefaultCacheStrategy
NewInstance(){
55 return new NonViralNameDefaultCacheStrategy();
61 protected NonViralNameDefaultCacheStrategy(){
65 /* **************** GETTER / SETTER **************************************/
68 * String that separates the NameCache part from the AuthorCache part
71 public String
getNameAuthorSeperator() {
72 return NameAuthorSeperator
;
76 public void setNameAuthorSeperator(String nameAuthorSeperator
) {
77 NameAuthorSeperator
= nameAuthorSeperator
;
82 * String the basionym author part starts with e.g. '('.
83 * This should correspond with the {@link NonViralNameDefaultCacheStrategy#getBasionymEnd() basionymEnd} attribute
86 public String
getBasionymStart() {
91 public void setBasionymStart(String basionymStart
) {
92 BasionymStart
= basionymStart
;
97 * String the basionym author part ends with e.g. ')'.
98 * This should correspond with the {@link NonViralNameDefaultCacheStrategy#getBasionymStart() basionymStart} attribute
101 public String
getBasionymEnd() {
106 public void setBasionymEnd(String basionymEnd
) {
107 BasionymEnd
= basionymEnd
;
112 * String to seperate ex author from author.
115 public String
getExAuthorSeperator() {
116 return ExAuthorSeperator
;
120 public void setExAuthorSeperator(String exAuthorSeperator
) {
121 ExAuthorSeperator
= exAuthorSeperator
;
126 * String that seperates the basionym/original_combination author part from the combination author part
129 public CharSequence
getBasionymAuthorCombinationAuthorSeperator() {
130 return BasionymAuthorCombinationAuthorSeperator
;
134 public void setBasionymAuthorCombinationAuthorSeperator(
135 CharSequence basionymAuthorCombinationAuthorSeperator
) {
136 BasionymAuthorCombinationAuthorSeperator
= basionymAuthorCombinationAuthorSeperator
;
140 //** *****************************************************************************************/
144 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getNameCache()
148 public String
getTitleCache(T nonViralName
) {
149 if (nonViralName
== null){
153 if (isAutonym(nonViralName
)){
154 String speciesPart
= getSpeciesNameCache(nonViralName
);
155 //TODO should this include basionym authors and ex authors
156 INomenclaturalAuthor author
= nonViralName
.getCombinationAuthorTeam();
157 String authorPart
= "";
159 authorPart
= CdmUtils
.Nz(author
.getNomenclaturalTitle());
161 INomenclaturalAuthor basAuthor
= nonViralName
.getBasionymAuthorTeam();
162 String basAuthorPart
= "";
163 if (basAuthor
!= null){
164 basAuthorPart
= CdmUtils
.Nz(basAuthor
.getNomenclaturalTitle());
166 if (! "".equals(basAuthorPart
)){
167 authorPart
= "("+ basAuthorPart
+")" + authorPart
;
169 String infraSpeciesPart
= (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet()));
170 result
= CdmUtils
.concat(" ", new String
[]{speciesPart
, authorPart
, infraSpeciesPart
});
171 result
= result
.trim().replace("null", "");
173 String nameCache
= CdmUtils
.Nz(getNameCache(nonViralName
));
174 String authorCache
= CdmUtils
.Nz(getAuthorshipCache(nonViralName
));
175 result
= CdmUtils
.concat(NameAuthorSeperator
, nameCache
, authorCache
);
182 * Generates and returns the "name cache" (only scientific name without author teams and year).
183 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.TaxonNameBase)
185 public String
getNameCache(T nonViralName
) {
186 if (nonViralName
== null){
190 Rank rank
= nonViralName
.getRank();
193 result
= getRanklessNameCache(nonViralName
);
194 }else if (rank
.isInfraSpecific()){
195 result
= getInfraSpeciesNameCache(nonViralName
);
196 }else if (rank
.isSpecies()){
197 result
= getSpeciesNameCache(nonViralName
);
198 }else if (rank
.isInfraGeneric()){
199 result
= getInfraGenusNameCache(nonViralName
);
200 }else if (rank
.isGenus()){
201 result
= getGenusOrUninomialNameCache(nonViralName
);
202 }else if (rank
.isSupraGeneric()){
203 result
= getGenusOrUninomialNameCache(nonViralName
);
205 logger
.warn("Name Strategy for Name (UUID: " + nonViralName
.getUuid() + ") not yet implemented");
213 * @see eu.etaxonomy.cdm.strategy.cache.INonViralNameCacheStrategy#getAuthorCache(eu.etaxonomy.cdm.model.name.NonViralName)
215 public String
getAuthorshipCache(T nonViralName
) {
216 if (nonViralName
== null){
220 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorTeam();
221 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorTeam();
222 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorTeam();
223 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorTeam();
224 String basionymPart
= "";
225 String authorPart
= "";
227 if (basionymAuthor
!= null || exBasionymAuthor
!= null){
228 basionymPart
= BasionymStart
+ getAuthorAndExAuthor(basionymAuthor
, exBasionymAuthor
) + BasionymEnd
;
230 if (combinationAuthor
!= null || exCombinationAuthor
!= null){
231 authorPart
= getAuthorAndExAuthor(combinationAuthor
, exCombinationAuthor
);
233 result
= CdmUtils
.concat(BasionymAuthorCombinationAuthorSeperator
, basionymPart
, authorPart
);
238 * Returns the AuthorCache part for a combination of an author and an ex author. This applies on combination authors
239 * as well as on basionym/orginal combination authors.
240 * @param author the author
241 * @param exAuthor the ex-author
244 protected String
getAuthorAndExAuthor(INomenclaturalAuthor author
, INomenclaturalAuthor exAuthor
){
246 String authorString
= "";
247 String exAuthorString
= "";
249 authorString
= CdmUtils
.Nz(author
.getNomenclaturalTitle());
251 if (exAuthor
!= null){
252 exAuthorString
= CdmUtils
.Nz(exAuthor
.getNomenclaturalTitle());
254 if (exAuthorString
.length() > 0 ){
255 exAuthorString
= exAuthorString
+ ExAuthorSeperator
;
257 result
= exAuthorString
+ authorString
;
264 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.common.CdmBase)
267 public List
<Object
> getTaggedName(T nonViralName
) {
268 List
<Object
> tags
= new ArrayList
<Object
>();
269 tags
.add(nonViralName
.getGenusOrUninomial());
270 if (nonViralName
.isSpecies() || nonViralName
.isInfraSpecific()){
271 tags
.add(nonViralName
.getSpecificEpithet());
273 if (nonViralName
.isInfraSpecific()){
274 tags
.add(nonViralName
.getRank());
275 tags
.add(nonViralName
.getInfraSpecificEpithet());
277 if (nonViralName
.isInfraGeneric()){
278 //TODO choose right strategy or generic approach?
279 // --- strategy 1 ---
280 tags
.add(nonViralName
.getRank());
281 tags
.add(nonViralName
.getInfraGenericEpithet());
282 // --- strategy 2 ---
283 // tags.add('('+nvn.getInfraGenericEpithet()+')');
285 Team authorTeam
= Team
.NewInstance();
286 authorTeam
.setProtectedTitleCache(true);
287 authorTeam
.setTitleCache(nonViralName
.getAuthorshipCache());
288 tags
.add(authorTeam
);
289 if (nonViralName
.getNomenclaturalReference() != null){
290 INomenclaturalReference nomenclaturalReference
= nonViralName
.getNomenclaturalReference();
291 tags
.add(nomenclaturalReference
);//nonViralName.getNomenclaturalReference().getNomenclaturalCitation(nonViralName.getNomenclaturalMicroReference()));
299 /************** PRIVATES ****************/
301 protected String
getRanklessNameCache(NonViralName nonViralName
){
303 result
= (result
+ (nonViralName
.getGenusOrUninomial())).trim().replace("null", "-");
304 result
+= " " + (CdmUtils
.Nz(nonViralName
.getSpecificEpithet())).trim();
305 result
+= " " + (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet())).trim();
306 result
= result
.trim().replace("null", "-");
307 //result += " (rankless)";
312 protected String
getGenusOrUninomialNameCache(NonViralName nonViralName
){
314 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
318 protected String
getInfraGenusNameCache(NonViralName nonViralName
){
320 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
321 result
+= " (" + (CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()) + ")").trim().replace("null", "");
326 protected String
getSpeciesNameCache(NonViralName nonViralName
){
328 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
329 result
+= " " + CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim().replace("null", "");
334 protected String
getInfraSpeciesNameCache(NonViralName nonViralName
){
336 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
337 result
+= " " + (CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim()).replace("null", "");
338 if (! isAutonym(nonViralName
)){
339 result
+= " " + (nonViralName
.getRank().getAbbreviation()).trim().replace("null", "");
341 result
+= " " + (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet())).trim().replace("null", "");
348 * @return true, if name has Rank, Rank is below species and species epithet equals infraSpeciesEpithtet, else false
350 protected boolean isAutonym(NonViralName nonViralName
){
351 if (nonViralName
!= null && nonViralName
.getRank() != null && nonViralName
.getSpecificEpithet() != null && nonViralName
.getInfraSpecificEpithet() != null &&
352 nonViralName
.getRank().isInfraSpecific() && nonViralName
.getSpecificEpithet().trim().equals(nonViralName
.getInfraSpecificEpithet().trim())){