| 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 javax.persistence.Entity; |
|---|
| 17 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 18 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 19 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 20 | import javax.xml.bind.annotation.XmlType; |
|---|
| 21 | |
|---|
| 22 | import org.apache.log4j.Logger; |
|---|
| 23 | import org.hibernate.envers.Audited; |
|---|
| 24 | import org.hibernate.search.annotations.Indexed; |
|---|
| 25 | |
|---|
| 26 | import eu.etaxonomy.cdm.model.common.OrderedTermBase; |
|---|
| 27 | import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Controlled vocabulary to differentiate levels of areas such as province, state, |
|---|
| 31 | * etc. |
|---|
| 32 | * @author m.doering |
|---|
| 33 | * @version 1.0 |
|---|
| 34 | * @created 08-Nov-2007 13:06:36 |
|---|
| 35 | */ |
|---|
| 36 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 37 | @XmlType(name = "NamedAreaLevel") |
|---|
| 38 | @XmlRootElement(name = "NamedAreaLevel") |
|---|
| 39 | @Entity |
|---|
| 40 | @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase") |
|---|
| 41 | @Audited |
|---|
| 42 | public class NamedAreaLevel extends OrderedTermBase<NamedAreaLevel> { |
|---|
| 43 | private static final long serialVersionUID = -7977901140330659208L; |
|---|
| 44 | @SuppressWarnings("unused") |
|---|
| 45 | private static final Logger logger = Logger.getLogger(NamedAreaLevel.class); |
|---|
| 46 | |
|---|
| 47 | protected static Map<UUID, NamedAreaLevel> termMap = null; |
|---|
| 48 | |
|---|
| 49 | private static final UUID uuidTdwgLevel1 = UUID.fromString("cd7771b2-7427-4a01-9057-7d7a897dddaf"); |
|---|
| 50 | private static final UUID uuidTdwgLevel2 = UUID.fromString("38efa5fd-d7f0-451c-9de9-e6cce41e2225"); |
|---|
| 51 | private static final UUID uuidTdwgLevel3 = UUID.fromString("25b563b6-6a6c-401b-b090-c9498886c50b"); |
|---|
| 52 | private static final UUID uuidTdwgLevel4 = UUID.fromString("160ff2c8-9bfc-49c2-9afd-049c21a91695"); |
|---|
| 53 | private static final UUID uuidNatureReserve = UUID.fromString("340b9050-a65d-4dd4-9523-bc10f977bc68"); |
|---|
| 54 | private static final UUID uuidState = UUID.fromString("08aa6127-8ebc-4120-8411-a468a7257e02"); |
|---|
| 55 | private static final UUID uuidProvince = UUID.fromString("401d48b4-9f09-4354-be0f-c2138444f72d"); |
|---|
| 56 | private static final UUID uuidTown = UUID.fromString("f127b4d2-f6bc-4019-9c87-ee3f4de1f094"); |
|---|
| 57 | private static final UUID uuidCountry = UUID.fromString("79db63a4-1563-461e-8e41-48f5722feca4"); |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * Factory method |
|---|
| 61 | * @return |
|---|
| 62 | */ |
|---|
| 63 | public static NamedAreaLevel NewInstance(){ |
|---|
| 64 | return new NamedAreaLevel(); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Factory method |
|---|
| 69 | * @return |
|---|
| 70 | */ |
|---|
| 71 | public static NamedAreaLevel NewInstance(String term, String label, String labelAbbrev){ |
|---|
| 72 | return new NamedAreaLevel(term, label, labelAbbrev); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Constructor |
|---|
| 77 | */ |
|---|
| 78 | public NamedAreaLevel() { |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | protected NamedAreaLevel(String term, String label, String labelAbbrev) { |
|---|
| 82 | super(term, label, labelAbbrev); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | //************************** METHODS ******************************** |
|---|
| 88 | |
|---|
| 89 | protected static NamedAreaLevel getTermByUuid(UUID uuid){ |
|---|
| 90 | if (termMap == null){ |
|---|
| 91 | return null; //better return null then initialize the termMap in an unwanted way |
|---|
| 92 | } |
|---|
| 93 | return (NamedAreaLevel)termMap.get(uuid); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * continents |
|---|
| 98 | */ |
|---|
| 99 | public static final NamedAreaLevel TDWG_LEVEL1(){ |
|---|
| 100 | return getTermByUuid(uuidTdwgLevel1); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * larger regions |
|---|
| 105 | */ |
|---|
| 106 | public static final NamedAreaLevel TDWG_LEVEL2(){ |
|---|
| 107 | return getTermByUuid(uuidTdwgLevel2); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * mostly countries |
|---|
| 112 | */ |
|---|
| 113 | public static final NamedAreaLevel TDWG_LEVEL3(){ |
|---|
| 114 | return getTermByUuid(uuidTdwgLevel3); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | public static final NamedAreaLevel TDWG_LEVEL4(){ |
|---|
| 118 | return getTermByUuid(uuidTdwgLevel4); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public static final NamedAreaLevel NATURE_RESERVE(){ |
|---|
| 122 | return getTermByUuid(uuidNatureReserve); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public static final NamedAreaLevel STATE(){ |
|---|
| 126 | return getTermByUuid(uuidState); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | public static final NamedAreaLevel PROVINCE(){ |
|---|
| 130 | return getTermByUuid(uuidProvince); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public static final NamedAreaLevel TOWN(){ |
|---|
| 134 | return getTermByUuid(uuidTown); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public static final NamedAreaLevel COUNTRY(){ |
|---|
| 138 | return getTermByUuid(uuidCountry); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public static final boolean isTDWG_LEVEL1(String str){ |
|---|
| 142 | boolean result = false; |
|---|
| 143 | if (uuidTdwgLevel1.compareTo(UUID.fromString(str)) == 0){ |
|---|
| 144 | result = true; |
|---|
| 145 | } |
|---|
| 146 | return result; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | public static final boolean isTDWG_LEVEL2(String str){ |
|---|
| 150 | boolean result = false; |
|---|
| 151 | if (uuidTdwgLevel2.compareTo(UUID.fromString(str)) == 0){ |
|---|
| 152 | result = true; |
|---|
| 153 | } |
|---|
| 154 | return result; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | public static final boolean isTDWG_LEVEL3(String str){ |
|---|
| 158 | boolean result = false; |
|---|
| 159 | if (uuidTdwgLevel3.compareTo(UUID.fromString(str)) == 0){ |
|---|
| 160 | result = true; |
|---|
| 161 | } |
|---|
| 162 | return result; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | public static final boolean isTDWG_LEVEL4(String str){ |
|---|
| 166 | boolean result = false; |
|---|
| 167 | if (uuidTdwgLevel4.compareTo(UUID.fromString(str)) == 0){ |
|---|
| 168 | result = true; |
|---|
| 169 | } |
|---|
| 170 | return result; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | /* (non-Javadoc) |
|---|
| 175 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms() |
|---|
| 176 | */ |
|---|
| 177 | @Override |
|---|
| 178 | public void resetTerms(){ |
|---|
| 179 | termMap = null; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | @Override |
|---|
| 185 | protected void setDefaultTerms(TermVocabulary<NamedAreaLevel> termVocabulary) { |
|---|
| 186 | termMap = new HashMap<UUID, NamedAreaLevel>(); |
|---|
| 187 | for (NamedAreaLevel term : termVocabulary.getTerms()){ |
|---|
| 188 | termMap.put(term.getUuid(), (NamedAreaLevel)term); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | } |
|---|