Project

General

Profile

Download (43.4 KB) Statistics
| Branch: | Tag: | Revision:
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

    
30
import eu.etaxonomy.cdm.common.CdmUtils;
31
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
32
import eu.etaxonomy.cdm.model.common.Language;
33
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
34
import eu.etaxonomy.cdm.model.common.Representation;
35
import eu.etaxonomy.cdm.model.common.TermType;
36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
37
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
38

    
39
/**
40
 * The class representing the taxonomical ranks (like "Family", "Genus" or
41
 * "Species") used for {@link TaxonName taxon names} across all {@link NomenclaturalCode nomenclatural codes}
42
 * for bacteria (ICNB), viruses (ICVCN), plants and fungi (ICBN),
43
 * cultivars (ICNCP) and animals (ICZN).
44
 * <P>
45
 * A standard (ordered) list of taxonomical rank instances will be automatically
46
 * created as the project starts. But this class allows to extend this standard
47
 * list by creating new instances of additional taxonomical ranks if needed.
48
 * <P>
49
 * This class corresponds to: <ul>
50
 * <li> TaxonRankTerm according to the TDWG ontology
51
 * <li> TaxonomicRankEnum according to the TCS
52
 * <li> Rank according to the ABCD schema
53
 * </ul>
54
 *
55
 * @author m.doering
56
 * @created 08-Nov-2007 13:06:46
57
 */
