Project

General

Profile

Download (43.7 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
    //additional (not yet in csv files, but used in single databases)
141
    //https://dev.e-taxonomy.eu/redmine/issues/7285
142
    public static final UUID uuidCohort = UUID.fromString("3e4dc2fa-79e8-4ee7-b7d8-4c02a18fe555");  //edaphobase
143
    public static final UUID uuidHyporder = UUID.fromString("2a1bdf1f-80fc-4846-b4d7-edcbf664f270");  //edaphobase
144

    
145

    
146

    
147
    private static Map<String, UUID> idInVocMap = null;
148
    private static Map<String, UUID> labelMap = null;
149

    
150
    protected static Map<UUID, Rank> termMap = null;
151

    
152
//*********************** Factory methods ********************************************/
153

    
154
//    /**
155
//     * Creates a new empty rank.
156
//     *
157
//     * @see #NewInstance(String, String, String)
158
//     */
159
//    private static Rank NewInstance(){
160
//        return new Rank();
161
//    }
162

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

    
178
    /**
179
     * The {@link RankClass rank class} of a rank. It is usually needed for correct formatting of a
180
     * rank by using e.g. isSupraGeneric(). Prior to v3.3 this was computed by comparison of ranks.
181
     */
182
    @XmlAttribute(name ="RankClass")
183
    @NotNull
184
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
185
        parameters = {@org.hibernate.annotations.Parameter(name="enumClass", value="eu.etaxonomy.cdm.model.name.RankClass")}
186
    )
187
    @Audited
188
    private RankClass rankClass;
189

    
190

    
191
//********************************** Constructor *********************************/
192

    
193
      //for hibernate use only
194
      @Deprecated
195
      protected Rank() {
196
        super(TermType.Rank);
197
    }
198

    
199
    /**
200
     * Class constructor: creates an additional rank instance with a description
201
     * (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), a label and a label abbreviation.
202
     *
203
     * @param	term  		 the string (in the default language) describing the
204
     * 						 new rank to be created
205
     * @param	label  		 the string identifying the new rank to be created
206
     * @param	labelAbbrev  the string identifying (in abbreviated form) the
207
     * 						 new rank to be created
208
     * @see 	#Rank()
209
     */
210
    protected Rank(RankClass rankClass, String term, String label, String labelAbbrev) {
211
        super(TermType.Rank, term, label, labelAbbrev);
212
        this.rankClass = rankClass;
213
    }
214

    
215

    
216
//********* METHODS **************************************/
217

    
218
    /* (non-Javadoc)
219
     * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
220
     */
221
    @Override
222
    public void resetTerms(){
223
        termMap = null;
224
    }
225

    
226

    
227

    
228
    protected static Rank getTermByUuid(UUID uuid){
229
        if (termMap == null || termMap.isEmpty()){
230
           return getTermByClassAndUUID(Rank.class, uuid);
231
        } else {
232
            return termMap.get(uuid);
233
        }
234
    }
235

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

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

    
465
// ************************ GETTER / SETTER **********************************/
466

    
467
    public RankClass getRankClass() {
468
        return rankClass;
469
    }
470

    
471
    public void setRankClass(RankClass rankClass) {
472
        this.rankClass = rankClass;
473
    }
474

    
475
// ******************************** METHODS ***************************************/
476

    
477
    /**
478
     * Returns the boolean value indicating whether <i>this</i> rank is higher than
479
     * the genus rank (true) or not (false). Returns false if <i>this</i> rank is null.
480
     *
481
     * @see  #isGenus()
482
     * @see  #isInfraGeneric()
483
     * @see  #isSpecies()
484
     * @see  #isInfraSpecific()
485
     */
486
    @Transient
487
    public boolean isSupraGeneric(){
488
        return this.rankClass.equals(RankClass.Suprageneric); // (this.isHigher(Rank.GENUS()));
489
    }
490

    
491
    /**
492
     * Returns the boolean value indicating whether <i>this</i> rank is the genus rank
493
     * (true) or not (false). Returns false if <i>this</i> rank is null.
494
     *
495
     * @see  #isSupraGeneric()
496
     * @see  #isInfraGeneric()
497
     * @see  #isSpecies()
498
     * @see  #isInfraSpecific()
499
     */
500
    @Transient
