Project

General

Profile

Download (26.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.description;
11

    
12
import java.text.ParseException;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.UUID;
17

    
18
import javax.persistence.Entity;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlAttribute;
22
import javax.xml.bind.annotation.XmlRootElement;
23
import javax.xml.bind.annotation.XmlType;
24

    
25
import org.apache.commons.lang3.StringUtils;
26
import org.apache.log4j.Logger;
27
import org.hibernate.envers.Audited;
28

    
29
import eu.etaxonomy.cdm.model.common.CdmBase;
30
import eu.etaxonomy.cdm.model.common.Language;
31
import eu.etaxonomy.cdm.model.location.NamedArea;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
34
import eu.etaxonomy.cdm.model.term.OrderedTermBase;
35
import eu.etaxonomy.cdm.model.term.TermType;
36
import eu.etaxonomy.cdm.model.term.TermVocabulary;
37

    
38

    
39
/**
40
 * This class represents terms describing the {@link AbsenceTerm absence}
41
 * (like "extinct") or the {@link PresenceTerm presence} (like "cultivated") of a
42
 * {@link Taxon taxon} in an {@link NamedArea area}. These terms are only
43
 * used for {@link Distribution distributions}.
44
 *
45
 * The current implementation includes multiple qualities of distribution status:<BR><BR>
46
 *
47
 *  1. Degree of "presence": present, presence questionable, reported in error, absent, ...<BR>
48
 *  2. Nativeness/naturalization/...: native, alien (introduced), naturalized, cultivated, invasive, ... <BR>
49
 *  <BR>
50
 *  There might be further qualities like adventive(unwanted)<->introduced(wanted - for cultivation)
51
 * <BR>
52
 * For an interesting discussion of these status see Pyšek & al.: Alien plants in checklists and floras;
53
 * Taxon 53(1), Feb. 2004: 131-143 <BR>
54
 *
55
 * Pyšek et al. distinguises<BR>
56
 *  native - alien<BR>
57
 *  alien => cultivated-outside cultivation<BR>
58
 *  outside cultivation=>casual - naturalized<BR>
59
 *  naturalized => non invasive - invasive<BR>
60
 *  invasive => not harmful - transformers - weeds
61
 *
62
 * @see http://dev.e-taxonomy.eu/redmine/issues/6000
63
 *
64
 * @author m.doering
65
 * @since 08-Nov-2007 13:06:44
66
 * @author a.mueller
67
 */
68
@XmlAccessorType(XmlAccessType.FIELD)
69
@XmlType(name = "PresenceAbsenceTerm")
70
@XmlRootElement(name = "PresenceAbsenceTerm")
71
@Entity
72
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
73
//@Indexed(index = "eu.etaxonomy.cdm.model.term.DefinedTermBase")
74
@Audited
75
public class PresenceAbsenceTerm extends OrderedTermBase<PresenceAbsenceTerm> {
76
	private static final long serialVersionUID = 1036807546935584396L;
77
	private static final Logger logger = Logger.getLogger(PresenceAbsenceTerm.class);
78

    
79

    
80
	//presence base
81
	public static final UUID uuidPresent=UUID.fromString("cef81d25-501c-48d8-bbea-542ec50de2c2");
82
	private static final UUID uuidPD=UUID.fromString("75a60279-a4c2-4f53-bc57-466028a4b3db");
83

    
84
	//presence
85
	public static final UUID uuidNative = UUID.fromString("ddeac4f2-d8fa-43b8-ad7e-ca13abdd32c7");
86
	private static final UUID uuidND = UUID.fromString("310373bf-7df4-4d02-8cb3-bcc7448805fc");
87
	public static final UUID uuidCultivated = UUID.fromString("9eb99fe6-59e2-4445-8e6a-478365bd0fa9");
88
	public static final UUID uuidIntroduced = UUID.fromString("643cf9d1-a5f1-4622-9837-82ef961e880b");
89
	private static final UUID uuidID = UUID.fromString("0c54761e-4887-4788-9dfa-7190c88746e3");
90
	public static final UUID uuidIntroducedUncertainDegreeNaturalisation = UUID.fromString("da159544-b0dd-4599-a9c9-640826af8c17");
91
	public static final UUID uuidIntroducesAdventitious = UUID.fromString("42946bd6-9c22-45ad-a910-7427e8f60bfd");
92
	public static final UUID uuidNaturalised = UUID.fromString("e191e89a-a751-4b0c-b883-7f1de70915c9");
93
	private static final UUID uuidIC = UUID.fromString("fac8c347-8262-44a1-b0a4-db4de451c021");
94
	private static final UUID uuidE = UUID.fromString("c3ee7048-15b7-4be1-b687-9ce9c1a669d6");
95

    
96
	private static final UUID uuidNotE = UUID.fromString("2fda5393-7423-4076-814c-1fa7678d7d33");
97
	private static final UUID uuidUnkE = UUID.fromString("094aa2e4-8048-4086-aca1-2d671a05a86e");
98

    
99
	//	private static final UUID uuidNa=UUID.fromString("4e04990a-66fe-4fdf-856c-f40772fbcf0a");
100
	private static final UUID uuidNI=UUID.fromString("dc536e3d-a753-4bbe-a386-dd8aff35c234");
101

    
102
	private static final UUID uuidNN = UUID.fromString("1b025e8b-901a-42e8-9739-119b410c6f03");
103

    
104
	//doubtfully present
105
	public static final UUID uuidNativePresenceQuestionable = UUID.fromString("925662c1-bb10-459a-8c53-da5a738ac770");
106
	private static final UUID uuidCQ = UUID.fromString("4f31bfc8-3058-4d83-aea5-3a1fe9773f9f");
107
	private static final UUID uuidIQ = UUID.fromString("83eb0aa0-1a45-495a-a3ca-bf6958b74366");
108
	private static final UUID uuidEQ = UUID.fromString("5f954f08-267a-4928-b073-12328f74c187");
109
	//intr. naturalized questionable
110
	private static final UUID uuidINQ = UUID.fromString("9e0b413b-5a68-4e5b-91f2-227b4f832466");
111
	//natur. invasive questionable
112
	private static final UUID uuidNIQ = UUID.fromString("ac429d5f-e8ad-49ae-a41c-e4779b58b96a");
113
	//natur. non-invasive questionable
114
    private static final UUID uuidNNQ = UUID.fromString("11f56e2f-c16c-4b3d-a870-bb5d3b20e624");
115

    
116

    
117
	//absence
118
	private static final UUID uuidAbsence=UUID.fromString("59709861-f7d9-41f9-bb21-92559cedd598");
119
	private static final UUID uuidReportedInError = UUID.fromString("38604788-cf05-4607-b155-86db456f7680");
120

    
121
	public static final UUID uuidNativeError = UUID.fromString("61cee840-801e-41d8-bead-015ad866c2f1");
122
	private static final UUID uuidIF = UUID.fromString("aeec2947-2700-4623-8e32-9e3a430569d1");
123
	private static final UUID uuidCF = UUID.fromString("9d4d3431-177a-4abe-8e4b-1558573169d6");
124
	private static final UUID uuidNE = UUID.fromString("5c397f7b-59ef-4c11-a33c-45691ceda91b");
125
	private static final UUID uuidNDE = UUID.fromString("71b72e24-c2b6-44a5-bdab-39f083bf0f06");
126
	private static final UUID uuidIE = UUID.fromString("b74dc30b-ee93-496d-8c00-4d00abae1ec7");
127
	private static final UUID uuidEE = UUID.fromString("679b215d-c231-4ee2-ae12-3ffc3dd528ad");
128
	private static final UUID uuidNaE = UUID.fromString("8d918a37-3add-4e1c-a233-c37dbee209aa");
129
	private static final UUID uuidIAQ = UUID.fromString("73f75493-1185-4a3e-af1e-9a1f2e8dadb7");
130
	private static final UUID uuidIAF = UUID.fromString("9b910b7b-43e3-4260-961c-6063b11cb7dc");
131

    
132

    
133
	protected static Map<UUID, PresenceAbsenceTerm> termMap = null;
134

    
135
    private String defaultColor = "000000";
136

    
137
    @XmlAttribute(name = "absenceTerm")
138
    private boolean absenceTerm = false;
139

    
140
	//********* METHODS **************************************/
141
	/**
142
	 * Creates a new empty presence term.
143
	 *
144
	 * @see #NewInstance(String, String, String)
145
	 */
146
	public static PresenceAbsenceTerm NewInstance(){
147
		return new PresenceAbsenceTerm();
148
	}
149

    
150
	/**
151
	 * Creates a new presence term with a description (in the {@link Language#DEFAULT() default language}),
152
	 * a label and a label abbreviation.
153
	 *
154
	 * @param	term  		 the string (in the default language) describing the
155
	 * 						 new presence term to be created
156
	 * @param	label  		 the string identifying the new presence term to be created
157
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
158
	 * 						 new presence term to be created
159
	 * @see 				 #NewInstance()
160
	 */
161
	public static PresenceAbsenceTerm NewPresenceInstance(String term, String label, String labelAbbrev){
162
		return new PresenceAbsenceTerm(term, label, labelAbbrev, false);
163
	}
164

    
165
	/**
166
	 * Creates a new absence term with a description (in the {@link Language#DEFAULT() default language}),
167
	 * a label and a label abbreviation.
168
	 *
169
	 * @param	term  		 the string (in the default language) describing the
170
	 * 						 new presence term to be created
171
	 * @param	label  		 the string identifying the new presence term to be created
172
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
173
	 * 						 new presence term to be created
174
	 * @see 				 #NewInstance()
175
	 */
176
	public static PresenceAbsenceTerm NewAbsenceInstance(String term, String label, String labelAbbrev){
177
		return new PresenceAbsenceTerm(term, label, labelAbbrev, true);
178
	}
179

    
180

    
181
//********************************** Constructor *******************************************************************/
182

    
183
  	//for hibernate use only
184
  	@Deprecated
185
  	protected PresenceAbsenceTerm() {
186
    	super(TermType.PresenceAbsenceTerm);
187
    }
188

    
189
    /**
190
     * Class constructor: creates a new presence or absence term with a description
191
     * (in the {@link Language#DEFAULT() default language}), a label and a label abbreviation.
192
     *
193
     * @param	term  		 the string (in the default language) describing the
194
     * 						 new presence or absence term to be created
195
     * @param	label  		 the string identifying the new presence or absence term to be created
196
     * @param	labelAbbrev  the string identifying (in abbreviated form) the
197
     * 						 new presence or absence term to be created
198
     * @param   isAbsenceTerm  boolean value indicating if this term represents an absence or not
199
     * @see 				 #PresenceAbsenceTermBase()
200
     */
201
    protected PresenceAbsenceTerm(String term, String label, String labelAbbrev, boolean isAbsenceTerm) {
202
        super(TermType.PresenceAbsenceTerm, term, label, labelAbbrev);
203
        this.setAbsenceTerm(isAbsenceTerm);
204
    }
205

    
206

    
207
  //******************************* STATIC METHODS *****************************************
208

    
209
  	protected static PresenceAbsenceTerm getTermByUuid(UUID uuid){
210
        if (termMap == null || termMap.isEmpty()){
211
            return getTermByClassAndUUID(PresenceAbsenceTerm.class, uuid);
212
        } else {
213
  			return termMap.get(uuid);
214
  		}
215
  	}
216

    
217
   	//TODO read from label(abbrevs) like in TDWGArea
218
  	public static PresenceAbsenceTerm getPresenceAbsenceTermByAbbreviation(String abbrev) {
219
  		if (abbrev == null) { throw new NullPointerException("abbrev is 'null' in getPresenceTermByAbbreviation");
220
  		} else if (abbrev.equalsIgnoreCase("c"))  { return PresenceAbsenceTerm.CULTIVATED();
221
  		} else if (abbrev.equalsIgnoreCase("e"))  { return PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA();
222
  		} else if (abbrev.equalsIgnoreCase("i"))  { return PresenceAbsenceTerm.INTRODUCED();
223
  		} else if (abbrev.equalsIgnoreCase("ia")) { return PresenceAbsenceTerm.CASUAL();
224
  		} else if (abbrev.equalsIgnoreCase("ic")) { return PresenceAbsenceTerm.INTRODUCED_CULTIVATED();
225
  		} else if (abbrev.equalsIgnoreCase("id")) { return PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED();
226
  		} else if (abbrev.equalsIgnoreCase("in")) { return PresenceAbsenceTerm.NATURALISED();
227
  		} else if (abbrev.equalsIgnoreCase("ip")) { return PresenceAbsenceTerm.INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION();
228
  		} else if (abbrev.equalsIgnoreCase("iq")) { return PresenceAbsenceTerm.INTRODUCED_PRESENCE_QUESTIONABLE();
229
  		} else if (abbrev.equalsIgnoreCase("n"))  { return PresenceAbsenceTerm.NATIVE();
230
  		} else if (abbrev.equalsIgnoreCase("nd")) { return PresenceAbsenceTerm.NATIVE_DOUBTFULLY_NATIVE();
231
  		} else if (abbrev.equalsIgnoreCase("nq")) { return PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE();
232
  		} else if (abbrev.equalsIgnoreCase("p"))  { return PresenceAbsenceTerm.PRESENT();
233
  		} else if (abbrev.equalsIgnoreCase("na"))  { return PresenceAbsenceTerm.NATURALISED();
234
  		} else if (abbrev.equalsIgnoreCase("iv"))  { return PresenceAbsenceTerm.INVASIVE();
235
  		//absence
236
		} else if (abbrev.equalsIgnoreCase("cf")) { return PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
237
		} else if (abbrev.equalsIgnoreCase("if")) { return PresenceAbsenceTerm.INTRODUCED_REPORTED_IN_ERROR();
238
		} else if (abbrev.equalsIgnoreCase("nf")) { return PresenceAbsenceTerm.NATIVE_REPORTED_IN_ERROR();
239
		} else if (abbrev.equalsIgnoreCase("ne")) { return PresenceAbsenceTerm.NATIVE_FORMERLY_NATIVE();
240
		} else if (abbrev.equalsIgnoreCase("ie")) { return PresenceAbsenceTerm.INTRODUCED_FORMERLY_INTRODUCED();
241
		} else {
242
			logger.warn("Unknown presence or absence status term abbreviation: " + abbrev);
243
			return null;
244
		}
245
  	}
246

    
247
    /**
248
     * The taxon is endemic for the given area.
249
     * @see #PRESENT()
250
     * @see #NATIVE()
251
     * @see #ENDEMIC_DOUBTFULLY_PRESENT()
252
     * @see #ENDEMIC_REPORTED_IN_ERROR()
253
     */
254
    public static final PresenceAbsenceTerm ENDEMIC_FOR_THE_RELEVANT_AREA(){
255
        return getTermByUuid(uuidE);
256
    }
257

    
258
    /**
259
     * The taxon is present but not endemic for the given area.
260
     * @see #PRESENT()
261
     * @see #NATIVE()
262
     * @see #ENDEMIC_FOR_THE_RELEVANT_AREA()
263
     * @see #ENDEMIC_DOUBTFULLY_PRESENT()
264
     * @see #ENDEMIC_REPORTED_IN_ERROR()
265
     */
266
    public static final PresenceAbsenceTerm NOT_ENDEMIC_FOR_THE_RELEVANT_AREA(){
267
        return getTermByUuid(uuidNotE);
268
    }
269

    
270
    /**
271
     * The taxon is present but with unknown endemism for the given area.
272
     * @see #PRESENT()
273
     * @see #NATIVE()
274
     * @see #ENDEMIC_FOR_THE_RELEVANT_AREA()
275
     * @see #ENDEMIC_DOUBTFULLY_PRESENT()
276
     * @see #ENDEMIC_REPORTED_IN_ERROR()
277
     * @see #NOT_ENDEMIC_FOR_THE_RELEVANT_AREA()
278
     */
279
    public static final PresenceAbsenceTerm ENDEMISM_UNKNOWN(){
280
        return getTermByUuid(uuidUnkE);
281
    }
282

    
283
    /**
284
     * The taxon is endemic for the given area but doubtfully present.
285
     * @see #ENDEMIC_FOR_THE_RELEVANT_AREA()
286
     * @see #ENDEMIC_REPORTED_IN_ERROR()
287
     * @see #PRESENT_DOUBTFULLY()
288
     * @see #NATIVE_PRESENCE_QUESTIONABLE()
289
     */
290
    public static final PresenceAbsenceTerm ENDEMIC_DOUBTFULLY_PRESENT(){
291
        return getTermByUuid(uuidEQ);
292
    }
293

    
294
    /**
295
     * The taxon if it exists is endemic for the given area but was only
296
     * erroneously reported.
297
     * So it either does not exist or it is unclear where it was originally found.
298
     * @see #ENDEMIC_FOR_THE_RELEVANT_AREA()
299
     * @see #ENDEMIC_DOUBTFULLY_PRESENT()
300
     * @see #REPORTED_IN_ERROR()
301
     * @see #NATIVE_REPORTED_IN_ERROR()
302
     */
303
    public static final PresenceAbsenceTerm ENDEMIC_REPORTED_IN_ERROR(){
304
        return getTermByUuid(uuidEE);
305
    }
306

    
307

    
308
	/**
309
	 * The taxon is present in the given area. No information given about
310
	 * nativeness/establishment means.
311
	 *
312
	 * @see #PRESENT_DOUBTFULLY()
313
	 * @see #ABSENT()
314
	 */
315
	public static final PresenceAbsenceTerm PRESENT(){
316
		return getTermByUuid(uuidPresent);
317
	}
318

    
319
	/**
320
     * Presence of the taxon in the given area is doubtful. No information given about
321
     * nativeness/establishment means.
322
     *
323
     * @see #PRESENT()
324
     * @see #ABSENT()
325
     */
326
	public static final PresenceAbsenceTerm PRESENT_DOUBTFULLY(){
327
		return getTermByUuid(uuidPD);
328
	}
329

    
330
	/**
331
	 * The taxon is not native but cultivated.
332
	 *
333
	 * @see #CULTIVATED_PRESENCE_QUESTIONABLE()
334
	 * @see #CULTIVATED_REPORTED_IN_ERROR()
335
	 */
336
	public static final PresenceAbsenceTerm CULTIVATED(){
337
		return getTermByUuid(uuidCultivated);
338
	}
339

    
340
	/**
341
     * The taxon is cultivated but presence is questionable.
342
     *
343
     * @see #CULTIVATED()
344
     * @see #CULTIVATED_REPORTED_IN_ERROR()
345
     */
346
    public static final PresenceAbsenceTerm CULTIVATED_PRESENCE_QUESTIONABLE(){
347
        return getTermByUuid(uuidCQ);
348
    }
349

    
350
    /**
351
     * The taxon is erroneously reported as cultivated.
352
     *
353
     * @see #CULTIVATED()
354
     * @see #CULTIVATED_REPORTED_IN_ERROR()
355
     */
356
    public static final PresenceAbsenceTerm CULTIVATED_REPORTED_IN_ERROR(){
357
        return getTermByUuid(uuidCF);
358
    }
359

    
360

    
361
	public static final PresenceAbsenceTerm INTRODUCED(){
362
		return getTermByUuid(uuidIntroduced);
363
	}
364

    
365
    /**
366
     * Casual alien or introduced: adventive (casual)
367
     *
368
     * @see #CASUAL_REPORTED_IN_ERROR()
369
     * @see #CASUAL_PRESENCE_QUESTIONABLE()
370
     * @see #INTRODUCED_ADVENTITIOUS()
371
     */
372
    public static final PresenceAbsenceTerm CASUAL(){
373
        return getTermByUuid(uuidIntroducesAdventitious);
374
    }
375
    /**
376
     * Casual alien, presence questionable
377
     *
378
     * @see #CASUAL()
379
     * @see #CASUAL_REPORTED_IN_ERROR()
380
     * @see #PRESENT_DOUBTFULLY()
381
     */
382
    public static final PresenceAbsenceTerm CASUAL_PRESENCE_QUESTIONABLE(){
383
        return getTermByUuid(uuidIAQ);
384
    }
385
    /**
386
     * Casual alien, reported in error
387
     *
388
     * @see #CASUAL()
389
     * @see #CASUAL_PRESENCE_QUESTIONABLE()
390
     * @see #REPORTED_IN_ERROR()
391
     */
392
    public static final PresenceAbsenceTerm CASUAL_REPORTED_IN_ERROR(){
393
        return getTermByUuid(uuidIAF);
394
    }
395

    
396

    
397
	/**
398
	 * This term is of questional value. Introduced often is handled as opposite
399
	 * of adventitious/adventive and describes how the alien species came
400
	 * - on purpose for cultivation (introduced) or not (adventive).
401
	 * Adventitious or better adventive is often a synonym for casual which might
402
	 * be the better term here.
403
	 *
404
	 * @deprecated better use {@link #CASUAL()}, which has the same result (same semantics, but more precise)
405
	 */
406
	@Deprecated
407
	public static final PresenceAbsenceTerm INTRODUCED_ADVENTITIOUS(){
408
		return getTermByUuid(uuidIntroducesAdventitious);
409
	}
410

    
411
	public static final PresenceAbsenceTerm INTRODUCED_CULTIVATED(){
412
		return getTermByUuid(uuidIC);
413
	}
414

    
415
	public static final PresenceAbsenceTerm INTRODUCED_DOUBTFULLY_INTRODUCED(){
416
		return getTermByUuid(uuidID);
417
	}
418

    
419

    
420
    public static final PresenceAbsenceTerm INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION(){
421
        return getTermByUuid(uuidIntroducedUncertainDegreeNaturalisation);
422
    }
423

    
424
	public static final PresenceAbsenceTerm INTRODUCED_PRESENCE_QUESTIONABLE(){
425
		return getTermByUuid(uuidIQ);
426
	}
427

    
428
    public static final PresenceAbsenceTerm INTRODUCED_FORMERLY_INTRODUCED(){
429
        return getTermByUuid(uuidIE);
430
    }
431

    
432
    public static final PresenceAbsenceTerm INTRODUCED_REPORTED_IN_ERROR(){
433
        return getTermByUuid(uuidIF);
434
    }
435

    
436
	/**
437
	 * Use native if the taxon is native in the according area. Native and indigenous
438
	 * have the same meaning. Native might be problematic because the abbreviation
439
	 * N is already used for naturalised.
440
	 *
441
	 * @see #NATIVE_DOUBTFULLY_NATIVE()
442
     * @see #NATIVE_PRESENCE_QUESTIONABLE()
443
     * @see #NATIVE_REPORTED_IN_ERROR()
444
	 */
445
	public static final PresenceAbsenceTerm NATIVE(){
446
		return getTermByUuid(uuidNative);
447
	}
448

    
449
    /**
450
     * Same as {@link #NATIVE()} but presence is questionable
451
     * @see #NATIVE()
452
     * @see #NATIVE_DOUBTFULLY_NATIVE()
453
     * @see #NATIVE_REPORTED_IN_ERROR()
454
     */
455
    public static final PresenceAbsenceTerm NATIVE_PRESENCE_QUESTIONABLE(){
456
        return getTermByUuid(uuidNativePresenceQuestionable);
457
    }
458

    
459
    /**
460
     * The taxon was formerly native, but is extinct now in the given area.
461
     *
462
     * @see #NATIVE()
463
     * @see #ABSENT()
464
     */
465
    public static final PresenceAbsenceTerm NATIVE_FORMERLY_NATIVE(){
466
        return getTermByUuid(uuidNE);
467
    }
468

    
469
    /**
470
     * Same as {@link #NATIVE()} but presence was reported in error, so
471
     * finally it is not native.
472
     * @see #NATIVE()
473
     * @see #NATIVE_PRESENCE_QUESTIONABLE()
474
     * @see #NATIVE_DOUBTFULLY_NATIVE()
475
     */
476
    public static final PresenceAbsenceTerm NATIVE_REPORTED_IN_ERROR(){
477
        return getTermByUuid(uuidNativeError );
478
    }
479

    
480
	/**
481
	 * Same as {@link #NATIVE()} but the nativeness is doubtful, while presence
482
	 * is NOT questionable
483
	 * @see #NATIVE()
484
	 * @see #NATIVE_PRESENCE_QUESTIONABLE()
485
	 * @see #NATIVE_REPORTED_IN_ERROR()
486
	 */
487
	public static final PresenceAbsenceTerm NATIVE_DOUBTFULLY_NATIVE(){
488
		return getTermByUuid(uuidND);
489
	}
490

    
491
    /**
492
     * Same as {@link #NATIVE()} but the nativeness is doubtful, while presence
493
     * is NOT questionable
494
     * @see #NATIVE_DOUBTFULLY_NATIVE()
495
     * @see #NATIVE()
496
     * @see #NATIVE_PRESENCE_QUESTIONABLE()
497
     */
498
    public static final PresenceAbsenceTerm NATIVE_DOUBTFULLY_NATIVE_REPORTED_IN_ERROR(){
499
        return getTermByUuid(uuidNDE);
500
    }
501

    
502

    
503
    /**
504
     * Naturalized (or introduced: naturalized). Further distinction can be made by
505
     * distinguishing invasive / non-invasive
506
     * @see #NATURALISED_PRESENCE_QUESTIONABLE()
507
     * @see #NATURALISED_REPORTED_IN_ERROR()
508
     * @see #INVASIVE()
509
     * @see #NON_INVASIVE
510
     */
511
    public static final PresenceAbsenceTerm NATURALISED(){
512
        return getTermByUuid(uuidNaturalised);
513
    }
514

    
515
    /**
516
    *
517
    * @see #NATURALISED()
518
    */
519
   public static final PresenceAbsenceTerm NATURALISED_PRESENCE_QUESTIONABLE(){
520
       return getTermByUuid(uuidINQ);
521
   }
522

    
523
    public static final PresenceAbsenceTerm NATURALISED_REPORTED_IN_ERROR(){
524
        return getTermByUuid(uuidNaE);
525
    }
526

    
527
	/**
528
	 * Naturalized invasive. <BR>
529
	 * The taxon is present but not native in the given area. Additionally
530
	 * it is spreading fast.
531
	 *
532
	 * @see #INVASIVE_PRESENCE_QUESTIONABLE()
533
	 * @see #NON_INVASIVE()
534
	 * @see #NON_INVASIVE_PRESENCE_QUESTIONABLE()
535
	 */
536
	public static final PresenceAbsenceTerm INVASIVE(){
537
		return getTermByUuid(uuidNI);
538
	}
539
    /**
540
     * Invasive, presence questionable.
541
     *
542
     * @see #INVASIVE()
543
     * @see #NON_INVASIVE()
544
     * @see #NON_INVASIVE_PRESENCE_QUESTIONABLE()
545
     */
546
    public static final PresenceAbsenceTerm INVASIVE_PRESENCE_QUESTIONABLE(){
547
        return getTermByUuid(uuidNIQ);
548
    }
549
    /**
550
     * The taxon is present but not native in the given area (naturalized).
551
     * Additionally it is spreading not so fast.
552
     *
553
     * @see #INVASIVE()
554
     * @see #INVASIVE_PRESENCE_QUESTIONABLE()
555
     * @see #NON_INVASIVE_PRESENCE_QUESTIONABLE()
556
     */
557
    public static final PresenceAbsenceTerm NON_INVASIVE(){
558
        return getTermByUuid(uuidNN);
559
    }
560
    /**
561
     * The taxon is questionable present and not native in the given area (naturalized).
562
     * Additionally it is spreading not so fast
563
     *
564
     * @see #NON_INVASIVE()
565
     * @see #INVASIVE()
566
     * @see #INVASIVE_PRESENCE_QUESTIONABLE()
567
     */
568
    public static final PresenceAbsenceTerm NON_INVASIVE_PRESENCE_QUESTIONABLE(){
569
        return getTermByUuid(uuidNNQ);
570
    }
571

    
572

    
573
	/**
574
	 * @see #PRESENT()
575
	 * @see #REPORTED_IN_ERROR()
576
	 */
577
	public static final PresenceAbsenceTerm ABSENT(){
578
		return getTermByUuid(uuidAbsence);
579
	}
580

    
581
	/**
582
	 * The taxon is {@link #ABSENT() absent} in the given area
583
	 * but was erroneously reported as present.
584
	 *
585
	 * @see #ABSENT()
586
	 * @see #NATIVE_REPORTED_IN_ERROR()
587
	 * @see #INTRODUCED_REPORTED_IN_ERROR()
588
	 */
589
	public static final PresenceAbsenceTerm REPORTED_IN_ERROR(){
590
        return getTermByUuid(uuidReportedInError);
591
    }
592

    
593

    
594
//******************************** METHODS ****************************/
595

    
596
	@Override
597
	public void resetTerms(){
598
		termMap = null;
599
	}
600

    
601
	@Override
602
	protected void setDefaultTerms(TermVocabulary<PresenceAbsenceTerm> termVocabulary) {
603
		termMap = new HashMap<>();
604
		for (PresenceAbsenceTerm term : termVocabulary.getTerms()){
605
			termMap.put(term.getUuid(), term);
606
		}
607
	}
608

    
609
    @Override
610
    public PresenceAbsenceTerm readCsvLine(Class<PresenceAbsenceTerm> termClass, List<String> csvLine, TermType termType,
611
            Map<UUID,DefinedTermBase> terms, boolean abbrevAsId){
612
    	PresenceAbsenceTerm newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
613
        String abbreviatedLabel = csvLine.get(4);
614
//		String uuid = (String)csvLine.get(0);
615
//		map.put(abbreviatedLabel, UUID.fromString(uuid));
616
        String symbol = csvLine.get(5);
617
        newInstance.setSymbol(symbol);
618
        String color = csvLine.get(6);
619
        try {
620
			newInstance.setDefaultColor(color);
621
		} catch (ParseException e) {
622
			throw new RuntimeException(e);
623
		}
624
        boolean isAbsence = csvLine.get(7).equals("1") ? true : false;
625
        newInstance.setAbsenceTerm(isAbsence);
626

    
627
        newInstance.getRepresentation(Language.DEFAULT()).setAbbreviatedLabel(abbreviatedLabel);
628
        return newInstance;
629
    }
630

    
631
    /**
632
     * @return the defaultColor
633
     */
634
    public String getDefaultColor() {
635
        return defaultColor;
636
    }
637

    
638
    /**
639
     * @param defaultColor the defaultColor to set
640
     * @throws ParseException
641
     */
642
    //TODO make format checking a hibernate validation rule
643
    public void setDefaultColor(String defaultColor) throws ParseException  {
644
    	String regEx = "[0-9a-fA-F]{6}";
645
    	if (StringUtils.isEmpty(defaultColor)){
646
    		this.defaultColor = null;
647
    	}else if (StringUtils.isEmpty(defaultColor) || defaultColor.matches(regEx)){
648
        		this.defaultColor = defaultColor;
649
    	}else{
650
    		throw new java.text.ParseException("Default color is not of correct format. Required is 'FFFFFF'", -1);
651
    	}
652
    }
653

    
654
    /**
655
     * Compares this OrderedTermBase with the specified OrderedTermBase for
656
     * order. Returns a -1, 0, or +1 if the orderId of this object is greater
657
     * than, equal to, or less than the specified object.
658
     * <p>
659
     * <b>Note:</b> The compare logic of this method is the <b>inverse logic</b>
660
     * of the the one implemented in
661
     * {@link java.lang.Comparable#compareTo(java.lang.Object)}
662
     *
663
     * @param orderedTerm
664
     *            the OrderedTermBase to be compared
665
     * @param skipVocabularyCheck
666
     *            whether to skip checking if both terms to compare are in the
667
     *            same vocabulary
668
     * @throws NullPointerException
669
     *             if the specified object is null
670
     */
671
    @Override
672
    protected int performCompareTo(PresenceAbsenceTerm presenceAbsenceTerm, boolean skipVocabularyCheck) {
673

    
674
    	PresenceAbsenceTerm presenceAbsenceTermLocal = CdmBase.deproxy(presenceAbsenceTerm, PresenceAbsenceTerm.class);
675
        if(! skipVocabularyCheck){
676
            if (this.vocabulary == null || presenceAbsenceTermLocal.vocabulary == null){
677
                throw new IllegalStateException("An ordered term (" + this.toString() + " or " +
678
                		presenceAbsenceTermLocal.toString() + ") of class " + this.getClass() + " or " +
679
                		presenceAbsenceTermLocal.getClass() + " does not belong to a vocabulary and therefore "
680
                		+ "can not be compared");
681
            }
682
            if (presenceAbsenceTermLocal.isAbsenceTerm() != this.isAbsenceTerm() ){
683
              if (presenceAbsenceTermLocal.isAbsenceTerm()){
684
            		return 1;
685
            	}else{
686
            		return -1;
687
            	}
688

    
689
            }
690
        }
691

    
692
        int orderThat;
693
        int orderThis;
694
        try {
695
            orderThat = presenceAbsenceTermLocal.orderIndex;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
696
            orderThis = orderIndex; //OLD: this.getVocabulary().getTerms().indexOf(this);
697
        } catch (RuntimeException e) {
698
            throw e;
699
        }
700
        if (orderThis > orderThat){
701
            return -1;
702
        }else if (orderThis < orderThat){
703
            return 1;
704
        }else {
705
            return 0;
706
        }
707
    }
708

    
709

    
710
	public boolean isAbsenceTerm() {
711
		return absenceTerm;
712
	}
713

    
714
	public void setAbsenceTerm(boolean isAbsenceTerm) {
715
		this.absenceTerm = isAbsenceTerm;
716
	}
717

    
718

    
719
}
(24-24/38)