Project

General

Profile

Download (23.5 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.Arrays;
13
import java.util.EnumSet;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.context.event.EventListener;
19
import org.springframework.security.core.Authentication;
20
import org.springframework.transaction.TransactionStatus;
21

    
22
import com.vaadin.spring.annotation.SpringComponent;
23
import com.vaadin.spring.annotation.ViewScope;
24
import com.vaadin.ui.Label;
25
import com.vaadin.ui.UI;
26
import com.vaadin.ui.VerticalLayout;
27
import com.vaadin.ui.Window;
28

    
29
import eu.etaxonomy.cdm.api.service.INameService;
30
import eu.etaxonomy.cdm.api.service.IRegistrationService;
31
import eu.etaxonomy.cdm.api.service.idminter.IdentifierMinter.Identifier;
32
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter;
33
import eu.etaxonomy.cdm.model.common.User;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.name.Registration;
36
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
37
import eu.etaxonomy.cdm.model.name.TaxonName;
38
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
39
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
40
import eu.etaxonomy.cdm.model.reference.Reference;
41
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
42
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
43
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
44
import eu.etaxonomy.cdm.service.CdmStore;
45
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
46
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
47
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
48
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
49
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
50
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
51
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
52
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction;
53
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
54
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
55
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
56
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
57
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
58
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
59
import eu.etaxonomy.cdm.vaadin.view.name.NameTypeDesignationPopupEditor;
60
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
61
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
62
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
63
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
64
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
65
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
66
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
67
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
68

    
69
/**
70
 * @author a.kohlbecker
71
 * @since Mar 3, 2017
72
 *
73
 */
74
@SpringComponent
75
@ViewScope
76
public class RegistrationWorkingsetPresenter extends AbstractPresenter<RegistrationWorkingsetView> {
77

    
78
    private static final long serialVersionUID = 1L;
79

    
80
    @Autowired
81
    private IRegistrationWorkingSetService workingSetService;
82

    
83
    @Autowired
84
    private RegistrationIdentifierMinter minter;
85

    
86
    /**
87
     * @return the workingSetService
88
     */
89
    public IRegistrationWorkingSetService getWorkingSetService() {
90
        return workingSetService;
91
    }
92

    
93
    private RegistrationWorkingSet workingset;
94

    
95
    private TaxonName newTaxonNameForRegistration = null;
96

    
97
    private RegistrationDTO newRegistrationDTOWithExistingName;
98

    
99
    private RegistrationDTO newNameTypeDesignationTarget;
100

    
101

    
102
    /**
103
     *
104
     */
105
    public RegistrationWorkingsetPresenter() {
106
    }
107

    
108

    
109
    /**
110
     * Always create a new Store
111
     *
112
     * @return
113
     */
114
    protected CdmStore<Registration, IRegistrationService> getRegistrationStore(){
115
        return new CdmStore<Registration, IRegistrationService>(getRepo(), getRepo().getRegistrationService());
116
    }
117

    
118
    /**
119
     * Always create a new Store
120
     *
121
     * @return
122
     */
123
    protected CdmStore<TaxonName, INameService> getTaxonNameStore(){
124
        return new  CdmStore<TaxonName, INameService>(getRepo(), getRepo().getNameService());
125
    }
126

    
127

    
128
    /**
129
     * @param taxonNameId
130
     * @return
131
     */
132
    protected Registration createNewRegistrationForName(Integer taxonNameId) {
133
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134
        // move into RegistrationWorkflowStateMachine
135
        TransactionStatus txStatus = getRepo().startTransaction();
136
        long identifier = System.currentTimeMillis();
137

    
138
        Identifier<String> identifiers = minter.mint();
139
        if(identifiers.getIdentifier() == null){
140
            throw new RuntimeException("RegistrationIdentifierMinter configuration incomplete.");
141
        }
142
        Registration reg = Registration.NewInstance(
143
                identifiers.getIdentifier(),
144
                identifiers.getLocalId(),
145
                taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
146
                null);
147
        Authentication authentication = currentSecurityContext().getAuthentication();
148
        reg.setSubmitter((User)authentication.getPrincipal());
149
        EntityChangeEvent event = getRegistrationStore().saveBean(reg);
150
        UserHelper.fromSession().createAuthorityForCurrentUser(Registration.class, event.getEntityId(), Operation.UPDATE, RegistrationStatus.PREPARATION.name());
151
        getRepo().commitTransaction(txStatus);
152
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153
        return getRepo().getRegistrationService().find(event.getEntityId());
154
    }
155

    
156

    
157
    /**
158
     * @param doReload TODO
159
     *
160
     */
161
    protected void refreshView(boolean doReload) {
162
        if(workingset == null){
163
            return; // nothing to do
164
        }
165
        if(doReload){
166
            loadWorkingSet(workingset.getCitationId());
167
        }
168
        getView().setWorkingset(workingset);
169
    }
170

    
171

    
172
    /**
173
     * {@inheritDoc}
174
     */
175
    @Override
176
    public void handleViewEntered() {
177

    
178
        super.handleViewEntered();
179

    
180
        loadWorkingSet(getView().getCitationID());
181
        getView().setWorkingset(workingset);
182

    
183
        CdmFilterablePagingProvider<TaxonName, TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(
184
                getRepo().getNameService());
185
        CdmTitleCacheCaptionGenerator<TaxonName> titleCacheGenrator = new CdmTitleCacheCaptionGenerator<TaxonName>();
186
        getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenrator);
187
        getView().getAddExistingNameCombobox().loadFrom(pagingProvider, pagingProvider, pagingProvider.getPageSize());
188
    }
189

    
190

    
191
    /**
192
     * @param referenceID
193
     */
194
    protected void loadWorkingSet(Integer referenceID) {
195
        try {
196
            workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
197
        } catch (RegistrationValidationException error) {
198
            logger.error(error);
199
            Window errorDialog = new Window("Validation Error");
200
            errorDialog.setModal(true);
201
            VerticalLayout subContent = new VerticalLayout();
202
            subContent.setMargin(true);
203
            errorDialog.setContent(subContent);
204
            subContent.addComponent(new Label(error.getMessage()));
205
            UI.getCurrent().addWindow(errorDialog);
206
        }
207
        if(workingset == null || workingset.getCitationId() == null){
208
            Reference citation = getRepo().getReferenceService().find(referenceID);
209
            workingset = new RegistrationWorkingSet(citation);
210
        }
211
    }
212

    
213
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).ADD")
214
    public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