58
@XmlAccessorType(XmlAccessType.FIELD)
59
@XmlType(name = "Rank")
60
@Entity
61
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
62
//@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
63
@Audited
64
public class Rank extends OrderedTermBase<Rank> {
65
    private static final long serialVersionUID = -8648081681348758485L;
66
    private static final Logger logger = Logger.getLogger(Rank.class);
67

    
68
    private static final UUID uuidEmpire = UUID.fromString("ac470211-1586-4b24-95ca-1038050b618d");
69
    private static final UUID uuidDomain = UUID.fromString("ffca6ec8-8b88-417b-a6a0-f7c992aac19b");
70
    private static final UUID uuidSuperkingdom = UUID.fromString("64223610-7625-4cfd-83ad-b797bf7f0edd");
71
    private static final UUID uuidKingdom = UUID.fromString("fbe7109d-66b3-498c-a697-c6c49c686162");
72
    private static final UUID uuidSubkingdom = UUID.fromString("a71bd9d8-f3ab-4083-afb5-d89315d71655");
73
    private static final UUID uuidInfrakingdom = UUID.fromString("1e37930c-86cf-44f6-90fd-7822928df260");
74
    private static final UUID uuidSuperphylum = UUID.fromString("0d0cecb1-e254-4607-b210-6801e7ecbb04");
75
    private static final UUID uuidPhylum = UUID.fromString("773430d2-76b4-438c-b817-97a543a33287");
76
    private static final UUID uuidSubphylum = UUID.fromString("23a9b6ff-9408-49c9-bd9e-7a2ca5ab4725");
77
    private static final UUID uuidInfraphylum = UUID.fromString("1701de3a-7693-42a5-a2d3-42697f944190");
78
    private static final UUID uuidSuperdivision = UUID.fromString("a735a48f-4fc8-49a7-ae0c-6a984f658131");
79
    private static final UUID uuidDivision = UUID.fromString("7e56f5cc-123a-4fd1-8cbb-6fd80358b581");
80
    private static final UUID uuidSubdivision = UUID.fromString("931c840f-7a6b-4d76-ad38-bfdd77d7b2e8");
81
    private static final UUID uuidInfradivision = UUID.fromString("c0ede273-be52-4dee-b411-66ee08d30c94");
82
    private static final UUID uuidSuperclass = UUID.fromString("e65b4e1a-21ec-428d-9b9f-e87721ab967c");
83
    private static final UUID uuidClass = UUID.fromString("f23d14c4-1d34-4ee6-8b4e-eee2eb9a3daf");
84
    private static final UUID uuidSubclass = UUID.fromString("8cb26733-e2f5-46cb-ab5c-f99254f877aa");
85
    private static final UUID uuidInfraclass = UUID.fromString("ad23cfda-879a-4021-8629-c54d27caf717");
86
    private static final UUID uuidSuperorder = UUID.fromString("c8c67a22-301a-4219-b882-4a49121232ff");
87
    private static final UUID uuidOrder = UUID.fromString("b0785a65-c1c1-4eb4-88c7-dbd3df5aaad1");
88
    private static final UUID uuidSuborder = UUID.fromString("768ad378-fa85-42ab-b668-763225832f57");
89
    private static final UUID uuidInfraorder = UUID.fromString("84099182-a6f5-47d7-8586-33c9e9955a10");
90
    private static final UUID uuidSectionZoology = UUID.fromString("691d371e-10d7-43f0-93db-3d7fa1a62c54");
91
    private static final UUID uuidSubsectionZoology = UUID.fromString("0ed32d28-adc4-4303-a9ca-68e2acd67e33");
92
    private static final UUID uuidSuperfamily = UUID.fromString("2cfa510a-dcea-4a03-b66a-b1528f9b0796");
93
    private static final UUID uuidFamily = UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6");
94
    private static final UUID uuidSubfamily = UUID.fromString("862526ee-7592-4760-a23a-4ff3641541c5");
95
    private static final UUID uuidInfrafamily = UUID.fromString("c3f2e3bb-6eef-4a26-9fb7-b14f4c8c5e4f");
96
    private static final UUID uuidSupertribe = UUID.fromString("11e94828-8c61-499b-87d6-1de35ce2c51c");
97
    private static final UUID uuidTribe = UUID.fromString("4aa6890b-0363-4899-8d7c-ee0cb78e6166");
98
    private static final UUID uuidSubtribe = UUID.fromString("ae41ecc5-5165-4126-9d24-79939ae5d822");
99
    private static final UUID uuidInfratribe = UUID.fromString("1ec02e8f-f2b7-4c65-af9f-b436b34c79a3");
100
    private static final UUID uuidSupragenericTaxon = UUID.fromString("1fdc0b93-c354-441a-8406-091e0303ff5c");
101
    public static final UUID uuidGenus = UUID.fromString("1b11c34c-48a8-4efa-98d5-84f7f66ef43a");
102
    private static final UUID uuidSubgenus = UUID.fromString("78786e16-2a70-48af-a608-494023b91904");
103
    private static final UUID uuidInfragenus = UUID.fromString("a9972969-82cd-4d54-b693-a096422f13fa");
104
    private static final UUID uuidSectionBotany = UUID.fromString("3edff68f-8527-49b5-bf91-7e4398bb975c");
105
    private static final UUID uuidSubsectionBotany = UUID.fromString("d20f5b61-d463-4448-8f8a-c1ff1f262f59");
106
    private static final UUID uuidSeries = UUID.fromString("d7381ecf-48f8-429b-9c54-f461656978cd");
107
    private static final UUID uuidSubseries = UUID.fromString("80c9a263-f4db-4a13-b6c2-b7fec1aa1200");
108
    private static final UUID uuidSpeciesAggregate = UUID.fromString("1ecae058-4217-4f75-9c27-6d8ba099ac7a");
109
    private static final UUID uuidSpeciesGroup = UUID.fromString("d1988a11-292b-46fa-8fb7-bc64ea6d8fc6");
110
    public static final UUID uuidInfragenericTaxon = UUID.fromString("41bcc6ac-37d3-4fd4-bb80-3cc5b04298b9");
111
    public static final UUID uuidSpecies = UUID.fromString("b301f787-f319-4ccc-a10f-b4ed3b99a86d");
112
    private static final UUID uuidSubspecificAggregate = UUID.fromString("72c248b9-027d-4402-b375-dd4f0850c9ad");
113
    private static final UUID uuidSubspecies = UUID.fromString("462a7819-8b00-4190-8313-88b5be81fad5");
114
    private static final UUID uuidInfraspecies = UUID.fromString("f28ebc9e-bd50-4194-9af1-42f5cb971a2c");
115
    private static final UUID uuidNatio = UUID.fromString("965f2f38-7f97-4270-ab5a-1999bf050a22");
116
    private static final UUID uuidVariety = UUID.fromString("d5feb6a5-af5c-45ef-9878-bb4f36aaf490");
117
    private static final UUID uuidBioVariety = UUID.fromString("a3a364cb-1a92-43fc-a717-3c44980a0991");
118
    private static final UUID uuidPathoVariety = UUID.fromString("2f4f4303-a099-47e3-9048-d749d735423b");
119
    private static final UUID uuidSubvariety = UUID.fromString("9a83862a-7aee-480c-a98d-4bceaf8712ca");
120
    private static final UUID uuidSubsubvariety = UUID.fromString("bff22f84-553a-4429-a4e7-c4b3796c3a18");
121

    
122
    private static final UUID uuidProles = UUID.fromString("8810d1ba-6a34-4ae3-a355-919ccd1cd1a5");
123
    private static final UUID uuidRace = UUID.fromString("196dee39-cfd8-4460-8bf0-88b83da27f62");
124
    private static final UUID uuidSublusus = UUID.fromString("1fafa596-a8e7-4e62-a378-3cc8cb3627ca");
125

    
126
    private static final UUID uuidConvar = UUID.fromString("2cc740c9-cebb-43c8-9b06-1bef79e6a56a");
127
    private static final UUID uuidForm = UUID.fromString("0461281e-458a-47b9-8d41-19a3d39356d5");
128
    private static final UUID uuidSpecialForm = UUID.fromString("bed20aee-2f5a-4635-9c02-eff06246d067");
129
    private static final UUID uuidSubform = UUID.fromString("47cfc5b0-0fb7-4ceb-b61d-e1dd8de8b569");
130
    private static final UUID uuidSubsubform = UUID.fromString("1c8ac389-4349-4ae0-87be-7239f6635068");
131
    public static final UUID uuidInfraspecificTaxon = UUID.fromString("eb75c27d-e154-4570-9d96-227b2df60474");
132
    private static final UUID uuidCandidate = UUID.fromString("ead9a1f5-dfd4-4de2-9121-70a47accb10b");
133
    private static final UUID uuidDenominationClass = UUID.fromString("49bdf74a-2170-40ed-8be2-887a0db517bf");
134
    private static final UUID uuidGrex = UUID.fromString("08dcb4ff-ac58-48a3-93af-efb3d836ac84");
135
    private static final UUID uuidGraftChimaera = UUID.fromString("6b4063bc-f934-4796-9bf3-0ef3aea5c1cb");
136
    private static final UUID uuidCultivarGroup = UUID.fromString("d763e7d3-e7de-4bb1-9d75-225ca6948659");
137
    private static final UUID uuidCultivar = UUID.fromString("5e98415b-dc6e-440b-95d6-ea33dbb39ad0");
138
    private static final UUID uuidUnknownRank = UUID.fromString("5c4d6755-2cf6-44ca-9220-cccf8881700b");
139

    
140
    private static Map<String, UUID> idInVocMap = null;
141
    private static Map<String, UUID> labelMap = null;
142

    
143
    protected static Map<UUID, Rank> termMap = null;
144

    
145
//*********************** Factory methods ********************************************/
146

    
147
//    /**
148
//     * Creates a new empty rank.
149
//     *
150
//     * @see #NewInstance(String, String, String)
151
//     */
152
//    private static Rank NewInstance(){
153
//        return new Rank();
154
//    }
155

    
156
    /**
157
     * Creates an additional rank with a description (in the {@link Language#DEFAULT() default language}),
158
     * a label and a label abbreviation.
159
     *
160
     * @param	term  		 the string (in the default language) describing the
161
     * 						 new rank to be created
162
     * @param	label  		 the string identifying the new rank to be created
163
     * @param	labelAbbrev  the string identifying (in abbreviated form) the
164
     * 						 new rank to be created
165
     * @see 				 #NewInstance()
166
     */
167
    public static Rank NewInstance(RankClass rankClass, String term, String label, String labelAbbrev){
168
        return new Rank(rankClass, term, label, labelAbbrev);
169
    }
170

    
171
    /**
172
     * The {@link RankClass rank class} of a rank. It is usually needed for correct formatting of a
173
     * rank by using e.g. isSupraGeneric(). Prior to v3.3 this was computed by comparison of ranks.
174
     */
175
    @XmlAttribute(name ="RankClass")
176
    @NotNull
177
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
178
        parameters = {@org.hibernate.annotations.Parameter(name="enumClass", value="eu.etaxonomy.cdm.model.name.RankClass")}
179
    )
