Project

General

Profile

Download (5.92 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
import eu.etaxonomy.cdm.model.taxon.Taxon;
31

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

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

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

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

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

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

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

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

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

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

    
176
}
(1-1/40)