| 1 | // $Id$ |
|---|
| 2 | /** |
|---|
| 3 | * Copyright (C) 2007 EDIT |
|---|
| 4 | * European Distributed Institute of Taxonomy |
|---|
| 5 | * http://www.e-taxonomy.eu |
|---|
| 6 | * |
|---|
| 7 | * The contents of this file are subject to the Mozilla Public License Version 1.1 |
|---|
| 8 | * See LICENSE.TXT at the top of this package for the full license terms. |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | package eu.etaxonomy.cdm.model.description; |
|---|
| 12 | |
|---|
| 13 | import java.util.HashSet; |
|---|
| 14 | import java.util.Set; |
|---|
| 15 | |
|---|
| 16 | import javax.persistence.Entity; |
|---|
| 17 | import javax.persistence.FetchType; |
|---|
| 18 | import javax.persistence.JoinColumn; |
|---|
| 19 | import javax.persistence.JoinTable; |
|---|
| 20 | import javax.persistence.ManyToMany; |
|---|
| 21 | import javax.validation.constraints.NotNull; |
|---|
| 22 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 23 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 24 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 25 | import javax.xml.bind.annotation.XmlElementWrapper; |
|---|
| 26 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 27 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 28 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 29 | import javax.xml.bind.annotation.XmlType; |
|---|
| 30 | |
|---|
| 31 | import org.apache.log4j.Logger; |
|---|
| 32 | import org.hibernate.envers.Audited; |
|---|
| 33 | import org.hibernate.search.annotations.Indexed; |
|---|
| 34 | |
|---|
| 35 | import eu.etaxonomy.cdm.model.location.NamedArea; |
|---|
| 36 | import eu.etaxonomy.cdm.model.taxon.Taxon; |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * |
|---|
| 40 | * The class representing multi-access dynamic keys used to identify |
|---|
| 41 | * {@link SpecimenOrObservationBase specimens or observations} (this means to assign {@link Taxon taxa} to). |
|---|
| 42 | * The determination process is performed by an identification software. |
|---|
| 43 | * |
|---|
| 44 | * @author h.fradin |
|---|
| 45 | * @created 13.08.2009 |
|---|
| 46 | * @version 1.0 |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 50 | @XmlType(name = "MultiAccessKey", propOrder = { |
|---|
| 51 | "coveredTaxa", |
|---|
| 52 | "taxonomicScope", |
|---|
| 53 | "geographicalScope", |
|---|
| 54 | "scopeRestrictions" |
|---|
| 55 | }) |
|---|
| 56 | @XmlRootElement(name = "MultiAccessKey") |
|---|
| 57 | @Entity |
|---|
| 58 | @Indexed(index = "eu.etaxonomy.cdm.model.media.WorkingSet") |
|---|
| 59 | @Audited |
|---|
| 60 | |
|---|
| 61 | public class MultiAccessKey extends WorkingSet implements IIdentificationKey{ |
|---|
| 62 | private static final long serialVersionUID = -240407483572972239L; |
|---|
| 63 | @SuppressWarnings("unused") |
|---|
| 64 | private static final Logger logger = Logger.getLogger(MultiAccessKey.class); |
|---|
| 65 | |
|---|
| 66 | @XmlElementWrapper(name = "CoveredTaxa") |
|---|
| 67 | @XmlElement(name = "CoveredTaxon") |
|---|
| 68 | @XmlIDREF |
|---|
| 69 | @XmlSchemaType(name = "IDREF") |
|---|
| 70 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 71 | @NotNull |
|---|
| 72 | private Set<Taxon> coveredTaxa = new HashSet<Taxon>(); |
|---|
| 73 | |
|---|
| 74 | @XmlElementWrapper(name = "TaxonomicScope") |
|---|
| 75 | @XmlElement(name = "Taxon") |
|---|
| 76 | @XmlIDREF |
|---|
| 77 | @XmlSchemaType(name = "IDREF") |
|---|
| 78 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 79 | @JoinTable( |
|---|
| 80 | name="MultiAccessKey_Taxon", |
|---|
| 81 | joinColumns=@JoinColumn(name="multiAccessKey_id"), |
|---|
| 82 | inverseJoinColumns=@JoinColumn(name="taxon_id") |
|---|
| 83 | ) |
|---|
| 84 | @NotNull |
|---|
| 85 | private Set<Taxon> taxonomicScope = new HashSet<Taxon>(); |
|---|
| 86 | |
|---|
| 87 | @XmlElementWrapper( name = "GeographicalScope") |
|---|
| 88 | @XmlElement( name = "Area") |
|---|
| 89 | @XmlIDREF |
|---|
| 90 | @XmlSchemaType(name = "IDREF") |
|---|
| 91 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 92 | @JoinTable(name="MultiAccessKey_NamedArea") |
|---|
| 93 | @NotNull |
|---|
| 94 | private Set<NamedArea> geographicalScope = new HashSet<NamedArea>(); |
|---|
| 95 | |
|---|
| 96 | @XmlElementWrapper( name = "ScopeRestrictions") |
|---|
| 97 | @XmlElement( name = "Restriction") |
|---|
| 98 | @XmlIDREF |
|---|
| 99 | @XmlSchemaType(name = "IDREF") |
|---|
| 100 | @ManyToMany(fetch = FetchType.LAZY) |
|---|
| 101 | @JoinTable(name="MultiAccessKey_Scope") |
|---|
| 102 | @NotNull |
|---|
| 103 | private Set<Scope> scopeRestrictions = new HashSet<Scope>(); |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Class constructor: creates a new empty multi-access key instance. |
|---|
| 107 | */ |
|---|
| 108 | protected MultiAccessKey() { |
|---|
| 109 | super(); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * Creates a new empty identification multi-access key instance. |
|---|
| 114 | */ |
|---|
| 115 | public static MultiAccessKey NewInstance(){ |
|---|
| 116 | return new MultiAccessKey(); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Returns the set of possible {@link Taxon taxa} corresponding to |
|---|
| 121 | * <i>this</i> identification key. |
|---|
| 122 | */ |
|---|
| 123 | public Set<Taxon> getCoveredTaxa() { |
|---|
| 124 | if(coveredTaxa == null) { |
|---|
| 125 | this.coveredTaxa = new HashSet<Taxon>(); |
|---|
| 126 | } |
|---|
| 127 | return coveredTaxa; |
|---|
| 128 | } |
|---|
| 129 | /** |
|---|
| 130 | * @see #getCoveredTaxa() |
|---|
| 131 | */ |
|---|
| 132 | protected void setCoveredTaxa(Set<Taxon> coveredTaxa) { |
|---|
| 133 | this.coveredTaxa = coveredTaxa; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * Adds a {@link Taxon taxa} to the set of {@link #getCoveredTaxa() covered taxa} |
|---|
| 138 | * corresponding to <i>this</i> identification key. |
|---|
| 139 | * |
|---|
| 140 | * @param taxon the taxon to be added to <i>this</i> identification key |
|---|
| 141 | * @see #getCoveredTaxa() |
|---|
| 142 | */ |
|---|
| 143 | public void addCoveredTaxon(Taxon taxon) { |
|---|
| 144 | this.coveredTaxa.add(taxon); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * Removes one element from the set of {@link #getCoveredTaxa() covered taxa} |
|---|
| 149 | * corresponding to <i>this</i> identification key. |
|---|
| 150 | * |
|---|
| 151 | * @param taxon the taxon which should be removed |
|---|
| 152 | * @see #getCoveredTaxa() |
|---|
| 153 | * @see #addCoveredTaxon(Taxon) |
|---|
| 154 | */ |
|---|
| 155 | public void removeCoveredTaxon(Taxon taxon) { |
|---|
| 156 | this.coveredTaxa.remove(taxon); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * Returns the set of {@link NamedArea named areas} indicating the geospatial |
|---|
| 161 | * data where <i>this</i> identification key is valid. |
|---|
| 162 | */ |
|---|
| 163 | public Set<NamedArea> getGeographicalScope() { |
|---|
| 164 | if(geographicalScope == null) { |
|---|
| 165 | this.geographicalScope = new HashSet<NamedArea>(); |
|---|
| 166 | } |
|---|
| 167 | return geographicalScope; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | * Adds a {@link NamedArea geoScope} to the set of {@link #getGeoScopes() geogspatial scopes} |
|---|
| 172 | * corresponding to <i>this</i> identification key. |
|---|
| 173 | * |
|---|
| 174 | * @param geoScope the named area to be added to <i>this</i> identification key |
|---|
| 175 | * @see #getGeoScopes() |
|---|
| 176 | */ |
|---|
| 177 | public void addGeographicalScope(NamedArea geoScope) { |
|---|
| 178 | this.geographicalScope.add(geoScope); |
|---|
| 179 | } |
|---|
| 180 | /** |
|---|
| 181 | * Removes one element from the set of {@link #getGeoScopes() geogspatial scopes} |
|---|
| 182 | * corresponding to <i>this</i> identification key. |
|---|
| 183 | * |
|---|
| 184 | * @param geoScope the named area which should be removed |
|---|
| 185 | * @see #getGeoScopes() |
|---|
| 186 | * @see #addGeoScope(NamedArea) |
|---|
| 187 | */ |
|---|
| 188 | public void removeGeographicalScope(NamedArea geoScope) { |
|---|
| 189 | this.geographicalScope.remove(geoScope); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | /** |
|---|
| 193 | * Returns the set of {@link Taxon taxa} that define the taxonomic |
|---|
| 194 | * scope of <i>this</i> identification key |
|---|
| 195 | */ |
|---|
| 196 | public Set<Taxon> getTaxonomicScope() { |
|---|
| 197 | if(taxonomicScope == null) { |
|---|
| 198 | this.taxonomicScope = new HashSet<Taxon>(); |
|---|
| 199 | } |
|---|
| 200 | return taxonomicScope; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * Adds a {@link Taxon taxa} to the set of {@link #getTaxonomicScope() taxonomic scopes} |
|---|
| 205 | * corresponding to <i>this</i> identification key. |
|---|
| 206 | * |
|---|
| 207 | * @param taxon the taxon to be added to <i>this</i> identification key |
|---|
| 208 | * @see #getTaxonomicScope() |
|---|
| 209 | */ |
|---|
| 210 | public void addTaxonomicScope(Taxon taxon) { |
|---|
| 211 | this.taxonomicScope.add(taxon); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | /** |
|---|
| 215 | * Removes one element from the set of {@link #getTaxonomicScope() taxonomic scopes} |
|---|
| 216 | * corresponding to <i>this</i> identification key. |
|---|
| 217 | * |
|---|
| 218 | * @param taxon the taxon which should be removed |
|---|
| 219 | * @see #getTaxonomicScope() |
|---|
| 220 | * @see #addTaxonomicScope(Taxon) |
|---|
| 221 | */ |
|---|
| 222 | public void removeTaxonomicScope(Taxon taxon) { |
|---|
| 223 | this.taxonomicScope.remove(taxon); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | /** |
|---|
| 227 | * Returns the set of {@link Scope scope restrictions} corresponding to |
|---|
| 228 | * <i>this</i> identification key |
|---|
| 229 | */ |
|---|
| 230 | public Set<Scope> getScopeRestrictions() { |
|---|
| 231 | if(scopeRestrictions == null) { |
|---|
| 232 | this.scopeRestrictions = new HashSet<Scope>(); |
|---|
| 233 | } |
|---|
| 234 | return scopeRestrictions; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | /** |
|---|
| 238 | * Adds a {@link Scope scope restriction} to the set of {@link #getScopeRestrictions() scope restrictions} |
|---|
| 239 | * corresponding to <i>this</i> identification key. |
|---|
| 240 | * |
|---|
| 241 | * @param scopeRestriction the scope restriction to be added to <i>this</i> identification key |
|---|
| 242 | * @see #getScopeRestrictions() |
|---|
| 243 | */ |
|---|
| 244 | public void addScopeRestriction(Scope scopeRestriction) { |
|---|
| 245 | this.scopeRestrictions.add(scopeRestriction); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | /** |
|---|
| 249 | * Removes one element from the set of {@link #getScopeRestrictions() scope restrictions} |
|---|
| 250 | * corresponding to <i>this</i> identification key. |
|---|
| 251 | * |
|---|
| 252 | * @param scopeRestriction the scope restriction which should be removed |
|---|
| 253 | * @see #getScopeRestrictions() |
|---|
| 254 | * @see #addScopeRestriction(Scope) |
|---|
| 255 | */ |
|---|
| 256 | public void removeScopeRestriction(Scope scopeRestriction) { |
|---|
| 257 | this.scopeRestrictions.remove(scopeRestriction); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | //*********************** CLONE ********************************************************/ |
|---|
| 261 | |
|---|
| 262 | /** |
|---|
| 263 | * Clones <i>this</i> MultiAccessKey. This is a shortcut that enables to create |
|---|
| 264 | * a new instance that differs only slightly from <i>this</i> MultiAccessKey by |
|---|
| 265 | * modifying only some of the attributes. |
|---|
| 266 | * |
|---|
| 267 | * @see eu.etaxonomy.cdm.model.common.AnnotatableEntity#clone() |
|---|
| 268 | * @see java.lang.Object#clone() |
|---|
| 269 | */ |
|---|
| 270 | @Override |
|---|
| 271 | public Object clone() { |
|---|
| 272 | MultiAccessKey result; |
|---|
| 273 | |
|---|
| 274 | result = (MultiAccessKey)super.clone(); |
|---|
| 275 | |
|---|
| 276 | result.coveredTaxa = new HashSet<Taxon>(); |
|---|
| 277 | for (Taxon taxon: this.coveredTaxa){ |
|---|
| 278 | result.addCoveredTaxon(taxon); |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | result.geographicalScope = new HashSet<NamedArea>(); |
|---|
| 282 | for (NamedArea area: this.geographicalScope){ |
|---|
| 283 | result.addGeographicalScope(area); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | result.scopeRestrictions = new HashSet<Scope>(); |
|---|
| 287 | for (Scope scope: this.scopeRestrictions){ |
|---|
| 288 | result.addScopeRestriction(scope); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | result.taxonomicScope = new HashSet<Taxon>(); |
|---|
| 292 | for (Taxon taxon: this.taxonomicScope){ |
|---|
| 293 | result.addTaxonomicScope(taxon); |
|---|
| 294 | } |
|---|
| 295 | return result; |
|---|
| 296 | |
|---|
| 297 | } |
|---|
| 298 | } |
|---|