2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
.registration
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.EnumSet
;
14 import java
.util
.List
;
15 import java
.util
.Stack
;
16 import java
.util
.UUID
;
18 import org
.hibernate
.Session
;
19 import org
.hibernate
.Transaction
;
20 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
21 import org
.springframework
.security
.core
.Authentication
;
22 import org
.springframework
.transaction
.TransactionStatus
;
23 import org
.vaadin
.spring
.events
.annotation
.EventBusListenerMethod
;
25 import com
.vaadin
.spring
.annotation
.SpringComponent
;
26 import com
.vaadin
.spring
.annotation
.ViewScope
;
27 import com
.vaadin
.ui
.Label
;
28 import com
.vaadin
.ui
.UI
;
29 import com
.vaadin
.ui
.VerticalLayout
;
30 import com
.vaadin
.ui
.Window
;
32 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IRegistrationService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.idminter
.IdentifierMinter
.Identifier
;
35 import eu
.etaxonomy
.cdm
.api
.service
.idminter
.RegistrationIdentifierMinter
;
36 import eu
.etaxonomy
.cdm
.model
.common
.User
;
37 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
38 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
39 import eu
.etaxonomy
.cdm
.model
.name
.Registration
;
40 import eu
.etaxonomy
.cdm
.model
.name
.RegistrationStatus
;
41 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
43 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
45 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CRUD
;
46 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.Operation
;
47 import eu
.etaxonomy
.cdm
.service
.CdmFilterablePagingProvider
;
48 import eu
.etaxonomy
.cdm
.service
.CdmStore
;
49 import eu
.etaxonomy
.cdm
.service
.IRegistrationWorkingSetService
;
50 import eu
.etaxonomy
.cdm
.vaadin
.event
.AbstractEditorAction
.EditorActionContext
;
51 import eu
.etaxonomy
.cdm
.vaadin
.event
.EditorActionTypeFilter
;
52 import eu
.etaxonomy
.cdm
.vaadin
.event
.EntityChangeEvent
;
53 import eu
.etaxonomy
.cdm
.vaadin
.event
.ReferenceEditorAction
;
54 import eu
.etaxonomy
.cdm
.vaadin
.event
.RegistrationEditorAction
;
55 import eu
.etaxonomy
.cdm
.vaadin
.event
.ShowDetailsEvent
;
56 import eu
.etaxonomy
.cdm
.vaadin
.event
.ShowDetailsEventEntityTypeFilter
;
57 import eu
.etaxonomy
.cdm
.vaadin
.event
.TaxonNameEditorAction
;
58 import eu
.etaxonomy
.cdm
.vaadin
.event
.TypeDesignationWorkingsetEditorAction
;
59 import eu
.etaxonomy
.cdm
.vaadin
.event
.registration
.RegistrationWorkingsetAction
;
60 import eu
.etaxonomy
.cdm
.vaadin
.model
.EntityReference
;
61 import eu
.etaxonomy
.cdm
.vaadin
.model
.TypedEntityReference
;
62 import eu
.etaxonomy
.cdm
.vaadin
.model
.registration
.RegistrationWorkingSet
;
63 import eu
.etaxonomy
.cdm
.vaadin
.security
.UserHelper
;
64 import eu
.etaxonomy
.cdm
.vaadin
.ui
.RegistrationUIDefaults
;
65 import eu
.etaxonomy
.cdm
.vaadin
.util
.CdmTitleCacheCaptionGenerator
;
66 import eu
.etaxonomy
.cdm
.vaadin
.util
.converter
.TypeDesignationSetManager
.TypeDesignationWorkingSetType
;
67 import eu
.etaxonomy
.cdm
.vaadin
.view
.name
.NameTypeDesignationPopupEditor
;
68 import eu
.etaxonomy
.cdm
.vaadin
.view
.name
.SpecimenTypeDesignationWorkingsetPopupEditor
;
69 import eu
.etaxonomy
.cdm
.vaadin
.view
.name
.TaxonNamePopupEditor
;
70 import eu
.etaxonomy
.cdm
.vaadin
.view
.name
.TaxonNamePopupEditorMode
;
71 import eu
.etaxonomy
.cdm
.vaadin
.view
.name
.TypeDesignationWorkingsetEditorIdSet
;
72 import eu
.etaxonomy
.cdm
.vaadin
.view
.reference
.ReferencePopupEditor
;
73 import eu
.etaxonomy
.vaadin
.mvp
.AbstractPopupEditor
;
74 import eu
.etaxonomy
.vaadin
.mvp
.AbstractPresenter
;
75 import eu
.etaxonomy
.vaadin
.mvp
.AbstractView
;
76 import eu
.etaxonomy
.vaadin
.mvp
.BeanInstantiator
;
77 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
;
78 import eu
.etaxonomy
.vaadin
.ui
.view
.DoneWithPopupEvent
.Reason
;
81 * @author a.kohlbecker
87 public class RegistrationWorkingsetPresenter
extends AbstractPresenter
<RegistrationWorkingsetView
> {
89 private static final long serialVersionUID
= 1L;
92 private IRegistrationWorkingSetService regWorkingSetService
;
95 private RegistrationIdentifierMinter minter
;
98 * @return the regWorkingSetService
100 public IRegistrationWorkingSetService
getWorkingSetService() {
101 return regWorkingSetService
;
104 private RegistrationWorkingSet workingset
;
106 private TaxonName newTaxonNameForRegistration
= null;
108 private RegistrationDTO newRegistrationDTOWithExistingName
;
110 private RegistrationDTO newNameTypeDesignationTarget
;
116 public RegistrationWorkingsetPresenter() {
120 * Always create a new Store
124 protected CdmStore
<Registration
, IRegistrationService
> getRegistrationStore(){
125 return new CdmStore
<Registration
, IRegistrationService
>(getRepo(), getRepo().getRegistrationService());
129 * Always create a new Store
133 protected CdmStore
<TaxonName
, INameService
> getTaxonNameStore(){
134 return new CdmStore
<TaxonName
, INameService
>(getRepo(), getRepo().getNameService());
142 protected Registration
createNewRegistrationForName(Integer taxonNameId
) {
143 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 // move into RegistrationWorkflowStateMachine
145 TransactionStatus txStatus
= getRepo().startTransaction();
147 Identifier
<String
> identifiers
= minter
.mint();
148 if(identifiers
.getIdentifier() == null){
149 throw new RuntimeException("RegistrationIdentifierMinter configuration incomplete.");
151 Registration reg
= Registration
.NewInstance(
152 identifiers
.getIdentifier(),
153 identifiers
.getLocalId(),
154 taxonNameId
!= null ?
getRepo().getNameService().find(taxonNameId
) : null,
156 Authentication authentication
= currentSecurityContext().getAuthentication();
157 reg
.setSubmitter((User
)authentication
.getPrincipal());
158 EntityChangeEvent event
= getRegistrationStore().saveBean(reg
, (AbstractView
) getView());
159 UserHelper
.fromSession().createAuthorityForCurrentUser(Registration
.class, event
.getEntityId(), Operation
.UPDATE
, RegistrationStatus
.PREPARATION
.name());
160 getRepo().commitTransaction(txStatus
);
161 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162 return getRepo().getRegistrationService().find(event
.getEntityId());
167 * @param doReload TODO
170 protected void refreshView(boolean doReload
) {
171 if(workingset
== null){
172 return; // nothing to do
175 loadWorkingSet(workingset
.getCitationId());
177 getView().setWorkingset(workingset
);
185 public void handleViewEntered() {
187 super.handleViewEntered();
189 loadWorkingSet(getView().getCitationID());
190 getView().setWorkingset(workingset
);
192 CdmFilterablePagingProvider
<TaxonName
, TaxonName
> pagingProvider
= new CdmFilterablePagingProvider
<TaxonName
, TaxonName
>(
193 getRepo().getNameService());
194 CdmTitleCacheCaptionGenerator
<TaxonName
> titleCacheGenrator
= new CdmTitleCacheCaptionGenerator
<TaxonName
>();
195 getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenrator
);
196 getView().getAddExistingNameCombobox().loadFrom(pagingProvider
, pagingProvider
, pagingProvider
.getPageSize());
203 protected void loadWorkingSet(Integer referenceID
) {
205 workingset
= getWorkingSetService().loadWorkingSetByReferenceID(referenceID
);
206 } catch (RegistrationValidationException error
) {
208 Window errorDialog
= new Window("Validation Error");
209 errorDialog
.setModal(true);
210 VerticalLayout subContent
= new VerticalLayout();
211 subContent
.setMargin(true);
212 errorDialog
.setContent(subContent
);
213 subContent
.addComponent(new Label(error
.getMessage()));
214 UI
.getCurrent().addWindow(errorDialog
);
216 if(workingset
== null || workingset
.getCitationId() == null){
217 Reference citation
= getRepo().getReferenceService().find(referenceID
);
218 workingset
= new RegistrationWorkingSet(citation
);
223 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
224 public void onReferenceEditorActionAdd(ReferenceEditorAction event
) {
226 if(!checkFromOwnView(event
)){
230 ReferencePopupEditor popup
= getNavigationManager().showInPopup(ReferencePopupEditor
.class, getView());
231 popup
.withReferenceTypes(RegistrationUIDefaults
.PRINTPUB_REFERENCE_TYPES
);
232 popup
.loadInEditor(null);
235 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
236 public void onReferenceEditorActionEdit(ReferenceEditorAction event
) {
238 if(!checkFromOwnView(event
)){
241 ReferencePopupEditor popup
= getNavigationManager().showInPopup(ReferencePopupEditor
.class, getView());
242 popup
.withReferenceTypes(RegistrationUIDefaults
.PRINTPUB_REFERENCE_TYPES
);
243 popup
.withDeleteButton(true);
244 popup
.loadInEditor(event
.getEntityId());
247 @EventBusListenerMethod
248 public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event
) throws RegistrationValidationException
{
249 if(event
.getPopup() instanceof ReferencePopupEditor
){
250 if(event
.getReason().equals(Reason
.SAVE
)){
256 @EventBusListenerMethod
257 public void onDoneWithSpecimenTypeDesignationWorkingsetPopupEditor(DoneWithPopupEvent event
) throws RegistrationValidationException
{
258 if(event
.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor
){
259 if(event
.getReason().equals(Reason
.SAVE
)){
265 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
266 public void onRegistrationEditorAction(RegistrationEditorAction event
) {
268 if(!checkFromOwnView(event
)){
272 RegistrationPopupEditor popup
= getNavigationManager().showInPopup(RegistrationPopupEditor
.class, getView());
273 popup
.loadInEditor(event
.getEntityId());
276 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
277 public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event
) {
279 if(!checkFromOwnView(event
)){
283 TaxonNamePopupEditor popup
= getNavigationManager().showInPopup(TaxonNamePopupEditor
.class, getView());
284 popup
.setParentEditorActionContext(event
.getContext());
285 popup
.withDeleteButton(true);
286 configureTaxonNameEditor(popup
);
287 popup
.loadInEditor(event
.getEntityId());
288 if(event
.getSourceComponent() != null){
289 popup
.setReadOnly(event
.getSourceComponent().isReadOnly());
295 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
296 public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event
) {
298 if(!checkFromOwnView(event
)){
302 newTaxonNameForRegistration
= TaxonNameFactory
.NewNameInstance(RegistrationUIDefaults
.NOMENCLATURAL_CODE
, Rank
.SPECIES());
303 newTaxonNameForRegistration
.setNomenclaturalReference(getRepo().getReferenceService().find(workingset
.getCitationId()));
304 EntityChangeEvent nameSaveEvent
= getTaxonNameStore().saveBean(newTaxonNameForRegistration
, (AbstractView
) getView());
305 newTaxonNameForRegistration
= getRepo().getNameService().find(nameSaveEvent
.getEntityId());
306 TaxonNamePopupEditor popup
= getNavigationManager().showInPopup(TaxonNamePopupEditor
.class, getView());
307 popup
.setParentEditorActionContext(event
.getContext());
308 popup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
,CRUD
.DELETE
));
309 popup
.withDeleteButton(true);
310 configureTaxonNameEditor(popup
);
311 popup
.loadInEditor(newTaxonNameForRegistration
.getId());
315 * TODO consider putting this into a Configurer Bean per UIScope.
316 * In the configurator bean this methods popup papamerter should be of the type
317 * AbstractPopupEditor
321 protected void configureTaxonNameEditor(TaxonNamePopupEditor popup
) {
322 popup
.enableMode(TaxonNamePopupEditorMode
.suppressReplacementAuthorshipData
);
323 popup
.enableMode(TaxonNamePopupEditorMode
.nomenclaturalReferenceSectionEditingOnly
);
324 popup
.enableMode(TaxonNamePopupEditorMode
.requireNomenclaturalReference
);
328 * Creates a new <code>Registration</code> for a new name that has just been edited
329 * using the <code>TaxonNamePopupEditor</code>. The new name was previously created
330 * in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
331 * and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
332 * (<code>Reason.CANCEL</code>).
336 * @throws RegistrationValidationException
338 @EventBusListenerMethod
339 public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event
) throws RegistrationValidationException
{
340 if(event
.getPopup() instanceof TaxonNamePopupEditor
){
341 TransactionStatus txStatus
= getRepo().startTransaction();
342 if(event
.getReason().equals(Reason
.SAVE
)){
343 if(newTaxonNameForRegistration
!= null){
344 int taxonNameId
= newTaxonNameForRegistration
.getId();
345 getRepo().getSession().refresh(newTaxonNameForRegistration
);
346 Registration reg
= createNewRegistrationForName(taxonNameId
);
347 // reload workingset into current session
348 loadWorkingSet(workingset
.getCitationId());
352 } else if(event
.getReason().equals(Reason
.CANCEL
)){
353 if(newTaxonNameForRegistration
!= null){
355 getTaxonNameStore().deleteBean(newTaxonNameForRegistration
, (AbstractView
) getView());
358 getRepo().commitTransaction(txStatus
);
359 newTaxonNameForRegistration
= null;
365 * Creates a new Registration for an exiting (previously published name).
368 * @throws RegistrationValidationException
370 @EventBusListenerMethod
371 public void onRegistrationWorkflowEventActionStart(RegistrationWorkingsetAction event
) throws RegistrationValidationException
{
373 if(!event
.isStart()){
377 getView().getAddExistingNameCombobox().commit();
378 TaxonName typifiedName
= getView().getAddExistingNameCombobox().getValue();
379 if(typifiedName
!= null){
380 Registration newRegistrationWithExistingName
= createNewRegistrationForName(null);
381 Reference citation
= getRepo().getReferenceService().find(workingset
.getCitationId());
382 newRegistrationDTOWithExistingName
= new RegistrationDTO(newRegistrationWithExistingName
, typifiedName
, citation
);
383 workingset
.add(newRegistrationDTOWithExistingName
);
384 // tell the view to update the workingset
385 getView().setWorkingset(workingset
);
386 getView().getAddExistingNameRegistrationButton().setEnabled(false);
387 getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
389 logger
.error("Seletced name is NULL");
395 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Edit
.class)
396 public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event
) {
398 if(!checkFromOwnView(event
)){
402 if(event
.getWorkingSetType() == TypeDesignationWorkingSetType
.SPECIMEN_TYPE_DESIGNATION_WORKINGSET
){
403 SpecimenTypeDesignationWorkingsetPopupEditor popup
= getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor
.class, getView());
404 popup
.setParentEditorActionContext(event
.getContext());
405 popup
.withDeleteButton(true);
406 popup
.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event
.getRegistrationId(), event
.getBaseEntityRef()));
407 if(event
.getSourceComponent() != null){
408 // propagate readonly state from source component to popup
409 popup
.setReadOnly(event
.getSourceComponent().isReadOnly());
412 NameTypeDesignationPopupEditor popup
= getNavigationManager().showInPopup(NameTypeDesignationPopupEditor
.class, getView());
413 popup
.setParentEditorActionContext(event
.getContext());
414 popup
.withDeleteButton(true);
415 popup
.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event
.getRegistrationId(), event
.getBaseEntityRef()));
417 popup
.getCitationCombobox().setEnabled(false);
418 popup
.getTypifiedNamesComboboxSelect().setEnabled(false);
420 if(event
.getSourceComponent() != null){
421 // propagate readonly state from source component to popup
422 popup
.setReadOnly(event
.getSourceComponent().isReadOnly());
424 newNameTypeDesignationTarget
= workingset
.getRegistrationDTO(event
.getRegistrationId()).get();
428 @EventBusListenerMethod(filter
= EditorActionTypeFilter
.Add
.class)
429 public void onAddNewTypeDesignationWorkingset(TypeDesignationWorkingsetEditorAction event
) {
431 if(event
.getSourceComponent() != null){
435 if(event
.getWorkingSetType() == TypeDesignationWorkingSetType
.SPECIMEN_TYPE_DESIGNATION_WORKINGSET
){
436 SpecimenTypeDesignationWorkingsetPopupEditor popup
= getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor
.class, getView());
437 popup
.setParentEditorActionContext(event
.getContext());
438 TypeDesignationWorkingsetEditorIdSet identifierSet
;
439 Integer typifiedNameId
;
440 if(newRegistrationDTOWithExistingName
!= null){
441 typifiedNameId
= newRegistrationDTOWithExistingName
.getTypifiedNameRef().getId();
443 RegistrationDTO registrationDTO
= workingset
.getRegistrationDTO(event
.getRegistrationId()).get();
444 EntityReference typifiedNameRef
= registrationDTO
.getTypifiedNameRef();
445 if(typifiedNameRef
!= null){
446 // case for registrations without name, in which case the typifiedName is only defined via the typedesignations
447 typifiedNameId
= typifiedNameRef
.getId();
449 // case of registrations with a name in the nomenclatural act.
450 typifiedNameId
= registrationDTO
.getNameRef().getId();
453 identifierSet
= new TypeDesignationWorkingsetEditorIdSet(
454 event
.getRegistrationId(),
455 getView().getCitationID(),
458 popup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
, CRUD
.DELETE
));
459 popup
.loadInEditor(identifierSet
);
460 popup
.withDeleteButton(true);
461 if(event
.getSourceComponent() != null){
462 // propagate readonly state from source component to popup
463 popup
.setReadOnly(event
.getSourceComponent().isReadOnly());
466 NameTypeDesignationPopupEditor popup
= getNavigationManager().showInPopup(NameTypeDesignationPopupEditor
.class, getView());
467 popup
.setParentEditorActionContext(event
.getContext());
468 popup
.withDeleteButton(true);
469 popup
.grantToCurrentUser(EnumSet
.of(CRUD
.UPDATE
, CRUD
.DELETE
));
470 newNameTypeDesignationTarget
= workingset
.getRegistrationDTO(event
.getRegistrationId()).get();
471 popup
.setBeanInstantiator(new BeanInstantiator
<NameTypeDesignation
>() {
474 public NameTypeDesignation
createNewBean() {
475 NameTypeDesignation nameTypeDesignation
= NameTypeDesignation
.NewInstance();
476 nameTypeDesignation
.setCitation(newNameTypeDesignationTarget
.getCitation());
477 nameTypeDesignation
.getTypifiedNames().add(newNameTypeDesignationTarget
.getTypifiedName());
478 return nameTypeDesignation
;
481 popup
.loadInEditor(null);
482 popup
.getCitationCombobox().setEnabled(false);
483 popup
.getTypifiedNamesComboboxSelect().setEnabled(false);
484 if(event
.getSourceComponent() != null){
485 // propagate readonly state from source component to popup
486 popup
.setReadOnly(event
.getSourceComponent().isReadOnly());
492 * Performs final actions after a TypeDesignationEditor which has been
493 * opened to add a TypeDesignation to a Registration object which was
494 * created for an previously published name. Prior adding a typedesignation,
495 * the according Registration object is dangling, that has no association to
496 * any entity denoting an nomenclatural act which has a reference to a
497 * publication. This means that the registration object is not in the
502 * @throws RegistrationValidationException
504 @EventBusListenerMethod
505 public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event
) throws RegistrationValidationException
{
506 if(event
.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor
){
507 if(event
.getReason().equals(Reason
.SAVE
)){
509 } else if(event
.getReason().equals(Reason
.CANCEL
)){
512 newRegistrationDTOWithExistingName
= null;
513 } else if(event
.getPopup() instanceof NameTypeDesignationPopupEditor
){
514 if(event
.getReason().equals(Reason
.SAVE
)){
515 UUID uuid
= ((NameTypeDesignationPopupEditor
)event
.getPopup()).getBean().getUuid();
517 Session session
= getRepo().getSessionFactory().openSession();
518 Transaction txstate
= session
.beginTransaction();
519 TypeDesignationBase
<?
> nameTypeDesignation
= getRepo().getNameService().loadTypeDesignation(uuid
, Arrays
.asList(""));
520 // only load the typeDesignations with the registration so that the typified name can not be twice in the session
521 // otherwise multiple representation problems might occur
522 Registration registration
= getRepo().getRegistrationService().load(newNameTypeDesignationTarget
.getUuid(), Arrays
.asList("typeDesignations"));
523 registration
.getTypeDesignations().add(nameTypeDesignation
);
524 session
.merge(registration
);
529 } else if(event
.getReason().equals(Reason
.CANCEL
)){
532 newNameTypeDesignationTarget
= null;
534 // ignore other editors
538 @EventBusListenerMethod(filter
= ShowDetailsEventEntityTypeFilter
.RegistrationWorkingSet
.class)
539 public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent
<?
,?
> event
) {
540 List
<String
> messages
= new ArrayList
<>();
541 for(RegistrationDTO dto
: workingset
.getRegistrationDTOs()){
542 dto
.getMessages().forEach(m
-> messages
.add(dto
.getSummary() + ": " + m
));
544 if(event
.getProperty().equals("messages")){
545 getView().openDetailsPopup("Messages", messages
);
550 @EventBusListenerMethod(filter
= ShowDetailsEventEntityTypeFilter
.RegistrationDTO
.class)
551 public void onShowRegistrationMessages(ShowDetailsEvent
<?
,?
> event
) {
552 RegistrationDTO regDto
= regWorkingSetService
.loadDtoById((Integer
)event
.getIdentifier());
553 if(event
.getProperty().equals("messages")){
554 if(getView() != null){
555 getView().openDetailsPopup("Messages", regDto
.getMessages());
560 @EventBusListenerMethod
561 public void onEntityChangeEvent(EntityChangeEvent event
){
562 if(workingset
== null){
565 if(Reference
.class.isAssignableFrom(event
.getEntityType())){
566 if(workingset
.getCitationId().equals(event
.getEntityId())){
570 if(Registration
.class.isAssignableFrom(event
.getEntityType())){
571 if(workingset
.getRegistrations().stream().anyMatch(reg
-> reg
.getId() == event
.getEntityId())){
575 if(TaxonName
.class.isAssignableFrom(event
.getEntityType())){
576 if(event
.getType().equals(EntityChangeEvent
.Type
.CREATED
)){
577 // new name! create a blocking registration
578 Stack
<EditorActionContext
>context
= ((AbstractPopupEditor
)event
.getSourceView()).getEditorActionContext();
579 EditorActionContext rootContext
= context
.get(0);
580 if(rootContext
.getParentView().equals(getView())){
581 Registration blockingRegistration
= createNewRegistrationForName(event
.getEntityId());
582 TypedEntityReference
<Registration
> regReference
= (TypedEntityReference
<Registration
>)rootContext
.getParentEntity();
583 Registration registration
= getRepo().getRegistrationService().load(regReference
.getId(), Arrays
.asList("$", "blockedBy"));
584 registration
.getBlockedBy().add(blockingRegistration
);
585 getRepo().getRegistrationService().saveOrUpdate(registration
);
586 logger
.debug("Blocking registration created");
588 logger
.debug("Nn blocking registration, since a new name for a new registration has been created");
591 if(workingset
.getRegistrationDTOs().stream().anyMatch(reg
->
592 reg
.getTypifiedNameRef() != null
593 && reg
.getTypifiedNameRef().getId() == event
.getEntityId())){
597 if(TypeDesignationBase
.class.isAssignableFrom(event
.getEntityType())){
598 if(workingset
.getRegistrationDTOs().stream().anyMatch(
599 reg
-> reg
.getTypeDesignations() != null && reg
.getTypeDesignations().stream().anyMatch(
600 td
-> td
.getId() == event
.getEntityId()