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
|
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import javax.persistence.Entity;
|
17
|
import javax.persistence.FetchType;
|
18
|
import javax.persistence.JoinTable;
|
19
|
import javax.persistence.ManyToOne;
|
20
|
import javax.persistence.MapKeyJoinColumn;
|
21
|
import javax.persistence.OneToMany;
|
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.XmlIDREF;
|
26
|
import javax.xml.bind.annotation.XmlRootElement;
|
27
|
import javax.xml.bind.annotation.XmlSchemaType;
|
28
|
import javax.xml.bind.annotation.XmlType;
|
29
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
30
|
|
31
|
import org.apache.log4j.Logger;
|
32
|
import org.hibernate.annotations.Cascade;
|
33
|
import org.hibernate.annotations.CascadeType;
|
34
|
import org.hibernate.envers.Audited;
|
35
|
import org.hibernate.search.annotations.Indexed;
|
36
|
|
37
|
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
|
38
|
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;
|
39
|
import eu.etaxonomy.cdm.model.common.Language;
|
40
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
41
|
import eu.etaxonomy.cdm.model.common.MultilanguageText;
|
42
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
43
|
|
44
|
/**
|
45
|
* This class represents associations between the described
|
46
|
* {@link SpecimenOrObservationBase specimen or observation}
|
47
|
* and a second one (for instance a host).
|
48
|
* Only {@link SpecimenDescription specimen descriptions} may contain individuals association.
|
49
|
* The association itself is described by a {@link MultilanguageText multilanguage text}.
|
50
|
* <P>
|
51
|
* This class corresponds (partially) to NaturalLanguageDescriptionType
|
52
|
* according to the SDD schema.
|
53
|
*
|
54
|
* @author m.doering
|
55
|
* @since 08-Nov-2007 13:06:28
|
56
|
*/
|
57
|
@XmlAccessorType(XmlAccessType.FIELD)
|
58
|
@XmlType(name = "IndividualsAssociation", propOrder = {
|
59
|
"description",
|
60
|
"associatedSpecimenOrObservation"
|
61
|
})
|
62
|
@XmlRootElement(name = "IndividualsAssociation")
|
63
|
@Entity
|
64
|
@Audited
|
65
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
66
|
public class IndividualsAssociation extends DescriptionElementBase
|
67
|
implements IMultiLanguageTextHolder, Cloneable{
|
68
|
private static final long serialVersionUID = -4117554860254531809L;
|
69
|
private static final Logger logger = Logger.getLogger(IndividualsAssociation.class);
|
70
|
|
71
|
@XmlElement(name = "Description")
|
72
|
@XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
|
73
|
@OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
|
74
|
@MapKeyJoinColumn(name="description_mapkey_id")
|
75
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE })
|
76
|
@JoinTable(name = "IndividualsAssociation_LanguageString") //to distinguish from other DescriptionElementBase_LanguageString cases
|
77
|
private Map<Language,LanguageString> description = new HashMap<>();
|
78
|
|
79
|
@XmlElement(name = "AssociatedSpecimenOrObservation")
|
80
|
@XmlIDREF
|
81
|
@XmlSchemaType(name = "IDREF")
|
82
|
@ManyToOne(fetch = FetchType.LAZY)
|
83
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
84
|
private SpecimenOrObservationBase associatedSpecimenOrObservation;
|
85
|
|
86
|
/**
|
87
|
* Class constructor: creates a new empty individuals association instance.
|
88
|
*/
|
89
|
protected IndividualsAssociation(){
|
90
|
super(null);
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Creates a new empty individuals association instance.
|
95
|
*/
|
96
|
public static IndividualsAssociation NewInstance(){
|
97
|
return NewInstance(null);
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* Creates a new empty individuals association instance.
|
102
|
*/
|
103
|
public static IndividualsAssociation NewInstance(SpecimenOrObservationBase specimen){
|
104
|
IndividualsAssociation result = new IndividualsAssociation();
|
105
|
result.setFeature(Feature.INDIVIDUALS_ASSOCIATION());
|
106
|
result.setAssociatedSpecimenOrObservation(specimen);
|
107
|
return result;
|
108
|
}
|
109
|
|
110
|
|
111
|
/**
|
112
|
* Returns the second {@link SpecimenOrObservationBase specimen or observation}
|
113
|
* involved in <i>this</i> individuals association.
|
114
|
* The first specimen or observation is the specimen or observation
|
115
|
* described in the corresponding {@link SpecimenDescription specimen description}.
|
116
|
*/
|
117
|
public SpecimenOrObservationBase getAssociatedSpecimenOrObservation() {
|
118
|
return associatedSpecimenOrObservation;
|
119
|
}
|
120
|
/**
|
121
|
* @see #getAssociatedSpecimenOrObservation()
|
122
|
*/
|
123
|
public void setAssociatedSpecimenOrObservation(
|
124
|
SpecimenOrObservationBase associatedSpecimenOrObservation) {
|
125
|
this.associatedSpecimenOrObservation = associatedSpecimenOrObservation;
|
126
|
}
|
127
|
|
128
|
|
129
|
/**
|
130
|
* Returns the {@link MultilanguageText multilanguage text} used to describe
|
131
|
* <i>this</i> individuals association. The different {@link LanguageString language strings}
|
132
|
* contained in the multilanguage text should all have the same meaning.
|
133
|
*/
|
134
|
public Map<Language,LanguageString> getDescription(){
|
135
|
return this.description;
|
136
|
}
|
137
|
|
138
|
|
139
|
/**
|
140
|
* Adds a translated {@link LanguageString text in a particular language}
|
141
|
* to the {@link MultilanguageText multilanguage text} used to describe
|
142
|
* <i>this</i> individuals association.
|
143
|
*
|
144
|
* @param description the language string describing the individuals association
|
145
|
* in a particular language
|
146
|
* @see #getDescription()
|
147
|
* @see #putDescription(Language, String)
|
148
|
*
|
149
|
*/
|
150
|
public void putDescription(LanguageString description){
|
151
|
this.description.put(description.getLanguage(),description);
|
152
|
}
|
153
|
/**
|
154
|
* Creates a {@link LanguageString language string} based on the given text string
|
155
|
* and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
|
156
|
* used to describe <i>this</i> individuals association.
|
157
|
*
|
158
|
* @param text the string describing the individuals association
|
159
|
* in a particular language
|
160
|
* @param language the language in which the text string is formulated
|
161
|
* @see #getDescription()
|
162
|
* @see #putDescription(LanguageString)
|
163
|
*/
|
164
|
public void putDescription(Language language, String text){
|
165
|
this.description.put(language, LanguageString.NewInstance(text, language));
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* Removes from the {@link MultilanguageText multilanguage text} used to describe
|
170
|
* <i>this</i> individuals association the one {@link LanguageString language string}
|
171
|
* with the given {@link Language language}.
|
172
|
*
|
173
|
* @param language the language in which the language string to be removed
|
174
|
* has been formulated
|
175
|
* @see #getDescription()
|
176
|
*/
|
177
|
public void removeDescription(Language language){
|
178
|
this.description.remove(language);
|
179
|
}
|
180
|
|
181
|
|
182
|
//*********************************** CLONE *****************************************/
|
183
|
|
184
|
/**
|
185
|
* Clones <i>this</i> individuals association. This is a shortcut that enables to create
|
186
|
* a new instance that differs only slightly from <i>this</i> individuals association by
|
187
|
* modifying only some of the attributes.
|
188
|
*
|
189
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
|
190
|
* @see java.lang.Object#clone()
|
191
|
*/
|
192
|
@Override
|
193
|
public Object clone() {
|
194
|
|
195
|
try {
|
196
|
IndividualsAssociation result = (IndividualsAssociation)super.clone();
|
197
|
|
198
|
//description
|
199
|
result.description = cloneLanguageString(getDescription());
|
200
|
|
201
|
return result;
|
202
|
//no changes to: associatedSpecimenOrObservation
|
203
|
} catch (CloneNotSupportedException e) {
|
204
|
logger.warn("Object does not implement cloneable");
|
205
|
e.printStackTrace();
|
206
|
return null;
|
207
|
}
|
208
|
}
|
209
|
|
210
|
}
|