180
    @Audited
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 || termMap.isEmpty()){
223
           return getTermByClassAndUUID(Rank.class, uuid);
224
        } else {
225
            return termMap.get(uuid);
226
        }
227
    }
228

    
229
    public static final Rank EMPIRE(){
230
      return getTermByUuid(uuidEmpire);
231
    }
232
    public static final Rank DOMAIN(){
233
          return getTermByUuid(uuidDomain);
234
    }
235
    public static final Rank SUPERKINGDOM(){
236
        return getTermByUuid(uuidSuperkingdom);
237
    }
238
    public static final Rank KINGDOM(){
239
        return getTermByUuid(uuidKingdom);
240
    }
241
    public static final Rank SUBKINGDOM(){
242
        return getTermByUuid(uuidSubkingdom);
243
    }
244
    public static final Rank INFRAKINGDOM(){
245
        return getTermByUuid(uuidInfrakingdom);
246
    }
247
    public static final Rank SUPERPHYLUM(){
248
        return getTermByUuid(uuidSuperphylum);
249
    }
250
    public static final Rank PHYLUM(){
251
        return getTermByUuid(uuidPhylum);
252
    }
253
    public static final Rank SUBPHYLUM(){
254
        return getTermByUuid(uuidSubphylum);
255
    }
256
    public static final Rank INFRAPHYLUM(){
257
        return getTermByUuid(uuidInfraphylum);
258
    }
259
    public static final Rank SUPERDIVISION(){
260
        return getTermByUuid(uuidSuperdivision);
261
    }
262
    public static final Rank DIVISION(){
263
        return getTermByUuid(uuidDivision);
264
    }
265
    public static final Rank SUBDIVISION(){
266
        return getTermByUuid(uuidSubdivision);
267
    }
268
    public static final Rank INFRADIVISION(){
269
        return getTermByUuid(uuidInfradivision);
270
    }
271
    public static final Rank SUPERCLASS(){
272
        return getTermByUuid(uuidSuperclass);
273
    }
274
    public static final Rank CLASS(){
275
        return getTermByUuid(uuidClass);
276
    }
277
    public static final Rank SUBCLASS(){
278
        return getTermByUuid(uuidSubclass);
279
    }
280
    public static final Rank INFRACLASS(){
281
        return getTermByUuid(uuidInfraclass);
282
    }
283
    public static final Rank SUPERORDER(){
284
        return getTermByUuid(uuidSuperorder);
285
    }
286
    public static final Rank ORDER(){
287
        return getTermByUuid(uuidOrder);
288
    }
289
    public static final Rank SUBORDER(){
290
        return getTermByUuid(uuidSuborder);
291
    }
292
    public static final Rank INFRAORDER(){
293
        return getTermByUuid(uuidInfraorder);
294
    }
295
    public static final Rank SUPERFAMILY(){
296
        return getTermByUuid(uuidSuperfamily);
297
    }
298
    public static final Rank FAMILY(){
299
        return getTermByUuid(uuidFamily);
300
    }
301
    public static final Rank SUBFAMILY(){
302
        return getTermByUuid(uuidSubfamily);
303
    }
304
    public static final Rank INFRAFAMILY(){
305
        return getTermByUuid(uuidInfrafamily);
306
    }
307
    public static final Rank SUPERTRIBE(){
308
        return getTermByUuid(uuidSupertribe);
309
    }
310
    public static final Rank TRIBE(){
311
        return getTermByUuid(uuidTribe);
312
    }
313
    public static final Rank SUBTRIBE(){
314
        return getTermByUuid(uuidSubtribe);
315
    }
316
    public static final Rank INFRATRIBE(){
317
        return getTermByUuid(uuidInfratribe);
318
    }
319
    public static final Rank SUPRAGENERICTAXON(){
320
        return getTermByUuid(uuidSupragenericTaxon);
321
    }
322
    public static final Rank GENUS(){
323
        return getTermByUuid(uuidGenus);
324
    }
325
    public static final Rank SUBGENUS(){
326
        return getTermByUuid(uuidSubgenus);
327
    }
328
    public static final Rank INFRAGENUS(){
329
        return getTermByUuid(uuidInfragenus);
330
    }
331
    public static final Rank SECTION_BOTANY(){
332
        return getTermByUuid(uuidSectionBotany);
333
    }
334
    public static final Rank SUBSECTION_BOTANY(){
335
        return getTermByUuid(uuidSubsectionBotany);
336
    }
337
    public static final Rank SECTION_ZOOLOGY(){
338
        return getTermByUuid(uuidSectionZoology);
339
    }
340
    public static final Rank SUBSECTION_ZOOLOGY(){
341
        return getTermByUuid(uuidSubsectionZoology);
342
    }
343
    public static final Rank SERIES(){
344
        return getTermByUuid(uuidSeries);
345
    }
346
    public static final Rank SUBSERIES(){
347
        return getTermByUuid(uuidSubseries);
348
    }
349
    public static final Rank SPECIESAGGREGATE(){
350
        return getTermByUuid(uuidSpeciesAggregate);
351
    }
352
    public static final Rank SPECIESGROUP(){
353
        return getTermByUuid(uuidSpeciesGroup);
354
    }
355
    /**
356
     * 'Unranked infrageneric'. An infrageneric rank which is on purpose not further defined.
357
     * This sometimes holds for names from the 19th century.
358
     */
359
    public static final Rank INFRAGENERICTAXON(){
360
        return getTermByUuid(uuidInfragenericTaxon);
361
    }
362
    public static final Rank SPECIES(){
363
        return getTermByUuid(uuidSpecies);
364
    }
365
    public static final Rank SUBSPECIFICAGGREGATE(){
366
        return getTermByUuid(uuidSubspecificAggregate);
367
    }
