Project

General

Profile

« Previous | Next » 

Revision 3bd87058

Added by Andreas Kohlbecker about 5 years ago

ref #8031 wrapping addExistingName logic into readonly transaction

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
336 336
            logger.info(e);
337 337
            ((AccessRestrictedView)getView()).setAccessDeniedMessage(e.getMessage());
338 338
        }
339
        if(workingset == null || workingset.getCitationUuid() == null){
340
            Reference citation = getRepo().getReferenceService().find(referenceUuid);
341
            workingset = new RegistrationWorkingSet(citation);
342
        }
343 339
        cache = new CdmTransientEntityAndUuidCacher(this);
344 340
        for(Registration registration : workingset.getRegistrations()) {
345 341
            addRootEntity(registration);
......
553 549
        TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
554 550
        if(typifiedName != null){
555 551
            boolean doReloadWorkingSet = false;
556
            Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$"));
557
            // here we completely ignore the ExistingNameRegistrationType since the user should not have the choice
558
            // to create a typification only registration in the working (publication) set which contains
559
            // the protologe. This is known from the nomenclatural reference.
560
            if(canCreateNameRegistrationFor(typifiedName)){
561
                // the citation which is the base for workingset contains the protologe of the name and the name has not
562
                // been registered before:
563
                // create a registration for the name and the first typifications
564
                Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid());
565
                workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation));
566
                doReloadWorkingSet = true;
567
            } else {
568
                if(!checkWokingsetContainsProtologe(typifiedName)){
569
                    // create a typification only registration
570
                    Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration();
571
                    if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){
572
                        // oops, yet no registration for this name, so we create it as blocking registration:
573
                        Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid());
574
                        typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration);
552
            try {
553
                // TODO move into a service class --------------
554
                TransactionStatus txStatus = getRepo().startTransaction(true);
555
                Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$"));
556
                // here we completely ignore the ExistingNameRegistrationType since the user should not have the choice
557
                // to create a typification only registration in the working (publication) set which contains
558
                // the protologe. This is known from the nomenclatural reference.
559
                if(canCreateNameRegistrationFor(typifiedName)){
560
                    // the citation which is the base for workingset contains the protologe of the name and the name has not
561
                    // been registered before:
562
                    // create a registration for the name and the first typifications
563
                    Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid());
564
                    workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation));
565
                    doReloadWorkingSet = true;
566
                } else {
567
                    if(!checkWokingsetContainsProtologe(typifiedName)){
568
                        // create a typification only registration
569
                        Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration();
570
                        if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){
571
                            // oops, yet no registration for this name, so we create it as blocking registration:
572
                            Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid());
573
                            typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration);
574
                        }
575
                        RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation);
576
                        workingset.add(regDTO);
575 577
                    }
576
                    RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation);
577
                    workingset.add(regDTO);
578 578
                }
579
                getRepo().commitTransaction(txStatus);
580
                // --------------------------------------------------
581
                // tell the view to update the workingset
582
            } finally {
583
                getRepo().getSession().clear(); // #7702;
584
                refreshView(doReloadWorkingSet);
585
                getView().getAddExistingNameRegistrationButton().setEnabled(false);
579 586
            }
580
            // tell the view to update the workingset
581
            refreshView(doReloadWorkingSet);
582
            getView().getAddExistingNameRegistrationButton().setEnabled(false);
583 587
        } else {
584 588
            logger.error("Seletced name is NULL");
585 589
        }

Also available in: Unified diff