Project

General

Profile

Revision bfd1283e

IDbfd1283e6d671337a83b6c2990cc8ddf4eb03c99
Parent d0237f32
Child 57bddc87

Added by Andreas Kohlbecker 9 months ago

fix #8039 proper handling of un-persisted registrations with blocking registrations

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
138 138
    private RegistrationWorkingSet workingset;
139 139

  
140 140
    /**
141
     * 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.
141
     * Contains the poupeditor which has been opened to start the registration of a new name as long as it has not been saved or canceled.
142 142
     * There can always only be one popup editor for this purpose.
143 143
     */
144 144
    private TaxonNamePopupEditor newNameForRegistrationPopupEditor = null;
......
209 209
    }
210 210

  
211 211
    /**
212
     * @param doReload TODO
212
     * @param doReload reload the workingset from the persistent storage.
213
     *  Workingsets which are not yet persisted are preserved.
213 214
     *
214 215
     */
215 216
    protected void refreshView(boolean doReload) {
......
217 218
            return; // nothing to do
218 219
        }
219 220
        if(doReload){
221
            List<RegistrationDTO> unpersisted = new ArrayList<>();
222
            for(RegistrationDTO regDto : workingset.getRegistrationDTOs()){
223
                if(!regDto.registration().isPersited()){
224
                    unpersisted.add(regDto);
225
                }
226
            }
220 227
            loadWorkingSet(workingset.getCitationUuid());
228
            for(RegistrationDTO regDto : unpersisted){
229
                try {
230
                    workingset.add(regDto);
231
                } catch (RegistrationValidationException e) {
232
                    // would never happen here //
233
                }
234
            }
221 235
        }
222 236
        applyWorkingset();
223 237
    }
......
715 729
        } else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
716 730
            if(event.getReason().equals(Reason.SAVE)){
717 731
                UUID typeDesignationUuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
718
                getRepo().getSession().clear();
719
                UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup());
720
                getRepo().getRegistrationService().addTypeDesignation(regUUID, typeDesignationUuid);
721
                getRepo().getSession().clear();
722
                nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup());
723
                refreshView(true);
732

  
733
                try {
734
                    getRepo().getSession().clear();
735
                    // TODO move into a service class --------------
736
                    TransactionStatus txStatus = getRepo().startTransaction();
737
                    UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup());
738
                    Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext();
739
                    Registration registration = findRegistrationInContext(context);
740
                    getRepo().getRegistrationService().addTypeDesignation(registration, typeDesignationUuid);
741
                    getRepo().getRegistrationService().saveOrUpdate(registration);
742
                    nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup());
743
                    getRepo().commitTransaction(txStatus);
744
                    // TODO move into a service class --------------
745
                } finally {
746
                    getRepo().getSession().clear();
747
                    refreshView(true);
748
                }
724 749
            } else if(event.getReason().equals(Reason.CANCEL)){
725 750
                // noting to do
726 751
            }
......
772 797

  
773 798
                    try {
774 799
                        getRepo().getSession().clear();
800
                        // TODO move into a service class --------------
775 801
                        TransactionStatus txStatus = getRepo().startTransaction();
776 802
                        // create a blocking registration, the new Registration will be persisted
777 803
                        UUID taxonNameUUID = event.getEntityUuid();
......
785 811
                            newNameBlockingRegistrations.add(blockingRegistration);
786 812
                            logger.debug("Blocking registration created and memorized");
787 813
                        } else {
788
                            // some new name related somehow to an existing registration
789
                            TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity();
790
                            RegistrationDTO registrationDTO = workingset.getRegistrationDTO(regReference.getUuid()).get();
791
                            Registration registration = registrationDTO.registration();
792

  
793
                                registration = getRepo().getRegistrationService().load(registration.getUuid());
794
                                if(registration == null){
795
                                    throw new NullPointerException("Registration not found for " + regReference + " which has been hold in the rootContext");
796
                                }
797
                                registration.getBlockedBy().add(blockingRegistration);
814
                            // some new name somehow related to an existing registration
815
                            Registration registration = findRegistrationInContext(context);
816
                            registration.getBlockedBy().add(blockingRegistration);
817

  
818
                            if(registration.isPersited()){
798 819
                                getRepo().getRegistrationService().saveOrUpdate(registration);
799
                                getRepo().commitTransaction(txStatus);
800
                            logger.debug("Blocking registration created and added to registion");
820
                                logger.debug("Blocking registration created, added to registion and persited");
821
                            }
822
                            getRepo().commitTransaction(txStatus);
823
                            // TODO move into a service class --------------
801 824
                        }
802 825
                    } finally {
803 826
                        getRepo().getSession().clear();
......
826 849
        }
827 850
    }
828 851

  
852
    /**
853
     * @param context
854
     * @return
855
     */
856
    public Registration findRegistrationInContext(Stack<EditorActionContext> context) {
857
        EditorActionContext rootCtx = context.get(0);
858
        TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootCtx.getParentEntity();
859
        RegistrationDTO registrationDTO = workingset.getRegistrationDTO(regReference.getUuid()).get();
860
        Registration registration = registrationDTO.registration();
861

  
862
        if(registration.isPersited()){
863
             registration = getRepo().getRegistrationService().load(registration.getUuid());
864
             if(registration == null){
865
                 throw new NullPointerException("Registration not found for " + regReference + " which has been hold in the rootContext");
866
             }
867
         } else {
868
             logger.trace("Registration is not yet persisted.");
869
         }
870
        return registration;
871
    }
872

  
829 873
    @EventBusListenerMethod(filter = ShowDetailsEventEntityTypeFilter.RegistrationDTO.class)
830 874
    public void onShowDetailsEventForRegistrationDTO(ShowDetailsEvent<RegistrationDTO, UUID> event) {
831 875

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)