368
    public static final Rank SUBSPECIES(){
369
        return getTermByUuid(uuidSubspecies);
370
    }
371
    public static final Rank INFRASPECIES(){
372
        return getTermByUuid(uuidInfraspecies);
373
    }
374
    public static final Rank VARIETY(){
375
        return getTermByUuid(uuidVariety);
376
    }
377
    public static final Rank BIOVARIETY(){
378
        return getTermByUuid(uuidBioVariety);
379
    }
380
    public static final Rank PATHOVARIETY(){
381
        return getTermByUuid(uuidPathoVariety);
382
    }
383
    public static final Rank SUBVARIETY(){
384
        return getTermByUuid(uuidSubvariety);
385
    }
386
    public static final Rank SUBSUBVARIETY(){
387
        return getTermByUuid(uuidSubsubvariety );
388
    }
389
    public static final Rank PROLES(){
390
        return getTermByUuid(uuidProles);
391
    }
392
    public static final Rank RACE(){
393
        return getTermByUuid(uuidRace);
394
    }
395
    public static final Rank SUBLUSUS(){
396
        return getTermByUuid(uuidSublusus);
397
    }
398

    
399
    public static final Rank CONVAR(){
400
        return getTermByUuid(uuidConvar);
401
    }
402
    public static final Rank FORM(){
403
        return getTermByUuid(uuidForm);
404
    }
405
    public static final Rank SPECIALFORM(){
406
        return getTermByUuid(uuidSpecialForm);
407
    }
408
    public static final Rank SUBFORM(){
409
        return getTermByUuid(uuidSubform);
410
    }
411
    public static final Rank SUBSUBFORM(){
412
        return getTermByUuid(uuidSubsubform);
413
    }
414
    /**
415
     * 'Unranked infraspecific'. An infraspecific rank which is on purpose not further defined.
416
     * This sometimes holds for names from the 19th century.
417
     */
418
    public static final Rank INFRASPECIFICTAXON(){
419
        return getTermByUuid(uuidInfraspecificTaxon);
420
    }
421
    public static final Rank CANDIDATE(){
422
        return getTermByUuid(uuidCandidate);
423
    }
424
    public static final Rank DENOMINATIONCLASS(){
425
        return getTermByUuid(uuidDenominationClass);
426
    }
427
    public static final Rank GREX(){
428
        return getTermByUuid(uuidGrex);
429
    }
430
    public static final Rank GRAFTCHIMAERA(){
431
        return getTermByUuid(uuidGraftChimaera);
432
    }
433
    public static final Rank CULTIVARGROUP(){
434
        return getTermByUuid(uuidCultivarGroup);
435
    }
436
    public static final Rank CULTIVAR(){
437
        return getTermByUuid(uuidCultivar);
438
    }
439
    public static final Rank UNKNOWN_RANK(){
440
        return getTermByUuid(uuidUnknownRank);
441
    }
442
    public static final Rank NATIO(){
443
        return getTermByUuid(uuidNatio);
444
    }
445
    /**
446
     * @see #INFRASPECIFICTAXON()
447
     */
448
    public static final Rank UNRANKED_INFRASPECIFIC(){
449
        return getTermByUuid(uuidInfraspecificTaxon);
450
    }
451
    /**
452
     * @see #INFRAGENERICTAXON()
453
     */
454
    public static final Rank UNRANKED_INFRAGENERIC(){
455
        return getTermByUuid(uuidInfragenericTaxon);
456
    }
457

    
458
// ************************ GETTER / SETTER **********************************/
459

    
460
    public RankClass getRankClass() {
461
        return rankClass;
462
    }
463

    
464
    public void setRankClass(RankClass rankClass) {
465
        this.rankClass = rankClass;
466
    }
467

    
468
// ******************************** METHODS ***************************************/
469

    
470
    /**
471
     * Returns the boolean value indicating whether <i>this</i> rank is higher than
472
     * the genus rank (true) or not (false). Returns false if <i>this</i> rank is null.
473
     *
474
     * @see  #isGenus()
475
     * @see  #isInfraGeneric()
476
     * @see  #isSpecies()
477
     * @see  #isInfraSpecific()
478
     */
479
    @Transient
480
    public boolean isSupraGeneric(){
481
        return this.rankClass.equals(RankClass.Suprageneric); // (this.isHigher(Rank.GENUS()));
482
    }
483

    
484
    /**
485
     * Returns the boolean value indicating whether <i>this</i> rank is the genus rank
486
     * (true) or not (false). Returns false if <i>this</i> rank is null.
487
     *
488
     * @see  #isSupraGeneric()
489
     * @see  #isInfraGeneric()
490
     * @see  #isSpecies()
491
     * @see  #isInfraSpecific()
492
     */
493
    @Transient
494
    public boolean isGenus(){
495
        return this.rankClass.equals(RankClass.Genus); // (this.equals(Rank.GENUS()));
496
    }
497

    
498
    /**
499
     * Returns the boolean value indicating whether <i>this</i> rank is higher than the
500
     * species rank and lower than the genus rank (true) or not (false). Species groups or
501
     * aggregates are also handled as infrageneric ranks.
502
     * Returns false if <i>this</i> rank is null.
503
     *
504
     * @see  #isSupraGeneric()
505
     * @see  #isGenus()
506
     * @see  #isInfraGenericButNotSpeciesGroup()
507
     * @see  #isSpeciesAggregate()
508
     * @see  #isSpecies()
509
     * @see  #isInfraSpecific()
510
     */
511
    @Transient
512
    public boolean isInfraGeneric(){
513
        return this.rankClass.equals(RankClass.Infrageneric) || this.rankClass.equals(RankClass.SpeciesGroup) ; //(this.isLower(Rank.GENUS()) && this.isHigher(Rank.SPECIES()));
514
    }
515

    
516
    /**
517
     * Returns the boolean value indicating whether <i>this</i> rank is higher than the
518
     * species aggregate/group rank and lower than the genus rank (true) or not (false).
519
     * Returns false if <i>this</i> rank is null.
520
     *
521
     * @see  #isSupraGeneric()
522
     * @see  #isGenus()
523
     * @see  #isInfraGeneric()
524
     * @see  #isSpeciesAggregate()
525
     * @see  #isSpecies()
526
     * @see  #isInfraSpecific()
527
     */
