| 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.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.Language; |
|---|
| 27 | import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|---|
| 28 | import eu.etaxonomy.cdm.model.location.NamedArea; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * This class represents terms describing different types of presence |
|---|
| 32 | * (like "native" or "introduced") of a {@link Taxon taxon} in a {@link NamedArea particular area}. |
|---|
| 33 | * |
|---|
| 34 | * @author m.doering |
|---|
| 35 | * @version 1.0 |
|---|
| 36 | * @created 08-Nov-2007 13:06:44 |
|---|
| 37 | */ |
|---|
| 38 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 39 | @XmlType(name = "PresenceTerm") |
|---|
| 40 | @XmlRootElement(name = "PresenceTerm") |
|---|
| 41 | @Entity |
|---|
| 42 | @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase") |
|---|
| 43 | @Audited |
|---|
| 44 | public class PresenceTerm extends PresenceAbsenceTermBase<PresenceTerm> { |
|---|
| 45 | private static final long serialVersionUID = -2876981902335193596L; |
|---|
| 46 | private static final Logger logger = Logger.getLogger(PresenceTerm.class); |
|---|
| 47 | |
|---|
| 48 | protected static Map<UUID, PresenceTerm> termMap = null; |
|---|
| 49 | |
|---|
| 50 | private static final UUID uuidP=UUID.fromString("cef81d25-501c-48d8-bbea-542ec50de2c2"); |
|---|
| 51 | private static final UUID uuidPD=UUID.fromString("75a60279-a4c2-4f53-bc57-466028a4b3db"); |
|---|
| 52 | |
|---|
| 53 | private static final UUID uuidN=UUID.fromString("ddeac4f2-d8fa-43b8-ad7e-ca13abdd32c7"); |
|---|
| 54 | private static final UUID uuidNQ=UUID.fromString("925662c1-bb10-459a-8c53-da5a738ac770"); |
|---|
| 55 | private static final UUID uuidND=UUID.fromString("310373bf-7df4-4d02-8cb3-bcc7448805fc"); |
|---|
| 56 | private static final UUID uuidC=UUID.fromString("9eb99fe6-59e2-4445-8e6a-478365bd0fa9"); |
|---|
| 57 | private static final UUID uuidI=UUID.fromString("643cf9d1-a5f1-4622-9837-82ef961e880b"); |
|---|
| 58 | private static final UUID uuidIQ=UUID.fromString("83eb0aa0-1a45-495a-a3ca-bf6958b74366"); |
|---|
| 59 | private static final UUID uuidID=UUID.fromString("0c54761e-4887-4788-9dfa-7190c88746e3"); |
|---|
| 60 | private static final UUID uuidIP=UUID.fromString("da159544-b0dd-4599-a9c9-640826af8c17"); |
|---|
| 61 | private static final UUID uuidIA=UUID.fromString("42946bd6-9c22-45ad-a910-7427e8f60bfd"); |
|---|
| 62 | private static final UUID uuidIN=UUID.fromString("e191e89a-a751-4b0c-b883-7f1de70915c9"); |
|---|
| 63 | private static final UUID uuidIC=UUID.fromString("fac8c347-8262-44a1-b0a4-db4de451c021"); |
|---|
| 64 | private static final UUID uuidE=UUID.fromString("c3ee7048-15b7-4be1-b687-9ce9c1a669d6"); |
|---|
| 65 | private static final UUID uuidNA=UUID.fromString("4e04990a-66fe-4fdf-856c-f40772fbcf0a"); |
|---|
| 66 | private static final UUID uuidIV=UUID.fromString("dc536e3d-a753-4bbe-a386-dd8aff35c234"); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | //********* METHODS **************************************/ |
|---|
| 70 | /** |
|---|
| 71 | * Creates a new empty presence term. |
|---|
| 72 | * |
|---|
| 73 | * @see #NewInstance(String, String, String) |
|---|
| 74 | */ |
|---|
| 75 | public static PresenceTerm NewInstance(){ |
|---|
| 76 | return new PresenceTerm(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Creates a new presence term with a description (in the {@link Language#DEFAULT() default language}), |
|---|
| 81 | * a label and a label abbreviation. |
|---|
| 82 | * |
|---|
| 83 | * @param term the string (in the default language) describing the |
|---|
| 84 | * new presence term to be created |
|---|
| 85 | * @param label the string identifying the new presence term to be created |
|---|
| 86 | * @param labelAbbrev the string identifying (in abbreviated form) the |
|---|
| 87 | * new presence term to be created |
|---|
| 88 | * @see #NewInstance() |
|---|
| 89 | */ |
|---|
| 90 | public static PresenceTerm NewInstance(String term, String label, String labelAbbrev){ |
|---|
| 91 | return new PresenceTerm(term, label, labelAbbrev); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | // ************* CONSTRUCTORS *************/ |
|---|
| 95 | /** |
|---|
| 96 | * Class constructor: creates a new empty presence term. |
|---|
| 97 | * |
|---|
| 98 | * @see #PresenceTerm(String, String, String) |
|---|
| 99 | */ |
|---|
| 100 | public PresenceTerm() { |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * Class constructor: creates a new presence term with a description (in the {@link Language#DEFAULT() default language}), |
|---|
| 105 | * a label and a label abbreviation. |
|---|
| 106 | * |
|---|
| 107 | * @param term the string (in the default language) describing the |
|---|
| 108 | * new presence term to be created |
|---|
| 109 | * @param label the string identifying the new presence term to be created |
|---|
| 110 | * @param labelAbbrev the string identifying (in abbreviated form) the |
|---|
| 111 | * new presence term to be created |
|---|
| 112 | * @see #PresenceTerm() |
|---|
| 113 | */ |
|---|
| 114 | public PresenceTerm(String term, String label, String labelAbbrev) { |
|---|
| 115 | super(term, label, labelAbbrev); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | //******************************* STATIC METHODS ***************************************** |
|---|
| 121 | |
|---|
| 122 | protected static PresenceTerm getTermByUuid(UUID uuid){ |
|---|
| 123 | if (termMap == null){ |
|---|
| 124 | return null; |
|---|
| 125 | }else{ |
|---|
| 126 | return (PresenceTerm)termMap.get(uuid); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | public static final PresenceTerm PRESENT(){ |
|---|
| 132 | return getTermByUuid(uuidP); |
|---|
| 133 | } |
|---|
| 134 | public static final PresenceTerm PRESENT_DOUBTFULLY(){ |
|---|
| 135 | return getTermByUuid(uuidPD); |
|---|
| 136 | } |
|---|
| 137 | public static final PresenceTerm CULTIVATED(){ |
|---|
| 138 | return getTermByUuid(uuidC); |
|---|
| 139 | } |
|---|
| 140 | public static final PresenceTerm ENDEMIC_FOR_THE_RELEVANT_AREA(){ |
|---|
| 141 | return getTermByUuid(uuidE); |
|---|
| 142 | } |
|---|
| 143 | public static final PresenceTerm INTRODUCED(){ |
|---|
| 144 | return getTermByUuid(uuidI); |
|---|
| 145 | } |
|---|
| 146 | public static final PresenceTerm INTRODUCED_ADVENTITIOUS(){ |
|---|
| 147 | return getTermByUuid(uuidIA); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | public static final PresenceTerm INTRODUCED_CULTIVATED(){ |
|---|
| 151 | return getTermByUuid(uuidIC); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | public static final PresenceTerm INTRODUCED_DOUBTFULLY_INTRODUCED(){ |
|---|
| 155 | return getTermByUuid(uuidID); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | public static final PresenceTerm INTRODUCED_NATURALIZED(){ |
|---|
| 159 | return getTermByUuid(uuidIN); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | public static final PresenceTerm INTRODUCED_PRESENCE_QUESTIONABLE(){ |
|---|
| 163 | return getTermByUuid(uuidIQ); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public static final PresenceTerm INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION(){ |
|---|
| 167 | return getTermByUuid(uuidIP); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | public static final PresenceTerm NATIVE(){ |
|---|
| 171 | return getTermByUuid(uuidN); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | public static final PresenceTerm NATIVE_DOUBTFULLY_NATIVE(){ |
|---|
| 175 | return getTermByUuid(uuidND); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | public static final PresenceTerm NATIVE_PRESENCE_QUESTIONABLE(){ |
|---|
| 179 | return getTermByUuid(uuidNQ); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | public static final PresenceTerm INVASIVE(){ |
|---|
| 183 | return getTermByUuid(uuidIV); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | public static final PresenceTerm NATURALISED(){ |
|---|
| 187 | return getTermByUuid(uuidNA); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | //TODO read from label(abbrevs) like in TDWGArea |
|---|
| 191 | public static PresenceTerm getPresenceTermByAbbreviation(String abbrev) { |
|---|
| 192 | if (abbrev == null) { throw new NullPointerException("abbrev is 'null' in getPresenceTermByAbbreviation"); |
|---|
| 193 | } else if (abbrev.equalsIgnoreCase("c")) { return PresenceTerm.CULTIVATED(); |
|---|
| 194 | } else if (abbrev.equalsIgnoreCase("e")) { return PresenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA(); |
|---|
| 195 | } else if (abbrev.equalsIgnoreCase("i")) { return PresenceTerm.INTRODUCED(); |
|---|
| 196 | } else if (abbrev.equalsIgnoreCase("ia")) { return PresenceTerm.INTRODUCED_ADVENTITIOUS(); |
|---|
| 197 | } else if (abbrev.equalsIgnoreCase("ic")) { return PresenceTerm.INTRODUCED_CULTIVATED(); |
|---|
| 198 | } else if (abbrev.equalsIgnoreCase("id")) { return PresenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED(); |
|---|
| 199 | } else if (abbrev.equalsIgnoreCase("in")) { return PresenceTerm.INTRODUCED_NATURALIZED(); |
|---|
| 200 | } else if (abbrev.equalsIgnoreCase("ip")) { return PresenceTerm.INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION(); |
|---|
| 201 | } else if (abbrev.equalsIgnoreCase("iq")) { return PresenceTerm.INTRODUCED_PRESENCE_QUESTIONABLE(); |
|---|
| 202 | } else if (abbrev.equalsIgnoreCase("n")) { return PresenceTerm.NATIVE(); |
|---|
| 203 | } else if (abbrev.equalsIgnoreCase("nd")) { return PresenceTerm.NATIVE_DOUBTFULLY_NATIVE(); |
|---|
| 204 | } else if (abbrev.equalsIgnoreCase("nq")) { return PresenceTerm.NATIVE_PRESENCE_QUESTIONABLE(); |
|---|
| 205 | } else if (abbrev.equalsIgnoreCase("p")) { return PresenceTerm.PRESENT(); |
|---|
| 206 | } else if (abbrev.equalsIgnoreCase("na")) { return PresenceTerm.NATURALISED(); |
|---|
| 207 | } else if (abbrev.equalsIgnoreCase("iv")) { return PresenceTerm.INVASIVE(); |
|---|
| 208 | } else { |
|---|
| 209 | logger.warn("Unknown presence status term: " + abbrev); |
|---|
| 210 | return null; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | //************************** METHODS ******************************** |
|---|
| 215 | |
|---|
| 216 | /* (non-Javadoc) |
|---|
| 217 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms() |
|---|
| 218 | */ |
|---|
| 219 | @Override |
|---|
| 220 | public void resetTerms(){ |
|---|
| 221 | termMap = null; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | /* (non-Javadoc) |
|---|
| 225 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#setDefaultTerms(eu.etaxonomy.cdm.model.common.TermVocabulary) |
|---|
| 226 | */ |
|---|
| 227 | @Override |
|---|
| 228 | protected void setDefaultTerms(TermVocabulary<PresenceTerm> termVocabulary) { |
|---|
| 229 | termMap = new HashMap<UUID, PresenceTerm>(); |
|---|
| 230 | for (PresenceTerm term : termVocabulary.getTerms()){ |
|---|
| 231 | termMap.put(term.getUuid(), (PresenceTerm)term); //TODO casting |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | } |
|---|