Remove javadoc in Rank
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / Rank.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
10 package eu.etaxonomy.cdm.model.name;
11
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import javax.persistence.Entity;
18 import javax.persistence.Transient;
19 import javax.validation.constraints.NotNull;
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlAttribute;
23 import javax.xml.bind.annotation.XmlType;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.log4j.Logger;
27 import org.hibernate.annotations.Type;
28 import org.hibernate.envers.Audited;
29 import org.hibernate.search.annotations.Indexed;
30
31 import eu.etaxonomy.cdm.common.CdmUtils;
32 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
33 import eu.etaxonomy.cdm.model.common.Language;
34 import eu.etaxonomy.cdm.model.common.OrderedTermBase;
35 import eu.etaxonomy.cdm.model.common.Representation;
36 import eu.etaxonomy.cdm.model.common.TermType;
37 import eu.etaxonomy.cdm.model.common.TermVocabulary;
38 import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
39
40 /**
41 * The class representing the taxonomical ranks (like "Family", "Genus" or
42 * "Species") used for {@link TaxonNameBase taxon names} across all {@link NomenclaturalCode nomenclatural codes}
43 * for bacteria (ICNB), viruses (ICVCN), plants and fungi (ICBN),
44 * cultivars (ICNCP) and animals (ICZN).
45 * <P>
46 * A standard (ordered) list of taxonomical rank instances will be automatically
47 * created as the project starts. But this class allows to extend this standard
48 * list by creating new instances of additional taxonomical ranks if needed.
49 * <P>
50 * This class corresponds to: <ul>
51 * <li> TaxonRankTerm according to the TDWG ontology
52 * <li> TaxonomicRankEnum according to the TCS
53 * <li> Rank according to the ABCD schema
54 * </ul>
55 *
56 * @author m.doering
57 * @version 1.0
58 * @created 08-Nov-2007 13:06:46
59 */
60 @XmlAccessorType(XmlAccessType.FIELD)
61 @XmlType(name = "Rank")
62 @Entity
63 @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
64 @Audited
65 public class Rank extends OrderedTermBase<Rank> {
66 private static final long serialVersionUID = -8648081681348758485L;
67 private static final Logger logger = Logger.getLogger(Rank.class);
68
69 private static final UUID uuidEmpire = UUID.fromString("ac470211-1586-4b24-95ca-1038050b618d");
70 private static final UUID uuidDomain = UUID.fromString("ffca6ec8-8b88-417b-a6a0-f7c992aac19b");
71 private static final UUID uuidSuperkingdom = UUID.fromString("64223610-7625-4cfd-83ad-b797bf7f0edd");
72 private static final UUID uuidKingdom = UUID.fromString("fbe7109d-66b3-498c-a697-c6c49c686162");
73 private static final UUID uuidSubkingdom = UUID.fromString("a71bd9d8-f3ab-4083-afb5-d89315d71655");
74 private static final UUID uuidInfrakingdom = UUID.fromString("1e37930c-86cf-44f6-90fd-7822928df260");
75 private static final UUID uuidSuperphylum = UUID.fromString("0d0cecb1-e254-4607-b210-6801e7ecbb04");
76 private static final UUID uuidPhylum = UUID.fromString("773430d2-76b4-438c-b817-97a543a33287");
77 private static final UUID uuidSubphylum = UUID.fromString("23a9b6ff-9408-49c9-bd9e-7a2ca5ab4725");
78 private static final UUID uuidInfraphylum = UUID.fromString("1701de3a-7693-42a5-a2d3-42697f944190");
79 private static final UUID uuidSuperdivision = UUID.fromString("a735a48f-4fc8-49a7-ae0c-6a984f658131");
80 private static final UUID uuidDivision = UUID.fromString("7e56f5cc-123a-4fd1-8cbb-6fd80358b581");
81 private static final UUID uuidSubdivision = UUID.fromString("931c840f-7a6b-4d76-ad38-bfdd77d7b2e8");
82 private static final UUID uuidInfradivision = UUID.fromString("c0ede273-be52-4dee-b411-66ee08d30c94");
83 private static final UUID uuidSuperclass = UUID.fromString("e65b4e1a-21ec-428d-9b9f-e87721ab967c");
84 private static final UUID uuidClass = UUID.fromString("f23d14c4-1d34-4ee6-8b4e-eee2eb9a3daf");
85 private static final UUID uuidSubclass = UUID.fromString("8cb26733-e2f5-46cb-ab5c-f99254f877aa");
86 private static final UUID uuidInfraclass = UUID.fromString("ad23cfda-879a-4021-8629-c54d27caf717");
87 private static final UUID uuidSuperorder = UUID.fromString("c8c67a22-301a-4219-b882-4a49121232ff");
88 private static final UUID uuidOrder = UUID.fromString("b0785a65-c1c1-4eb4-88c7-dbd3df5aaad1");
89 private static final UUID uuidSuborder = UUID.fromString("768ad378-fa85-42ab-b668-763225832f57");
90 private static final UUID uuidInfraorder = UUID.fromString("84099182-a6f5-47d7-8586-33c9e9955a10");
91 private static final UUID uuidSectionZoology = UUID.fromString("691d371e-10d7-43f0-93db-3d7fa1a62c54");
92 private static final UUID uuidSubsectionZoology = UUID.fromString("0ed32d28-adc4-4303-a9ca-68e2acd67e33");
93 private static final UUID uuidSuperfamily = UUID.fromString("2cfa510a-dcea-4a03-b66a-b1528f9b0796");
94 private static final UUID uuidFamily = UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6");
95 private static final UUID uuidSubfamily = UUID.fromString("862526ee-7592-4760-a23a-4ff3641541c5");
96 private static final UUID uuidInfrafamily = UUID.fromString("c3f2e3bb-6eef-4a26-9fb7-b14f4c8c5e4f");
97 private static final UUID uuidSupertribe = UUID.fromString("11e94828-8c61-499b-87d6-1de35ce2c51c");
98 private static final UUID uuidTribe = UUID.fromString("4aa6890b-0363-4899-8d7c-ee0cb78e6166");
99 private static final UUID uuidSubtribe = UUID.fromString("ae41ecc5-5165-4126-9d24-79939ae5d822");
100 private static final UUID uuidInfratribe = UUID.fromString("1ec02e8f-f2b7-4c65-af9f-b436b34c79a3");
101 private static final UUID uuidSupragenericTaxon = UUID.fromString("1fdc0b93-c354-441a-8406-091e0303ff5c");
102 public static final UUID uuidGenus = UUID.fromString("1b11c34c-48a8-4efa-98d5-84f7f66ef43a");
103 private static final UUID uuidSubgenus = UUID.fromString("78786e16-2a70-48af-a608-494023b91904");
104 private static final UUID uuidInfragenus = UUID.fromString("a9972969-82cd-4d54-b693-a096422f13fa");
105 private static final UUID uuidSectionBotany = UUID.fromString("3edff68f-8527-49b5-bf91-7e4398bb975c");
106 private static final UUID uuidSubsectionBotany = UUID.fromString("d20f5b61-d463-4448-8f8a-c1ff1f262f59");
107 private static final UUID uuidSeries = UUID.fromString("d7381ecf-48f8-429b-9c54-f461656978cd");
108 private static final UUID uuidSubseries = UUID.fromString("80c9a263-f4db-4a13-b6c2-b7fec1aa1200");
109 private static final UUID uuidSpeciesAggregate = UUID.fromString("1ecae058-4217-4f75-9c27-6d8ba099ac7a");
110 private static final UUID uuidSpeciesGroup = UUID.fromString("d1988a11-292b-46fa-8fb7-bc64ea6d8fc6");
111 public static final UUID uuidInfragenericTaxon = UUID.fromString("41bcc6ac-37d3-4fd4-bb80-3cc5b04298b9");
112 public static final UUID uuidSpecies = UUID.fromString("b301f787-f319-4ccc-a10f-b4ed3b99a86d");
113 private static final UUID uuidSubspecificAggregate = UUID.fromString("72c248b9-027d-4402-b375-dd4f0850c9ad");
114 private static final UUID uuidSubspecies = UUID.fromString("462a7819-8b00-4190-8313-88b5be81fad5");
115 private static final UUID uuidInfraspecies = UUID.fromString("f28ebc9e-bd50-4194-9af1-42f5cb971a2c");
116 private static final UUID uuidNatio = UUID.fromString("965f2f38-7f97-4270-ab5a-1999bf050a22");
117 private static final UUID uuidVariety = UUID.fromString("d5feb6a5-af5c-45ef-9878-bb4f36aaf490");
118 private static final UUID uuidBioVariety = UUID.fromString("a3a364cb-1a92-43fc-a717-3c44980a0991");
119 private static final UUID uuidPathoVariety = UUID.fromString("2f4f4303-a099-47e3-9048-d749d735423b");
120 private static final UUID uuidSubvariety = UUID.fromString("9a83862a-7aee-480c-a98d-4bceaf8712ca");
121 private static final UUID uuidSubsubvariety = UUID.fromString("bff22f84-553a-4429-a4e7-c4b3796c3a18");
122
123 private static final UUID uuidProles = UUID.fromString("8810d1ba-6a34-4ae3-a355-919ccd1cd1a5");
124 private static final UUID uuidRace = UUID.fromString("196dee39-cfd8-4460-8bf0-88b83da27f62");
125 private static final UUID uuidSublusus = UUID.fromString("1fafa596-a8e7-4e62-a378-3cc8cb3627ca");
126
127 private static final UUID uuidConvar = UUID.fromString("2cc740c9-cebb-43c8-9b06-1bef79e6a56a");
128 private static final UUID uuidForm = UUID.fromString("0461281e-458a-47b9-8d41-19a3d39356d5");
129 private static final UUID uuidSpecialForm = UUID.fromString("bed20aee-2f5a-4635-9c02-eff06246d067");
130 private static final UUID uuidSubform = UUID.fromString("47cfc5b0-0fb7-4ceb-b61d-e1dd8de8b569");
131 private static final UUID uuidSubsubform = UUID.fromString("1c8ac389-4349-4ae0-87be-7239f6635068");
132 public static final UUID uuidInfraspecificTaxon = UUID.fromString("eb75c27d-e154-4570-9d96-227b2df60474");
133 private static final UUID uuidCandidate = UUID.fromString("ead9a1f5-dfd4-4de2-9121-70a47accb10b");
134 private static final UUID uuidDenominationClass = UUID.fromString("49bdf74a-2170-40ed-8be2-887a0db517bf");
135 private static final UUID uuidGrex = UUID.fromString("08dcb4ff-ac58-48a3-93af-efb3d836ac84");
136 private static final UUID uuidGraftChimaera = UUID.fromString("6b4063bc-f934-4796-9bf3-0ef3aea5c1cb");
137 private static final UUID uuidCultivarGroup = UUID.fromString("d763e7d3-e7de-4bb1-9d75-225ca6948659");
138 private static final UUID uuidCultivar = UUID.fromString("5e98415b-dc6e-440b-95d6-ea33dbb39ad0");
139 private static final UUID uuidUnknownRank = UUID.fromString("5c4d6755-2cf6-44ca-9220-cccf8881700b");
140
141 private static Map<String, UUID> idInVocMap = null;
142 private static Map<String, UUID> labelMap = null;
143
144 protected static Map<UUID, Rank> termMap = null;
145
146 //*********************** Factory methods ********************************************/
147
148 // /**
149 // * Creates a new empty rank.
150 // *
151 // * @see #NewInstance(String, String, String)
152 // */
153 // private static Rank NewInstance(){
154 // return new Rank();
155 // }
156
157 /**
158 * Creates an additional rank with a description (in the {@link Language#DEFAULT() default language}),
159 * a label and a label abbreviation.
160 *
161 * @param term the string (in the default language) describing the
162 * new rank to be created
163 * @param label the string identifying the new rank to be created
164 * @param labelAbbrev the string identifying (in abbreviated form) the
165 * new rank to be created
166 * @see #NewInstance()
167 */
168 public static Rank NewInstance(RankClass rankClass, String term, String label, String labelAbbrev){
169 return new Rank(rankClass, term, label, labelAbbrev);
170 }
171
172 /**
173 * The {@link RankClass rank class} of a rank. It is usually needed for correct formatting of a
174 * rank by using e.g. isSupraGeneric(). Prior to v3.3 this was computed by comparison of ranks.
175 */
176 @XmlAttribute(name ="RankClass")
177 @NotNull
178 @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
179 parameters = {@org.hibernate.annotations.Parameter(name="enumClass", value="eu.etaxonomy.cdm.model.name.RankClass")}
180 )
181 private RankClass rankClass;
182
183
184 //********************************** Constructor *********************************/
185
186 //for hibernate use only
187 @Deprecated
188 protected Rank() {
189 super(TermType.Rank);
190 }
191
192 /**
193 * Class constructor: creates an additional rank instance with a description
194 * (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), a label and a label abbreviation.
195 *
196 * @param term the string (in the default language) describing the
197 * new rank to be created
198 * @param label the string identifying the new rank to be created
199 * @param labelAbbrev the string identifying (in abbreviated form) the
200 * new rank to be created
201 * @see #Rank()
202 */
203 protected Rank(RankClass rankClass, String term, String label, String labelAbbrev) {
204 super(TermType.Rank, term, label, labelAbbrev);
205 this.rankClass = rankClass;
206 }
207
208
209 //********* METHODS **************************************/
210
211 /* (non-Javadoc)
212 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
213 */
214 @Override
215 public void resetTerms(){
216 termMap = null;
217 }
218
219
220
221 protected static Rank getTermByUuid(UUID uuid){
222 if (termMap == null){
223 return null; //better return null then initialize the termMap in an unwanted way
224 }
225 return (Rank)termMap.get(uuid);
226 }
227
228 public static final Rank EMPIRE(){
229 return getTermByUuid(uuidEmpire);
230 }
231 public static final Rank DOMAIN(){
232 return getTermByUuid(uuidDomain);
233 }
234 public static final Rank SUPERKINGDOM(){
235 return getTermByUuid(uuidSuperkingdom);
236 }
237 public static final Rank KINGDOM(){
238 return getTermByUuid(uuidKingdom);
239 }
240 public static final Rank SUBKINGDOM(){
241 return getTermByUuid(uuidSubkingdom);
242 }
243 public static final Rank INFRAKINGDOM(){
244 return getTermByUuid(uuidInfrakingdom);
245 }
246 public static final Rank SUPERPHYLUM(){
247 return getTermByUuid(uuidSuperphylum);
248 }
249 public static final Rank PHYLUM(){
250 return getTermByUuid(uuidPhylum);
251 }
252 public static final Rank SUBPHYLUM(){
253 return getTermByUuid(uuidSubphylum);
254 }
255 public static final Rank INFRAPHYLUM(){
256 return getTermByUuid(uuidInfraphylum);
257 }
258 public static final Rank SUPERDIVISION(){
259 return getTermByUuid(uuidSuperdivision);
260 }
261 public static final Rank DIVISION(){
262 return getTermByUuid(uuidDivision);
263 }
264 public static final Rank SUBDIVISION(){
265 return getTermByUuid(uuidSubdivision);
266 }
267 public static final Rank INFRADIVISION(){
268 return getTermByUuid(uuidInfradivision);
269 }
270 public static final Rank SUPERCLASS(){
271 return getTermByUuid(uuidSuperclass);
272 }
273 public static final Rank CLASS(){
274 return getTermByUuid(uuidClass);
275 }
276 public static final Rank SUBCLASS(){
277 return getTermByUuid(uuidSubclass);
278 }
279 public static final Rank INFRACLASS(){
280 return getTermByUuid(uuidInfraclass);
281 }
282 public static final Rank SUPERORDER(){
283 return getTermByUuid(uuidSuperorder);
284 }
285 public static final Rank ORDER(){
286 return getTermByUuid(uuidOrder);
287 }
288 public static final Rank SUBORDER(){
289 return getTermByUuid(uuidSuborder);
290 }
291 public static final Rank INFRAORDER(){
292 return getTermByUuid(uuidInfraorder);
293 }
294 public static final Rank SUPERFAMILY(){
295 return getTermByUuid(uuidSuperfamily);
296 }
297 public static final Rank FAMILY(){
298 return getTermByUuid(uuidFamily);
299 }
300 public static final Rank SUBFAMILY(){
301 return getTermByUuid(uuidSubfamily);
302 }
303 public static final Rank INFRAFAMILY(){
304 return getTermByUuid(uuidInfrafamily);
305 }
306 public static final Rank SUPERTRIBE(){
307 return getTermByUuid(uuidSupertribe);
308 }
309 public static final Rank TRIBE(){
310 return getTermByUuid(uuidTribe);
311 }
312 public static final Rank SUBTRIBE(){
313 return getTermByUuid(uuidSubtribe);
314 }
315 public static final Rank INFRATRIBE(){
316 return getTermByUuid(uuidInfratribe);
317 }
318 public static final Rank SUPRAGENERICTAXON(){
319 return getTermByUuid(uuidSupragenericTaxon);
320 }
321 public static final Rank GENUS(){
322 return getTermByUuid(uuidGenus);
323 }
324 public static final Rank SUBGENUS(){
325 return getTermByUuid(uuidSubgenus);
326 }
327 public static final Rank INFRAGENUS(){
328 return getTermByUuid(uuidInfragenus);
329 }
330 public static final Rank SECTION_BOTANY(){
331 return getTermByUuid(uuidSectionBotany);
332 }
333 public static final Rank SUBSECTION_BOTANY(){
334 return getTermByUuid(uuidSubsectionBotany);
335 }
336 public static final Rank SECTION_ZOOLOGY(){
337 return getTermByUuid(uuidSectionZoology);
338 }
339 public static final Rank SUBSECTION_ZOOLOGY(){
340 return getTermByUuid(uuidSubsectionZoology);
341 }
342 public static final Rank SERIES(){
343 return getTermByUuid(uuidSeries);
344 }
345 public static final Rank SUBSERIES(){
346 return getTermByUuid(uuidSubseries);
347 }
348 public static final Rank SPECIESAGGREGATE(){
349 return getTermByUuid(uuidSpeciesAggregate);
350 }
351 public static final Rank SPECIESGROUP(){
352 return getTermByUuid(uuidSpeciesGroup);
353 }
354 /**
355 * 'Unranked infrageneric'. An infrageneric rank which is on purpose not further defined.
356 * This sometimes holds for names from the 19th century.
357 */
358 public static final Rank INFRAGENERICTAXON(){
359 return getTermByUuid(uuidInfragenericTaxon);
360 }
361 public static final Rank SPECIES(){
362 return getTermByUuid(uuidSpecies);
363 }
364 public static final Rank SUBSPECIFICAGGREGATE(){
365 return getTermByUuid(uuidSubspecificAggregate);
366 }
367 public static final Rank SUBSPECIES(){
368 return getTermByUuid(uuidSubspecies);
369 }
370 public static final Rank INFRASPECIES(){
371 return getTermByUuid(uuidInfraspecies);
372 }
373 public static final Rank VARIETY(){
374 return getTermByUuid(uuidVariety);
375 }
376 public static final Rank BIOVARIETY(){
377 return getTermByUuid(uuidBioVariety);
378 }
379 public static final Rank PATHOVARIETY(){
380 return getTermByUuid(uuidPathoVariety);
381 }
382 public static final Rank SUBVARIETY(){
383 return getTermByUuid(uuidSubvariety);
384 }
385 public static final Rank SUBSUBVARIETY(){
386 return getTermByUuid(uuidSubsubvariety );
387 }
388 public static final Rank PROLES(){
389 return getTermByUuid(uuidProles);
390 }
391 public static final Rank RACE(){
392 return getTermByUuid(uuidRace);
393 }
394 public static final Rank SUBLUSUS(){
395 return getTermByUuid(uuidSublusus);
396 }
397
398 public static final Rank CONVAR(){
399 return getTermByUuid(uuidConvar);
400 }
401 public static final Rank FORM(){
402 return getTermByUuid(uuidForm);
403 }
404 public static final Rank SPECIALFORM(){
405 return getTermByUuid(uuidSpecialForm);
406 }
407 public static final Rank SUBFORM(){
408 return getTermByUuid(uuidSubform);
409 }
410 public static final Rank SUBSUBFORM(){
411 return getTermByUuid(uuidSubsubform);
412 }
413 /**
414 * 'Unranked infraspecific'. An infraspecific rank which is on purpose not further defined.
415 * This sometimes holds for names from the 19th century.
416 */
417 public static final Rank INFRASPECIFICTAXON(){
418 return getTermByUuid(uuidInfraspecificTaxon);
419 }
420 public static final Rank CANDIDATE(){
421 return getTermByUuid(uuidCandidate);
422 }
423 public static final Rank DENOMINATIONCLASS(){
424 return getTermByUuid(uuidDenominationClass);
425 }
426 public static final Rank GREX(){
427 return getTermByUuid(uuidGrex);
428 }
429 public static final Rank GRAFTCHIMAERA(){
430 return getTermByUuid(uuidGraftChimaera);
431 }
432 public static final Rank CULTIVARGROUP(){
433 return getTermByUuid(uuidCultivarGroup);
434 }
435 public static final Rank CULTIVAR(){
436 return getTermByUuid(uuidCultivar);
437 }
438 public static final Rank UNKNOWN_RANK(){
439 return getTermByUuid(uuidUnknownRank);
440 }
441 public static final Rank NATIO(){
442 return getTermByUuid(uuidNatio);
443 }
444 /**
445 * @see #INFRASPECIFICTAXON()
446 */
447 public static final Rank UNRANKED_INFRASPECIFIC(){
448 return getTermByUuid(uuidInfraspecificTaxon);
449 }
450 /**
451 * @see #INFRAGENERICTAXON()
452 */
453 public static final Rank UNRANKED_INFRAGENERIC(){
454 return getTermByUuid(uuidInfragenericTaxon);
455 }
456
457 // ************************ GETTER / SETTER **********************************/
458
459 public RankClass getRankClass() {
460 return rankClass;
461 }
462
463 public void setRankClass(RankClass rankClass) {
464 this.rankClass = rankClass;
465 }
466
467 // ******************************** METHODS ***************************************/
468
469 /**
470 * Returns the boolean value indicating whether <i>this</i> rank is higher than
471 * the genus rank (true) or not (false). Returns false if <i>this</i> rank is null.
472 *
473 * @see #isGenus()
474 * @see #isInfraGeneric()
475 * @see #isSpecies()
476 * @see #isInfraSpecific()
477 */
478 @Transient
479 public boolean isSupraGeneric(){
480 return this.rankClass.equals(RankClass.Suprageneric); // (this.isHigher(Rank.GENUS()));
481 }
482
483 /**
484 * Returns the boolean value indicating whether <i>this</i> rank is the genus rank
485 * (true) or not (false). Returns false if <i>this</i> rank is null.
486 *
487 * @see #isSupraGeneric()
488 * @see #isInfraGeneric()
489 * @see #isSpecies()
490 * @see #isInfraSpecific()
491 */
492 @Transient
493 public boolean isGenus(){
494 return this.rankClass.equals(RankClass.Genus); // (this.equals(Rank.GENUS()));
495 }
496
497 /**
498 * Returns the boolean value indicating whether <i>this</i> rank is higher than the
499 * species rank and lower than the genus rank (true) or not (false). Species groups or
500 * aggregates are also handled as infrageneric ranks.
501 * Returns false if <i>this</i> rank is null.
502 *
503 * @see #isSupraGeneric()
504 * @see #isGenus()
505 * @see #isSpeciesAggregate()
506 * @see #isSpecies()
507 * @see #isInfraSpecific()
508 */
509 @Transient
510 public boolean isInfraGeneric(){
511 return this.rankClass.equals(RankClass.Infrageneric) || this.rankClass.equals(RankClass.SpeciesGroup) ; //(this.isLower(Rank.GENUS()) && this.isHigher(Rank.SPECIES()));
512 }
513
514 /**
515 * Returns true if this rank indicates a rank that aggregates species
516 * like species aggregates or species groups, false otherwise.
517 * @return
518 */
519 @Transient
520 public boolean isSpeciesAggregate(){
521 return this.rankClass.equals(RankClass.SpeciesGroup); //(this.equals(Rank.SPECIESAGGREGATE()) || (this.isLower(Rank.SPECIESAGGREGATE()) && this.isHigher(Rank.SPECIES())));
522 }
523
524 /**
525 * Returns the boolean value indicating whether <i>this</i> rank is the species
526 * rank (true) or not (false). Returns false if <i>this</i> rank is null.
527 *
528 * @see #isSupraGeneric()
529 * @see #isGenus()
530 * @see #isInfraGeneric()
531 * @see #isInfraSpecific()
532 */
533 @Transient
534 public boolean isSpecies(){
535 return this.rankClass.equals(RankClass.Species); //(this.equals(Rank.SPECIES()));
536 }
537
538 /**
539 * Returns the boolean value indicating whether <i>this</i> rank is lower than the
540 * species rank (true) or not (false). Returns false if <i>this</i> rank is null.
541 *
542 * @see #isSupraGeneric()
543 * @see #isGenus()
544 * @see #isInfraGeneric()
545 * @see #isSpecies()
546 */
547 @Transient
548 public boolean isInfraSpecific(){
549 return this.rankClass.equals(RankClass.Infraspecific); // (this.isLower(Rank.SPECIES()));
550 }
551
552
553 /**
554 * Returns the rank identified through a label or the identifier within the vocabulary
555 * Preliminary implementation for BotanicalNameParser.
556 *
557 * @param strRank the string identifying the rank
558 * @return the rank
559 */
560 public static Rank getRankByNameOrIdInVoc(String strRank) throws UnknownCdmTypeException{
561 return getRankByNameOrIdInVoc(strRank, false);
562 }
563
564 /**
565 * Returns the rank identified through a label or the identifier within the vocabulary
566 * for a given nomenclatural code.
567 * Preliminary implementation for BotanicalNameParser.
568 *
569 * @param strRank the string identifying the rank
570 * @param nc the nomenclatural code
571 * @return the rank
572 */
573 public static Rank getRankByNameOrIdInVoc(String strRank, NomenclaturalCode nc) throws UnknownCdmTypeException{
574 return getRankByNameOrIdInVoc(strRank, nc, false);
575 }
576
577 // TODO
578 // Preliminary implementation for BotanicalNameParser.
579 // not yet complete
580 /**
581 * Returns the rank identified through a label or the identifier within the vocabulary.
582 * Preliminary implementation for BotanicalNameParser.
583 *
584 * @param strRank the string identifying the rank
585 * @param useUnknown if true the rank UNKNOWN_RANK is returned if the abbrev is
586 * unknown or not yet implemented
587 * @return the rank
588 */
589 public static Rank getRankByNameOrIdInVoc(String strRank, boolean useUnknown) throws UnknownCdmTypeException{
590 try {
591 return getRankByIdInVoc(strRank);
592 } catch (UnknownCdmTypeException e) {
593 return getRankByName(strRank, useUnknown);
594 }
595 }
596
597 // TODO
598 // Preliminary implementation for BotanicalNameParser.
599 // not yet complete
600 /**
601 * Returns the rank identified through a label or the identifier within the vocabulary.
602 * Preliminary implementation for BotanicalNameParser.
603 *
604 * @param strRank the string identifying the rank
605 * @param nc the nomenclatural code
606 * @param useUnknown if true the rank UNKNOWN_RANK is returned if the abbrev is
607 * unknown or not yet implemented
608 * @return the rank
609 */
610 public static Rank getRankByNameOrIdInVoc(String strRank, NomenclaturalCode nc, boolean useUnknown)
611 throws UnknownCdmTypeException{
612 try {
613 return getRankByIdInVoc(strRank, nc);
614 } catch (UnknownCdmTypeException e) {
615 return getRankByName(strRank, nc, useUnknown);
616 }
617 }
618
619 /**
620 * Returns the rank identified through the vocabulary identifier.
621 * Preliminary implementation for BotanicalNameParser.<BR>
622 * Note: For abbrev = "[unranked]" the result is undefined.
623 * It maybe the infrageneric unranked or the infraspecific unranked.
624 * You need to define by context which one is correct.
625 *
626 * @param abbrev the string for the name abbreviation
627 * @return the rank
628 */
629 public static Rank getRankByIdInVoc(String abbrev) throws UnknownCdmTypeException{
630 return getRankByIdInVoc(abbrev, false);
631 }
632
633 /**
634 * Returns the rank identified through an abbreviated name for a given nomenclatural code.
635 * See also {@link #getRankByIdInVoc(String, boolean)}
636 *
637 * @param abbrev the string for the name abbreviation
638 * @param nc the nomenclatural code
639 * @return the rank
640 */
641 public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc) throws UnknownCdmTypeException{
642 return getRankByIdInVoc(abbrev, nc, false);
643 }
644
645 // TODO
646 // Preliminary implementation for BotanicalNameParser.
647 // not yet complete
648 /**
649 * Returns the rank identified through an abbreviated representation.
650 * At the moment it uses the English abbreviations (being Latin because
651 * we do not have Latin representations yet.
652 * TODO
653 * If no according abbreviation is available it throws either an UnknownCdmTypeException
654 * or an #Rank.UNKNOWN() object depending on the useUnknown flag.
655 *
656 * @param idInVoc the string for the name abbreviation
657 * @param useUnknown if true the rank UNKNOWN_RANK is returned if the abbrev is
658 * unknown or not yet existent
659 * @return the rank
660 */
661 public static Rank getRankByIdInVoc(String idInVoc, boolean useUnknown) throws UnknownCdmTypeException{
662 Rank result = null;
663 if (idInVoc == null){
664 throw new NullPointerException("idInVoc is NULL in getRankByIdInVoc");
665 }
666 if (StringUtils.isBlank(idInVoc)){
667 //handle empty idInVoc as unknown
668 idInVoc = "oijas34\u0155";
669 }
670 if (idInVocMap == null){
671 return null;
672 }
673 idInVoc = normalizeSectionAndSubsection(idInVoc);
674 UUID uuid = idInVocMap.get(idInVoc);
675 if (uuid != null ){
676 result = getTermByUuid(uuid);
677 }
678 if (result != null){
679 return result;
680 }else {
681 if (idInVoc == null){
682 idInVoc = "(null)";
683 }
684 if (useUnknown){
685 logger.info("Unknown rank name: " + idInVoc + ". Rank 'UNKNOWN_RANK' created instead");
686 return Rank.UNKNOWN_RANK();
687 }else{
688 throw new UnknownCdmTypeException("Unknown rank abbreviation: " + idInVoc);
689 }
690 }
691 }
692
693 private static String normalizeSectionAndSubsection(String idInVoc) {
694 if (idInVoc.equals("sect.")){
695 return "sect.(bot.)";
696 }else if (idInVoc.equals("subsect.")){
697 return "subsect.(bot.)";
698 }
699 return idInVoc;
700 }
701
702 // TODO
703 // Preliminary implementation to cover Botany and Zoology.
704 /**
705 * Returns the rank identified through an abbreviated name for a given nomenclatural code.
706 * Preliminary implementation for ICBN and ICZN.
707 * See also {@link #getRankByIdInVoc(String, boolean)}
708
709 *
710 * @param abbrev the string for the name abbreviation
711 * @param nc the nomenclatural code
712 * @param useUnknown if true the rank UNKNOWN_RANK is returned if the abbrev is
713 * unknown or not yet implemented
714 * @return the rank
715 */
716 public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc, boolean useUnknown)
717 throws UnknownCdmTypeException{
718
719 if (nc != null && nc.equals(NomenclaturalCode.ICZN)) {
720 if (abbrev != null){
721 if (abbrev.equalsIgnoreCase("sect.")) {
722 return Rank.SECTION_ZOOLOGY();
723 } else if (abbrev.equalsIgnoreCase("subsect.")) {
724 return Rank.SUBSECTION_ZOOLOGY();
725 }
726 }
727 }
728 return getRankByIdInVoc(abbrev, useUnknown);
729 }
730
731 // TODO
732 // Preliminary implementation for BotanicalNameParser.
733 // not yet complete
734 /**
735 * Returns the rank identified through a name.
736 * Preliminary implementation for BotanicalNameParser.
737 *
738 * @param rankName the string for the name of the rank
739 * @return the rank
740 */
741 public static Rank getRankByName(String rankName) throws UnknownCdmTypeException{
742 return getRankByName(rankName, false);
743 }
744
745
746 // TODO
747 // Preliminary implementation for ICBN and ICZN.
748 // not yet complete
749 /**
750 * Returns the rank identified through a name for a given nomenclatural code.
751 * Preliminary implementation for ICBN and ICZN.
752 *
753 * @param rankName the string for the name of the rank
754 * @param nc the nomenclatural code
755 * @return the rank
756 */
757 public static Rank getRankByName(String rankName, NomenclaturalCode nc) throws UnknownCdmTypeException{
758 return getRankByName(rankName, nc, false);
759 }
760
761 /**
762 * Returns the rank identified through a name.
763 * Preliminary implementation for BotanicalNameParser.
764 * TODO At the moment we do not have Latin representations yet.
765 *
766 * @param rankName the string for the name of the rank
767 * @param useUnknown if true the rank UNKNOWN_RANK is returned if the rank name is
768 * unknown or not yet implemented
769 * @return the rank
770 */
771 public static Rank getRankByName(String rankName, boolean useUnknown)
772 throws UnknownCdmTypeException{
773 if (rankName.equalsIgnoreCase("Regnum")){ return Rank.KINGDOM();
774 }else if (rankName.equalsIgnoreCase("Subregnum")){ return Rank.SUBKINGDOM();
775 }else if (rankName.equalsIgnoreCase("Phylum")){ return Rank.PHYLUM();
776 }else if (rankName.equalsIgnoreCase("Subphylum")){ return Rank.SUBPHYLUM();
777 }else if (rankName.equalsIgnoreCase("Divisio")){ return Rank.DIVISION();
778 }else if (rankName.equalsIgnoreCase("Subdivisio")){ return Rank.SUBDIVISION();
779 }else if (rankName.equalsIgnoreCase("Classis")){ return Rank.CLASS();
780 }else if (rankName.equalsIgnoreCase("Subclassis")){ return Rank.SUBCLASS();
781 }else if (rankName.equalsIgnoreCase("Superordo")){ return Rank.SUPERORDER();
782 }else if (rankName.equalsIgnoreCase("Ordo")){ return Rank.ORDER();
783 }else if (rankName.equalsIgnoreCase("Subordo")){ return Rank.SUBORDER();
784 }else if (rankName.equalsIgnoreCase("Familia")){ return Rank.FAMILY();
785 }else if (rankName.equalsIgnoreCase("Subfamilia")){ return Rank.SUBFAMILY();
786 }else if (rankName.equalsIgnoreCase("Tribus")){ return Rank.TRIBE();
787 }else if (rankName.equalsIgnoreCase("Subtribus")){ return Rank.SUBTRIBE();
788 }else if (rankName.equalsIgnoreCase("Genus")){ return Rank.GENUS();
789 }else if (rankName.equalsIgnoreCase("Subgenus")){ return Rank.SUBGENUS();
790 }else if (rankName.equalsIgnoreCase("Sectio")){ return Rank.SECTION_BOTANY();
791 }else if (rankName.equalsIgnoreCase("Subsectio")){ return Rank.SUBSECTION_BOTANY();
792 }else if (rankName.equalsIgnoreCase("Series")){ return Rank.SERIES();
793 }else if (rankName.equalsIgnoreCase("Subseries")){ return Rank.SUBSERIES();
794 }else if (rankName.equalsIgnoreCase("Aggregate")){ return Rank.SPECIESAGGREGATE();
795 }else if (rankName.equalsIgnoreCase("Speciesgroup")){ return Rank.SPECIESGROUP();
796 }else if (rankName.equalsIgnoreCase("Species")){ return Rank.SPECIES();
797 }else if (rankName.equalsIgnoreCase("Subspecies")){ return Rank.SUBSPECIES();
798 }else if (rankName.equalsIgnoreCase("Convarietas")){ return Rank.CONVAR();
799 }else if (rankName.equalsIgnoreCase("Varietas")){ return Rank.VARIETY();
800 }else if (rankName.equalsIgnoreCase("Subvarietas")){ return Rank.SUBVARIETY();
801 }else if (rankName.equalsIgnoreCase("Forma")){ return Rank.FORM();
802 }else if (rankName.equalsIgnoreCase("Subforma")){ return Rank.SUBFORM();
803 }else if (rankName.equalsIgnoreCase("Forma spec.")){ return Rank.SPECIALFORM();
804 }else if (rankName.equalsIgnoreCase("tax.infragen.")){ return Rank.INFRAGENERICTAXON();
805 }else if (rankName.equalsIgnoreCase("tax.infrasp.")){ return Rank.INFRASPECIFICTAXON();
806 // old ranks
807 }else if (rankName.equalsIgnoreCase("proles")){ return Rank.PROLES();
808 }else if (rankName.equalsIgnoreCase("race")){ return Rank.RACE();
809 }else if (rankName.equalsIgnoreCase("sublusus")){ return Rank.SUBLUSUS();
810
811 }else if (rankName.equalsIgnoreCase("taxon")){ return Rank.INFRASPECIFICTAXON(); //to create the name put 'taxon' and the infraspeciesepi to the field unnamed namephrase
812
813 }else{
814 if (rankName == null){
815 rankName = "(null)"; //see NPE above
816 }
817 if (useUnknown){
818 logger.info("Unknown rank name: " + rankName+". Rank 'UNKNOWN_RANK' created instead");
819 return Rank.UNKNOWN_RANK();
820 }else{
821 throw new UnknownCdmTypeException("Unknown rank name: " + rankName);
822 }
823 }
824 }
825
826 /**
827 * Defines the rank according to the English name.
828 * @param rankName English rank name.
829 * @param nc Defines the handling of the section and subsection ranks. These are in different orders depending on the
830 * nomenclatural code.
831 * @param useUnknown if true, the "Unknown" rank is returned as a placeholder.
832 * @return
833 * @throws UnknownCdmTypeException never thrown if useUnknown is true
834 */
835 public static Rank getRankByEnglishName(String rankName, NomenclaturalCode nc, boolean useUnknown) throws UnknownCdmTypeException{
836 Rank result = null;
837 if (rankName == null){
838 throw new NullPointerException("Abbrev is NULL in getRankByAbbreviation");
839 }
840 if (labelMap == null){
841 return null;
842 }
843 //handle section and subsection (not unique representations)
844 if (rankName.equalsIgnoreCase("Section")){
845 if (nc != null && nc.equals(NomenclaturalCode.ICZN)){ return Rank.SECTION_ZOOLOGY();
846 }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)){return Rank.SECTION_BOTANY();
847 }else{
848 String errorWarning = "Section is only defined for ICZN and ICNAFP at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
849 logger.warn(errorWarning);
850 throw new UnknownCdmTypeException (errorWarning);
851 }
852 }else if (rankName.equalsIgnoreCase("Subsection")){
853 if (nc != null && nc.equals(NomenclaturalCode.ICZN)){ return Rank.SUBSECTION_ZOOLOGY();
854 }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)){ return Rank.SUBSECTION_BOTANY();
855 }else{
856 String errorWarning = "Subsection is only defined for ICZN and ICBN at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
857 logger.warn(errorWarning);
858 throw new UnknownCdmTypeException (errorWarning);
859 }
860 }
861
862 rankName = rankName.toLowerCase();
863
864 UUID uuid = labelMap.get(rankName);
865 if (uuid != null ){
866 result = getTermByUuid(uuid);
867 }
868 if (result != null){
869 return result;
870 }else {
871 if (rankName == null){
872 rankName = "(null)";
873 }
874 if (useUnknown){
875 logger.info("Unknown rank name: " + rankName + ". Rank 'UNKNOWN_RANK' created instead");
876 return Rank.UNKNOWN_RANK();
877 }else{
878 throw new UnknownCdmTypeException("Unknown rank: " + rankName);
879 }
880 }
881 }
882
883
884 public static Rank getRankByName(String rankName, NomenclaturalCode nc, boolean useUnknown)
885 throws UnknownCdmTypeException {
886
887 if (nc.equals(NomenclaturalCode.ICZN)) {
888 if (rankName.equalsIgnoreCase("Sectio")) { return Rank.SECTION_ZOOLOGY();
889 }else if (rankName.equalsIgnoreCase("Subsectio")) { return Rank.SUBSECTION_ZOOLOGY();
890 }
891 }
892 return getRankByName(rankName, useUnknown);
893 }
894
895 /**
896 * Returns the abbreviated rank name for <i>this</i> rank according to the English representation
897 * abbreviated label.
898 * TODO Needs to be changed to Latin as soon as Latin representations are available.
899 *
900 * @return the abbreviation string for <i>this</i> rank
901 */
902 public String getAbbreviation(){
903 Language language = Language.ENGLISH();
904 String result = this.getRepresentation(language).getAbbreviatedLabel();
905 if (result== null) {
906 logger.warn("Abbreviation for this Rank " + this.toString() + " not yet implemented");
907 return "no abbreviation available.";
908 }else{
909 return result;
910 }
911 }
912 @Transient
913 public String getInfraGenericMarker() throws UnknownCdmTypeException{
914 String result = null;
915 if (! this.isInfraGeneric()){
916 throw new IllegalStateException("An infrageneric marker is only available for a infrageneric rank but was asked for rank: " + this.toString());
917 }else{
918 result = this.getAbbreviation();
919 }
920 if (result == null){
921 throw new UnknownCdmTypeException("Abbreviation for rank unknown: " + this.toString());
922 }
923 return result;
924 }
925
926
927
928 @Override
929 public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, Map<UUID, DefinedTermBase> terms, boolean abbrevAsId) {
930 Rank rank = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
931 RankClass rankClass = RankClass.getByKey(csvLine.get(5));
932 assert rankClass != null: "XXXXXXXXXXXXXXXXXXXXX Rank class must not be null: " + csvLine ;
933 rank.setRankClass(rankClass);
934 return rank;
935 }
936
937 @Override
938 protected void setDefaultTerms(TermVocabulary<Rank> termVocabulary) {
939 termMap = new HashMap<UUID, Rank>();
940 for (Rank term : termVocabulary.getTerms()){
941 termMap.put(term.getUuid(), (Rank)term);
942 addRank(term);
943 }
944 }
945
946 /**
947 * @param term
948 */
949 private void addRank(Rank rank) {
950 if (rank == null){
951 logger.warn("rank is NULL");
952 return;
953 }
954 if (rank.getUuid().equals(uuidSectionZoology) || rank.getUuid().equals(uuidSubsectionZoology )){
955 //sect./subsect. is used for botanical sections, see also #getRankByAbbreviation(String, NomenclaturalCode, boolean)
956 return;
957 }
958 Language lang = Language.DEFAULT(); //TODO should be Latin but at the moment we have only English representations
959 Representation representation = rank.getRepresentation(lang);
960 String abbrevLabel = representation.getAbbreviatedLabel();
961 String label = representation.getLabel();
962
963 //initialize maps
964 if (idInVocMap == null){
965 idInVocMap = new HashMap<String, UUID>();
966 }
967 if (labelMap == null){
968 labelMap = new HashMap<String, UUID>();
969 }
970 labelMap.put(label.toLowerCase(), rank.getUuid());
971 //add to map
972 if (StringUtils.isBlank(abbrevLabel)){
973 logger.info("Abbreviated label for rank is NULL or empty.Can't add rank to abbrevLabel map: " + CdmUtils.Nz(rank.getLabel()));
974 }else{
975 idInVocMap.put(abbrevLabel, rank.getUuid());
976 }
977 }
978
979
980 /**
981 * It is necessary to skip the vocabulary check, otherwise we would have
982 * problems in some CacheStrategies, due to uninitialized Vocabularies.
983 *
984 * @see eu.etaxonomy.cdm.model.common.OrderedTermBase#compareTo(eu.etaxonomy.cdm.model.common.OrderedTermBase)
985 */
986 @Override
987 public int compareTo(Rank orderedTerm) {
988 return performCompareTo(orderedTerm, true);
989 }
990
991 }