Project

General

Profile

Download (7.32 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.vaadin.view.registration;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.commons.lang3.StringUtils;
20
import org.apache.log4j.Logger;
21
import org.joda.time.DateTime;
22

    
23
import eu.etaxonomy.cdm.model.common.TimePeriod;
24
import eu.etaxonomy.cdm.model.name.Registration;
25
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
26
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
27
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
28
import eu.etaxonomy.cdm.model.reference.IReference;
29
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
30
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationConverter;
31

    
32
public class RegistrationDTO{
33

    
34
    private static final Logger logger = Logger.getLogger(RegistrationDTO.class);
35

    
36
    private String summary = "";
37

    
38
    private RegistrationType registrationType;
39

    
40
    private IReference citation = null;
41

    
42
    private String citationDetail = null;
43

    
44
    private String submitterUserName = null;
45

    
46
    private EntityReference name = null;
47

    
48
    private TypeDesignationConverter typeDesignationConverter;
49

    
50
    private Registration reg;
51

    
52
    private List<String> messages = new ArrayList<>();
53

    
54
    private Set<eu.etaxonomy.cdm.model.name.Registration> blockedBy = new HashSet<>();
55

    
56

    
57
    /**
58
     * @param reg
59
     * @param typifiedName should be provided in for Registrations for TypeDesignations
60
     * @throws RegistrationValidationException
61
     */
62
    public RegistrationDTO(Registration reg) {
63

    
64
         this.reg = reg;
65

    
66
         registrationType = RegistrationType.from(reg);
67

    
68
         if(reg.getSubmitter() != null ){
69
             submitterUserName = reg.getSubmitter().getUsername();
70
         }
71

    
72
        if(hasName(reg)){
73
            citation = reg.getName().getNomenclaturalReference();
74
            citationDetail = reg.getName().getNomenclaturalMicroReference();
75
            name = new EntityReference(reg.getName().getId(), reg.getName().getTitleCache());
76
        }
77
        if(hasTypifications(reg)){
78
            if(!reg.getTypeDesignations().isEmpty()){
79
                for(TypeDesignationBase td : reg.getTypeDesignations()){
80
                    if(citation == null) {
81
                        citation = td.getCitation();
82
                        citationDetail = td.getCitationMicroReference();
83
                    }
84
                }
85
            }
86
        }
87
        switch(registrationType) {
88
        case EMPTY:
89
            summary = "BLANK REGISTRATION";
90
            break;
91
        case NAME:
92
            summary = reg.getName().getTitleCache();
93
            break;
94
        case NAME_AND_TYPIFICATION:
95
        case TYPIFICATION:
96
        default:
97
            try {
98
                typeDesignationConverter = new TypeDesignationConverter(reg.getTypeDesignations());
99
                summary = typeDesignationConverter.buildString().print();
100
            } catch (RegistrationValidationException e) {
101
                messages.add("Validation errors: " + e.getMessage());
102
            }
103
            break;
104
        }
105

    
106
        // trigger initialization of the reference
107
        getNomenclaturalCitationString();
108

    
109
    }
110

    
111
    /**
112
     * @param reg
113
     * @return
114
     */
115
    private boolean hasTypifications(Registration reg) {
116
        return reg.getTypeDesignations() != null && reg.getTypeDesignations().size() > 0;
117
    }
118

    
119
    /**
120
     * @param reg
121
     * @return
122
     */
123
    private boolean hasName(Registration reg) {
124
        return reg.getName() != null;
125
    }
126

    
127

    
128
    /**
129
     * Provides access to the Registration entity this DTO has been build from.
130
     * This method is purposely not a getter to hide the original Registration
131
     * from generic processes which are exposing, binding bean properties.
132
     *IReference
133
     * @return
134
     */
135
    public Registration registration() {
136
        return reg;
137
    }
138

    
139

    
140
    /**
141
     * @return the summary
142
     */
143
    public String getSummary() {
144
        return summary;
145
    }
146

    
147
    public String getSubmitterUserName(){
148
        return submitterUserName;
149
    }
150

    
151
    /**
152
     * @return the registrationType
153
     */
154
    public RegistrationType getRegistrationType() {
155
        return registrationType;
156
    }
157

    
158
    /**
159
     * @return the status
160
     */
161
    public RegistrationStatus getStatus() {
162
        return reg.getStatus();
163
    }
164

    
165
    /**
166
     * @return the identifier
167
     */
168
    public String getIdentifier() {
169
        return reg.getIdentifier();
170
    }
171

    
172

    
173
    /**
174
     * The entity ID of the Registration Item
175
     * @return
176
     */
177
    public int getId() {
178
        return reg.getId();
179
    }
180

    
181

    
182
    public UUID getUuid() {
183
        return reg.getUuid();
184
    }
185

    
186
    /**
187
     * @return the specificIdentifier
188
     */
189
    public String getSpecificIdentifier() {
190
        return reg.getSpecificIdentifier();
191
    }
192

    
193
    /**
194
     * @return the registrationDate
195
     */
196
    public DateTime getRegistrationDate() {
197
        return reg.getRegistrationDate();
198
    }
199

    
200
    /**
201
     * @return the registrationDate
202
     */
203
    public TimePeriod getDatePublished() {
204
        return citation == null ? null : citation.getDatePublished();
205
    }
206

    
207
    /**
208
     * @return the created
209
     */
210
    public DateTime getCreated() {
211
        return reg.getCreated();
212
    }
213

    
214
    public IReference getCitation() {
215
        return citation;
216
    }
217

    
218
    /**
219
     * @return the citationID
220
     */
221
    public Integer getCitationID() {
222
        return citation == null ? null : citation.getId();
223
    }
224

    
225
    public EntityReference getTypifiedName() {
226
        return typeDesignationConverter != null ? typeDesignationConverter.getTypifiedName() : null;
227
    }
228

    
229
    public EntityReference getName() {
230
        return name;
231
    }
232

    
233
    public Map<String, Collection<EntityReference>> getTypeDesignations() {
234
        return typeDesignationConverter != null ? typeDesignationConverter.getOrderedTypeDesignationRepresentations() : null;
235
    }
236

    
237
    /**
238
     * @return the citationString
239
     */
240
    public String getNomenclaturalCitationString() {
241
        if(citation == null){
242
            return null;
243
        }
244
        if(INomenclaturalReference.class.isAssignableFrom(citation.getClass())){
245
            return ((INomenclaturalReference)citation).getNomenclaturalCitation(citationDetail);
246
        } else {
247
            logger.error("The citation is not a NomenclaturalReference");
248
            return citation.generateTitle();
249
        }
250
    }
251

    
252
    /**
253
     * @return the citationString
254
     */
255
    public String getBibliographicCitationString() {
256
        if(citation == null){
257
            return null;
258
        } else {
259
            if(StringUtils.isNotEmpty(citationDetail)){
260
                // TODO see https://dev.e-taxonomy.eu/redmine/issues/6623
261
                return citation.generateTitle().replaceAll("\\.$", "") + (StringUtils.isNotEmpty(citationDetail) ? ": " + citationDetail : "");
262
            } else {
263
                return citation.generateTitle();
264

    
265
            }
266

    
267
        }
268
    }
269

    
270
    /**
271
     * @return the blockedBy
272
     */
273
    public Set<Registration> getBlockedBy() {
274
        return blockedBy;
275
    }
276

    
277
    /**
278
     * @return
279
     */
280
    public List<String> getMessages() {
281
        return messages;
282
    }
283

    
284
}
(5-5/17)