Revision 8af7fcc2
ref #8050 creating blocking registrations for exising names which are used in the context of another registration
src/main/java/eu/etaxonomy/cdm/service/IRegistrationWorkflowService.java | ||
---|---|---|
39 | 39 |
@Transactional(readOnly=true) |
40 | 40 |
void reloadRegistration(Registration registration); |
41 | 41 |
|
42 |
/** |
|
43 |
* Creates a new registration for the name referenced by the {@code taxonNameUUID} parameter |
|
44 |
* if there isn't one already and adds this new registration as blocking registration to the passed |
|
45 |
* {@code registration}. |
|
46 |
* |
|
47 |
* Already existing registrations must not be added as blocking registration. |
|
48 |
* |
|
49 |
* @param taxonNameUUID |
|
50 |
* @param registration |
|
51 |
*/ |
|
42 | 52 |
@Transactional |
43 |
void addBlockingRegistration(UUID taxonNameUUID, Registration registration);
|
|
53 |
Registration addBlockingRegistration(UUID nameUUID, Registration registration);
|
|
44 | 54 |
|
45 | 55 |
@Transactional |
46 | 56 |
void addTypeDesignation(UUID typeDesignationUuid, Registration registration); |
src/main/java/eu/etaxonomy/cdm/service/RegistrationWorkflowService.java | ||
---|---|---|
21 | 21 |
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO; |
22 | 22 |
import eu.etaxonomy.cdm.api.service.dto.RegistrationWorkingSet; |
23 | 23 |
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException; |
24 |
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter; |
|
24 | 25 |
import eu.etaxonomy.cdm.model.name.Registration; |
25 | 26 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
26 | 27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
... | ... | |
40 | 41 |
@Qualifier("cdmRepository") |
41 | 42 |
private CdmRepository repo; |
42 | 43 |
|
44 |
@Autowired |
|
45 |
private RegistrationIdentifierMinter minter; |
|
46 |
|
|
43 | 47 |
private CdmRepository getRepo() { |
44 | 48 |
return repo; |
45 | 49 |
} |
... | ... | |
109 | 113 |
* @param registration |
110 | 114 |
*/ |
111 | 115 |
@Override |
112 |
public void addBlockingRegistration(UUID taxonNameUUID, Registration registration) { |
|
113 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(taxonNameUUID); |
|
114 |
reloadRegistration(registration); |
|
115 |
registration.getBlockedBy().add(blockingRegistration); |
|
116 |
if(registration.isPersited()){ |
|
117 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
118 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
116 |
public Registration addBlockingRegistration(UUID nameUUID, Registration registration) { |
|
117 |
|
|
118 |
TaxonName name = getRepo().getNameService().load(nameUUID); |
|
119 |
|
|
120 |
boolean registrationExists = false; |
|
121 |
for(Registration regForName : name.getRegistrations()){ |
|
122 |
if(minter.identifierPattern().matcher(regForName.getIdentifier()).matches()){ |
|
123 |
registrationExists = true; |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
if(!registrationExists){ |
|
129 |
Registration blockingRegistration = getRepo().getRegistrationService().createRegistrationForName(nameUUID); |
|
130 |
reloadRegistration(registration); |
|
131 |
registration.getBlockedBy().add(blockingRegistration); |
|
132 |
if(registration.isPersited()){ |
|
133 |
getRepo().getRegistrationService().saveOrUpdate(registration); |
|
134 |
logger.debug("Blocking registration created, added to registion and persited"); |
|
135 |
} |
|
136 |
return blockingRegistration; |
|
119 | 137 |
} |
138 |
return null; |
|
120 | 139 |
} |
121 | 140 |
|
122 | 141 |
/** |
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java | ||
---|---|---|
94 | 94 |
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent; |
95 | 95 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent; |
96 | 96 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason; |
97 |
import eu.etaxonomy.vaadin.ui.view.PopupView; |
|
97 | 98 |
|
98 | 99 |
/** |
99 | 100 |
* @author a.kohlbecker |
... | ... | |
340 | 341 |
} |
341 | 342 |
} |
342 | 343 |
|
343 |
@EventBusListenerMethod |
|
344 |
public void onDoneWithSpecimenTypeDesignationWorkingsetPopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{ |
|
345 |
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){ |
|
346 |
if(event.getReason().equals(Reason.SAVE)){ |
|
347 |
refreshView(true); |
|
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
|
|
352 | 344 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class) |
353 | 345 |
public void onRegistrationEditorAction(RegistrationEditorAction event) { |
354 | 346 |
|
... | ... | |
423 | 415 |
* @throws RegistrationValidationException |
424 | 416 |
*/ |
425 | 417 |
@EventBusListenerMethod |
426 |
public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
|
418 |
public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) { |
|
427 | 419 |
if(event.getPopup() instanceof TaxonNamePopupEditor){ |
420 |
Registration registration = null; |
|
421 |
boolean doRefreshView = false; |
|
428 | 422 |
if(newNameForRegistrationPopupEditor != null && event.getPopup().equals(newNameForRegistrationPopupEditor)){ |
429 | 423 |
if(event.getReason().equals(Reason.SAVE)){ |
430 | 424 |
try { |
431 | 425 |
TaxonName taxonName = newNameForRegistrationPopupEditor.getBean().cdmEntity(); |
432 |
registrationWorkflowService.createRegistration(taxonName, newNameBlockingRegistrations); |
|
426 |
registration = registrationWorkflowService.createRegistration(taxonName, newNameBlockingRegistrations);
|
|
433 | 427 |
loadWorkingSet(workingset.getCitationUuid()); |
434 |
refreshView(true); |
|
435 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
|
436 | 428 |
} finally { |
437 | 429 |
clearSession(); |
438 |
refreshView(true);
|
|
430 |
doRefreshView = true;
|
|
439 | 431 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
440 | 432 |
} |
441 | 433 |
} |
... | ... | |
443 | 435 |
newNameForRegistrationPopupEditor = null; |
444 | 436 |
newNameBlockingRegistrations.clear(); |
445 | 437 |
getView().getAddNewNameRegistrationButton().setEnabled(true); |
446 |
} else { |
|
447 |
refreshView(true); |
|
448 | 438 |
} |
439 |
|
|
440 |
if(registration == null){ |
|
441 |
// no new registration has been created above, so there must be an existing one. |
|
442 |
registration = findRegistrationInContext(event.getPopup()); |
|
443 |
} |
|
444 |
|
|
445 |
// Check if the other names used in the context of the name are registered yet. |
|
446 |
TaxonNamePopupEditor nameEditor = (TaxonNamePopupEditor)event.getPopup(); |
|
447 |
Set<TaxonName> namesToCheck = new HashSet<>(); |
|
448 |
|
|
449 |
namesToCheck.addAll(nameEditor.getBasionymComboboxSelect().getValue()); |
|
450 |
namesToCheck.addAll(nameEditor.getReplacedSynonymsComboboxSelect().getValue()); |
|
451 |
namesToCheck.add(nameEditor.getValidationField().getRelatedNameComboBox().getValue()); |
|
452 |
namesToCheck.add(nameEditor.getOrthographicVariantField().getRelatedNameComboBox().getValue()); |
|
453 |
|
|
454 |
for(TaxonName name : namesToCheck){ |
|
455 |
if(name != null){ |
|
456 |
doRefreshView |= registrationWorkflowService.addBlockingRegistration(name.getUuid(), registration) != null; |
|
457 |
} |
|
458 |
} |
|
459 |
|
|
460 |
refreshView(doRefreshView); |
|
449 | 461 |
} |
450 | 462 |
} |
451 | 463 |
|
... | ... | |
605 | 617 |
} |
606 | 618 |
} else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){ |
607 | 619 |
if(event.getReason().equals(Reason.SAVE)){ |
620 |
|
|
621 |
Registration registration = null; |
|
622 |
boolean doRefreshView = false; |
|
623 |
|
|
608 | 624 |
UUID typeDesignationUuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid(); |
609 | 625 |
|
610 | 626 |
try { |
611 | 627 |
clearSession(); |
612 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getPopup()).getEditorActionContext(); |
|
613 |
Registration registration = findRegistrationInContext(context); |
|
614 | 628 |
getRepo().getSession().clear(); |
615 | 629 |
registrationWorkflowService.addTypeDesignation(typeDesignationUuid, registration); |
616 | 630 |
nameTypeDesignationPopupEditorRegistrationUUIDMap.remove(event.getPopup()); |
617 | 631 |
} finally { |
618 | 632 |
clearSession(); |
619 |
refreshView(true); |
|
633 |
doRefreshView = true; |
|
634 |
} |
|
635 |
|
|
636 |
if(registration == null){ |
|
637 |
// no new registration has been created above, so there must be an existing one. |
|
638 |
registration = findRegistrationInContext(event.getPopup()); |
|
639 |
} |
|
640 |
|
|
641 |
// Check if the other names used in the context of the name are registered yet. |
|
642 |
NameTypeDesignationPopupEditor nameEditor = (NameTypeDesignationPopupEditor)event.getPopup(); |
|
643 |
Set<TaxonName> namesToCheck = new HashSet<>(); |
|
644 |
|
|
645 |
namesToCheck.add(nameEditor.getTypeNameField().getValue()); |
|
646 |
|
|
647 |
for(TaxonName name : namesToCheck){ |
|
648 |
if(name != null){ |
|
649 |
doRefreshView |= registrationWorkflowService.addBlockingRegistration(name.getUuid(), registration) != null; |
|
650 |
} |
|
651 |
|
|
620 | 652 |
} |
653 |
|
|
654 |
refreshView(doRefreshView); |
|
655 |
|
|
621 | 656 |
} else if(event.getReason().equals(Reason.CANCEL)){ |
622 | 657 |
// noting to do |
623 | 658 |
} |
... | ... | |
719 | 754 |
} |
720 | 755 |
} |
721 | 756 |
|
757 |
public Registration findRegistrationInContext(PopupView popupView) { |
|
758 |
Stack<EditorActionContext>context = ((AbstractPopupEditor)popupView).getEditorActionContext(); |
|
759 |
return findRegistrationInContext(context); |
|
760 |
} |
|
722 | 761 |
/** |
723 | 762 |
* Finds the Registration in the EditorContext stack |
724 | 763 |
* |
Also available in: Unified diff