Project

General

Profile

« Previous | Next » 

Revision d02788a3

Added by Andreas Kohlbecker over 5 years ago

ref #7630 fixing creation of blocking registrations realted to new unsaved names

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
138 138

  
139 139
    private RegistrationWorkingSet workingset;
140 140

  
141
    /**
142
     * Contains the poupeditor which has neen opend to start the registration of a new name as long as it has not been saved or canceled.
143
     * There can always only be one popup editor for this purpose.
144
     */
141 145
    private TaxonNamePopupEditor newNameForRegistrationPopupEditor = null;
142 146

  
147
    /**
148
     * Contains
149
     */
150
    private List<Registration> newNameBlockingRegistrations = new ArrayList<>();
151

  
143 152
    private Map<NameTypeDesignationPopupEditor, UUID> nameTypeDesignationPopupEditorRegistrationUUIDMap = new HashMap<>();
144 153

  
145 154

  
......
469 478

  
470 479
    /**
471 480
     * Creates a new <code>Registration</code> for a new name that has just been edited
472
     * using the <code>TaxonNamePopupEditor</code>. The new name was previously created
473
     * in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
474
     * and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
475
     * (<code>Reason.CANCEL</code>).
476
     *
481
     * using a <code>TaxonNamePopupEditor</code>. The popup editor which has been opened to
482
     * edit the new name was remembered in <code>newNameForRegistrationPopupEditor</code>.
483
     * Any blocking registrations which have been created while editing the new name are
484
     * temporarily stored in <code>newNameBlockingRegistrations</code> until the registration
485
     * for the first name has been created. Additional new names are created for example
486
     * when a new name as basionym, replaced synonym, etc to the new name is created.
487
     * <p>
488
     * See also {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)}).
477 489
     *
478 490
     * @param event
479 491
     * @throws RegistrationValidationException
......
481 493
    @EventBusListenerMethod
482 494
    public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
483 495
        if(event.getPopup() instanceof TaxonNamePopupEditor){
484
            try {
485
                if(event.getReason().equals(Reason.SAVE)){
486
                    TransactionStatus txStatus = getRepo().startTransaction();
487
                    if(newNameForRegistrationPopupEditor != null){
488
                        UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid();
489
                        if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){
490
                            getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity());
496
                    if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){
497
                        if(event.getReason().equals(Reason.SAVE)){
498
                        try {
499
                            TransactionStatus txStatus = getRepo().startTransaction();
500
                            UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid();
501
                            if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){
502
                                getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity());
503
                            }
504
                            Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
505
                            if(!newNameBlockingRegistrations.isEmpty()){
506
                                for(Registration blockingReg : newNameBlockingRegistrations){
507
                                    blockingReg = getRepo().getRegistrationService().load(blockingReg.getUuid());
508
                                    reg.getBlockedBy().add(blockingReg);
509
                                }
510
                                getRepo().getRegistrationService().saveOrUpdate(reg);
511
                                newNameBlockingRegistrations.clear();
512
                            }
513
                            // reload workingset into current session
514
                            loadWorkingSet(workingset.getCitationUuid());
515
                            workingset.add(reg);
516
                            getRepo().commitTransaction(txStatus);
517
                        } finally {
518
                            getRepo().getSession().clear(); // #7702
519
                            refreshView(true);
520
                            getView().getAddNewNameRegistrationButton().setEnabled(true);
491 521
                        }
492
                        Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid);
493
                        // reload workingset into current session
494
                        loadWorkingSet(workingset.getCitationUuid());
495
                        workingset.add(reg);
522
                        // nullify and clear the memory on this popup editor in any case (SAVE, CANCEL, DELETE)
523
                        newNameForRegistrationPopupEditor = null;
524
                        newNameBlockingRegistrations.clear();
496 525
                    }
497
                    refreshView(true);
498
                    getRepo().commitTransaction(txStatus);
499 526
                }
500
            } finally {
501
                getRepo().getSession().clear(); // #7702
502
            }
503
            newNameForRegistrationPopupEditor = null;
504
            getView().getAddNewNameRegistrationButton().setEnabled(true);
527

  
505 528
        }
506 529
    }
507 530

  
......
734 757
            if(event.getType().equals(EntityChangeEvent.Type.CREATED)){
735 758
                Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getSourceView()).getEditorActionContext();
736 759
                EditorActionContext rootContext = context.get(0);
737
                if(rootContext.getParentView().equals(getView())){
738
                    // new name! create a blocking registration
760
                if(rootContext.getParentView().equals(getView()) && event.getSourceView() != newNameForRegistrationPopupEditor){
761

  
762
                    // create a blocking registration, the new Registration will be persisted
739 763
                    UUID taxonNameUUID = event.getEntityUuid();
740 764
                    Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID);
741
                    TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity();
742
                    RegistrationDTO registrationDTO = workingset.getRegistrationDTO(regReference.getUuid()).get();
743
                    Registration registration = registrationDTO.registration();
744
                    if(registration == null){
745
                        throw new NullPointerException("Registration not found for " + regReference + " which has been hold in the rootContext");
765

  
766
                    if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){
767
                        // Oha!! The event came from a popup editor and the
768
                        // first popup in the context is a TaxonNameEditor with un-persisted name
769
                        // This is a name for a new registration which has not yet been created.
770
                        // It is necessary to store blocking registrations in the newNameBlockingRegistrations
771
                        newNameBlockingRegistrations.add(blockingRegistration);
772
                        logger.debug("Blocking registration created and memorized");
773
                    } else {
774
                        // some new name related somehow to an existing registration
775
                        TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity();
776
                        RegistrationDTO registrationDTO = workingset.getRegistrationDTO(regReference.getUuid()).get();
777
                        Registration registration = registrationDTO.registration();
778
                        if(registration == null){
779
                            throw new NullPointerException("Registration not found for " + regReference + " which has been hold in the rootContext");
780
                        }
781
                        registration.getBlockedBy().add(blockingRegistration);
782
                        getRepo().getRegistrationService().saveOrUpdate(registration);
783
                        logger.debug("Blocking registration created and added to registion");
746 784
                    }
747
                    registration.getBlockedBy().add(blockingRegistration);
748
                    getRepo().getRegistrationService().saveOrUpdate(registration);
749
                    logger.debug("Blocking registration created");
750 785
                } else {
751 786
                    // in case of creating a new name for a registration the parent view is the TaxonNamePopupEditor
752 787
                    // this is set

Also available in: Unified diff