Project

General

Profile

Download (7.49 KB) Statistics
| Branch: | Tag: | Revision:
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
    public void setStatus(RegistrationStatus status) {this.status = status;}
183

    
184
    public DateTime getRegistrationDate() {return registrationDate;}
185
    public void setRegistrationDate(DateTime registrationDate) {this.registrationDate = registrationDate;}
186

    
187
    public Institution getInstitution() {return institution;}
188
    public void setInstitution(Institution institution) {this.institution = institution;}
189

    
190
    public TaxonName getName() {return name;}
191
    public void setName(TaxonName name) {
192
        if (this.name != null && !this.name.equals(name)){
193
            this.name.getRegistrations().remove(this);
194
        }
195
        if (name != null && !name.equals(this.name)){
196
            name.getRegistrations().add(this);
197
        }
198
        this.name = name;
199
    }
200

    
201
    public User getSubmitter() {return submitter;}
202
    public void setSubmitter(User submitter) {this.submitter = submitter;}
203

    
204
    public Set<Registration> getBlockedBy() {return blockedBy;}
205
    @SuppressWarnings("unused")
206
    private void setBlockedBy(Set<Registration> blockedBy) {this.blockedBy = blockedBy;}
207

    
208
    public Set<TypeDesignationBase> getTypeDesignations() {return typeDesignations;}
209
    public void setTypeDesignations(Set<TypeDesignationBase> typeDesignations) {
210
        this.typeDesignations = typeDesignations;
211
    }
212

    
213
    public void addTypeDesignation(TypeDesignationBase designation) {
214
        this.typeDesignations.add(designation);
215
        if (!designation.getRegistrations().contains(this)){
216
            designation.getRegistrations().add(this);
217
        }
218
    }
219
    public void removeTypeDesignation(TypeDesignationBase designation) {
220
        this.typeDesignations.remove(designation);
221
        if (designation.getRegistrations().contains(this)){
222
            designation.getRegistrations().remove(this);
223
        }
224
    }
225

    
226

    
227
}
(25-25/36)