528
    @Transient
529
    public boolean isInfraGenericButNotSpeciesGroup(){
530
        return this.rankClass.equals(RankClass.Infrageneric) ;
531
    }
532

    
533
    /**
534
     * Returns true if this rank indicates a rank that aggregates species
535
     * like species aggregates or species groups, false otherwise.
536
     * @return
537
     */
538
    @Transient
539
    public boolean isSpeciesAggregate(){
540
        return this.rankClass.equals(RankClass.SpeciesGroup); //(this.equals(Rank.SPECIESAGGREGATE()) || (this.isLower(Rank.SPECIESAGGREGATE()) && this.isHigher(Rank.SPECIES())));
541
    }
542

    
543
    /**
544
     * Returns the boolean value indicating whether <i>this</i> rank is the species
545
     * rank (true) or not (false). Returns false if <i>this</i> rank is null.
546
     *
547
     * @see  #isSupraGeneric()
548
     * @see  #isGenus()
549
     * @see  #isInfraGeneric()
550
     * @see  #isInfraSpecific()
551
     */
552
    @Transient
553
    public boolean isSpecies(){
554
        return this.rankClass.equals(RankClass.Species); //(this.equals(Rank.SPECIES()));
555
    }
556

    
557
    /**
558
     * Returns the boolean value indicating whether <i>this</i> rank is lower than the
559
     * species rank (true) or not (false). Returns false if <i>this</i> rank is null.
560
     *
561
     * @see  #isSupraGeneric()
562
     * @see  #isGenus()
563
     * @see  #isInfraGeneric()
564
     * @see  #isSpecies()
565
     */
566
    @Transient
567
    public boolean isInfraSpecific(){
568
        return this.rankClass.equals(RankClass.Infraspecific); // (this.isLower(Rank.SPECIES()));
569
    }
570

    
571

    
572
    /**
573
     * Returns the rank identified through a label or the identifier within the vocabulary
574
     * Preliminary implementation for BotanicalNameParser.
575
     *
576
     * @param	strRank	the string identifying the rank
577
     * @return  		the rank
578
     */
579
    public static Rank getRankByNameOrIdInVoc(String strRank) throws UnknownCdmTypeException{
580
        return getRankByNameOrIdInVoc(strRank, false);
581
    }
582

    
583
    /**
584
     * Returns the rank identified through a label or the identifier within the vocabulary
585
     * for a given nomenclatural code.
586
     * Preliminary implementation for BotanicalNameParser.
587
     *
588
     * @param	strRank	the string identifying the rank
589
     * @param   nc      the nomenclatural code
590
     * @return  		the rank
591
     */
592
    public static Rank getRankByNameOrIdInVoc(String strRank, NomenclaturalCode nc) throws UnknownCdmTypeException{
593
        return getRankByNameOrIdInVoc(strRank, nc, false);
594
    }
595

    
596
    // TODO
597
    // Preliminary implementation for BotanicalNameParser.
598
    // not yet complete
599
    /**
600
     * Returns the rank identified through a label or the identifier within the vocabulary.
601
     * Preliminary implementation for BotanicalNameParser.
602
     *
603
     * @param	strRank	the string identifying the rank
604
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is
605
     * 			unknown or not yet implemented
606
     * @return  		the rank
607
     */
608
    public static Rank getRankByNameOrIdInVoc(String strRank, boolean useUnknown) throws UnknownCdmTypeException{
609
        try {
610
            return getRankByIdInVoc(strRank);
611
        } catch (UnknownCdmTypeException e) {
612
            return getRankByName(strRank, useUnknown);
613
        }
614
    }
615

    
616
    // TODO
617
    // Preliminary implementation for BotanicalNameParser.
618
    // not yet complete
619
    /**
620
     * Returns the rank identified through a label or the identifier within the vocabulary.
621
     * Preliminary implementation for BotanicalNameParser.
622
     *
623
     * @param	strRank	the string identifying the rank
624
     * @param   nc      the nomenclatural code
625
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is
626
     * 			unknown or not yet implemented
627
     * @return  		the rank
628
     */
629
    public static Rank getRankByNameOrIdInVoc(String strRank, NomenclaturalCode nc, boolean useUnknown)
630
            throws UnknownCdmTypeException{
631
        try {
632
            return getRankByIdInVoc(strRank, nc);
633
        } catch (UnknownCdmTypeException e) {
634
            return getRankByName(strRank, nc, useUnknown);
635
        }
636
    }
637

    
638
    /**
639
     * Returns the rank identified through the vocabulary identifier.
640
     * Preliminary implementation for BotanicalNameParser.<BR>
641
     * Note: For abbrev = "[unranked]" the result is undefined.
642
     * It maybe the infrageneric unranked or the infraspecific unranked.
643
     * You need to define by context which one is correct.
644
     *
645
     * @param	abbrev	the string for the name abbreviation
646
     * @return  		the rank
647
     */
648
    public static Rank getRankByIdInVoc(String abbrev) throws UnknownCdmTypeException{
649
        return getRankByIdInVoc(abbrev, false);
650
    }
651

    
652
    /**
653
     * Returns the rank identified through an abbreviated name for a given nomenclatural code.
654
     * See also {@link #getRankByIdInVoc(String, boolean)}
655
     *
656
     * @param	abbrev	the string for the name abbreviation
657
     * @param	nc	    the nomenclatural code
658
     * @return  		the rank
659
     */
660
    public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc) throws UnknownCdmTypeException{
661
        return getRankByIdInVoc(abbrev, nc, false);
662
    }
663

    
664
    // TODO
665
    // Preliminary implementation for BotanicalNameParser.
666
    // not yet complete
667
    /**
668
     * Returns the rank identified through an abbreviated representation.
669
     * At the moment it uses the English abbreviations (being Latin because
670
     * we do not have Latin representations yet.
671
     * TODO
672
     * If no according abbreviation is available it throws either an UnknownCdmTypeException
673
     * or an #Rank.UNKNOWN() object depending on the useUnknown flag.
674
     *
675
     * @param	idInVoc		the string for the name abbreviation
676
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is
677
     * 			unknown or not yet existent
678
     * @return  the rank
679
     */
