Project

General

Profile

Download (5.03 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.location;
11

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

    
16
import eu.etaxonomy.cdm.model.common.AnnotationType;
17
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
18
import eu.etaxonomy.cdm.model.common.TermVocabulary;
19

    
20
import org.apache.log4j.Logger;
21
import org.hibernate.envers.Audited;
22
import org.hibernate.search.annotations.Indexed;
23

    
24
import javax.persistence.*;
25
import javax.xml.bind.annotation.XmlAccessType;
26
import javax.xml.bind.annotation.XmlAccessorType;
27
import javax.xml.bind.annotation.XmlRootElement;
28
import javax.xml.bind.annotation.XmlType;
29

    
30
/**
31
 * Controlled vocabulary to differentiate levels of areas such as province, state,
32
 * etc.
33
 * @author m.doering
34
 * @version 1.0
35
 * @created 08-Nov-2007 13:06:36
36
 */
37
@XmlAccessorType(XmlAccessType.FIELD)
38
@XmlType(name = "NamedAreaLevel")
39
@XmlRootElement(name = "NamedAreaLevel")
40
@Entity
41
@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
42
@Audited
43
public class NamedAreaLevel extends OrderedTermBase<NamedAreaLevel> {
44
	private static final long serialVersionUID = -7977901140330659208L;
45
	@SuppressWarnings("unused")
46
	private static final Logger logger = Logger.getLogger(NamedAreaLevel.class);
47

    
48
	protected static Map<UUID, NamedAreaLevel> termMap = null;		
49

    
50
	private static final UUID uuidTdwgLevel1 = UUID.fromString("cd7771b2-7427-4a01-9057-7d7a897dddaf");
51
	private static final UUID uuidTdwgLevel2 = UUID.fromString("38efa5fd-d7f0-451c-9de9-e6cce41e2225");
52
	private static final UUID uuidTdwgLevel3 = UUID.fromString("25b563b6-6a6c-401b-b090-c9498886c50b");
53
	private static final UUID uuidTdwgLevel4 = UUID.fromString("160ff2c8-9bfc-49c2-9afd-049c21a91695");
54
	private static final UUID uuidNatureReserve = UUID.fromString("340b9050-a65d-4dd4-9523-bc10f977bc68");
55
	private static final UUID uuidState = UUID.fromString("08aa6127-8ebc-4120-8411-a468a7257e02");
56
	private static final UUID uuidProvince = UUID.fromString("401d48b4-9f09-4354-be0f-c2138444f72d");
57
	private static final UUID uuidTown = UUID.fromString("f127b4d2-f6bc-4019-9c87-ee3f4de1f094");
58
	private static final UUID uuidCountry = UUID.fromString("79db63a4-1563-461e-8e41-48f5722feca4");
59
	
60
	/**
61
	 * Factory method
62
	 * @return
63
	 */
64
	public static NamedAreaLevel NewInstance(){
65
		return new NamedAreaLevel();
66
	}
67

    
68
	/**
69
	 * Factory method
70
	 * @return
71
	 */
72
	public static NamedAreaLevel NewInstance(String term, String label, String labelAbbrev){
73
		return new NamedAreaLevel(term, label, labelAbbrev);
74
	}
75
	
76
	/**
77
	 * Constructor
78
	 */
79
	public NamedAreaLevel() {
80
	}
81

    
82
	protected NamedAreaLevel(String term, String label, String labelAbbrev) {
83
		super(term, label, labelAbbrev);
84
	}
85

    
86
	
87
	
88
//************************** METHODS ********************************
89
	
90
	protected static NamedAreaLevel getTermByUuid(UUID uuid){
91
		if (termMap == null){
92
			return null;  //better return null then initialize the termMap in an unwanted way 
93
		}
94
		return (NamedAreaLevel)termMap.get(uuid);
95
	}
96
		
97
	/**
98
	 * continents
99
	 */
100
	public static final NamedAreaLevel TDWG_LEVEL1(){
101
		return getTermByUuid(uuidTdwgLevel1);
102
	}
103

    
104
	/**
105
	 * larger regions
106
	 */
107
	public static final NamedAreaLevel TDWG_LEVEL2(){
108
		return getTermByUuid(uuidTdwgLevel2);
109
	}
110

    
111
	/**
112
	 * mostly countries
113
	 */
114
	public static final NamedAreaLevel TDWG_LEVEL3(){
115
		return getTermByUuid(uuidTdwgLevel3);
116
	}
117

    
118
	public static final NamedAreaLevel TDWG_LEVEL4(){
119
		return getTermByUuid(uuidTdwgLevel4);
120
	}
121

    
122
	public static final NamedAreaLevel NATURE_RESERVE(){
123
		return getTermByUuid(uuidNatureReserve);
124
	}
125

    
126
	public static final NamedAreaLevel STATE(){
127
		return getTermByUuid(uuidState);
128
	}
129

    
130
	public static final NamedAreaLevel PROVINCE(){
131
		return getTermByUuid(uuidProvince);
132
	}
133

    
134
	public static final NamedAreaLevel TOWN(){
135
		return getTermByUuid(uuidTown);
136
	}
137

    
138
	public static final NamedAreaLevel COUNTRY(){
139
		return getTermByUuid(uuidCountry);
140
	}
141

    
142
	public static final boolean isTDWG_LEVEL1(String str){
143
		boolean result = false;
144
		if (uuidTdwgLevel1.compareTo(UUID.fromString(str)) == 0){
145
			result = true;
146
		}
147
		return result;
148
	}
149
	
150
	public static final boolean isTDWG_LEVEL2(String str){
151
		boolean result = false;
152
		if (uuidTdwgLevel2.compareTo(UUID.fromString(str)) == 0){
153
			result = true;
154
		}
155
		return result;
156
	}
157
	
158
	public static final boolean isTDWG_LEVEL3(String str){
159
		boolean result = false;
160
		if (uuidTdwgLevel3.compareTo(UUID.fromString(str)) == 0){
161
			result = true;
162
		}
163
		return result;
164
	}
165
	
166
	public static final boolean isTDWG_LEVEL4(String str){
167
		boolean result = false;
168
		if (uuidTdwgLevel4.compareTo(UUID.fromString(str)) == 0){
169
			result = true;
170
		}
171
		return result;
172
	}
173
	
174
	@Override
175
	protected void setDefaultTerms(TermVocabulary<NamedAreaLevel> termVocabulary) {
176
		termMap = new HashMap<UUID, NamedAreaLevel>();
177
		for (NamedAreaLevel term : termVocabulary.getTerms()){
178
			termMap.put(term.getUuid(), (NamedAreaLevel)term);
179
		}	
180
	}
181
}
(3-3/10)