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
;
20 * This class is a default implementation for the INonViralNameCacheStrategy<T extends NonViralName> interface.
21 * The method actually implements a cache strategy for botanical names so no method has to be overwritten by
22 * a subclass for botanic names.
23 * Where differing from this Default BotanicNameCacheStrategy other subclasses should overwrite the existing methods
24 * e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor
32 public class NonViralNameDefaultCacheStrategy
<T
extends NonViralName
> extends NameCacheStrategyBase
<T
> implements INonViralNameCacheStrategy
<T
> {
33 private static final Logger logger
= Logger
.getLogger(NonViralNameDefaultCacheStrategy
.class);
35 final static UUID uuid
= UUID
.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
37 protected String NameAuthorSeperator
= " ";
38 protected String BasionymStart
= "(";
39 protected String BasionymEnd
= ")";
40 protected String ExAuthorSeperator
= " ex. ";
41 protected CharSequence BasionymAuthorCombinationAuthorSeperator
= " ";
43 public UUID
getUuid(){
50 * @return NonViralNameDefaultCacheStrategy A new instance of NonViralNameDefaultCacheStrategy
52 public static NonViralNameDefaultCacheStrategy
NewInstance(){
53 return new NonViralNameDefaultCacheStrategy();
59 protected NonViralNameDefaultCacheStrategy(){
63 /* **************** GETTER / SETTER **************************************/
66 * String that separates the NameCache part from the AuthorCache part
69 public String
getNameAuthorSeperator() {
70 return NameAuthorSeperator
;
74 public void setNameAuthorSeperator(String nameAuthorSeperator
) {
75 NameAuthorSeperator
= nameAuthorSeperator
;
80 * String the basionym author part starts with e.g. '('.
81 * This should correspond with the {@link NonViralNameDefaultCacheStrategy#getBasionymEnd() basionymEnd} attribute
84 public String
getBasionymStart() {
89 public void setBasionymStart(String basionymStart
) {
90 BasionymStart
= basionymStart
;
95 * String the basionym author part ends with e.g. ')'.
96 * This should correspond with the {@link NonViralNameDefaultCacheStrategy#getBasionymStart() basionymStart} attribute
99 public String
getBasionymEnd() {
104 public void setBasionymEnd(String basionymEnd
) {
105 BasionymEnd
= basionymEnd
;
110 * String to seperate ex author from author.
113 public String
getExAuthorSeperator() {
114 return ExAuthorSeperator
;
118 public void setExAuthorSeperator(String exAuthorSeperator
) {
119 ExAuthorSeperator
= exAuthorSeperator
;
124 * String that seperates the basionym/original_combination author part from the combination author part
127 public CharSequence
getBasionymAuthorCombinationAuthorSeperator() {
128 return BasionymAuthorCombinationAuthorSeperator
;
132 public void setBasionymAuthorCombinationAuthorSeperator(
133 CharSequence basionymAuthorCombinationAuthorSeperator
) {
134 BasionymAuthorCombinationAuthorSeperator
= basionymAuthorCombinationAuthorSeperator
;
138 //** *****************************************************************************************/
142 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getNameCache()
146 public String
getTitleCache(T nonViralName
) {
147 if (nonViralName
== null){
151 if (isAutonym(nonViralName
)){
152 String speciesPart
= getSpeciesNameCache(nonViralName
);
153 //TODO should this include basionym authors and ex authors
154 INomenclaturalAuthor author
= nonViralName
.getCombinationAuthorTeam();
155 String authorPart
= "";
157 authorPart
= CdmUtils
.Nz(author
.getNomenclaturalTitle());
159 String infraSpeciesPart
= (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet()));
160 result
= CdmUtils
.concat(" ", new String
[]{speciesPart
, authorPart
, infraSpeciesPart
});
161 result
= result
.trim().replace("null", "");
163 String nameCache
= CdmUtils
.Nz(getNameCache(nonViralName
));
164 String authorCache
= CdmUtils
.Nz(getAuthorshipCache(nonViralName
));
165 result
= CdmUtils
.concat(NameAuthorSeperator
, nameCache
, authorCache
);
172 * Generates and returns the "name cache" (only scientific name without author teams and year).
173 * @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.TaxonNameBase)
175 public String
getNameCache(T nonViralName
) {
176 if (nonViralName
== null){
180 Rank rank
= nonViralName
.getRank();
183 result
= getRanklessNameCache(nonViralName
);
184 }else if (rank
.isInfraSpecific()){
185 result
= getInfraSpeciesNameCache(nonViralName
);
186 }else if (rank
.isSpecies()){
187 result
= getSpeciesNameCache(nonViralName
);
188 }else if (rank
.isInfraGeneric()){
189 result
= getInfraGenusNameCache(nonViralName
);
190 }else if (rank
.isGenus()){
191 result
= getGenusOrUninomialNameCache(nonViralName
);
192 }else if (rank
.isSupraGeneric()){
193 result
= getGenusOrUninomialNameCache(nonViralName
);
195 logger
.warn("Name Strategy for Name (UUID: " + nonViralName
.getUuid() + ") not yet implemented");
203 * @see eu.etaxonomy.cdm.strategy.cache.INonViralNameCacheStrategy#getAuthorCache(eu.etaxonomy.cdm.model.name.NonViralName)
205 public String
getAuthorshipCache(T nonViralName
) {
206 if (nonViralName
== null){
210 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorTeam();
211 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorTeam();
212 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorTeam();
213 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorTeam();
214 String basionymPart
= "";
215 String authorPart
= "";
217 if (basionymAuthor
!= null || exBasionymAuthor
!= null){
218 basionymPart
= BasionymStart
+ getAuthorAndExAuthor(basionymAuthor
, exBasionymAuthor
) + BasionymEnd
;
220 if (combinationAuthor
!= null || exCombinationAuthor
!= null){
221 authorPart
= getAuthorAndExAuthor(combinationAuthor
, exCombinationAuthor
);
223 result
= CdmUtils
.concat(BasionymAuthorCombinationAuthorSeperator
, basionymPart
, authorPart
);
228 * Returns the AuthorCache part for a combination of an author and an ex author. This applies on combination authors
229 * as well as on basionym/orginal combination authors.
230 * @param author the author
231 * @param exAuthor the ex-author
234 protected String
getAuthorAndExAuthor(INomenclaturalAuthor author
, INomenclaturalAuthor exAuthor
){
236 String authorString
= "";
237 String exAuthorString
= "";
239 authorString
= CdmUtils
.Nz(author
.getNomenclaturalTitle());
241 if (exAuthor
!= null){
242 exAuthorString
= CdmUtils
.Nz(exAuthor
.getNomenclaturalTitle());
244 if (exAuthorString
.length() > 0 ){
245 exAuthorString
= ExAuthorSeperator
+ exAuthorString
;
247 result
= authorString
+ exAuthorString
;
254 * @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.common.CdmBase)
257 public List
<Object
> getTaggedName(T nvn
) {
258 List
<Object
> tags
= new ArrayList
<Object
>();
259 tags
.add(nvn
.getGenusOrUninomial());
260 if (nvn
.isSpecies() || nvn
.isInfraSpecific()){
261 tags
.add(nvn
.getSpecificEpithet());
263 if (nvn
.isInfraSpecific()){
264 tags
.add(nvn
.getRank());
265 tags
.add(nvn
.getInfraSpecificEpithet());
267 if (nvn
.isInfraGeneric()){
268 //TODO choose right strategy or generic approach?
269 // --- strategy 1 ---
270 tags
.add(nvn
.getRank());
271 tags
.add(nvn
.getInfraGenericEpithet());
272 // --- strategy 2 ---
273 // tags.add('('+nvn.getInfraGenericEpithet()+')');
275 Team at
= Team
.NewInstance();
276 at
.setProtectedTitleCache(true);
277 at
.setTitleCache(nvn
.getAuthorshipCache());
279 tags
.add(nvn
.getNomenclaturalReference());
284 /************** PRIVATES ****************/
286 protected String
getRanklessNameCache(NonViralName nonViralName
){
288 result
= (result
+ (nonViralName
.getGenusOrUninomial())).trim().replace("null", "-");
289 result
+= " " + (CdmUtils
.Nz(nonViralName
.getSpecificEpithet())).trim();
290 result
+= " " + (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet())).trim();
291 result
= result
.trim().replace("null", "-");
292 //result += " (rankless)";
297 protected String
getGenusOrUninomialNameCache(NonViralName nonViralName
){
299 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
303 protected String
getInfraGenusNameCache(NonViralName nonViralName
){
305 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
306 result
+= " (" + (CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()) + ")").trim().replace("null", "");
311 protected String
getSpeciesNameCache(NonViralName nonViralName
){
313 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
314 result
+= " " + CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim().replace("null", "");
319 protected String
getInfraSpeciesNameCache(NonViralName nonViralName
){
321 result
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial());
322 result
+= " " + (CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim()).replace("null", "");
323 if (! isAutonym(nonViralName
)){
324 result
+= " " + (nonViralName
.getRank().getAbbreviation()).trim().replace("null", "");
326 result
+= " " + (CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet())).trim().replace("null", "");
333 * @return true, if name has Rank, Rank is below species and species epithet equals infraSpeciesEpithtet, else false
335 protected boolean isAutonym(NonViralName nonViralName
){
336 if (nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific() && nonViralName
.getSpecificEpithet() != null && nonViralName
.getSpecificEpithet().trim().equals(nonViralName
.getInfraSpecificEpithet().trim())){