680
    public static Rank getRankByIdInVoc(String idInVoc, boolean useUnknown) throws UnknownCdmTypeException{
681
        Rank result = null;
682
        if (idInVoc == null){
683
            throw new NullPointerException("idInVoc is NULL in getRankByIdInVoc");
684
        }
685
        if (StringUtils.isBlank(idInVoc)){
686
            //handle empty idInVoc as unknown
687
            idInVoc = "oijas34\u0155";
688
        }
689
        if (idInVocMap == null){
690
            return null;
691
        }
692
        idInVoc = normalizeSectionAndSubsection(idInVoc);
693
        idInVoc = normalizeSubgen(idInVoc);
694
        idInVoc = normalizeSpecialForm(idInVoc);
695
        idInVoc = normalizeSsp(idInVoc);
696
        idInVoc = normalizeForma(idInVoc);
697
        UUID uuid = idInVocMap.get(idInVoc);
698
        if (uuid != null ){
699
            result = getTermByUuid(uuid);
700
        }
701
        if (result != null){
702
            return result;
703
        }else {
704
            if (idInVoc == null){
705
                idInVoc = "(null)";
706
            }
707
            if (useUnknown){
708
                logger.info("Unknown rank name: " + idInVoc + ". Rank 'UNKNOWN_RANK' created instead");
709
                return Rank.UNKNOWN_RANK();
710
            }else{
711
                throw new UnknownCdmTypeException("Unknown rank abbreviation: " + idInVoc);
712
            }
713
        }
714
    }
715

    
716
    private static String normalizeSectionAndSubsection(String idInVoc) {
717
        if (idInVoc.equals("sect.")){
718
            return "sect.(bot.)";
719
        }else if (idInVoc.equals("subsect.")){
720
            return "subsect.(bot.)";
721
        }
722
        return idInVoc;
723
    }
724

    
725
    private static String normalizeSubgen(String idInVoc) {
726
        if (idInVoc.equals("subgen.")){
727
            return "subg.";
728
        }
729
        return idInVoc;
730
    }
731

    
732
    private static String normalizeSpecialForm(String idInVoc) {
733
        if (idInVoc.equals("f.sp.") || idInVoc.equals("f. sp.")){
734
            return "f.spec.";
735
        }
736
        return idInVoc;
737
    }
738

    
739
    private static String normalizeForma(String idInVoc) {
740
        if (idInVoc.equals("forma")){
741
            return "f.";
742
        }
743
        return idInVoc;
744
    }
745

    
746
    private static String normalizeSsp(String idInVoc) {
747
        if (idInVoc.equals("ssp.") && !idInVocMap.containsKey("ssp.") && idInVocMap.containsKey("subsp.")){
748
            return "subsp.";
749
        }
750
        return idInVoc;
751
    }
752

    
753
    // TODO
754
    // Preliminary implementation to cover Botany and Zoology.
755
    /**
756
     * Returns the rank identified through an abbreviated name for a given nomenclatural code.
757
     * Preliminary implementation for ICBN and ICZN.
758
     * See also {@link #getRankByIdInVoc(String, boolean)}
759

    
760
     *
761
     * @param	abbrev		the string for the name abbreviation
762
     * @param	nc	        the nomenclatural code
763
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is
764
     * 			unknown or not yet implemented
765
     * @return  the rank
766
     */
767
    public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc, boolean useUnknown)
768
            throws UnknownCdmTypeException{
769

    
770
        if (nc != null && nc.equals(NomenclaturalCode.ICZN)) {
771
            if (abbrev != null){
772
                if (abbrev.equalsIgnoreCase("sect.")) {
773
                    return Rank.SECTION_ZOOLOGY();
774
                } else if (abbrev.equalsIgnoreCase("subsect.")) {
775
                    return Rank.SUBSECTION_ZOOLOGY();
776
                }
777
            }
778
        }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)) {
779
            if (abbrev != null){
780
                if (abbrev.equalsIgnoreCase("sect.")) {
781
                    return Rank.SECTION_BOTANY();
782
                } else if (abbrev.equalsIgnoreCase("subsect.")) {
783
                    return Rank.SUBSECTION_BOTANY();
784
                }
785
            }
786
        }
787
        return getRankByIdInVoc(abbrev, useUnknown);
788
    }
789

    
790
    // TODO
791
    // Preliminary implementation for BotanicalNameParser.
792
    // not yet complete
793
    /**
794
     * Returns the rank identified through a name.
795
     * Preliminary implementation for BotanicalNameParser.
796
     *
797
     * @param	rankName	the string for the name of the rank
798
     * @return  			the rank
799
     */
800
    public static Rank getRankByName(String rankName) throws UnknownCdmTypeException{
801
        return getRankByName(rankName, false);
802
    }
803

    
804

    
805
    // TODO
806
    // Preliminary implementation for ICBN and ICZN.
807
    // not yet complete
808
    /**
809
     * Returns the rank identified through a name for a given nomenclatural code.
810
     * Preliminary implementation for ICBN and ICZN.
811
     *
812
     * @param	rankName	the string for the name of the rank
813
     * @param	nc	        the nomenclatural code
814
     * @return  			the rank
815
     */
816
    public static Rank getRankByName(String rankName, NomenclaturalCode nc) throws UnknownCdmTypeException{
817
        return getRankByName(rankName, nc, false);
818
    }
819

    
820
    /**
821
     * Returns the rank identified through a name.
822
     * Preliminary implementation for BotanicalNameParser.
823
     * TODO At the moment we do not have Latin representations yet.
824
     *
825
     * @param	rankName	the string for the name of the rank
826
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the rank name is
827
     * 			unknown or not yet implemented
828
     * @return  			the rank
829
     */
830
    public static Rank getRankByName(String rankName, boolean useUnknown)
