Project

General

Profile

Download (5.87 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

    
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.UUID;
16

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

    
23
import org.apache.log4j.Logger;
24
import org.hibernate.envers.Audited;
25
import org.hibernate.search.annotations.Indexed;
26

    
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29
import eu.etaxonomy.cdm.model.location.NamedArea;
30

    
31
/**
32
 * This class represents terms describing different types of absence
33
 * (like "extinct" or just "absent") of a {@link Taxon taxon} in a {@link NamedArea particular area}.
34
 * 
35
 * @author m.doering
36
 * @version 1.0
37
 * @created 08-Nov-2007 13:06:08
38
 */
39
@XmlAccessorType(XmlAccessType.FIELD)
40
@XmlType(name = "AbsenceTerm")
41
@XmlRootElement(name = "AbsenceTerm")
42
@Entity
43
@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
44
@Audited
45
public class AbsenceTerm extends PresenceAbsenceTermBase<AbsenceTerm> {
46
	private static final long serialVersionUID = -7125360212309512860L;
47
	private static final Logger logger = Logger.getLogger(AbsenceTerm.class);
48
	
49
	private static Map<UUID, AbsenceTerm> termMap = null;
50
	
51
	private static final UUID uuidAbsence=UUID.fromString("59709861-f7d9-41f9-bb21-92559cedd598");
52
	private static final UUID uuidNF=UUID.fromString("61cee840-801e-41d8-bead-015ad866c2f1");
53
	private static final UUID uuidIF=UUID.fromString("aeec2947-2700-4623-8e32-9e3a430569d1");
54
	private static final UUID uuidCF=UUID.fromString("9d4d3431-177a-4abe-8e4b-1558573169d6");
55
	private static final UUID uuidNE=UUID.fromString("5c397f7b-59ef-4c11-a33c-45691ceda91b");
56
	private static final UUID uuidIE=UUID.fromString("b74dc30b-ee93-496d-8c00-4d00abae1ec7");
57
	
58

    
59
	/** 
60
	 * Creates a new empty absence term.
61
	 * 
62
	 * @see #NewInstance(String, String, String)
63
	 */
64
	public static AbsenceTerm NewInstance(){
65
		logger.debug("NewInstance");
66
		return new AbsenceTerm();
67
	}
68
	
69
	/** 
70
	 * Creates a new absence term with a description (in the {@link Language#DEFAULT() default language}),
71
	 * a label and a label abbreviation.
72
	 * 
73
	 * @param	term  		 the string (in the default language) describing the
74
	 * 						 new absence term to be created 
75
	 * @param	label  		 the string identifying the new absence term to be created
76
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
77
	 * 						 new absence term to be created
78
	 * @see 				 #NewInstance()
79
	 */
80
	public static AbsenceTerm NewInstance(String term, String label, String labelAbbrev){
81
		return new AbsenceTerm(term, label, labelAbbrev);
82
	}
83
		
84
	// ************* CONSTRUCTORS *************/	
85
	/** 
86
	 * Class constructor: creates a new empty absence term.
87
	 * 
88
	 * @see #AbsenceTerm(String, String, String)
89
	 */
90
	public AbsenceTerm() {
91
	}
92

    
93
	/** 
94
	 * Class constructor: creates a new absence term with a description (in the {@link Language#DEFAULT() default language}),
95
	 * a label and a label abbreviation.
96
	 * 
97
	 * @param	term  		 the string (in the default language) describing the
98
	 * 						 new absence term to be created 
99
	 * @param	label  		 the string identifying the new absence term to be created
100
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
101
	 * 						 new absence term to be created
102
	 * @see 				 #AbsenceTerm()
103
	 */
104
	public AbsenceTerm(String term, String label, String labelAbbrev) {
105
		super(term, label, labelAbbrev);
106
	}
107

    
108
	
109
//************************** METHODS ********************************
110
	
111
	/* (non-Javadoc)
112
	 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
113
	 */
114
	@Override
115
	public void resetTerms(){
116
		termMap = null;
117
	}
118

    
119
	protected static AbsenceTerm getTermByUuid(UUID uuid){
120
		if (termMap == null){
121
			return null;
122
		}else{
123
			return (AbsenceTerm)termMap.get(uuid);
124
		}
125
	}
126

    
127
	
128
	public static final AbsenceTerm ABSENT(){
129
		return getTermByUuid(uuidAbsence);
130
	}
131
	
132
	public static final AbsenceTerm NATIVE_REPORTED_IN_ERROR(){
133
		return getTermByUuid(uuidNF);
134
	}
135
	
136
	public static final AbsenceTerm CULTIVATED_REPORTED_IN_ERROR(){
137
		return getTermByUuid(uuidCF);
138
	}
139

    
140
	public static final AbsenceTerm INTRODUCED_REPORTED_IN_ERROR(){
141
		return getTermByUuid(uuidIF);
142
	}
143

    
144
	public static final AbsenceTerm NATIVE_FORMERLY_NATIVE(){
145
		return getTermByUuid(uuidNE);
146
	}
147

    
148
	public static final AbsenceTerm INTRODUCED_FORMERLY_INTRODUCED(){
149
		return getTermByUuid(uuidIE);
150
	}
151
	
152
	//TODO make automatic like in TDWGArea
153
	public static AbsenceTerm getPresenceTermByAbbreviation(String abbrev) { 
154
		if (abbrev == null) { throw new NullPointerException("abbrev is 'null' in getPresenceTermByAbbreviation");
155
		} else if (abbrev.equalsIgnoreCase("cf")) { return AbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
156
		} else if (abbrev.equalsIgnoreCase("if")) { return AbsenceTerm.INTRODUCED_REPORTED_IN_ERROR();
157
		} else if (abbrev.equalsIgnoreCase("nf")) { return AbsenceTerm.NATIVE_REPORTED_IN_ERROR();
158
		} else if (abbrev.equalsIgnoreCase("ne")) { return AbsenceTerm.NATIVE_FORMERLY_NATIVE();
159
		} else if (abbrev.equalsIgnoreCase("ie")) { return AbsenceTerm.INTRODUCED_FORMERLY_INTRODUCED();
160
		} else {
161
			logger.warn("Unknown absence status term: " + abbrev);
162
			return null;
163
		}
164
	}
165

    
166
	
167
	@Override
168
	protected void setDefaultTerms(TermVocabulary<AbsenceTerm> termVocabulary) {
169
		termMap = new HashMap<UUID, AbsenceTerm>();
170
		for (AbsenceTerm term : termVocabulary.getTerms()){
171
			termMap.put(term.getUuid(), (AbsenceTerm)term);  //TODO casting
172
		}
173
	}
174

    
175
}
(1-1/40)