bugfixes for mapping of model changes (JoinTable bug) - MediaKey
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / MediaKey.java
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.HashSet;
13 import java.util.Set;
14
15 import javax.persistence.Entity;
16 import javax.persistence.FetchType;
17 import javax.persistence.JoinColumn;
18 import javax.persistence.JoinTable;
19 import javax.persistence.ManyToMany;
20 import javax.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import javax.xml.bind.annotation.XmlIDREF;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlSchemaType;
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.apache.log4j.Logger;
30 import org.hibernate.envers.Audited;
31 import org.hibernate.search.annotations.Indexed;
32
33 import eu.etaxonomy.cdm.model.common.Representation;
34 import eu.etaxonomy.cdm.model.location.NamedArea;
35 import eu.etaxonomy.cdm.model.media.Media;
36 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
37 import eu.etaxonomy.cdm.model.taxon.Taxon;
38
39 /**
40 * The class representing single-access fixed dichotomous or polytomous authored
41 * decision keys (as opposed to {@link FeatureTree multiple-access keys}) used to identify
42 * {@link SpecimenOrObservationBase specimens or observations} (this means to assign {@link Taxon taxa} to).
43 * The determination process is based on the tree structure of the key and on
44 * the statements of its leads.
45 *
46 * @author m.doering
47 * @version 1.0
48 * @created 08-Nov-2007 13:06:28
49 */
50
51 @XmlAccessorType(XmlAccessType.FIELD)
52 @XmlType(name = "MediaKey", propOrder = {
53 "coveredTaxa",
54 "taxonomicScope",
55 "geographicalScope",
56 "scopeRestrictions",
57 "keyRepresentations"
58 })
59 @XmlRootElement(name = "MediaKey")
60 @Entity
61 @Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
62 @Audited
63 public class MediaKey extends Media implements IIdentificationKey{
64
65 private static final long serialVersionUID = -29095811051894471L;
66 @SuppressWarnings("unused")
67 private static final Logger logger = Logger.getLogger(MediaKey.class);
68
69 @XmlElementWrapper(name = "CoveredTaxa")
70 @XmlElement(name = "CoveredTaxon")
71 @XmlIDREF
72 @XmlSchemaType(name = "IDREF")
73 @ManyToMany(fetch = FetchType.LAZY)
74 private Set<Taxon> coveredTaxa = new HashSet<Taxon>();
75
76 @XmlElementWrapper( name = "GeographicalScope")
77 @XmlElement( name = "Area")
78 @XmlIDREF
79 @XmlSchemaType(name = "IDREF")
80 @ManyToMany(fetch = FetchType.LAZY)
81 @JoinTable(name="MediaKey_NamedArea")
82 private Set<NamedArea> geographicalScope = new HashSet<NamedArea>();
83
84 @XmlElementWrapper(name = "TaxonomicScope")
85 @XmlElement(name = "Taxon")
86 @XmlIDREF
87 @XmlSchemaType(name = "IDREF")
88 @ManyToMany(fetch = FetchType.LAZY)
89 @JoinTable(
90 name="MediaKey_Taxon",
91 joinColumns=@JoinColumn(name="mediaKey_fk"),
92 inverseJoinColumns=@JoinColumn(name="taxon_fk")
93 )
94 private Set<Taxon> taxonomicScope = new HashSet<Taxon>();
95
96 @XmlElementWrapper( name = "ScopeRestrictions")
97 @XmlElement( name = "Restriction")
98 @XmlIDREF
99 @XmlSchemaType(name = "IDREF")
100 @ManyToMany(fetch = FetchType.LAZY)
101 @JoinTable(name="MediaKey_Scope")
102 private Set<Scope> scopeRestrictions = new HashSet<Scope>();
103
104 @XmlElementWrapper( name = "KeyRepresentations")
105 @XmlElement( name = "KeyRepresentation")
106 @XmlIDREF
107 @XmlSchemaType(name = "IDREF")
108 @ManyToMany(fetch = FetchType.LAZY)
109 private Set<Representation> keyRepresentations = new HashSet<Representation>();
110
111 /**
112 * Class constructor: creates a new empty identification key instance.
113 */
114 protected MediaKey() {
115 super();
116 }
117
118 /**
119 * Creates a new empty identification key instance.
120 */
121 public static MediaKey NewInstance(){
122 return new MediaKey();
123 }
124
125
126 /**
127 * Returns the set of possible {@link Taxon taxa} corresponding to
128 * <i>this</i> identification key.
129 */
130 public Set<Taxon> getCoveredTaxa() {
131 return coveredTaxa;
132 }
133 /**
134 * @see #getCoveredTaxa()
135 */
136 protected void setCoveredTaxa(Set<Taxon> coveredTaxa) {
137 this.coveredTaxa = coveredTaxa;
138 }
139
140 /**
141 * Adds a {@link Taxon taxa} to the set of {@link #getCoveredTaxa() covered taxa}
142 * corresponding to <i>this</i> identification key.
143 *
144 * @param taxon the taxon to be added to <i>this</i> identification key
145 * @see #getCoveredTaxa()
146 */
147 public void addCoveredTaxon(Taxon taxon) {
148 this.coveredTaxa.add(taxon);
149 }
150
151 /**
152 * Removes one element from the set of {@link #getCoveredTaxa() covered taxa}
153 * corresponding to <i>this</i> identification key.
154 *
155 * @param taxon the taxon which should be removed
156 * @see #getCoveredTaxa()
157 * @see #addCoveredTaxon(Taxon)
158 */
159 public void removeCoveredTaxon(Taxon taxon) {
160 this.coveredTaxa.remove(taxon);
161 }
162
163 /**
164 * Returns the set of {@link NamedArea named areas} indicating the geospatial
165 * data where <i>this</i> identification key is valid.
166 */
167 public Set<NamedArea> getGeographicalScope() {
168 return geographicalScope;
169 }
170
171 /**
172 * Adds a {@link NamedArea geoScope} to the set of {@link #getGeoScopes() geogspatial scopes}
173 * corresponding to <i>this</i> identification key.
174 *
175 * @param geoScope the named area to be added to <i>this</i> identification key
176 * @see #getGeoScopes()
177 */
178 public void addGeographicalScope(NamedArea geoScope) {
179 this.geographicalScope.add(geoScope);
180 }
181 /**
182 * Removes one element from the set of {@link #getGeoScopes() geogspatial scopes}
183 * corresponding to <i>this</i> identification key.
184 *
185 * @param geoScope the named area which should be removed
186 * @see #getGeoScopes()
187 * @see #addGeoScope(NamedArea)
188 */
189 public void removeGeographicalScope(NamedArea geoScope) {
190 this.geographicalScope.remove(geoScope);
191 }
192
193 /**
194 * Returns the set of {@link Taxon taxa} that define the taxonomic
195 * scope of <i>this</i> identification key
196 */
197 public Set<Taxon> getTaxonomicScope() {
198 return taxonomicScope;
199 }
200
201 /**
202 * Adds a {@link Taxon taxa} to the set of {@link #getTaxonomicScope() taxonomic scopes}
203 * corresponding to <i>this</i> identification key.
204 *
205 * @param taxon the taxon to be added to <i>this</i> identification key
206 * @see #getTaxonomicScope()
207 */
208 public void addTaxonomicScope(Taxon taxon) {
209 this.taxonomicScope.add(taxon);
210 }
211
212 /**
213 * Removes one element from the set of {@link #getTaxonomicScope() taxonomic scopes}
214 * corresponding to <i>this</i> identification key.
215 *
216 * @param taxon the taxon which should be removed
217 * @see #getTaxonomicScope()
218 * @see #addTaxonomicScope(Taxon)
219 */
220 public void removeTaxonomicScope(Taxon taxon) {
221 this.taxonomicScope.remove(taxon);
222 }
223
224 /**
225 * Returns the set of {@link Representation key representations} corresponding to
226 * <i>this</i> identification key
227 */
228 public Set<Representation> getKeyRepresentations() {
229 return keyRepresentations;
230 }
231
232 /**
233 * Adds a {@link Representation key representation} to the set of {@link #getKeyRepresentations() key representations}
234 * corresponding to <i>this</i> identification key.
235 *
236 * @param keyRepresentation the key representation to be added to <i>this</i> identification key
237 * @see #getKeyRepresentations()
238 */
239 public void addKeyRepresentation(Representation keyRepresentation) {
240 this.keyRepresentations.add(keyRepresentation);
241 }
242
243 /**
244 * Removes one element from the set of {@link #getKeyRepresentations() key representations}
245 * corresponding to <i>this</i> identification key.
246 *
247 * @param keyRepresentation the key representation which should be removed
248 * @see #getKeyRepresentations()
249 * @see #addKeyRepresentation(Representation)
250 */
251 public void removeKeyRepresentation(Representation keyRepresentation) {
252 this.keyRepresentations.remove(keyRepresentation);
253 }
254
255 /**
256 * Returns the set of {@link Scope scope restrictions} corresponding to
257 * <i>this</i> identification key
258 */
259 public Set<Scope> getScopeRestrictions() {
260 return scopeRestrictions;
261 }
262
263 /**
264 * Adds a {@link Scope scope restriction} to the set of {@link #getScopeRestrictions() scope restrictions}
265 * corresponding to <i>this</i> identification key.
266 *
267 * @param scopeRestriction the scope restriction to be added to <i>this</i> identification key
268 * @see #getScopeRestrictions()
269 */
270 public void addScopeRestriction(Scope scopeRestriction) {
271 this.scopeRestrictions.add(scopeRestriction);
272 }
273
274 /**
275 * Removes one element from the set of {@link #getScopeRestrictions() scope restrictions}
276 * corresponding to <i>this</i> identification key.
277 *
278 * @param scopeRestriction the scope restriction which should be removed
279 * @see #getScopeRestrictions()
280 * @see #addScopeRestriction(Scope)
281 */
282 public void removeScopeRestriction(Scope scopeRestriction) {
283 this.scopeRestrictions.remove(scopeRestriction);
284 }
285
286 }