501
    public boolean isGenus(){
502
        return this.rankClass.equals(RankClass.Genus); // (this.equals(Rank.GENUS()));
503
    }
504

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

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

    
540
    /**
541
     * Returns true if this rank indicates a rank that aggregates species
542
     * like species aggregates or species groups, false otherwise.
543
     * @return
544
     */
545
    @Transient
546
    public boolean isSpeciesAggregate(){
547
        return this.rankClass.equals(RankClass.SpeciesGroup); //(this.equals(Rank.SPECIESAGGREGATE()) || (this.isLower(Rank.SPECIESAGGREGATE()) && this.isHigher(Rank.SPECIES())));
548
    }
549

    
550
    /**
551
     * Returns the boolean value indicating whether <i>this</i> rank is the species
552
     * rank (true) or not (false). Returns false if <i>this</i> rank is null.
553
     *
554
     * @see  #isSupraGeneric()
555
     * @see  #isGenus()
556
     * @see  #isInfraGeneric()
557
     * @see  #isInfraSpecific()
558
     */
559
    @Transient
560
    public boolean isSpecies(){
561
        return this.rankClass.equals(RankClass.Species); //(this.equals(Rank.SPECIES()));
562
    }
563

    
564
    /**
565
     * Returns the boolean value indicating whether <i>this</i> rank is lower than the
566
     * species rank (true) or not (false). Returns false if <i>this</i> rank is null.
567
     *
568
     * @see  #isSupraGeneric()
569
     * @see  #isGenus()
570
     * @see  #isInfraGeneric()
571
     * @see  #isSpecies()
572
     */
573
    @Transient
574
    public boolean isInfraSpecific(){
575
        return this.rankClass.equals(RankClass.Infraspecific); // (this.isLower(Rank.SPECIES()));
576
    }
577

    
578

    
579
    /**
580
     * Returns the rank identified through a label or the identifier within the vocabulary
581
     * Preliminary implementation for BotanicalNameParser.
582
     *
583
     * @param	strRank	the string identifying the rank
584
     * @return  		the rank
585
     */
586
    public static Rank getRankByNameOrIdInVoc(String strRank) throws UnknownCdmTypeException{
587
        return getRankByNameOrIdInVoc(strRank, false);
588
    }
589

    
590
    /**
591
     * Returns the rank identified through a label or the identifier within the vocabulary
592
     * for a given nomenclatural code.
593
     * Preliminary implementation for BotanicalNameParser.
594
     *
595
     * @param	strRank	the string identifying the rank
596
     * @param   nc      the nomenclatural code
597
     * @return  		the rank
598
     */
599
    public static Rank getRankByNameOrIdInVoc(String strRank, NomenclaturalCode nc) throws UnknownCdmTypeException{
600
        return getRankByNameOrIdInVoc(strRank, nc, false);
601
    }
602

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

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

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

    
659
    /**
660
     * Returns the rank identified through an abbreviated name for a given nomenclatural code.
661
     * See also {@link #getRankByIdInVoc(String, boolean)}
662
     *
663
     * @param	abbrev	the string for the name abbreviation
664
     * @param	nc	    the nomenclatural code
665
     * @return  		the rank
666
     */
667
    public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc) throws UnknownCdmTypeException{
668
        return getRankByIdInVoc(abbrev, nc, false);
669
    }
670

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

    
723
    private static String normalizeSectionAndSubsection(String idInVoc) {
724
        if (idInVoc.equals("sect.")){
725
            return "sect.(bot.)";
726
        }else if (idInVoc.equals("subsect.")){
727
            return "subsect.(bot.)";
728
        }
729
        return idInVoc;
730
    }
731

    
732
    private static String normalizeSubgen(String idInVoc) {
733
        if (idInVoc.equals("subgen.")){
734
            return "subg.";
735
        }
736
        return idInVoc;
737
    }
738

    
739
    private static String normalizeSpecialForm(String idInVoc) {
740
        if (idInVoc.equals("f.sp.") || idInVoc.equals("f. sp.")){
741
            return "f.spec.";
742
        }
743
        return idInVoc;
744
    }
745

    
746
    private static String normalizeForma(String idInVoc) {
747
        if (idInVoc.equals("forma")){
748
            return "f.";
749
        }
750
        return idInVoc;
751
    }