215

    
216
        if(!checkFromOwnView(event)){
217
            return;
218
        }
219

    
220
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
221
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
222
        popup.loadInEditor(null);
223
    }
224

    
225
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
226
    public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
227

    
228
        if(!checkFromOwnView(event)){
229
            return;
230
        }
231
        ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
232
        popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
233
        popup.withDeleteButton(true);
234
        popup.loadInEditor(event.getEntityId());
235
    }
236

    
237
    @EventListener
238
    public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
239
        if(event.getPopup() instanceof ReferencePopupEditor){
240
            if(event.getReason().equals(Reason.SAVE)){
241
                refreshView(true);
242
            }
243
        }
244
    }
245

    
246
    @EventListener
247
    public void onDoneWithSpecimenTypeDesignationWorkingsetPopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
248
        if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
249
            if(event.getReason().equals(Reason.SAVE)){
250
                refreshView(true);
251
            }
252
        }
253
    }
254

    
255
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
256
    public void onRegistrationEditorAction(RegistrationEditorAction event) {
257

    
258
        if(!checkFromOwnView(event)){
259
            return;
260
        }
261

    
262
        RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
263
        popup.loadInEditor(event.getEntityId());
264
    }
265

    
266
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
267
    public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
268

    
269
        if(!checkFromOwnView(event)){
270
            return;
271
        }
272

    
273
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
274
        popup.withDeleteButton(true);
275
        configureTaxonNameEditor(popup);
276
        popup.loadInEditor(event.getEntityId());
277
        if(event.getSourceComponent() != null){
278
            popup.setReadOnly(event.getSourceComponent().isReadOnly());
279
        }
280

    
281
    }
282

    
283

    
284
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).ADD")
285
    public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
286

    
287
        if(!checkFromOwnView(event)){
288
            return;
289
        }
290

    
291
        newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
292
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
293
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
294
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
295
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
296
        popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
297
        popup.withDeleteButton(true);
298
        configureTaxonNameEditor(popup);
299
        popup.loadInEditor(newTaxonNameForRegistration.getId());
300
    }
