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.time.ZonedDateTime;
12
import java.util.HashSet;
13
import java.util.Set;
14

    
15
import javax.persistence.Basic;
16
import javax.persistence.Column;
17
import javax.persistence.Entity;
18
import javax.persistence.FetchType;
19
import javax.persistence.ManyToMany;
20
import javax.persistence.ManyToOne;
21
import javax.validation.constraints.NotNull;
22
import javax.xml.bind.annotation.XmlAccessType;
23
import javax.xml.bind.annotation.XmlAccessorType;
24
import javax.xml.bind.annotation.XmlAttribute;
25
import javax.xml.bind.annotation.XmlElement;
26
import javax.xml.bind.annotation.XmlElementWrapper;
27
import javax.xml.bind.annotation.XmlIDREF;
28
import javax.xml.bind.annotation.XmlSchemaType;
29
import javax.xml.bind.annotation.XmlType;
30
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31

    
32
import org.hibernate.annotations.Cascade;
33
import org.hibernate.annotations.CascadeType;
34
import org.hibernate.annotations.Type;
35
import org.hibernate.envers.Audited;
36
import org.hibernate.search.annotations.IndexedEmbedded;
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 the same citation and citation detail.
49
 *
50
 *
51
 * @author a.mueller
52
 * @date 13.03.2017
53
 *
54
 */
55

    
56
@XmlAccessorType(XmlAccessType.FIELD)
57
@XmlType(name = "Registration", propOrder = {
58
    "identifier",
59
    "specificIdentifier",
60
    "registrationDate",
61
    "status",
62
    "institution",
63
    "name",
64
    "typeDesignations",
65
    "blockedBy",
66
    "submitter"
67
})
68
@Entity
69
@Audited
70
public class Registration extends AnnotatableEntity {
71

    
72
    private static final long serialVersionUID = -5633923579539766801L;
73

    
74
    @XmlElement(name = "Identifier")
75
    @NullOrNotEmpty
76
    @Column(length=255)
77
    private String identifier;
78

    
79
    //id without http-domain
80
    @XmlElement(name = "SpecificIdentifier")
81
    @NullOrNotEmpty
82
    @Column(length=255)
83
    private String specificIdentifier;
84

    
85
    @XmlElement (name = "RegistrationDate", type= String.class)
86
    @XmlJavaTypeAdapter(DateTimeAdapter.class)
87
    @Type(type="dateTimeUserType")
88
    //TODO ??
89
    @Basic(fetch = FetchType.LAZY)
90
//    @Field(analyze = Analyze.NO)
91
//    @FieldBridge(impl = DateTimeBridge.class)
92
    private ZonedDateTime registrationDate;
93

    
94
    @XmlAttribute(name ="Status")
95
    @Column(name="status", length=10)
96
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
97
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.name.RegistrationStatus")}
98
    )
99
    @NotNull
100
    private RegistrationStatus status = RegistrationStatus.PREPARATION;
101

    
102
    @XmlElement(name = "Institution")
103
    @XmlIDREF
104
    @XmlSchemaType(name = "IDREF")
105
    @ManyToOne(fetch = FetchType.LAZY)
106
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
107
    @IndexedEmbedded
108
    private Institution institution;
109

    
110
    @XmlElement(name = "Name")
111
    @XmlIDREF
112
    @XmlSchemaType(name = "IDREF")
113
    @ManyToOne(fetch = FetchType.LAZY)
114
//    @IndexedEmbedded(includeEmbeddedObjectId=true)
115
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
116
    private TaxonName name;
117

    
118
    @XmlElementWrapper(name = "TypeDesignations")
119
    @XmlElement(name = "TypeDesignation")
120
    @XmlIDREF
121
    @XmlSchemaType(name = "IDREF")
122
    @ManyToMany(fetch = FetchType.LAZY)
123
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
124
    @NotNull
125
    private Set<TypeDesignationBase> typeDesignations = new HashSet<>();
126

    
127
    @XmlElementWrapper(name = "BlockingRegistrations")
128
    @XmlElement(name = "BlockedBy")
129
    @XmlIDREF
130
    @XmlSchemaType(name = "IDREF")
131
    @ManyToMany(fetch = FetchType.LAZY)
132
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
133
    @NotNull
134
    private Set<Registration> blockedBy = new HashSet<>();
135

    
136
    @XmlElement (name = "Submitter")
137
    @XmlIDREF
138
    @XmlSchemaType(name = "IDREF")
139
    @ManyToOne(fetch=FetchType.LAZY)
140
    private User submitter;
141

    
142
// ****************** Factory ******************/
143

    
144
    public static Registration NewInstance(){
145
        return new Registration();
146
    }
147

    
148

    
149
    /**
150
     * @param identifier
151
     * @param specificIdentifier
152
     * @param name can be <code>null</code>
153
     * @param typeDesignations can be <code>null</code>
154
     * @return
155
     */
156
    public static Registration NewInstance(String identifier, String specificIdentifier,
157
            TaxonName name, Set<TypeDesignationBase> typeDesignations){
158
        Registration result = new Registration();
159
        result.setIdentifier(identifier);
160
        result.setSpecificIdentifier(specificIdentifier);
161
        result.setName(name);
162
        if (typeDesignations != null){
163
            result.setTypeDesignations(typeDesignations);
164
        }
165
        return result;
166
    }
167

    
168
// **************** CONSTRUCTOR ****************/
169

    
170
    private Registration(){}
171

    
172

    
173

    
174
// *************** GETTER / SETTER  *************/
175

    
176
    public String getIdentifier() {return identifier;}
177
    public void setIdentifier(String identifier) {this.identifier = identifier;}
178

    
179
    public String getSpecificIdentifier() {return specificIdentifier;}
180
    public void setSpecificIdentifier(String specificIdentifier) {this.specificIdentifier = specificIdentifier;}
181

    
182
    public RegistrationStatus getStatus() {return status;}
183
    public void setStatus(RegistrationStatus status) {this.status = status;}
184

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

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

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

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

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

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

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

    
227

    
228
}
(25-25/36)