156 |
156 |
|
157 |
157 |
private Collection<CdmBase> rootEntities = new HashSet<>();
|
158 |
158 |
|
159 |
|
/**
|
160 |
|
*
|
161 |
|
*/
|
|
159 |
|
162 |
160 |
public RegistrationWorkingsetPresenter() {
|
163 |
161 |
}
|
164 |
162 |
|
... | ... | |
467 |
465 |
}
|
468 |
466 |
// just ignore on CANCEL
|
469 |
467 |
} else {
|
470 |
|
Registration registration = null;
|
|
468 |
Optional<Registration> registrationOpt = Optional.ofNullable(null);
|
471 |
469 |
if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){
|
472 |
470 |
if(event.getReason().equals(Reason.SAVE)){
|
473 |
471 |
try {
|
474 |
472 |
TaxonName taxonName = newNameForRegistrationPopupEditor.getBean().cdmEntity();
|
475 |
|
registration = registrationWorkflowService.createRegistration(taxonName, newNameBlockingRegistrations);
|
|
473 |
registrationOpt = Optional.of(registrationWorkflowService.createRegistration(taxonName, newNameBlockingRegistrations));
|
476 |
474 |
loadWorkingSet(workingset.getCitationUuid());
|
477 |
475 |
} finally {
|
478 |
476 |
clearSession();
|
... | ... | |
486 |
484 |
}
|
487 |
485 |
|
488 |
486 |
if(event.getReason().equals(Reason.SAVE)){
|
489 |
|
if(registration == null){
|
|
487 |
if(!registrationOpt.isPresent()){
|
490 |
488 |
// no new registration has been created above, so there must be an existing one.
|
491 |
|
registration = findRegistrationInContext(event.getPopup());
|
|
489 |
registrationOpt = findRegistrationInContext(event.getPopup());
|
492 |
490 |
}
|
493 |
491 |
|
494 |
492 |
// Check if the other names used in the context of the name are registered yet.
|
... | ... | |
499 |
497 |
namesToCheck.addAll(nameEditor.getReplacedSynonymsComboboxSelect().getValue());
|
500 |
498 |
namesToCheck.add(nameEditor.getValidationField().getRelatedNameComboBox().getValue());
|
501 |
499 |
namesToCheck.add(nameEditor.getOrthographicVariantField().getRelatedNameComboBox().getValue());
|
|
500 |
// NOTE: according to https://dev.e-taxonomy.eu/redmine/issues/8049#note-2 we will not create blocking
|
|
501 |
// registrations for names in WeaklyRelatedEntityFields
|
502 |
502 |
|
503 |
503 |
for(TaxonName name : namesToCheck){
|
504 |
504 |
if(name != null){
|
505 |
505 |
clearSession();
|
506 |
|
registrationWorkflowService.addBlockingRegistration(name.getUuid(), registration);
|
|
506 |
assocciateOrQueueBlockingRegistration(registrationOpt, name.getUuid());
|
507 |
507 |
}
|
508 |
508 |
}
|
509 |
509 |
} else if (event.getReason().equals(Reason.DELETE)){
|
... | ... | |
674 |
674 |
} else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
|
675 |
675 |
if(event.getReason().equals(Reason.SAVE)){
|
676 |
676 |
|
677 |
|
Registration registration = null;
|
|
677 |
Optional<Registration> registrationOpt = Optional.ofNullable(null);
|
678 |
678 |
|
679 |
679 |
UUID typeDesignationUuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
|
680 |
680 |
|
681 |
681 |
try {
|
682 |
682 |
clearSession();
|
683 |
|
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext();
|
684 |
|
registration = findRegistrationInContext(context);
|
685 |
|
registrationWorkflowService.addTypeDesignation(typeDesignationUuid, registration);
|
686 |
|
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup());
|
|
683 |
registrationOpt = findRegistrationInContext(event.getPopup());
|
|
684 |
registrationOpt.ifPresent(reg -> {
|
|
685 |
registrationWorkflowService.addTypeDesignation(typeDesignationUuid, reg);
|
|
686 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup());
|
|
687 |
});
|
|
688 |
|
687 |
689 |
} finally {
|
688 |
690 |
clearSession();
|
689 |
691 |
}
|
690 |
692 |
|
691 |
|
if(registration == null){
|
692 |
|
// no new registration has been created above, so there must be an existing one.
|
693 |
|
registration = findRegistrationInContext(event.getPopup());
|
694 |
|
}
|
695 |
|
|
696 |
|
// Check if the other names used in the context of the name are registered yet.
|
697 |
|
NameTypeDesignationPopupEditor nameEditor = (NameTypeDesignationPopupEditor)event.getPopup();
|
|
693 |
// Check if other names used in the context of the name are registered yet.
|
|
694 |
NameTypeDesignationPopupEditor nameTypeDesignationEditor = (NameTypeDesignationPopupEditor)event.getPopup();
|
698 |
695 |
Set<TaxonName> namesToCheck = new HashSet<>();
|
699 |
696 |
|
700 |
|
namesToCheck.add(nameEditor.getTypeNameField().getValue());
|
|
697 |
namesToCheck.add(nameTypeDesignationEditor.getTypeNameField().getValue());
|
701 |
698 |
|
702 |
699 |
for(TaxonName name : namesToCheck){
|
703 |
700 |
if(name != null){
|
704 |
|
registrationWorkflowService.addBlockingRegistration(name.getUuid(), registration);
|
|
701 |
assocciateOrQueueBlockingRegistration(registrationOpt, name.getUuid());
|
705 |
702 |
}
|
706 |
703 |
|
707 |
704 |
}
|
... | ... | |
717 |
714 |
}
|
718 |
715 |
|
719 |
716 |
/**
|
|
717 |
* @param registrationOpt
|
|
718 |
* @param name
|
|
719 |
*/
|
|
720 |
private void assocciateOrQueueBlockingRegistration(Optional<Registration> registrationOpt, UUID nameUuid) {
|
|
721 |
registrationOpt.ifPresent(reg -> registrationWorkflowService.addBlockingRegistration(nameUuid, reg));
|
|
722 |
if(!registrationOpt.isPresent()){
|
|
723 |
// not present!
|
|
724 |
Registration blockingRegistration = registrationWorkflowService.prepareBlockingRegistration(nameUuid);
|
|
725 |
if(blockingRegistration != null){
|
|
726 |
newNameBlockingRegistrations.add(blockingRegistration);
|
|
727 |
logger.debug("Blocking registration created and queued for later association with the main registration.");
|
|
728 |
}
|
|
729 |
}
|
|
730 |
}
|
|
731 |
|
|
732 |
/**
|
720 |
733 |
*
|
721 |
734 |
*/
|
722 |
735 |
public void clearSession() {
|
... | ... | |
769 |
782 |
if(rootContext.getParentView().equals(getView()) && event.getSourceView() != newNameForRegistrationPopupEditor){
|
770 |
783 |
try {
|
771 |
784 |
clearSession();
|
772 |
|
// create a blocking registration, the new Registration will be persisted
|
|
785 |
// create a blocking registration
|
773 |
786 |
UUID taxonNameUUID = event.getEntityUuid();
|
774 |
|
|
775 |
|
if(context.get(1).getParentView() instanceof TaxonNamePopupEditor && !((TaxonNamePopupEditor)context.get(1).getParentView()).getBean().cdmEntity().isPersited()){
|
776 |
|
// Oha!! The event came from a popup editor and the
|
777 |
|
// first popup in the context is a TaxonNameEditor with un-persisted name
|
778 |
|
// This is a name for a new registration which has not yet been created.
|
779 |
|
// It is necessary to store blocking registrations in the newNameBlockingRegistrations
|
780 |
|
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID);
|
781 |
|
newNameBlockingRegistrations.add(blockingRegistration);
|
782 |
|
logger.debug("Blocking registration created and memorized");
|
783 |
|
} else {
|
784 |
|
Registration registration = findRegistrationInContext(context);
|
785 |
|
// some new name somehow related to an existing registration
|
786 |
|
registrationWorkflowService.addBlockingRegistration(taxonNameUUID, registration);
|
787 |
|
}
|
|
787 |
Optional<Registration> registrationOpt = findRegistrationInContext(context);
|
|
788 |
assocciateOrQueueBlockingRegistration(registrationOpt, taxonNameUUID);
|
788 |
789 |
} finally {
|
789 |
790 |
clearSession();
|
790 |
791 |
}
|
... | ... | |
815 |
816 |
|
816 |
817 |
|
817 |
818 |
|
818 |
|
public Registration findRegistrationInContext(PopupView popupView) {
|
|
819 |
public Optional<Registration> findRegistrationInContext(PopupView popupView) {
|
819 |
820 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)popupView).getEditorActionContext();
|
820 |
821 |
return findRegistrationInContext(context);
|
821 |
822 |
}
|
... | ... | |
826 |
827 |
* @param context
|
827 |
828 |
* @return
|
828 |
829 |
*/
|
829 |
|
public Registration findRegistrationInContext(Stack<EditorActionContext> context) {
|
|
830 |
public Optional<Registration> findRegistrationInContext(Stack<EditorActionContext> context) {
|
830 |
831 |
EditorActionContext rootCtx = context.get(0);
|
831 |
832 |
TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootCtx.getParentEntity();
|
832 |
833 |
Optional<RegistrationDTO> registrationDTOOptional = workingset.getRegistrationDTO(regReference.getUuid());
|
|
834 |
Optional<Registration> registrationOptional;
|
833 |
835 |
if(!registrationDTOOptional.isPresent()){
|
834 |
|
logger.error("RegistrationDTO missing in rootCtx.");
|
|
836 |
logger.debug("No RegistrationDTO in found rootCtx -> user is about to create a registration for a new name.");
|
|
837 |
registrationOptional = Optional.ofNullable(null);
|
|
838 |
}
|
|
839 |
|
|
840 |
Optional<Registration> regOpt;
|
|
841 |
if(registrationDTOOptional.isPresent()){
|
|
842 |
regOpt = Optional.of(registrationDTOOptional.get().registration());
|
|
843 |
} else {
|
|
844 |
regOpt = Optional.ofNullable(null);
|
835 |
845 |
}
|
836 |
|
Registration registration = registrationDTOOptional.get().registration();
|
837 |
846 |
|
838 |
|
// registration = reloadRegistration(registration);
|
839 |
|
return registration;
|
|
847 |
return regOpt;
|
840 |
848 |
}
|
841 |
849 |
|
842 |
850 |
|
fix #8462 fuffering new blocking registrations for later association with main registration