301

    
302
    /**
303
     * TODO consider putting this into a Configurer Bean per UIScope.
304
     * In the configurator bean this methods popup papamerter should be of the type
305
     * AbstractPopupEditor
306
     *
307
     * @param popup
308
     */
309
    protected void configureTaxonNameEditor(TaxonNamePopupEditor popup) {
310
        popup.enableMode(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData);
311
        popup.enableMode(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly);
312
    }
313

    
314
    /**
315
     * Creates a new <code>Registration</code> for a new name that has just been edited
316
     * using the <code>TaxonNamePopupEditor</code>. The new name was previously created
317
     * in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
318
     * and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
319
     * (<code>Reason.CANCEL</code>).
320
     *
321
     *
322
     * @param event
323
     * @throws RegistrationValidationException
324
     */
325
    @EventListener
326
    public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
327
        if(event.getPopup() instanceof TaxonNamePopupEditor){
328
            TransactionStatus txStatus = getRepo().startTransaction();
329
            if(event.getReason().equals(Reason.SAVE)){
330
                if(newTaxonNameForRegistration != null){
331
                    int taxonNameId = newTaxonNameForRegistration.getId();
332
                    getRepo().getSession().refresh(newTaxonNameForRegistration);
333
                    Registration reg = createNewRegistrationForName(taxonNameId);
334
                    // reload workingset into current session
335
                    loadWorkingSet(workingset.getCitationId());
336
                    workingset.add(reg);
337
                }
338
                refreshView(true);
339
            } else if(event.getReason().equals(Reason.CANCEL)){
340
                if(newTaxonNameForRegistration != null){
341
                    // clean up
342
                    getTaxonNameStore().deleteBean(newTaxonNameForRegistration);
343
                }
344
            }
345
            getRepo().commitTransaction(txStatus);
346
            newTaxonNameForRegistration = null;
347
        }
348
    }
349

    
350

    
351
    /**
352
     * Creates a new Registration for an exiting (previously published name).
353
     *
354
     * @param event
355
     * @throws RegistrationValidationException
356
     */
357
    @EventListener(condition = "#event.action == T(eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction.Action).start")
358
    public void onRegistrationWorkflowEventActionStart(RegistrationWorkingsetAction event) throws RegistrationValidationException {
359

    
360
        getView().getAddExistingNameCombobox().commit();
361
        TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
362
        if(typifiedName != null){
363
            Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
364
            Reference citation = getRepo().getReferenceService().find(workingset.getCitationId());
365
            newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
366
            workingset.add(newRegistrationDTOWithExistingName);
367
            // tell the view to update the workingset
368
            getView().setWorkingset(workingset);
369
            getView().getAddExistingNameRegistrationButton().setEnabled(false);
370
            getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
371
        } else {
372
            logger.error("Seletced name is NULL");
373
        }
374

    
375
    }
376

    
377
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).EDIT")
378
    public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
379

    
380
        if(!checkFromOwnView(event)){
381
            return;
382
        }
383

    
384
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
385
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
386
            popup.withDeleteButton(true);
387
            popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getEntityId()));
388
            if(event.getSourceComponent() != null){
389
                // TODO document this !!!!!!!!!!!
390
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
391
            }
392
        } else {
393
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
394
            popup.withDeleteButton(true);
395
            popup.loadInEditor(event.getEntityId());
396
            if(event.getSourceComponent() != null){
397
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
398
            }
399
            newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
400
        }
401
    }
402

    
403
    @EventListener(condition = "#event.type == T(eu.etaxonomy.vaadin.event.EditorActionType).ADD && #event.sourceComponent == null")
404
    public void onAddNewTypeDesignationWorkingset(TypeDesignationWorkingsetEditorAction event) {
405

    
406
        if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
407
            SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
408
            TypeDesignationWorkingsetEditorIdSet identifierSet;
409
            Integer typifiedNameId;
410
            if(newRegistrationDTOWithExistingName != null){
411
                typifiedNameId = newRegistrationDTOWithExistingName.getTypifiedNameRef().getId();
412
            } else {
413
                RegistrationDTO registrationDTO = workingset.getRegistrationDTO(event.getRegistrationId()).get();
414
                EntityReference typifiedNameRef = registrationDTO.getTypifiedNameRef();
415
                if(typifiedNameRef != null){
416
                    // case for registrations without name, in which case the typifiedName is only defined via the typedesignations
417
                    typifiedNameId = typifiedNameRef.getId();
418
                } else {
419
                    // case of registrations with a name in the nomenclatural act.
420
                    typifiedNameId = registrationDTO.getNameRef().getId();
421
                }
422
            }
423
            identifierSet = new TypeDesignationWorkingsetEditorIdSet(
424
                    event.getRegistrationId(),
425
                    getView().getCitationID(),
426
                    typifiedNameId
427
                    );
428
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
429
            popup.loadInEditor(identifierSet);
430
            popup.withDeleteButton(true);
431
        } else {
432
            NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class);