752

    
753
    private static String normalizeSsp(String idInVoc) {
754
        if (idInVoc.equals("ssp.") && !idInVocMap.containsKey("ssp.") && idInVocMap.containsKey("subsp.")){
755
            return "subsp.";
756
        }
757
        return idInVoc;
758
    }
759

    
760
    // TODO
761
    // Preliminary implementation to cover Botany and Zoology.
762
    /**
763
     * Returns the rank identified through an abbreviated name for a given nomenclatural code.
764
     * Preliminary implementation for ICBN and ICZN.
765
     * See also {@link #getRankByIdInVoc(String, boolean)}
766

    
767
     *
768
     * @param	abbrev		the string for the name abbreviation
769
     * @param	nc	        the nomenclatural code
770
     * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is
771
     * 			unknown or not yet implemented
772
     * @return  the rank
773
     */
774
    public static Rank getRankByIdInVoc(String abbrev, NomenclaturalCode nc, boolean useUnknown)
775
            throws UnknownCdmTypeException{
776

    
777
        if (nc != null && nc.equals(NomenclaturalCode.ICZN)) {
778
            if (abbrev != null){
779
                if (abbrev.equalsIgnoreCase("sect.")) {
780
                    return Rank.SECTION_ZOOLOGY();
781
                } else if (abbrev.equalsIgnoreCase("subsect.")) {
782
                    return Rank.SUBSECTION_ZOOLOGY();
783
                }
784
            }
785
        }else if (nc != null && nc.equals(NomenclaturalCode.ICNAFP)) {
786
            if (abbrev != null){
787
                if (abbrev.equalsIgnoreCase("sect.")) {
788
                    return Rank.SECTION_BOTANY();
789
                } else if (abbrev.equalsIgnoreCase("subsect.")) {
790
                    return Rank.SUBSECTION_BOTANY();
791
                }
792
            }
793
        }
794
        return getRankByIdInVoc(abbrev, useUnknown);
795
    }
796

    
797
    // TODO
798
    // Preliminary implementation for BotanicalNameParser.
799
    // not yet complete
800
    /**
801
     * Returns the rank identified through a name.
802
     * Preliminary implementation for BotanicalNameParser.
803
     *
804
     * @param	rankName	the string for the name of the rank
805
     * @return  			the rank
806
     */
807
    public static Rank getRankByName(String rankName) throws UnknownCdmTypeException{
808
        return getRankByName(rankName, false);
809
    }
810

    
811

    
812
    // TODO
813
    // Preliminary implementation for ICBN and ICZN.
814
    // not yet complete
815
    /**
816
     * Returns the rank identified through a name for a given nomenclatural code.
817
     * Preliminary implementation for ICBN and ICZN.
818
     *
819
     * @param	rankName	the string for the name of the rank
820
     * @param	nc	        the nomenclatural code
821
     * @return  			the rank
822
     */
823
    public static Rank getRankByName(String rankName, NomenclaturalCode nc) throws UnknownCdmTypeException{
824
        return getRankByName(rankName, nc, false);
825
    }
826

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

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

    
879
        }else{
880
            if (rankName == null){
881
                rankName = "(null)";  //see NPE above
882
            }
883
            if (useUnknown){
884
                if (logger.isInfoEnabled()){logger.info("Unknown rank name: " + rankName+". Rank 'UNKNOWN_RANK' created instead");}
885
                return Rank.UNKNOWN_RANK();
886
            }else{
887
                throw new UnknownCdmTypeException("Unknown rank name: " + rankName);
888
            }
889
        }
890
    }
891

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

    
928
        rankName = rankName.toLowerCase();
929

    
930
        UUID uuid = labelMap.get(rankName);
931
        if (uuid != null ){
932
            result = getTermByUuid(uuid);
933
        }
934
        if (result != null){
935
            return result;
936
        }else {
937
            if (rankName == null){
938
                rankName = "(null)";
939
            }
940
            if (useUnknown){
941
                if (logger.isInfoEnabled()){logger.info("Unknown rank name: " + rankName + ". Rank 'UNKNOWN_RANK' created instead");}
942
                return Rank.UNKNOWN_RANK();
943
            }else{
944
                throw new UnknownCdmTypeException("Unknown rank: " + rankName);
945
            }
946
        }
947
    }
948

    
949

    
950
    public static Rank getRankByName(String rankName, NomenclaturalCode nc, boolean useUnknown)