831
            throws UnknownCdmTypeException{
832
        if (rankName.equalsIgnoreCase("Regnum")){ return Rank.KINGDOM();
833
        }else if (rankName.equalsIgnoreCase("Subregnum")){ return Rank.SUBKINGDOM();
834
        }else if (rankName.equalsIgnoreCase("Phylum")){ return Rank.PHYLUM();
835
        }else if (rankName.equalsIgnoreCase("Subphylum")){ return Rank.SUBPHYLUM();
836
        }else if (rankName.equalsIgnoreCase("Divisio")){ return Rank.DIVISION();
837
        }else if (rankName.equalsIgnoreCase("Subdivisio")){ return Rank.SUBDIVISION();
838
        }else if (rankName.equalsIgnoreCase("Classis")){ return Rank.CLASS();
839
        }else if (rankName.equalsIgnoreCase("Subclassis")){ return Rank.SUBCLASS();
840
        }else if (rankName.equalsIgnoreCase("Superordo")){ return Rank.SUPERORDER();
841
        }else if (rankName.equalsIgnoreCase("Ordo")){ return Rank.ORDER();
842
        }else if (rankName.equalsIgnoreCase("Subordo")){ return Rank.SUBORDER();
843
        }else if (rankName.equalsIgnoreCase("Familia")){ return Rank.FAMILY();
844
        }else if (rankName.equalsIgnoreCase("Subfamilia")){ return Rank.SUBFAMILY();
845
        }else if (rankName.equalsIgnoreCase("Tribus")){ return Rank.TRIBE();
846
        }else if (rankName.equalsIgnoreCase("Subtribus")){ return Rank.SUBTRIBE();
847
        }else if (rankName.equalsIgnoreCase("Genus")){ return Rank.GENUS();
848
        }else if (rankName.equalsIgnoreCase("Subgenus")){ return Rank.SUBGENUS();
849
        }else if (rankName.equalsIgnoreCase("Sectio")){ return Rank.SECTION_BOTANY();
850
        }else if (rankName.equalsIgnoreCase("Subsectio")){ return Rank.SUBSECTION_BOTANY();
851
        }else if (rankName.equalsIgnoreCase("Series")){ return Rank.SERIES();
852
        }else if (rankName.equalsIgnoreCase("Subseries")){ return Rank.SUBSERIES();
853
        }else if (rankName.equalsIgnoreCase("Aggregate")){ return Rank.SPECIESAGGREGATE();
854
        }else if (rankName.equalsIgnoreCase("Speciesgroup")){ return Rank.SPECIESGROUP();
855
        }else if (rankName.equalsIgnoreCase("Species")){ return Rank.SPECIES();
856
        }else if (rankName.equalsIgnoreCase("Subspecies")){ return Rank.SUBSPECIES();
857
        }else if (rankName.equalsIgnoreCase("Convarietas")){ return Rank.CONVAR();
858
        }else if (rankName.equalsIgnoreCase("Varietas")){ return Rank.VARIETY();
859
        }else if (rankName.equalsIgnoreCase("Subvarietas")){ return Rank.SUBVARIETY();
860
        }else if (rankName.equalsIgnoreCase("Forma")){ return Rank.FORM();
861
        }else if (rankName.equalsIgnoreCase("Subforma")){ return Rank.SUBFORM();
862
        }else if (rankName.equalsIgnoreCase("Forma spec.")){ return Rank.SPECIALFORM();
863
        }else if (rankName.equalsIgnoreCase("tax.infragen.")){ return Rank.INFRAGENERICTAXON();
864
        }else if (rankName.equalsIgnoreCase("tax.infrasp.")){ return Rank.INFRASPECIFICTAXON();
865
        // old ranks
866
        }else if (rankName.equalsIgnoreCase("proles")){ return Rank.PROLES();
867
        }else if (rankName.equalsIgnoreCase("race")){ return Rank.RACE();
868
        }else if (rankName.equalsIgnoreCase("sublusus")){ return Rank.SUBLUSUS();
869

    
870
        }else if (rankName.equalsIgnoreCase("taxon")){ return Rank.INFRASPECIFICTAXON(); //to create the name put 'taxon' and the infraspeciesepi to the field unnamed namephrase
871

    
872
        }else{
873
            if (rankName == null){
874
                rankName = "(null)";  //see NPE above
875
            }
876
            if (useUnknown){
877
                if (logger.isInfoEnabled()){logger.info("Unknown rank name: " + rankName+". Rank 'UNKNOWN_RANK' created instead");}
878
                return Rank.UNKNOWN_RANK();
879
            }else{
880
                throw new UnknownCdmTypeException("Unknown rank name: " + rankName);
881
            }
882
        }
883
    }
884

    
885
    /**
886
     * Defines the rank according to the English name.
887
     * @param rankName English rank name.
888
     * @param nc Defines the handling of the section and subsection ranks. These are in different orders depending on the
889
     * nomenclatural code.
890
     * @param useUnknown if true, the "Unknown" rank is returned as a placeholder.
891
     * @return
892
     * @throws UnknownCdmTypeException never thrown if useUnknown is true
893
     */
894
    public static Rank getRankByEnglishName(String rankName, NomenclaturalCode nc, boolean useUnknown) throws UnknownCdmTypeException{
895
        Rank result = null;
896
        if (rankName == null){
897
            throw new NullPointerException("Abbrev is NULL in getRankByAbbreviation");
898
        }
899
        if (labelMap == null){
900
            return null;
901
        }
902
        //handle section and subsection (not unique representations)
903
        if (rankName.equalsIgnoreCase("Section")){
904
            if (nc != null && nc.equals(NomenclaturalCode.ICZN)){	return Rank.SECTION_ZOOLOGY();
905
            }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)){return Rank.SECTION_BOTANY();
906
            }else{
907
                String errorWarning = "Section is only defined for ICZN and ICNAFP at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
908
                logger.warn(errorWarning);
909
                throw new UnknownCdmTypeException (errorWarning);
910
            }
911
        }else if (rankName.equalsIgnoreCase("Subsection")){
912
            if (nc != null && nc.equals(NomenclaturalCode.ICZN)){ return Rank.SUBSECTION_ZOOLOGY();
913
            }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)){ return Rank.SUBSECTION_BOTANY();
914
            }else{
915
                String errorWarning = "Subsection is only defined for ICZN and ICBN at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
916
                logger.warn(errorWarning);
917
                throw new UnknownCdmTypeException (errorWarning);
918
            }
