Project

General

Profile

Download (8.92 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.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.JoinTable;
18
import javax.persistence.ManyToMany;
19
import javax.validation.constraints.NotNull;
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

    
32
import eu.etaxonomy.cdm.model.common.DefinedTerm;
33
import eu.etaxonomy.cdm.model.location.NamedArea;
34
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36

    
37
/**
38
 *
39
 * The class representing multi-access dynamic keys used to identify
40
 * {@link SpecimenOrObservationBase specimens or observations} (this means to assign {@link Taxon taxa} to).
41
 * The determination process is performed by an identification software.
42
 *
43
 * @author h.fradin
44
 * @since 13.08.2009
45
 */
46

    
47
@XmlAccessorType(XmlAccessType.FIELD)
48
@XmlType(name = "MultiAccessKey", propOrder = {
49
    "coveredTaxa",
50
    "taxonomicScope",
51
    "geographicalScope",
52
    "scopeRestrictions"
53
})
54
@XmlRootElement(name = "MultiAccessKey")
55
@Entity
56
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
57
//@Indexed(index = "eu.etaxonomy.cdm.model.media.WorkingSet")
58
@Audited
59

    
60
public class MultiAccessKey extends WorkingSet implements IIdentificationKey{
61
	private static final long serialVersionUID = -240407483572972239L;
62
	@SuppressWarnings("unused")
63
	private static final Logger logger = Logger.getLogger(MultiAccessKey.class);
64

    
65
	@XmlElementWrapper(name = "CoveredTaxa")
66
	@XmlElement(name = "CoveredTaxon")
67
	@XmlIDREF
68
	@XmlSchemaType(name = "IDREF")
69
	@ManyToMany(fetch = FetchType.LAZY)
70
    @JoinTable(name="MultiAccessKey_CoveredTaxon")
71
    @NotNull
72
	private Set<Taxon> coveredTaxa = new HashSet<>();
73

    
74
	@XmlElementWrapper(name = "TaxonomicScope")
75
	@XmlElement(name = "Taxon")
76
	@XmlIDREF
77
	@XmlSchemaType(name = "IDREF")
78
	@ManyToMany(fetch = FetchType.LAZY)
79
	@JoinTable(name="MultiAccessKey_TaxonScope")
80
	@NotNull
81
	private Set<Taxon> taxonomicScope = new HashSet<>();
82

    
83
	@XmlElementWrapper( name = "GeographicalScope")
84
	@XmlElement( name = "Area")
85
	@XmlIDREF
86
	@XmlSchemaType(name = "IDREF")
87
	@ManyToMany(fetch = FetchType.LAZY)
88
    @JoinTable(name="MultiAccessKey_NamedArea")
89
	@NotNull
90
	private Set<NamedArea> geographicalScope = new HashSet<>();
91

    
92
	@XmlElementWrapper( name = "ScopeRestrictions")
93
	@XmlElement( name = "Restriction")
94
	@XmlIDREF
95
	@XmlSchemaType(name = "IDREF")
96
	@ManyToMany(fetch = FetchType.LAZY)
97
    @JoinTable(name="MultiAccessKey_Scope")
98
	@NotNull
99
	private Set<DefinedTerm> scopeRestrictions = new HashSet<>();
100

    
101
	/**
102
	 * Class constructor: creates a new empty multi-access key instance.
103
	 */
104
	protected MultiAccessKey() {
105
		super();
106
	}
107

    
108
	/**
109
	 * Creates a new empty identification multi-access key instance.
110
	 */
111
	public static MultiAccessKey NewInstance(){
112
		return new MultiAccessKey();
113
	}
114

    
115
	/**
116
	 * Returns the set of possible {@link Taxon taxa} corresponding to
117
	 * <i>this</i> identification key.
118
	 */
119
	@Override
120
    public Set<Taxon> getCoveredTaxa() {
121
		if(coveredTaxa == null) {
122
			this.coveredTaxa = new HashSet<Taxon>();
123
		}
124
		return coveredTaxa;
125
	}
126
	/**
127
	 * @see	#getCoveredTaxa()
128
	 */
129
	protected void setCoveredTaxa(Set<Taxon> coveredTaxa) {
130
		this.coveredTaxa = coveredTaxa;
131
	}
132

    
133
	/**
134
	 * Adds a {@link Taxon taxa} to the set of {@link #getCoveredTaxa() covered taxa}
135
	 * corresponding to <i>this</i> identification key.
136
	 *
137
	 * @param	taxon	the taxon to be added to <i>this</i> identification key
138
	 * @see    	   		#getCoveredTaxa()
139
	 */
140
	@Override
141
    public void addCoveredTaxon(Taxon taxon) {
142
		this.coveredTaxa.add(taxon);
143
	}
144

    
145
	/**
146
	 * Removes one element from the set of {@link #getCoveredTaxa() covered taxa}
147
	 * corresponding to <i>this</i> identification key.
148
	 *
149
	 * @param	taxon	the taxon which should be removed
150
	 * @see     		#getCoveredTaxa()
151
	 * @see     		#addCoveredTaxon(Taxon)
152
	 */
153
	@Override
154
    public void removeCoveredTaxon(Taxon taxon) {
155
		this.coveredTaxa.remove(taxon);
156
	}
157

    
158
	/**
159
	 * Returns the set of {@link NamedArea named areas} indicating the geospatial
160
	 * data where <i>this</i> identification key is valid.
161
	 */
162
	@Override
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
	@Override
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
	@Override
190
    public void removeGeographicalScope(NamedArea geoScope) {
191
		this.geographicalScope.remove(geoScope);
192
	}
193

    
194
	/**
195
	 * Returns the set of {@link Taxon taxa} that define the taxonomic
196
	 * scope of <i>this</i> identification key
197
	 */
198
	@Override
199
    public Set<Taxon> getTaxonomicScope() {
200
		if(taxonomicScope == null) {
201
			this.taxonomicScope = new HashSet<Taxon>();
202
		}
203
		return taxonomicScope;
204
	}
205

    
206
	/**
207
	 * Adds a {@link Taxon taxa} to the set of {@link #getTaxonomicScope() taxonomic scopes}
208
	 * corresponding to <i>this</i> identification key.
209
	 *
210
	 * @param	taxon	the taxon to be added to <i>this</i> identification key
211
	 * @see    	   		#getTaxonomicScope()
212
	 */
213
	@Override
214
    public void addTaxonomicScope(Taxon taxon) {
215
		this.taxonomicScope.add(taxon);
216
	}
217

    
218
	/**
219
	 * Removes one element from the set of {@link #getTaxonomicScope() taxonomic scopes}
220
	 * corresponding to <i>this</i> identification key.
221
	 *
222
	 * @param	taxon	the taxon which should be removed
223
	 * @see     		#getTaxonomicScope()
224
	 * @see     		#addTaxonomicScope(Taxon)
225
	 */
226
	@Override
227
    public void removeTaxonomicScope(Taxon taxon) {
228
		this.taxonomicScope.remove(taxon);
229
	}
230

    
231
	/**
232
	 * Returns the set of {@link Scope scope restrictions} corresponding to
233
	 * <i>this</i> identification key
234
	 */
235
	@Override
236
    public Set<DefinedTerm> getScopeRestrictions() {
237
		if(scopeRestrictions == null) {
238
			this.scopeRestrictions = new HashSet<DefinedTerm>();
239
		}
240
		return scopeRestrictions;
241
	}
242

    
243
	/**
244
	 * Adds a {@link Scope scope restriction} to the set of {@link #getScopeRestrictions() scope restrictions}
245
	 * corresponding to <i>this</i> identification key.
246
	 *
247
	 * @param	scopeRestriction	the scope restriction to be added to <i>this</i> identification key
248
	 * @see    	   		#getScopeRestrictions()
249
	 */
250
	@Override
251
    public void addScopeRestriction(DefinedTerm scopeRestriction) {
252
		this.scopeRestrictions.add(scopeRestriction);
253
	}
254

    
255
	/**
256
	 * Removes one element from the set of {@link #getScopeRestrictions() scope restrictions}
257
	 * corresponding to <i>this</i> identification key.
258
	 *
259
	 * @param	scopeRestriction	the scope restriction which should be removed
260
	 * @see     		#getScopeRestrictions()
261
	 * @see     		#addScopeRestriction(Scope)
262
	 */
263
	@Override
264
    public void removeScopeRestriction(DefinedTerm scopeRestriction) {
265
		this.scopeRestrictions.remove(scopeRestriction);
266
	}
267

    
268
//*********************** CLONE ********************************************************/
269

    
270
	/**
271
	 * Clones <i>this</i> MultiAccessKey. This is a shortcut that enables to create
272
	 * a new instance that differs only slightly from <i>this</i> MultiAccessKey by
273
	 * modifying only some of the attributes.
274
	 *
275
	 * @see eu.etaxonomy.cdm.model.common.AnnotatableEntity#clone()
276
	 * @see java.lang.Object#clone()
277
	 */
278
	@Override
279
	public Object clone() {
280
		MultiAccessKey result;
281

    
282
			result = (MultiAccessKey)super.clone();
283

    
284
			result.coveredTaxa = new HashSet<Taxon>();
285
			for (Taxon taxon: this.coveredTaxa){
286
				result.addCoveredTaxon(taxon);
287
			}
288

    
289
			result.geographicalScope = new HashSet<NamedArea>();
290
			for (NamedArea area: this.geographicalScope){
291
				result.addGeographicalScope(area);
292
			}
293

    
294
			result.scopeRestrictions = new HashSet<DefinedTerm>();
295
			for (DefinedTerm scope: this.scopeRestrictions){
296
				result.addScopeRestriction(scope);
297
			}
298

    
299
			result.taxonomicScope = new HashSet<Taxon>();
300
			for (Taxon taxon: this.taxonomicScope){
301
				result.addTaxonomicScope(taxon);
302
			}
303
			return result;
304

    
305
	}
306
}
(19-19/37)