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.Arrays;
|
13
|
import java.util.EnumSet;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.hibernate.Session;
|
18
|
import org.hibernate.Transaction;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.security.core.Authentication;
|
21
|
import org.springframework.transaction.TransactionStatus;
|
22
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
23
|
|
24
|
import com.vaadin.spring.annotation.SpringComponent;
|
25
|
import com.vaadin.spring.annotation.ViewScope;
|
26
|
import com.vaadin.ui.Label;
|
27
|
import com.vaadin.ui.UI;
|
28
|
import com.vaadin.ui.VerticalLayout;
|
29
|
import com.vaadin.ui.Window;
|
30
|
|
31
|
import eu.etaxonomy.cdm.api.service.INameService;
|
32
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
33
|
import eu.etaxonomy.cdm.api.service.idminter.IdentifierMinter.Identifier;
|
34
|
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter;
|
35
|
import eu.etaxonomy.cdm.model.common.User;
|
36
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
37
|
import eu.etaxonomy.cdm.model.name.Rank;
|
38
|
import eu.etaxonomy.cdm.model.name.Registration;
|
39
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
40
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
42
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
43
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
44
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
45
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
|
46
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
47
|
import eu.etaxonomy.cdm.service.CdmStore;
|
48
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
49
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
50
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
51
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
52
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
53
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
54
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEventEntityTypeFilter;
|
55
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
56
|
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
|
57
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction;
|
58
|
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
|
59
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
60
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
61
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
62
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
63
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
|
64
|
import eu.etaxonomy.cdm.vaadin.view.name.NameTypeDesignationPopupEditor;
|
65
|
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
|
66
|
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
|
67
|
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
|
68
|
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
|
69
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
70
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
71
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
72
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
|
73
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
|
74
|
|
75
|
/**
|
76
|
* @author a.kohlbecker
|
77
|
* @since Mar 3, 2017
|
78
|
*
|
79
|
*/
|
80
|
@SpringComponent
|
81
|
@ViewScope
|
82
|
public class RegistrationWorkingsetPresenter extends AbstractPresenter<RegistrationWorkingsetView> {
|
83
|
|
84
|
private static final long serialVersionUID = 1L;
|
85
|
|
86
|
@Autowired
|
87
|
private IRegistrationWorkingSetService regWorkingSetService;
|
88
|
|
89
|
@Autowired
|
90
|
private RegistrationIdentifierMinter minter;
|
91
|
|
92
|
/**
|
93
|
* @return the regWorkingSetService
|
94
|
*/
|
95
|
public IRegistrationWorkingSetService getWorkingSetService() {
|
96
|
return regWorkingSetService;
|
97
|
}
|
98
|
|
99
|
private RegistrationWorkingSet workingset;
|
100
|
|
101
|
private TaxonName newTaxonNameForRegistration = null;
|
102
|
|
103
|
private RegistrationDTO newRegistrationDTOWithExistingName;
|
104
|
|
105
|
private RegistrationDTO newNameTypeDesignationTarget;
|
106
|
|
107
|
|
108
|
/**
|
109
|
*
|
110
|
*/
|
111
|
public RegistrationWorkingsetPresenter() {
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Always create a new Store
|
116
|
*
|
117
|
* @return
|
118
|
*/
|
119
|
protected CdmStore<Registration, IRegistrationService> getRegistrationStore(){
|
120
|
return new CdmStore<Registration, IRegistrationService>(getRepo(), getRepo().getRegistrationService());
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Always create a new Store
|
125
|
*
|
126
|
* @return
|
127
|
*/
|
128
|
protected CdmStore<TaxonName, INameService> getTaxonNameStore(){
|
129
|
return new CdmStore<TaxonName, INameService>(getRepo(), getRepo().getNameService());
|
130
|
}
|
131
|
|
132
|
|
133
|
/**
|
134
|
* @param taxonNameId
|
135
|
* @return
|
136
|
*/
|
137
|
protected Registration createNewRegistrationForName(Integer taxonNameId) {
|
138
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
139
|
// move into RegistrationWorkflowStateMachine
|
140
|
TransactionStatus txStatus = getRepo().startTransaction();
|
141
|
long identifier = System.currentTimeMillis();
|
142
|
|
143
|
Identifier<String> identifiers = minter.mint();
|
144
|
if(identifiers.getIdentifier() == null){
|
145
|
throw new RuntimeException("RegistrationIdentifierMinter configuration incomplete.");
|
146
|
}
|
147
|
Registration reg = Registration.NewInstance(
|
148
|
identifiers.getIdentifier(),
|
149
|
identifiers.getLocalId(),
|
150
|
taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
|
151
|
null);
|
152
|
Authentication authentication = currentSecurityContext().getAuthentication();
|
153
|
reg.setSubmitter((User)authentication.getPrincipal());
|
154
|
EntityChangeEvent event = getRegistrationStore().saveBean(reg);
|
155
|
UserHelper.fromSession().createAuthorityForCurrentUser(Registration.class, event.getEntityId(), Operation.UPDATE, RegistrationStatus.PREPARATION.name());
|
156
|
getRepo().commitTransaction(txStatus);
|
157
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
158
|
return getRepo().getRegistrationService().find(event.getEntityId());
|
159
|
}
|
160
|
|
161
|
|
162
|
/**
|
163
|
* @param doReload TODO
|
164
|
*
|
165
|
*/
|
166
|
protected void refreshView(boolean doReload) {
|
167
|
if(workingset == null){
|
168
|
return; // nothing to do
|
169
|
}
|
170
|
if(doReload){
|
171
|
loadWorkingSet(workingset.getCitationId());
|
172
|
}
|
173
|
getView().setWorkingset(workingset);
|
174
|
}
|
175
|
|
176
|
|
177
|
/**
|
178
|
* {@inheritDoc}
|
179
|
*/
|
180
|
@Override
|
181
|
public void handleViewEntered() {
|
182
|
|
183
|
super.handleViewEntered();
|
184
|
|
185
|
loadWorkingSet(getView().getCitationID());
|
186
|
getView().setWorkingset(workingset);
|
187
|
|
188
|
CdmFilterablePagingProvider<TaxonName, TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(
|
189
|
getRepo().getNameService());
|
190
|
CdmTitleCacheCaptionGenerator<TaxonName> titleCacheGenrator = new CdmTitleCacheCaptionGenerator<TaxonName>();
|
191
|
getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenrator);
|
192
|
getView().getAddExistingNameCombobox().loadFrom(pagingProvider, pagingProvider, pagingProvider.getPageSize());
|
193
|
}
|
194
|
|
195
|
|
196
|
/**
|
197
|
* @param referenceID
|
198
|
*/
|
199
|
protected void loadWorkingSet(Integer referenceID) {
|
200
|
try {
|
201
|
workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
|
202
|
} catch (RegistrationValidationException error) {
|
203
|
logger.error(error);
|
204
|
Window errorDialog = new Window("Validation Error");
|
205
|
errorDialog.setModal(true);
|
206
|
VerticalLayout subContent = new VerticalLayout();
|
207
|
subContent.setMargin(true);
|
208
|
errorDialog.setContent(subContent);
|
209
|
subContent.addComponent(new Label(error.getMessage()));
|
210
|
UI.getCurrent().addWindow(errorDialog);
|
211
|
}
|
212
|
if(workingset == null || workingset.getCitationId() == null){
|
213
|
Reference citation = getRepo().getReferenceService().find(referenceID);
|
214
|
workingset = new RegistrationWorkingSet(citation);
|
215
|
}
|
216
|
}
|
217
|
|
218
|
|
219
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
220
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
221
|
|
222
|
if(!checkFromOwnView(event)){
|
223
|
return;
|
224
|
}
|
225
|
|
226
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
227
|
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
|
228
|
popup.loadInEditor(null);
|
229
|
}
|
230
|
|
231
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
232
|
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
233
|
|
234
|
if(!checkFromOwnView(event)){
|
235
|
return;
|
236
|
}
|
237
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
238
|
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
|
239
|
popup.withDeleteButton(true);
|
240
|
popup.loadInEditor(event.getEntityId());
|
241
|
}
|
242
|
|
243
|
@EventBusListenerMethod
|
244
|
public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
245
|
if(event.getPopup() instanceof ReferencePopupEditor){
|
246
|
if(event.getReason().equals(Reason.SAVE)){
|
247
|
refreshView(true);
|
248
|
}
|
249
|
}
|
250
|
}
|
251
|
|
252
|
@EventBusListenerMethod
|
253
|
public void onDoneWithSpecimenTypeDesignationWorkingsetPopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
254
|
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
|
255
|
if(event.getReason().equals(Reason.SAVE)){
|
256
|
refreshView(true);
|
257
|
}
|
258
|
}
|
259
|
}
|
260
|
|
261
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
262
|
public void onRegistrationEditorAction(RegistrationEditorAction event) {
|
263
|
|
264
|
if(!checkFromOwnView(event)){
|
265
|
return;
|
266
|
}
|
267
|
|
268
|
RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
|
269
|
popup.loadInEditor(event.getEntityId());
|
270
|
}
|
271
|
|
272
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
273
|
public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
|
274
|
|
275
|
if(!checkFromOwnView(event)){
|
276
|
return;
|
277
|
}
|
278
|
|
279
|
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
|
280
|
popup.withDeleteButton(true);
|
281
|
configureTaxonNameEditor(popup);
|
282
|
popup.loadInEditor(event.getEntityId());
|
283
|
if(event.getSourceComponent() != null){
|
284
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
285
|
}
|
286
|
|
287
|
}
|
288
|
|
289
|
|
290
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
291
|
public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
|
292
|
|
293
|
if(!checkFromOwnView(event)){
|
294
|
return;
|
295
|
}
|
296
|
|
297
|
newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
|
298
|
newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
|
299
|
EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
|
300
|
newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
|
301
|
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
|
302
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
|
303
|
popup.withDeleteButton(true);
|
304
|
configureTaxonNameEditor(popup);
|
305
|
popup.loadInEditor(newTaxonNameForRegistration.getId());
|
306
|
}
|
307
|
|
308
|
/**
|
309
|
* TODO consider putting this into a Configurer Bean per UIScope.
|
310
|
* In the configurator bean this methods popup papamerter should be of the type
|
311
|
* AbstractPopupEditor
|
312
|
*
|
313
|
* @param popup
|
314
|
*/
|
315
|
protected void configureTaxonNameEditor(TaxonNamePopupEditor popup) {
|
316
|
popup.enableMode(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData);
|
317
|
popup.enableMode(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly);
|
318
|
}
|
319
|
|
320
|
/**
|
321
|
* Creates a new <code>Registration</code> for a new name that has just been edited
|
322
|
* using the <code>TaxonNamePopupEditor</code>. The new name was previously created
|
323
|
* in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
|
324
|
* and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
|
325
|
* (<code>Reason.CANCEL</code>).
|
326
|
*
|
327
|
*
|
328
|
* @param event
|
329
|
* @throws RegistrationValidationException
|
330
|
*/
|
331
|
@EventBusListenerMethod
|
332
|
public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
333
|
if(event.getPopup() instanceof TaxonNamePopupEditor){
|
334
|
TransactionStatus txStatus = getRepo().startTransaction();
|
335
|
if(event.getReason().equals(Reason.SAVE)){
|
336
|
if(newTaxonNameForRegistration != null){
|
337
|
int taxonNameId = newTaxonNameForRegistration.getId();
|
338
|
getRepo().getSession().refresh(newTaxonNameForRegistration);
|
339
|
Registration reg = createNewRegistrationForName(taxonNameId);
|
340
|
// reload workingset into current session
|
341
|
loadWorkingSet(workingset.getCitationId());
|
342
|
workingset.add(reg);
|
343
|
}
|
344
|
refreshView(true);
|
345
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
346
|
if(newTaxonNameForRegistration != null){
|
347
|
// clean up
|
348
|
getTaxonNameStore().deleteBean(newTaxonNameForRegistration);
|
349
|
}
|
350
|
}
|
351
|
getRepo().commitTransaction(txStatus);
|
352
|
newTaxonNameForRegistration = null;
|
353
|
}
|
354
|
}
|
355
|
|
356
|
|
357
|
/**
|
358
|
* Creates a new Registration for an exiting (previously published name).
|
359
|
*
|
360
|
* @param event
|
361
|
* @throws RegistrationValidationException
|
362
|
*/
|
363
|
@EventBusListenerMethod
|
364
|
public void onRegistrationWorkflowEventActionStart(RegistrationWorkingsetAction event) throws RegistrationValidationException {
|
365
|
|
366
|
if(!event.isStart()){
|
367
|
return;
|
368
|
}
|
369
|
|
370
|
getView().getAddExistingNameCombobox().commit();
|
371
|
TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
|
372
|
if(typifiedName != null){
|
373
|
Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
|
374
|
Reference citation = getRepo().getReferenceService().find(workingset.getCitationId());
|
375
|
newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
|
376
|
workingset.add(newRegistrationDTOWithExistingName);
|
377
|
// tell the view to update the workingset
|
378
|
getView().setWorkingset(workingset);
|
379
|
getView().getAddExistingNameRegistrationButton().setEnabled(false);
|
380
|
getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
|
381
|
} else {
|
382
|
logger.error("Seletced name is NULL");
|
383
|
}
|
384
|
|
385
|
}
|
386
|
|
387
|
|
388
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
389
|
public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
|
390
|
|
391
|
if(!checkFromOwnView(event)){
|
392
|
return;
|
393
|
}
|
394
|
|
395
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
|
396
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
|
397
|
popup.withDeleteButton(true);
|
398
|
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
|
399
|
if(event.getSourceComponent() != null){
|
400
|
// propagate readonly state from source component to popup
|
401
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
402
|
}
|
403
|
} else {
|
404
|
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
|
405
|
popup.withDeleteButton(true);
|
406
|
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
|
407
|
|
408
|
popup.getCitationCombobox().setEnabled(false);
|
409
|
popup.getTypifiedNamesComboboxSelect().setEnabled(false);
|
410
|
|
411
|
if(event.getSourceComponent() != null){
|
412
|
// propagate readonly state from source component to popup
|
413
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
414
|
}
|
415
|
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
416
|
}
|
417
|
}
|
418
|
|
419
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
420
|
public void onAddNewTypeDesignationWorkingset(TypeDesignationWorkingsetEditorAction event) {
|
421
|
|
422
|
if(event.getSourceComponent() != null){
|
423
|
return;
|
424
|
}
|
425
|
|
426
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
|
427
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
|
428
|
TypeDesignationWorkingsetEditorIdSet identifierSet;
|
429
|
Integer typifiedNameId;
|
430
|
if(newRegistrationDTOWithExistingName != null){
|
431
|
typifiedNameId = newRegistrationDTOWithExistingName.getTypifiedNameRef().getId();
|
432
|
} else {
|
433
|
RegistrationDTO registrationDTO = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
434
|
EntityReference typifiedNameRef = registrationDTO.getTypifiedNameRef();
|
435
|
if(typifiedNameRef != null){
|
436
|
// case for registrations without name, in which case the typifiedName is only defined via the typedesignations
|
437
|
typifiedNameId = typifiedNameRef.getId();
|
438
|
} else {
|
439
|
// case of registrations with a name in the nomenclatural act.
|
440
|
typifiedNameId = registrationDTO.getNameRef().getId();
|
441
|
}
|
442
|
}
|
443
|
identifierSet = new TypeDesignationWorkingsetEditorIdSet(
|
444
|
event.getRegistrationId(),
|
445
|
getView().getCitationID(),
|
446
|
typifiedNameId
|
447
|
);
|
448
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
449
|
popup.loadInEditor(identifierSet);
|
450
|
popup.withDeleteButton(true);
|
451
|
if(event.getSourceComponent() != null){
|
452
|
// propagate readonly state from source component to popup
|
453
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
454
|
}
|
455
|
} else {
|
456
|
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
|
457
|
popup.withDeleteButton(true);
|
458
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
459
|
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
460
|
popup.setBeanInstantiator(new BeanInstantiator<NameTypeDesignation>() {
|
461
|
|
462
|
@Override
|
463
|
public NameTypeDesignation createNewBean() {
|
464
|
NameTypeDesignation nameTypeDesignation = NameTypeDesignation.NewInstance();
|
465
|
nameTypeDesignation.setCitation(newNameTypeDesignationTarget.getCitation());
|
466
|
nameTypeDesignation.getTypifiedNames().add(newNameTypeDesignationTarget.getTypifiedName());
|
467
|
return nameTypeDesignation;
|
468
|
}
|
469
|
});
|
470
|
popup.loadInEditor(null);
|
471
|
popup.getCitationCombobox().setEnabled(false);
|
472
|
popup.getTypifiedNamesComboboxSelect().setEnabled(false);
|
473
|
if(event.getSourceComponent() != null){
|
474
|
// propagate readonly state from source component to popup
|
475
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
476
|
}
|
477
|
}
|
478
|
}
|
479
|
|
480
|
/**
|
481
|
* Performs final actions after a TypeDesignationEditor which has been
|
482
|
* opened to add a TypeDesignation to a Registration object which was
|
483
|
* created for an previously published name. Prior adding a typedesignation,
|
484
|
* the according Registration object is dangling, that has no association to
|
485
|
* any entity denoting an nomenclatural act which has a reference to a
|
486
|
* publication. This means that the registration object is not in the
|
487
|
* working set.
|
488
|
*
|
489
|
*
|
490
|
* @param event
|
491
|
* @throws RegistrationValidationException
|
492
|
*/
|
493
|
@EventBusListenerMethod
|
494
|
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
495
|
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
|
496
|
if(event.getReason().equals(Reason.SAVE)){
|
497
|
refreshView(true);
|
498
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
499
|
// clean up
|
500
|
if(newRegistrationDTOWithExistingName != null){
|
501
|
getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration());
|
502
|
}
|
503
|
}
|
504
|
// set newRegistrationDTOWithExistingName NULL in any case
|
505
|
newRegistrationDTOWithExistingName = null;
|
506
|
} else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
|
507
|
if(event.getReason().equals(Reason.SAVE)){
|
508
|
UUID uuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
|
509
|
|
510
|
Session session = getRepo().getSessionFactory().openSession();
|
511
|
Transaction txstate = session.beginTransaction();
|
512
|
TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, Arrays.asList(""));
|
513
|
// only load the typeDesignations with the registration so that the typified name can not be twice in the session
|
514
|
// otherwise multiple representation problems might occur
|
515
|
Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getUuid(), Arrays.asList("typeDesignations"));
|
516
|
registration.getTypeDesignations().add(nameTypeDesignation);
|
517
|
session.merge(registration);
|
518
|
txstate.commit();
|
519
|
session.close();
|
520
|
|
521
|
newNameTypeDesignationTarget = null;
|
522
|
refreshView(true);
|
523
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
524
|
// noting to do
|
525
|
}
|
526
|
}
|
527
|
// ignore other editors
|
528
|
}
|
529
|
|
530
|
|
531
|
@EventBusListenerMethod(filter = ShowDetailsEventEntityTypeFilter.RegistrationWorkingSet.class)
|
532
|
public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) {
|
533
|
List<String> messages = new ArrayList<>();
|
534
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
|
535
|
dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
|
536
|
}
|
537
|
if(event.getProperty().equals("messages")){
|
538
|
getView().openDetailsPopup("Messages", messages);
|
539
|
}
|
540
|
}
|
541
|
|
542
|
|
543
|
@EventBusListenerMethod(filter = ShowDetailsEventEntityTypeFilter.RegistrationDTO.class)
|
544
|
public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) {
|
545
|
RegistrationDTO regDto = regWorkingSetService.loadDtoById((Integer)event.getIdentifier());
|
546
|
if(event.getProperty().equals("messages")){
|
547
|
if(getView() != null){
|
548
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
549
|
}
|
550
|
}
|
551
|
}
|
552
|
|
553
|
@EventBusListenerMethod
|
554
|
public void onEntityChangeEvent(EntityChangeEvent event){
|
555
|
if(workingset == null){
|
556
|
return;
|
557
|
}
|
558
|
if(Reference.class.isAssignableFrom(event.getEntityType())){
|
559
|
if(workingset.getCitationId().equals(event.getEntityId())){
|
560
|
refreshView(true);
|
561
|
}
|
562
|
} else
|
563
|
if(Registration.class.isAssignableFrom(event.getEntityType())){
|
564
|
if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
|
565
|
refreshView(true);
|
566
|
}
|
567
|
} else
|
568
|
if(TaxonName.class.isAssignableFrom(event.getEntityType())){
|
569
|
if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
|
570
|
reg.getTypifiedNameRef() != null
|
571
|
&& reg.getTypifiedNameRef().getId() == event.getEntityId())){
|
572
|
refreshView(true);
|
573
|
}
|
574
|
} else
|
575
|
if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
|
576
|
if(workingset.getRegistrationDTOs().stream().anyMatch(
|
577
|
reg -> reg.getTypeDesignations() != null && reg.getTypeDesignations().stream().anyMatch(
|
578
|
td -> td.getId() == event.getEntityId()
|
579
|
)
|
580
|
)
|
581
|
){
|
582
|
refreshView(true);
|
583
|
}
|
584
|
}
|
585
|
|
586
|
}
|
587
|
|
588
|
}
|