919
        }
920

    
921
        rankName = rankName.toLowerCase();
922

    
923
        UUID uuid = labelMap.get(rankName);
924
        if (uuid != null ){
925
            result = getTermByUuid(uuid);
926
        }
927
        if (result != null){
928
            return result;
929
        }else {
930
            if (rankName == null){
931
                rankName = "(null)";
932
            }
933
            if (useUnknown){
934
                if (logger.isInfoEnabled()){logger.info("Unknown rank name: " + rankName + ". Rank 'UNKNOWN_RANK' created instead");}
935
                return Rank.UNKNOWN_RANK();
936
            }else{
937
                throw new UnknownCdmTypeException("Unknown rank: " + rankName);
938
            }
939
        }
940
    }
941

    
942

    
943
    public static Rank getRankByName(String rankName, NomenclaturalCode nc, boolean useUnknown)
944
        throws UnknownCdmTypeException {
945

    
946
        if (nc.equals(NomenclaturalCode.ICZN)) {
947
            if (rankName.equalsIgnoreCase("Sectio")) { return Rank.SECTION_ZOOLOGY();
948
            }else if (rankName.equalsIgnoreCase("Subsectio")) { return Rank.SUBSECTION_ZOOLOGY();
949
            }
950
        }
951
        return getRankByName(rankName, useUnknown);
952
    }
953

    
954
    /**
955
     * Returns the abbreviated rank name for <i>this</i> rank according to the English representation
956
     * abbreviated label.
957
     * TODO Needs to be changed to Latin as soon as Latin representations are available.
958
     *
959
     * @return	the abbreviation string for <i>this</i> rank
960
     */
961
    public String getAbbreviation(){
962
        Language language = Language.getLanguageFromUuid(Language.uuidEnglish);
963
        String result = this.getRepresentation(language).getAbbreviatedLabel();
964
        if (result== null) {
965
            logger.warn("Abbreviation for rank " + this.toString() +  " not yet implemented");
966
            return "no abbreviation available.";
967
        }else{
968
            return result;
969
        }
970
    }
971
    @Transient
972
    public String getInfraGenericMarker() throws UnknownCdmTypeException{
973
        String result = null;
974
        if (! this.isInfraGeneric()){
975
            throw new IllegalStateException("An infrageneric marker is only available for a infrageneric rank but was asked for rank: " + this.toString());
976
        }else{
977
            result = this.getAbbreviation();
978
        }
979
        if (result == null){
980
            throw new UnknownCdmTypeException("Abbreviation for rank unknown: " + this.toString());
981
        }
982
        return result;
983
    }
984

    
985

    
986

    
987
    @Override
988
    public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, Map<UUID, DefinedTermBase> terms, boolean abbrevAsId) {
989
        Rank rank = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
990
        RankClass rankClass = RankClass.getByKey(csvLine.get(5));
991
        assert rankClass != null: "XXXXXXXXXXXXXXXXXXXXX  Rank class must not be null: " + csvLine ;
992
        rank.setRankClass(rankClass);
993
        return rank;
994
    }
995

    
996
    @Override
997
    protected void setDefaultTerms(TermVocabulary<Rank> termVocabulary) {
998
        termMap = new HashMap<UUID, Rank>();
999
        for (Rank term : termVocabulary.getTerms()){
1000
            termMap.put(term.getUuid(), term);
1001
            addRank(term);
1002
        }
1003
    }
1004

    
1005
    // FIXME:Remoting This is a ugly hack and need to be removed
1006
    // once the static initialisation is refactored
1007
    public static void initDefaultTerms() {
1008
        TermVocabulary<Rank> vocabulary = getTermByUuid(uuidKingdom).getVocabulary();
1009
        if(idInVocMap != null) {
1010
            idInVocMap.clear();
1011
        }
1012
        (new Rank()).setDefaultTerms(vocabulary);
1013
    }
1014

    
1015
    /**
1016
     * @param term
1017
     */
1018
    private void addRank(Rank rank) {
1019
        if (rank == null){
1020
            logger.warn("rank is NULL");
1021
            return;
1022
        }
1023
        if (rank.getUuid().equals(uuidSectionZoology) || rank.getUuid().equals(uuidSubsectionZoology )){
1024
            //sect./subsect. is used for botanical sections, see also #getRankByAbbreviation(String, NomenclaturalCode, boolean)
1025
            return;
1026
        }
1027
        Language lang = Language.DEFAULT();  //TODO should be Latin but at the moment we have only English representations
1028
        Representation representation = rank.getRepresentation(lang);
1029
        String abbrevLabel = representation.getAbbreviatedLabel();
1030
        String label = representation.getLabel();
1031

    
1032
        //initialize maps
1033
        if (idInVocMap == null){
1034
            idInVocMap = new HashMap<String, UUID>();
1035
        }
1036
        if (labelMap == null){
1037
            labelMap = new HashMap<String, UUID>();
1038
        }
1039
        labelMap.put(label.toLowerCase(), rank.getUuid());
1040
        //add to map
1041
        if (StringUtils.isBlank(abbrevLabel)){
1042
            if (logger.isDebugEnabled()){logger.info("Abbreviated label for rank is NULL or empty.Can't add rank to abbrevLabel map: " + CdmUtils.Nz(rank.getLabel()));}
1043
        }else{
1044
            idInVocMap.put(abbrevLabel, rank.getUuid());
1045
        }
1046
    }
1047

    
1048

    
1049
    /**
1050
     * It is necessary to skip the vocabulary check, otherwise we would have
1051
     * problems in some CacheStrategies, due to uninitialized Vocabularies.
1052
     *
1053
     * @see eu.etaxonomy.cdm.model.common.OrderedTermBase#compareTo(eu.etaxonomy.cdm.model.common.OrderedTermBase)
1054
     */
1055
    @Override
1056
    public int compareTo(Rank orderedTerm) {
1057
        return performCompareTo(orderedTerm, true);
1058
    }
1059

    
1060
}
(27-27/42)