951
        throws UnknownCdmTypeException {
952

    
953
        if (nc.equals(NomenclaturalCode.ICZN)) {
954
            if (rankName.equalsIgnoreCase("Sectio")) { return Rank.SECTION_ZOOLOGY();
955
            }else if (rankName.equalsIgnoreCase("Subsectio")) { return Rank.SUBSECTION_ZOOLOGY();
956
            }
957
        }
958
        return getRankByName(rankName, useUnknown);
959
    }
960

    
961
    /**
962
     * Returns the abbreviated rank name for <i>this</i> rank according to the English representation
963
     * abbreviated label.
964
     * TODO Needs to be changed to Latin as soon as Latin representations are available.
965
     *
966
     * @return	the abbreviation string for <i>this</i> rank
967
     */
968
    public String getAbbreviation(){
969
        Language language = Language.getLanguageFromUuid(Language.uuidEnglish);
970
        String result = this.getRepresentation(language).getAbbreviatedLabel();
971
        if (result== null) {
972
            logger.warn("Abbreviation for rank " + this.toString() +  " not yet implemented");
973
            return "no abbreviation available.";
974
        }else{
975
            return result;
976
        }
977
    }
978

    
979
    @Transient
980
    public String getInfraGenericMarker() throws UnknownCdmTypeException{
981
        String result = null;
982
        if (! this.isInfraGeneric()){
983
            throw new IllegalStateException("An infrageneric marker is only available for an infrageneric rank but was asked for rank: " + this.toString());
984
        }else{
985
            result = this.getAbbreviation();
986
        }
987
        if (result == null){
988
            throw new UnknownCdmTypeException("Abbreviation for rank unknown: " + this.toString());
989
        }
990
        return result;
991
    }
992

    
993

    
994

    
995
    @Override
996
    public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, Map<UUID, DefinedTermBase> terms, boolean abbrevAsId) {
997
        Rank rank = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
998
        RankClass rankClass = RankClass.getByKey(csvLine.get(5));
999
        assert rankClass != null: "XXXXXXXXXXXXXXXXXXXXX  Rank class must not be null: " + csvLine ;
1000
        rank.setRankClass(rankClass);
1001
        return rank;
1002
    }
1003

    
1004
    @Override
1005
    protected void setDefaultTerms(TermVocabulary<Rank> termVocabulary) {
1006
        termMap = new HashMap<UUID, Rank>();
1007
        for (Rank term : termVocabulary.getTerms()){
1008
            termMap.put(term.getUuid(), term);
1009
            addRank(term);
1010
        }
1011
    }
1012

    
1013
    // FIXME:Remoting This is a ugly hack and need to be removed
1014
    // once the static initialisation is refactored
1015
    public static void initDefaultTerms() {
1016
        TermVocabulary<Rank> vocabulary = getTermByUuid(uuidKingdom).getVocabulary();
1017
        if(idInVocMap != null) {
1018
            idInVocMap.clear();
1019
        }
1020
        (new Rank()).setDefaultTerms(vocabulary);
1021
    }
1022

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

    
1040
        //initialize maps
1041
        if (idInVocMap == null){
1042
            idInVocMap = new HashMap<String, UUID>();
1043
        }
1044
        if (labelMap == null){
1045
            labelMap = new HashMap<String, UUID>();
1046
        }
1047
        labelMap.put(label.toLowerCase(), rank.getUuid());
1048
        //add to map
1049
        if (StringUtils.isBlank(abbrevLabel)){
1050
            if (logger.isDebugEnabled()){logger.info("Abbreviated label for rank is NULL or empty.Can't add rank to abbrevLabel map: " + CdmUtils.Nz(rank.getLabel()));}
1051
        }else{
1052
            idInVocMap.put(abbrevLabel, rank.getUuid());
1053
        }
1054
    }
1055

    
1056

    
1057
    /**
1058
     * It is necessary to skip the vocabulary check, otherwise we would have
1059
     * problems in some CacheStrategies, due to uninitialized Vocabularies.
1060
     *
1061
     * @see eu.etaxonomy.cdm.model.common.OrderedTermBase#compareTo(eu.etaxonomy.cdm.model.common.OrderedTermBase)
1062
     */
1063
    @Override
1064
    public int compareTo(Rank orderedTerm) {
1065
        return performCompareTo(orderedTerm, true);
1066
    }
1067

    
1068
}
(23-23/36)