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.util.converter.TypeDesignationConverter;
|
30
|
|
31
|
public class RegistrationDTO{
|
32
|
|
33
|
private static final Logger logger = Logger.getLogger(RegistrationDTO.class);
|
34
|
|
35
|
private String summary = "";
|
36
|
|
37
|
private RegistrationType registrationType;
|
38
|
|
39
|
private IReference citation = null;
|
40
|
|
41
|
private String citationDetail = null;
|
42
|
|
43
|
private String submitterUserName = null;
|
44
|
|
45
|
private IdAndString name = null;
|
46
|
|
47
|
private TypeDesignationConverter typeDesignationConverter;
|
48
|
|
49
|
private Registration reg;
|
50
|
|
51
|
private List<String> messages = new ArrayList<>();
|
52
|
|
53
|
private Set<eu.etaxonomy.cdm.model.name.Registration> blockedBy = new HashSet<>();
|
54
|
|
55
|
|
56
|
/**
|
57
|
* @param reg
|
58
|
* @param typifiedName should be provided in for Registrations for TypeDesignations
|
59
|
* @throws RegistrationValidationException
|
60
|
*/
|
61
|
public RegistrationDTO(Registration reg) {
|
62
|
|
63
|
this.reg = reg;
|
64
|
|
65
|
registrationType = RegistrationType.from(reg);
|
66
|
|
67
|
if(reg.getSubmitter() != null ){
|
68
|
submitterUserName = reg.getSubmitter().getUsername();
|
69
|
}
|
70
|
|
71
|
if(hasName(reg)){
|
72
|
citation = reg.getName().getNomenclaturalReference();
|
73
|
citationDetail = reg.getName().getNomenclaturalMicroReference();
|
74
|
name = new IdAndString(reg.getName().getId(), reg.getName().getTitleCache());
|
75
|
}
|
76
|
if(hasTypifications(reg)){
|
77
|
if(!reg.getTypeDesignations().isEmpty()){
|
78
|
for(TypeDesignationBase td : reg.getTypeDesignations()){
|
79
|
if(citation == null) {
|
80
|
citation = td.getCitation();
|
81
|
citationDetail = td.getCitationMicroReference();
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
switch(registrationType) {
|
87
|
case EMPTY:
|
88
|
summary = "BLANK REGISTRATION";
|
89
|
break;
|
90
|
case NAME:
|
91
|
summary = reg.getName().getTitleCache();
|
92
|
break;
|
93
|
case NAME_AND_TYPIFICATION:
|
94
|
case TYPIFICATION:
|
95
|
default:
|
96
|
try {
|
97
|
typeDesignationConverter = new TypeDesignationConverter(reg.getTypeDesignations());
|
98
|
summary = typeDesignationConverter.buildString().print();
|
99
|
} catch (RegistrationValidationException e) {
|
100
|
messages.add("Validation errors: " + e.getMessage());
|
101
|
}
|
102
|
break;
|
103
|
}
|
104
|
|
105
|
// trigger initialization of the reference
|
106
|
getNomenclaturalCitationString();
|
107
|
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* @param reg
|
112
|
* @return
|
113
|
*/
|
114
|
private boolean hasTypifications(Registration reg) {
|
115
|
return reg.getTypeDesignations() != null && reg.getTypeDesignations().size() > 0;
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* @param reg
|
120
|
* @return
|
121
|
*/
|
122
|
private boolean hasName(Registration reg) {
|
123
|
return reg.getName() != null;
|
124
|
}
|
125
|
|
126
|
|
127
|
/**
|
128
|
* Provides access to the Registration entity this DTO has been build from.
|
129
|
* This method is purposely not a getter to hide the original Registration
|
130
|
* from generic processes which are exposing, binding bean properties.
|
131
|
*IReference
|
132
|
* @return
|
133
|
*/
|
134
|
public Registration registration() {
|
135
|
return reg;
|
136
|
}
|
137
|
|
138
|
|
139
|
/**
|
140
|
* @return the summary
|
141
|
*/
|
142
|
public String getSummary() {
|
143
|
return summary;
|
144
|
}
|
145
|
|
146
|
public String getSubmitterUserName(){
|
147
|
return submitterUserName;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* @return the registrationType
|
152
|
*/
|
153
|
public RegistrationType getRegistrationType() {
|
154
|
return registrationType;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* @return the status
|
159
|
*/
|
160
|
public RegistrationStatus getStatus() {
|
161
|
return reg.getStatus();
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* @return the identifier
|
166
|
*/
|
167
|
public String getIdentifier() {
|
168
|
return reg.getIdentifier();
|
169
|
}
|
170
|
|
171
|
|
172
|
/**
|
173
|
* The entity ID of the Registration Item
|
174
|
* @return
|
175
|
*/
|
176
|
public int getId() {
|
177
|
return reg.getId();
|
178
|
}
|
179
|
|
180
|
|
181
|
public UUID getUuid() {
|
182
|
return reg.getUuid();
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* @return the specificIdentifier
|
187
|
*/
|
188
|
public String getSpecificIdentifier() {
|
189
|
return reg.getSpecificIdentifier();
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* @return the registrationDate
|
194
|
*/
|
195
|
public DateTime getRegistrationDate() {
|
196
|
return reg.getRegistrationDate();
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* @return the registrationDate
|
201
|
*/
|
202
|
public TimePeriod getDatePublished() {
|
203
|
return citation == null ? null : citation.getDatePublished();
|
204
|
}
|
205
|
|
206
|
/**
|
207
|
* @return the created
|
208
|
*/
|
209
|
public DateTime getCreated() {
|
210
|
return reg.getCreated();
|
211
|
}
|
212
|
|
213
|
public IReference getCitation() {
|
214
|
return citation;
|
215
|
}
|
216
|
|
217
|
/**
|
218
|
* @return the citationID
|
219
|
*/
|
220
|
public Integer getCitationID() {
|
221
|
return citation == null ? null : citation.getId();
|
222
|
}
|
223
|
|
224
|
public IdAndString getTypifiedName() {
|
225
|
return typeDesignationConverter != null ? typeDesignationConverter.getTypifiedName() : null;
|
226
|
}
|
227
|
|
228
|
public IdAndString getName() {
|
229
|
return name;
|
230
|
}
|
231
|
|
232
|
public Map<String, Collection<IdAndString>> getTypeDesignations() {
|
233
|
return typeDesignationConverter != null ? typeDesignationConverter.getOrderedTypeDesignationRepresentations() : null;
|
234
|
}
|
235
|
|
236
|
/**
|
237
|
* @return the citationString
|
238
|
*/
|
239
|
public String getNomenclaturalCitationString() {
|
240
|
if(citation == null){
|
241
|
return null;
|
242
|
}
|
243
|
if(INomenclaturalReference.class.isAssignableFrom(citation.getClass())){
|
244
|
return ((INomenclaturalReference)citation).getNomenclaturalCitation(citationDetail);
|
245
|
} else {
|
246
|
logger.error("The citation is not a NomenclaturalReference");
|
247
|
return citation.generateTitle();
|
248
|
}
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* @return the citationString
|
253
|
*/
|
254
|
public String getBibliographicCitationString() {
|
255
|
if(citation == null){
|
256
|
return null;
|
257
|
} else {
|
258
|
if(StringUtils.isNotEmpty(citationDetail)){
|
259
|
// TODO see https://dev.e-taxonomy.eu/redmine/issues/6623
|
260
|
return citation.generateTitle().replaceAll("\\.$", "") + (StringUtils.isNotEmpty(citationDetail) ? ": " + citationDetail : "");
|
261
|
} else {
|
262
|
return citation.generateTitle();
|
263
|
|
264
|
}
|
265
|
|
266
|
}
|
267
|
}
|
268
|
|
269
|
/**
|
270
|
* @return the blockedBy
|
271
|
*/
|
272
|
public Set<Registration> getBlockedBy() {
|
273
|
return blockedBy;
|
274
|
}
|
275
|
|
276
|
/**
|
277
|
* @return
|
278
|
*/
|
279
|
public List<String> getMessages() {
|
280
|
return messages;
|
281
|
}
|
282
|
|
283
|
}
|