433
            popup.withDeleteButton(true);
434
            popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
435
            popup.loadInEditor(null);
436
            if(event.getSourceComponent() != null){
437
                popup.setReadOnly(event.getSourceComponent().isReadOnly());
438
            }
439
            newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
440
        }
441
    }
442

    
443
    /**
444
     * Performs final actions after a TypeDesignationEditor which has been
445
     * opened to add a TypeDesignation to a Registration object which was
446
     * created for an previously published name. Prior adding a typedesignation,
447
     * the according Registration object is dangling, that has no association to
448
     * any entity denoting an nomenclatural act which has a reference to a
449
     * publication. This means that the registration object is not in the
450
     * working set.
451
     *
452
     *
453
     * @param event
454
     * @throws RegistrationValidationException
455
     */
456
    @EventListener
457
    public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
458
        if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
459
            if(event.getReason().equals(Reason.SAVE)){
460
                refreshView(true);
461
            } else if(event.getReason().equals(Reason.CANCEL)){
462
                // clean up
463
                if(newRegistrationDTOWithExistingName != null){
464
                    getRegistrationStore().deleteBean(newRegistrationDTOWithExistingName.registration());
465
                }
466
            }
467
            // set newRegistrationDTOWithExistingName NULL in any case
468
            newRegistrationDTOWithExistingName = null;
469
        } else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
470
            if(event.getReason().equals(Reason.SAVE)){
471
                UUID uuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
472
                TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, null);
473
                Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getId(), Arrays.asList("$", "typeDesignations"));
474
                registration.getTypeDesignations().add(nameTypeDesignation);
475
                getRepo().getRegistrationService().saveOrUpdate(registration);
476
                newNameTypeDesignationTarget = null;
477
                refreshView(true);
478
            } else if(event.getReason().equals(Reason.CANCEL)){
479
                // noting to do
480
            }
481
        }
482
        // ignore other editors
483
    }
484

    
485

    
486
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
487
    public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
488
        List<String> messages = new ArrayList<>();
489
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
490
            dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
491
        }
492
        if(event.getProperty().equals("messages")){
493
            getView().openDetailsPopup("Messages", messages);
494
        }
495
    }
496

    
497
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
498
    public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
499
        RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
500
        if(event.getProperty().equals("messages")){
501
            if(getView() != null){
502
                getView().openDetailsPopup("Messages", regDto.getMessages());
503
            }
504
        }
505
    }
506

    
507
    @EventListener
508
    public void onEntityChangeEvent(EntityChangeEvent event){
509
        if(workingset == null){
510
            return;
511
        }
512
        if(Reference.class.isAssignableFrom(event.getEntityType())){
513
            if(workingset.getCitationId().equals(event.getEntityId())){
514
                refreshView(true);
515
            }
516
        } else
517
        if(Registration.class.isAssignableFrom(event.getEntityType())){
518
            if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
519
                refreshView(true);
520
            }
521
        } else
522
        if(TaxonName.class.isAssignableFrom(event.getEntityType())){
523
            if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
524
                reg.getTypifiedNameRef() != null
525
                && reg.getTypifiedNameRef().getId() == event.getEntityId())){
526
                    refreshView(true);
527
            }
528
        } else
529
        if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
530
            if(workingset.getRegistrationDTOs().stream().anyMatch(
531
                    reg -> reg.getTypeDesignations() != null && reg.getTypeDesignations().stream().anyMatch(
532
                            td -> td.getId() == event.getEntityId()
533
                            )
534
                        )
535
                    ){
536
                refreshView(true);
537
            }
538
        }
539

    
540
    }
541

    
542
}
(12-12/19)