1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.cdm.model.name;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.persistence.Basic;
|
15
|
import javax.persistence.Column;
|
16
|
import javax.persistence.Entity;
|
17
|
import javax.persistence.FetchType;
|
18
|
import javax.persistence.ManyToMany;
|
19
|
import javax.persistence.ManyToOne;
|
20
|
import javax.validation.constraints.NotNull;
|
21
|
import javax.xml.bind.annotation.XmlAccessType;
|
22
|
import javax.xml.bind.annotation.XmlAccessorType;
|
23
|
import javax.xml.bind.annotation.XmlAttribute;
|
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.XmlSchemaType;
|
28
|
import javax.xml.bind.annotation.XmlType;
|
29
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
30
|
|
31
|
import org.hibernate.annotations.Cascade;
|
32
|
import org.hibernate.annotations.CascadeType;
|
33
|
import org.hibernate.annotations.Type;
|
34
|
import org.hibernate.envers.Audited;
|
35
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
36
|
import org.joda.time.DateTime;
|
37
|
|
38
|
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
|
39
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
40
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
41
|
import eu.etaxonomy.cdm.model.common.User;
|
42
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
43
|
|
44
|
/**
|
45
|
* A registration represents a nomenclatural act, either a {@link TaxonName taxon name}
|
46
|
* registration or a {@link TypeDesignationBase type} registration.
|
47
|
* <p>
|
48
|
* The name and all type designations associated with the Registration must share
|
49
|
* the same citation and citation detail.
|
50
|
*
|
51
|
* @author a.mueller
|
52
|
* @since 13.03.2017
|
53
|
*/
|
54
|
|
55
|
@XmlAccessorType(XmlAccessType.FIELD)
|
56
|
@XmlType(name = "Registration", propOrder = {
|
57
|
"identifier",
|
58
|
"specificIdentifier",
|
59
|
"registrationDate",
|
60
|
"status",
|
61
|
"institution",
|
62
|
"name",
|
63
|
"typeDesignations",
|
64
|
"blockedBy",
|
65
|
"submitter"
|
66
|
})
|
67
|
@Entity
|
68
|
@Audited
|
69
|
public class Registration extends AnnotatableEntity {
|
70
|
|
71
|
private static final long serialVersionUID = -5633923579539766801L;
|
72
|
|
73
|
@XmlElement(name = "Identifier")
|
74
|
@NullOrNotEmpty
|
75
|
@Column(length=255)
|
76
|
private String identifier;
|
77
|
|
78
|
//id without http-domain
|
79
|
@XmlElement(name = "SpecificIdentifier")
|
80
|
@NullOrNotEmpty
|
81
|
@Column(length=255)
|
82
|
private String specificIdentifier;
|
83
|
|
84
|
@XmlElement (name = "RegistrationDate", type= String.class)
|
85
|
@XmlJavaTypeAdapter(DateTimeAdapter.class)
|
86
|
@Type(type="dateTimeUserType")
|
87
|
//TODO ??
|
88
|
@Basic(fetch = FetchType.LAZY)
|
89
|
// @Field(analyze = Analyze.NO)
|
90
|
// @FieldBridge(impl = DateTimeBridge.class)
|
91
|
private DateTime registrationDate;
|
92
|
|
93
|
@XmlAttribute(name ="Status")
|
94
|
@Column(name="status", length=10)
|
95
|
@Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
|
96
|
parameters = {@org.hibernate.annotations.Parameter(name = "enumClass", value = "eu.etaxonomy.cdm.model.name.RegistrationStatus")}
|
97
|
)
|
98
|
@NotNull
|
99
|
private RegistrationStatus status = RegistrationStatus.PREPARATION;
|
100
|
|
101
|
@XmlElement(name = "Institution")
|
102
|
@XmlIDREF
|
103
|
@XmlSchemaType(name = "IDREF")
|
104
|
@ManyToOne(fetch = FetchType.LAZY)
|
105
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
106
|
@IndexedEmbedded
|
107
|
private Institution institution;
|
108
|
|
109
|
@XmlElement(name = "Name")
|
110
|
@XmlIDREF
|
111
|
@XmlSchemaType(name = "IDREF")
|
112
|
@ManyToOne(fetch = FetchType.LAZY)
|
113
|
// @IndexedEmbedded(includeEmbeddedObjectId=true)
|
114
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
115
|
private TaxonName name;
|
116
|
|
117
|
@XmlElementWrapper(name = "TypeDesignations")
|
118
|
@XmlElement(name = "TypeDesignation")
|
119
|
@XmlIDREF
|
120
|
@XmlSchemaType(name = "IDREF")
|
121
|
@ManyToMany(fetch = FetchType.LAZY)
|
122
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
123
|
@NotNull
|
124
|
private Set<TypeDesignationBase> typeDesignations = new HashSet<>();
|
125
|
|
126
|
@XmlElementWrapper(name = "BlockingRegistrations")
|
127
|
@XmlElement(name = "BlockedBy")
|
128
|
@XmlIDREF
|
129
|
@XmlSchemaType(name = "IDREF")
|
130
|
@ManyToMany(fetch = FetchType.LAZY)
|
131
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
132
|
@NotNull
|
133
|
private Set<Registration> blockedBy = new HashSet<>();
|
134
|
|
135
|
@XmlElement (name = "Submitter")
|
136
|
@XmlIDREF
|
137
|
@XmlSchemaType(name = "IDREF")
|
138
|
@ManyToOne(fetch=FetchType.LAZY)
|
139
|
private User submitter;
|
140
|
|
141
|
// ****************** Factory ******************/
|
142
|
|
143
|
public static Registration NewInstance(){
|
144
|
return new Registration();
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* @param identifier
|
150
|
* @param specificIdentifier
|
151
|
* @param name can be <code>null</code>
|
152
|
* @param typeDesignations can be <code>null</code>
|
153
|
* @return
|
154
|
*/
|
155
|
public static Registration NewInstance(String identifier, String specificIdentifier,
|
156
|
TaxonName name, Set<TypeDesignationBase> typeDesignations){
|
157
|
Registration result = new Registration();
|
158
|
result.setIdentifier(identifier);
|
159
|
result.setSpecificIdentifier(specificIdentifier);
|
160
|
result.setName(name);
|
161
|
if (typeDesignations != null){
|
162
|
result.setTypeDesignations(typeDesignations);
|
163
|
}
|
164
|
return result;
|
165
|
}
|
166
|
|
167
|
// **************** CONSTRUCTOR ****************/
|
168
|
|
169
|
private Registration(){}
|
170
|
|
171
|
|
172
|
|
173
|
// *************** GETTER / SETTER *************/
|
174
|
|
175
|
public String getIdentifier() {return identifier;}
|
176
|
public void setIdentifier(String identifier) {this.identifier = identifier;}
|
177
|
|
178
|
public String getSpecificIdentifier() {return specificIdentifier;}
|
179
|
public void setSpecificIdentifier(String specificIdentifier) {this.specificIdentifier = specificIdentifier;}
|
180
|
|
181
|
public RegistrationStatus getStatus() {return status;}
|
182
|
|
183
|
/**
|
184
|
* Sets the status to the passed value.
|
185
|
* <p>
|
186
|
* In most situations where the registration is controlled in a strict
|
187
|
* workflow you may want to use {@link #updateStatusAndDate(RegistrationStatus)} instead.
|
188
|
*
|
189
|
* @param status
|
190
|
*/
|
191
|
public void setStatus(RegistrationStatus status) {this.status = status;}
|
192
|
/**
|
193
|
* Sets the {@link RegistrationStatus} of the registration and manages the {@link #registrationDate}
|
194
|
* at the same time:
|
195
|
* <ul>
|
196
|
* <li>It will be set to <code>now</code> when the
|
197
|
* {@link #status} is set to {@link RegistrationStatus#PUBLISHED}.</li>
|
198
|
* <li>Removal of the
|
199
|
* <code>PUBLISHED</code> state will cause the the registrationDate to be reset to <code>null</code>.</li>
|
200
|
* </ul>
|
201
|
*
|
202
|
* @param status
|
203
|
*/
|
204
|
public void updateStatusAndDate(RegistrationStatus status) {
|
205
|
if(status != this.status){
|
206
|
if(status == RegistrationStatus.PUBLISHED){
|
207
|
setRegistrationDate(DateTime.now());
|
208
|
} else if(this.status == RegistrationStatus.PUBLISHED){
|
209
|
setRegistrationDate(null);
|
210
|
}
|
211
|
setStatus(status);
|
212
|
}
|
213
|
}
|
214
|
|
215
|
public DateTime getRegistrationDate() {return registrationDate;}
|
216
|
public void setRegistrationDate(DateTime registrationDate) {this.registrationDate = registrationDate;}
|
217
|
|
218
|
public Institution getInstitution() {return institution;}
|
219
|
public void setInstitution(Institution institution) {this.institution = institution;}
|
220
|
|
221
|
public TaxonName getName() {return name;}
|
222
|
public void setName(TaxonName name) {
|
223
|
if (this.name != null && !this.name.equals(name)){
|
224
|
this.name.getRegistrations().remove(this);
|
225
|
}
|
226
|
if (name != null && !name.equals(this.name)){
|
227
|
name.getRegistrations().add(this);
|
228
|
}
|
229
|
this.name = name;
|
230
|
}
|
231
|
|
232
|
public User getSubmitter() {return submitter;}
|
233
|
public void setSubmitter(User submitter) {this.submitter = submitter;}
|
234
|
|
235
|
public Set<Registration> getBlockedBy() {return blockedBy;}
|
236
|
@SuppressWarnings("unused")
|
237
|
private void setBlockedBy(Set<Registration> blockedBy) {this.blockedBy = blockedBy;}
|
238
|
public void addBlockedBy(Registration blockingRegistration) {
|
239
|
this.blockedBy.add(blockingRegistration);
|
240
|
}
|
241
|
public void removeBlockedBy(Registration blockingRegistration) {
|
242
|
this.blockedBy.remove(blockingRegistration);
|
243
|
}
|
244
|
|
245
|
public Set<TypeDesignationBase> getTypeDesignations() {return typeDesignations;}
|
246
|
public void setTypeDesignations(Set<TypeDesignationBase> typeDesignations) {
|
247
|
this.typeDesignations = typeDesignations;
|
248
|
}
|
249
|
|
250
|
public void addTypeDesignation(TypeDesignationBase designation) {
|
251
|
this.typeDesignations.add(designation);
|
252
|
if (!designation.getRegistrations().contains(this)){
|
253
|
designation.getRegistrations().add(this);
|
254
|
}
|
255
|
}
|
256
|
public void removeTypeDesignation(TypeDesignationBase designation) {
|
257
|
this.typeDesignations.remove(designation);
|
258
|
if (designation.getRegistrations().contains(this)){
|
259
|
designation.getRegistrations().remove(this);
|
260
|
}
|
261
|
}
|
262
|
|
263
|
|
264
|
}
|