Revision 6f71379a
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
468 | 468 |
if(event.getPopup() instanceof TaxonNamePopupEditor){ |
469 | 469 |
if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){ |
470 | 470 |
if(event.getReason().equals(Reason.SAVE)){ |
471 |
|
|
471 | 472 |
try { |
472 | 473 |
// TODO move into a service class -------------- |
473 | 474 |
TransactionStatus txStatus = getRepo().startTransaction(); |
474 |
UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid(); |
|
475 |
if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){ |
|
476 |
getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity()); |
|
477 |
} |
|
478 |
Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid); |
|
479 |
if(!newNameBlockingRegistrations.isEmpty()){ |
|
480 |
for(Registration blockingReg : newNameBlockingRegistrations){ |
|
481 |
blockingReg = getRepo().getRegistrationService().load(blockingReg.getUuid()); |
|
482 |
reg.getBlockedBy().add(blockingReg); |
|
475 |
try { |
|
476 |
UUID taxonNameUuid = newNameForRegistrationPopupEditor.getBean().getUuid(); |
|
477 |
if(newNameForRegistrationPopupEditor.getBean().cdmEntity().isPersited()){ |
|
478 |
getRepo().getSession().refresh(newNameForRegistrationPopupEditor.getBean().cdmEntity()); |
|
483 | 479 |
} |
484 |
getRepo().getRegistrationService().saveOrUpdate(reg); |
|
485 |
newNameBlockingRegistrations.clear(); |
|
480 |
Registration reg = getRepo().getRegistrationService().createRegistrationForName(taxonNameUuid); |
|
481 |
if(!newNameBlockingRegistrations.isEmpty()){ |
|
482 |
for(Registration blockingReg : newNameBlockingRegistrations){ |
|
483 |
blockingReg = getRepo().getRegistrationService().load(blockingReg.getUuid()); |
|
484 |
reg.getBlockedBy().add(blockingReg); |
|
485 |
} |
|
486 |
getRepo().getRegistrationService().saveOrUpdate(reg); |
|
487 |
newNameBlockingRegistrations.clear(); |
|
488 |
} |
|
489 |
getRepo().commitTransaction(txStatus); |
|
490 |
} catch (Exception e){ |
|
491 |
getRepo().getTransactionManager().rollback(txStatus); |
|
492 |
throw e; |
|
486 | 493 |
} |
487 |
getRepo().commitTransaction(txStatus); |
|
488 | 494 |
// -------------------------------------------------- |
489 | 495 |
// reload workingset into current session |
490 | 496 |
loadWorkingSet(workingset.getCitationUuid()); |
... | ... | |
494 | 500 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
495 | 501 |
} |
496 | 502 |
} |
503 |
|
|
497 | 504 |
// nullify and clear the memory on this popup editor in any case (SAVE, CANCEL, DELETE) |
498 | 505 |
newNameForRegistrationPopupEditor = null; |
499 | 506 |
newNameBlockingRegistrations.clear(); |
... | ... | |
525 | 532 |
try { |
526 | 533 |
// TODO move into a service class -------------- |
527 | 534 |
TransactionStatus txStatus = getRepo().startTransaction(true); |
528 |
Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$")); |
|
529 |
// here we completely ignore the ExistingNameRegistrationType since the user should not have the choice |
|
530 |
// to create a typification only registration in the working (publication) set which contains |
|
531 |
// the protologe. This is known from the nomenclatural reference. |
|
532 |
if(canCreateNameRegistrationFor(typifiedName)){ |
|
533 |
// the citation which is the base for workingset contains the protologe of the name and the name has not |
|
534 |
// been registered before: |
|
535 |
// create a registration for the name and the first typifications |
|
536 |
Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
537 |
workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation)); |
|
538 |
doReloadWorkingSet = true; |
|
539 |
} else { |
|
540 |
if(!checkWokingsetContainsProtologe(typifiedName)){ |
|
541 |
// create a typification only registration |
|
542 |
Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration(); |
|
543 |
if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){ |
|
544 |
// oops, yet no registration for this name, so we create it as blocking registration: |
|
545 |
Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
546 |
typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration); |
|
535 |
try { |
|
536 |
Reference citation = getRepo().getReferenceService().load(workingset.getCitationUuid(), Arrays.asList("authorship.$", "inReference.authorship.$")); |
|
537 |
// here we completely ignore the ExistingNameRegistrationType since the user should not have the choice |
|
538 |
// to create a typification only registration in the working (publication) set which contains |
|
539 |
// the protologe. This is known from the nomenclatural reference. |
|
540 |
if(canCreateNameRegistrationFor(typifiedName)){ |
|
541 |
// the citation which is the base for workingset contains the protologe of the name and the name has not |
|
542 |
// been registered before: |
|
543 |
// create a registration for the name and the first typifications |
|
544 |
Registration newRegistrationWithExistingName = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
545 |
workingset.add(new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation)); |
|
546 |
doReloadWorkingSet = true; |
|
547 |
} else { |
|
548 |
if(!checkWokingsetContainsProtologe(typifiedName)){ |
|
549 |
// create a typification only registration |
|
550 |
Registration typificationOnlyRegistration = getRepo().getRegistrationService().newRegistration(); |
|
551 |
if(!getRepo().getRegistrationService().checkRegistrationExistsFor(typifiedName)){ |
|
552 |
// oops, yet no registration for this name, so we create it as blocking registration: |
|
553 |
Registration blockingNameRegistration = getRepo().getRegistrationService().createRegistrationForName(typifiedName.getUuid()); |
|
554 |
typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration); |
|
555 |
} |
|
556 |
RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation); |
|
557 |
workingset.add(regDTO); |
|
547 | 558 |
} |
548 |
RegistrationDTO regDTO = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation); |
|
549 |
workingset.add(regDTO); |
|
550 | 559 |
} |
560 |
getRepo().commitTransaction(txStatus); |
|
561 |
} catch (Exception e){ |
|
562 |
getRepo().getTransactionManager().rollback(txStatus); |
|
563 |
throw e; |
|
551 | 564 |
} |
552 |
getRepo().commitTransaction(txStatus); |
|
553 | 565 |
// -------------------------------------------------- |
554 | 566 |
// tell the view to update the workingset |
555 | 567 |
} finally { |
... | ... | |
676 | 688 |
* @throws RegistrationValidationException |
677 | 689 |
*/ |
678 | 690 |
@EventBusListenerMethod |
679 |
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
|
691 |
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) { |
|
680 | 692 |
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){ |
681 | 693 |
if(event.getReason().equals(Reason.SAVE)){ |
682 | 694 |
// NOTE: adding the SpecimenTypeDesignations to the registration is done in the |
... | ... | |
693 | 705 |
getRepo().getSession().clear(); |
694 | 706 |
// TODO move into a service class -------------- |
695 | 707 |
TransactionStatus txStatus = getRepo().startTransaction(); |
696 |
UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup()); |
|
697 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext(); |
|
698 |
Registration registration = findRegistrationInContext(context); |
|
699 |
getRepo().getRegistrationService().addTypeDesignation(registration, typeDesignationUuid); |
|
700 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
701 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup()); |
|
702 |
getRepo().commitTransaction(txStatus); |
|
708 |
try { |
|
709 |
UUID regUUID = nameTypeDesignationPopupEditorRegistrationUUIDMap.get(event.getPopup()); |
|
710 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext(); |
|
711 |
Registration registration = findRegistrationInContext(context); |
|
712 |
getRepo().getRegistrationService().addTypeDesignation(registration, typeDesignationUuid); |
|
713 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
714 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup()); |
|
715 |
getRepo().commitTransaction(txStatus); |
|
716 |
} catch (Exception e){ |
|
717 |
getRepo().getTransactionManager().rollback(txStatus); |
|
718 |
throw e; |
|
719 |
} |
|
703 | 720 |
// TODO move into a service class -------------- |
704 | 721 |
} finally { |
705 | 722 |
getRepo().getSession().clear(); |
... | ... | |
758 | 775 |
getRepo().getSession().clear(); |
759 | 776 |
// TODO move into a service class -------------- |
760 | 777 |
TransactionStatus txStatus = getRepo().startTransaction(); |
761 |
// create a blocking registration, the new Registration will be persisted |
|
762 |
UUID taxonNameUUID = event.getEntityUuid(); |
|
763 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
764 |
|
|
765 |
if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){ |
|
766 |
// Oha!! The event came from a popup editor and the |
|
767 |
// first popup in the context is a TaxonNameEditor with un-persisted name |
|
768 |
// This is a name for a new registration which has not yet been created. |
|
769 |
// It is necessary to store blocking registrations in the newNameBlockingRegistrations |
|
770 |
newNameBlockingRegistrations.add(blockingRegistration); |
|
771 |
logger.debug("Blocking registration created and memorized"); |
|
772 |
} else { |
|
773 |
// some new name somehow related to an existing registration |
|
774 |
Registration registration = findRegistrationInContext(context); |
|
775 |
registration.getBlockedBy().add(blockingRegistration); |
|
776 |
|
|
777 |
if(registration.isPersited()){ |
|
778 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
779 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
778 |
try { |
|
779 |
// create a blocking registration, the new Registration will be persisted |
|
780 |
UUID taxonNameUUID = event.getEntityUuid(); |
|
781 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
782 |
|
|
783 |
if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){ |
|
784 |
// Oha!! The event came from a popup editor and the |
|
785 |
// first popup in the context is a TaxonNameEditor with un-persisted name |
|
786 |
// This is a name for a new registration which has not yet been created. |
|
787 |
// It is necessary to store blocking registrations in the newNameBlockingRegistrations |
|
788 |
newNameBlockingRegistrations.add(blockingRegistration); |
|
789 |
logger.debug("Blocking registration created and memorized"); |
|
790 |
} else { |
|
791 |
// some new name somehow related to an existing registration |
|
792 |
Registration registration = findRegistrationInContext(context); |
|
793 |
registration.getBlockedBy().add(blockingRegistration); |
|
794 |
|
|
795 |
if(registration.isPersited()){ |
|
796 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
797 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
798 |
} |
|
780 | 799 |
} |
800 |
getRepo().commitTransaction(txStatus); |
|
801 |
} catch (Exception e){ |
|
802 |
getRepo().getTransactionManager().rollback(txStatus); |
|
803 |
throw e; |
|
781 | 804 |
} |
782 |
getRepo().commitTransaction(txStatus); |
|
783 | 805 |
// TODO move into a service class -------------- |
784 | 806 |
} finally { |
785 | 807 |
getRepo().getSession().clear(); |
786 | 808 |
} |
809 |
|
|
787 | 810 |
} else { |
788 | 811 |
// in case of creating a new name for a registration the parent view is the TaxonNamePopupEditor |
789 | 812 |
// this is set |
Also available in: Unified diff
ref #8132 proper transaction rollback in RegistrationWorkingsetPresenter