fix #7629 restricting new registrations to those which make sense in the current...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 6 Aug 2018 10:04:48 +0000 (12:04 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 6 Aug 2018 10:04:48 +0000 (12:04 +0200)
src/main/java/eu/etaxonomy/cdm/vaadin/event/registration/RegistrationWorkingsetAction.java
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ExistingNameRegistrationType.java [deleted file]
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java

index 91f5b83e027cc7e03c1eee913c498622bb552fae..580529457d62d6233f6b193463d59a5a53ccdf7b 100644 (file)
@@ -10,8 +10,6 @@ package eu.etaxonomy.cdm.vaadin.event.registration;
 
 import java.util.UUID;
 
-import eu.etaxonomy.cdm.vaadin.view.registration.ExistingNameRegistrationType;
-
 /**
  * @author a.kohlbecker
  * @since Mar 3, 2017
@@ -21,17 +19,15 @@ public class RegistrationWorkingsetAction {
 
     private Action action;
     private UUID citationUuid = null;
-    private ExistingNameRegistrationType type;
 
     /**
      *
      * @param citationID the id of a {@link Reference} denoting a
      * complete registration working set.
      */
-    public RegistrationWorkingsetAction(UUID citationUuid, Action action, ExistingNameRegistrationType type){
+    public RegistrationWorkingsetAction(UUID citationUuid, Action action){
         this.action = action;
         this.citationUuid = citationUuid;
-        this.type = type;
     }
 
     /**
@@ -52,10 +48,6 @@ public class RegistrationWorkingsetAction {
         return action.equals(Action.start);
     }
 
-    public ExistingNameRegistrationType getType() {
-        return type;
-    }
-
 
     public enum Action {
         start, open;
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ExistingNameRegistrationType.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ExistingNameRegistrationType.java
deleted file mode 100644 (file)
index b032204..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
-* Copyright (C) 2018 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.vaadin.view.registration;
-
-public enum ExistingNameRegistrationType {
-    NAME_TYPIFICATION("covering the name and typifications"),
-    TYPIFICATION_ONLY("covering typifications only");
-
-    private String caption;
-
-    ExistingNameRegistrationType(String caption){
-        this.caption = caption;
-    }
-
-    @Override
-    public String toString() {
-        return caption;
-    }
-
-
-}
\ No newline at end of file
index a8a1eda71d5c5695a26a9a2ea860cf6db042adf1..0cf85053aa5d44bb422ead4c13e49bcceba6053f 100644 (file)
@@ -174,17 +174,20 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
     /**
      * Checks
      * <ol>
-     * <li>if there is any registration for this name created in the current registration system</li>
+     * <li>if there is NOT any registration for this name created in the current registration system</li>
      * <li>Checks if the name belongs to the current workingset</li>
      * </ol>
      * If both checks are successful the method returns <code>true</code>.
      */
-    public boolean canCreateRegistrationForName(TaxonName name) {
-        for(Registration reg : name.getRegistrations()){
-            if(minter.isFromOwnRegistration(reg.getIdentifier())){
-                return false;
-            }
-        }
+    public boolean canCreateNameRegistrationFor(TaxonName name) {
+        return !checkRegistrationExistsFor(name) && checkWokingsetContainsProtologe(name);
+    }
+
+    /**
+     * @param name
+     * @return
+     */
+    public boolean checkWokingsetContainsProtologe(TaxonName name) {
         Reference nomRef = name.getNomenclaturalReference();
         UUID citationUuid = workingset.getCitationUuid();
         // @formatter:off
@@ -197,6 +200,20 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
         // @formatter:on
     }
 
+    /**
+     * @param name
+     */
+    public boolean checkRegistrationExistsFor(TaxonName name) {
+
+        for(Registration reg : name.getRegistrations()){
+            if(minter.isFromOwnRegistration(reg.getIdentifier())){
+                return true;
+            }
+        }
+        return false;
+    }
+
+
 
     /**
      * @param taxonNameId
@@ -547,18 +564,24 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
             // here we completely ignore the ExistingNameRegistrationType since the user should not have the choice
             // to create a typification only registration in the working (publication) set which contains
             // the protologe. This is known from the nomenclatural reference.
-            if(canCreateRegistrationForName(typifiedName)){
-                // the citation which is the base for workingset contains the protologe of the name and the name hast not
+            if(canCreateNameRegistrationFor(typifiedName)){
+                // the citation which is the base for workingset contains the protologe of the name and the name has not
                 // been registered before:
                 // create a registration for the name and the first typifications
                 Registration newRegistrationWithExistingName = createNewRegistrationForName(typifiedName.getUuid());
                 newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
                 reloadWorkingSet = true;
             } else {
-                // create a typification only registration
-                // FIXME: this should not be possible if the names protologue is in the workingset --> #
-                Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
-                newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
+                if(!checkWokingsetContainsProtologe(typifiedName)){
+                    // create a typification only registration
+                    Registration typificationOnlyRegistration = createNewRegistrationForName(null);
+                    if(!checkRegistrationExistsFor(typifiedName)){
+                        // oops, yet no registration for this name, so we create it as blocking registration:
+                        Registration blockingNameRegistration = createNewRegistrationForName(typifiedName.getUuid());
+                        typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration);
+                    }
+                    newRegistrationDTOWithExistingName = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation);
+                }
             }
             workingset.add(newRegistrationDTOWithExistingName);
             // tell the view to update the workingset
index 5458c7e979abc765c8252ca5574bfbf9dc7030b5..91540383ff9fcfc33eb09150ff9c74b55138af61 100644 (file)
@@ -39,7 +39,6 @@ import com.vaadin.ui.CssLayout;
 import com.vaadin.ui.GridLayout;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.Label;
-import com.vaadin.ui.ListSelect;
 import com.vaadin.ui.Notification;
 import com.vaadin.ui.Panel;
 import com.vaadin.ui.UI;
@@ -88,23 +87,18 @@ import eu.etaxonomy.vaadin.event.EditorActionType;
 public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWorkingsetPresenter>
     implements RegistrationWorkingsetView, View, AccessRestrictedView {
 
-    /**
-     *
-     */
+
     private static final int COL_INDEX_STATE_LABEL = 0;
 
-    /**
-     *
-     */
     private static final int COL_INDEX_REG_ITEM = 1;
 
-    /**
-     *
-     */
     private static final int COL_INDEX_BUTTON_GROUP = 2;
 
     public static final String DOM_ID_WORKINGSET = "workingset";
 
+    public static final String TEXT_NAME_TYPIFICATION = "covering the name and typifications";
+    public static final String TEXT_TYPIFICATION_ONLY = "covering typifications only";
+
     private static final long serialVersionUID = -213040114015958970L;
 
     public static final String NAME = "workingset";
@@ -126,7 +120,7 @@ public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWo
 
     private Button addExistingNameButton;
 
-    private ListSelect existingNameRegistrationTypeSelect;
+    private Label existingNameRegistrationTypeLabel;
 
     private RegistrationItem workingsetHeader;
 
@@ -253,41 +247,36 @@ public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWo
         addNewNameRegistrationButton.addClickListener(
                 e -> getViewEventBus().publish(this, new TaxonNameEditorAction(EditorActionType.ADD, null, addNewNameRegistrationButton, null, this)));
 
-        existingNameRegistrationTypeSelect = new ListSelect(null, EnumSet.allOf(ExistingNameRegistrationType.class));
-        existingNameRegistrationTypeSelect.setRows(1);
-        existingNameRegistrationTypeSelect.setNullSelectionAllowed(true);
-        existingNameRegistrationTypeSelect.setEnabled(false);
+        existingNameRegistrationTypeLabel = new Label();
         addExistingNameButton = new Button("existing name:");
         addExistingNameButton.setEnabled(false);
         addExistingNameButton.addClickListener(
                 e -> getViewEventBus().publish(this, new RegistrationWorkingsetAction(
                         citationUuid,
-                        RegistrationWorkingsetAction.Action.start,
-                        (ExistingNameRegistrationType)existingNameRegistrationTypeSelect.getValue())
+                        RegistrationWorkingsetAction.Action.start
                 )
-             );
+             )
+                );
 
         existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
         existingNameCombobox.addValueChangeListener(
                 e -> {
                     boolean selectionNotEmpty = e.getProperty().getValue() != null;
-                    addExistingNameButton.setEnabled(selectionNotEmpty);
-                    existingNameRegistrationTypeSelect.setEnabled(selectionNotEmpty);
+                    addExistingNameButton.setEnabled(false);
+                    existingNameRegistrationTypeLabel.setValue(null);
                     if(selectionNotEmpty){
                         TaxonName name = (TaxonName)e.getProperty().getValue();
-                        if(getPresenter().canCreateRegistrationForName(name)){
-                            existingNameRegistrationTypeSelect.setValue(ExistingNameRegistrationType.NAME_TYPIFICATION);
-                            existingNameRegistrationTypeSelect.setEnabled(true);
-                            existingNameRegistrationTypeSelect.setNullSelectionAllowed(false);
+                        if(getPresenter().canCreateNameRegistrationFor(name)){
+                            existingNameRegistrationTypeLabel.setValue(TEXT_NAME_TYPIFICATION);
+                            addExistingNameButton.setEnabled(true);
                         } else {
-                            existingNameRegistrationTypeSelect.setValue(ExistingNameRegistrationType.TYPIFICATION_ONLY);
-                            existingNameRegistrationTypeSelect.setEnabled(false);
+                            if(!getPresenter().checkWokingsetContainsProtologe(name)){
+                                existingNameRegistrationTypeLabel.setValue(TEXT_TYPIFICATION_ONLY);
+                                addExistingNameButton.setEnabled(true);
+                            }
                         }
                     } else {
-                        existingNameRegistrationTypeSelect.setNullSelectionAllowed(true);
-                        existingNameRegistrationTypeSelect.clear();
-                        existingNameRegistrationTypeSelect.setEnabled(false);
-
+                        existingNameRegistrationTypeLabel.setValue(null);
                     }
                 }
                 );
@@ -298,7 +287,7 @@ public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWo
                 addRegistrationLabel_2,
                 addExistingNameButton,
                 existingNameCombobox,
-                existingNameRegistrationTypeSelect
+                existingNameRegistrationTypeLabel
                 );
         buttonContainer.setSpacing(true);
 //        buttonContainer.setWidth(100, Unit.PERCENTAGE);