Revision 23025c30
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
451 | 451 |
if(event.getPopup() instanceof TaxonNamePopupEditor){ |
452 | 452 |
if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){ |
453 | 453 |
if(event.getReason().equals(Reason.SAVE)){ |
454 |
|
|
454 | 455 |
try { |
455 | 456 |
// TODO move into a service class -------------- |
456 | 457 |
TransactionStatus txStatus = getRepo().startTransaction(); |
457 |
UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid(); |
|
458 |
if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){ |
|
459 |
getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity()); |
|
460 |
} |
|
461 |
Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid); |
|
462 |
if(!newNameBlockingRegistrations.isEmpty()){ |
|
463 |
for(Registration blockingReg : newNameBlockingRegistrations){ |
|
464 |
blockingReg = getRepo().getRegistrationService().load(blockingReg.getUuid()); |
|
465 |
reg.getBlockedBy().add(blockingReg); |
|
458 |
try { |
|
459 |
UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid(); |
|
460 |
if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){ |
|
461 |
getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity()); |
|
466 | 462 |
} |
467 |
getRepo().getRegistrationService().saveOrUpdate(reg); |
|
468 |
newNameBlockingRegistrations.clear(); |
|
463 |
Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid); |
|
464 |
if(!newNameBlockingRegistrations.isEmpty()){ |
|
465 |
for(Registration blockingReg : newNameBlockingRegistrations){ |
|
466 |
blockingReg = getRepo().getRegistrationService().load(blockingReg.getUuid()); |
|
467 |
reg.getBlockedBy().add(blockingReg); |
|
468 |
} |
|
469 |
getRepo().getRegistrationService().saveOrUpdate(reg); |
|
470 |
newNameBlockingRegistrations.clear(); |
|
471 |
} |
|
472 |
getRepo().commitTransaction(txStatus); |
|
473 |
} catch (Exception e){ |
|
474 |
getRepo().getTransactionManager().rollback(txStatus); |
|
475 |
throw e; |
|
469 | 476 |
} |
470 |
getRepo().commitTransaction(txStatus); |
|
471 | 477 |
// -------------------------------------------------- |
472 | 478 |
// reload workingset into current session |
473 | 479 |
loadWorkingSet(workingset.getCitationUuid()); |
... | ... | |
477 | 483 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
478 | 484 |
} |
479 | 485 |
} |
486 |
|
|
480 | 487 |
// nullify and clear the memory on this popup editor in any case (SAVE, CANCEL, DELETE) |
481 | 488 |
newNameForRegistrationPopupEditor = null; |
482 | 489 |
newNameBlockingRegistrations.clear(); |
... | ... | |
508 | 515 |
try { |
509 | 516 |
// TODO move into a service class -------------- |
510 | 517 |
TransactionStatus txStatus = getRepo().startTransaction(true); |
511 |
Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$")); |
|
512 |
// here we completely ignore the ExistingNameRegistrationType since the user should not have the choice |
|
513 |
// to create a typification only registration in the working (publication) set which contains |
|
514 |
// the protologe. This is known from the nomenclatural reference. |
|
515 |
if(canCreateNameRegistrationFor(typifiedName)){ |
|
516 |
// the citation which is the base for workingset contains the protologe of the name and the name has not |
|
517 |
// been registered before: |
|
518 |
// create a registration for the name and the first typifications |
|
519 |
Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
520 |
workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation)); |
|
521 |
doReloadWorkingSet = true; |
|
522 |
} else { |
|
523 |
if(!checkWokingsetContainsProtologe(typifiedName)){ |
|
524 |
// create a typification only registration |
|
525 |
Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration(); |
|
526 |
if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){ |
|
527 |
// oops, yet no registration for this name, so we create it as blocking registration: |
|
528 |
Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
529 |
typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration); |
|
518 |
try { |
|
519 |
Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$")); |
|
520 |
// here we completely ignore the ExistingNameRegistrationType since the user should not have the choice |
|
521 |
// to create a typification only registration in the working (publication) set which contains |
|
522 |
// the protologe. This is known from the nomenclatural reference. |
|
523 |
if(canCreateNameRegistrationFor(typifiedName)){ |
|
524 |
// the citation which is the base for workingset contains the protologe of the name and the name has not |
|
525 |
// been registered before: |
|
526 |
// create a registration for the name and the first typifications |
|
527 |
Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
528 |
workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation)); |
|
529 |
doReloadWorkingSet = true; |
|
530 |
} else { |
|
531 |
if(!checkWokingsetContainsProtologe(typifiedName)){ |
|
532 |
// create a typification only registration |
|
533 |
Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration(); |
|
534 |
if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){ |
|
535 |
// oops, yet no registration for this name, so we create it as blocking registration: |
|
536 |
Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
537 |
typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration); |
|
538 |
} |
|
539 |
RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation); |
|
540 |
workingset.add(regDTO); |
|
530 | 541 |
} |
531 |
RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation); |
|
532 |
workingset.add(regDTO); |
|
533 | 542 |
} |
543 |
getRepo().commitTransaction(txStatus); |
|
544 |
} catch (Exception e){ |
|
545 |
getRepo().getTransactionManager().rollback(txStatus); |
|
546 |
throw e; |
|
534 | 547 |
} |
535 |
getRepo().commitTransaction(txStatus); |
|
536 | 548 |
// -------------------------------------------------- |
537 | 549 |
// tell the view to update the workingset |
538 | 550 |
} finally { |
... | ... | |
659 | 671 |
* @throws RegistrationValidationException |
660 | 672 |
*/ |
661 | 673 |
@EventBusListenerMethod |
662 |
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
|
674 |
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) { |
|
663 | 675 |
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){ |
664 | 676 |
if(event.getReason().equals(Reason.SAVE)){ |
665 | 677 |
// NOTE: adding the SpecimenTypeDesignations to the registration is done in the |
... | ... | |
676 | 688 |
clearSession(); |
677 | 689 |
// TODO move into a service class -------------- |
678 | 690 |
TransactionStatus txStatus = getRepo().startTransaction(); |
679 |
UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup()); |
|
680 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext(); |
|
681 |
Registration registration = findRegistrationInContext(context); |
|
682 |
getRepo().getRegistrationService().addTypeDesignation(registration, typeDesignationUuid); |
|
683 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
684 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup()); |
|
685 |
getRepo().commitTransaction(txStatus); |
|
691 |
try { |
|
692 |
UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup()); |
|
693 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext(); |
|
694 |
Registration registration = findRegistrationInContext(context); |
|
695 |
getRepo().getRegistrationService().addTypeDesignation(registration, typeDesignationUuid); |
|
696 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
697 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup()); |
|
698 |
getRepo().commitTransaction(txStatus); |
|
699 |
} catch (Exception e){ |
|
700 |
getRepo().getTransactionManager().rollback(txStatus); |
|
701 |
throw e; |
|
702 |
} |
|
686 | 703 |
// TODO move into a service class -------------- |
687 | 704 |
} finally { |
688 | 705 |
clearSession(); |
... | ... | |
748 | 765 |
clearSession(); |
749 | 766 |
// TODO move into a service class -------------- |
750 | 767 |
TransactionStatus txStatus = getRepo().startTransaction(); |
751 |
// create a blocking registration, the new Registration will be persisted |
|
752 |
UUID taxonNameUUID = event.getEntityUuid(); |
|
753 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
754 |
|
|
755 |
if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){ |
|
756 |
// Oha!! The event came from a popup editor and the |
|
757 |
// first popup in the context is a TaxonNameEditor with un-persisted name |
|
758 |
// This is a name for a new registration which has not yet been created. |
|
759 |
// It is necessary to store blocking registrations in the newNameBlockingRegistrations |
|
760 |
newNameBlockingRegistrations.add(blockingRegistration); |
|
761 |
logger.debug("Blocking registration created and memorized"); |
|
762 |
} else { |
|
763 |
// some new name somehow related to an existing registration |
|
764 |
Registration registration = findRegistrationInContext(context); |
|
765 |
registration.getBlockedBy().add(blockingRegistration); |
|
766 |
|
|
767 |
if(registration.isPersited()){ |
|
768 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
769 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
768 |
try { |
|
769 |
// create a blocking registration, the new Registration will be persisted |
|
770 |
UUID taxonNameUUID = event.getEntityUuid(); |
|
771 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
772 |
|
|
773 |
if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){ |
|
774 |
// Oha!! The event came from a popup editor and the |
|
775 |
// first popup in the context is a TaxonNameEditor with un-persisted name |
|
776 |
// This is a name for a new registration which has not yet been created. |
|
777 |
// It is necessary to store blocking registrations in the newNameBlockingRegistrations |
|
778 |
newNameBlockingRegistrations.add(blockingRegistration); |
|
779 |
logger.debug("Blocking registration created and memorized"); |
|
780 |
} else { |
|
781 |
// some new name somehow related to an existing registration |
|
782 |
Registration registration = findRegistrationInContext(context); |
|
783 |
registration.getBlockedBy().add(blockingRegistration); |
|
784 |
|
|
785 |
if(registration.isPersited()){ |
|
786 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
787 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
788 |
} |
|
770 | 789 |
} |
790 |
getRepo().commitTransaction(txStatus); |
|
791 |
} catch (Exception e){ |
|
792 |
getRepo().getTransactionManager().rollback(txStatus); |
|
793 |
throw e; |
|
771 | 794 |
} |
772 |
getRepo().commitTransaction(txStatus); |
|
773 | 795 |
// TODO move into a service class -------------- |
774 | 796 |
} finally { |
775 | 797 |
clearSession(); |
776 | 798 |
} |
799 |
|
|
777 | 800 |
} else { |
778 | 801 |
// in case of creating a new name for a registration the parent view is the TaxonNamePopupEditor |
779 | 802 |
// this is set |
Also available in: Unified diff
ref #8132 proper transaction rollback in RegistrationWorkingsetPresenter