Project

General

Profile

« Previous | Next » 

Revision 11247507

Added by Andreas Kohlbecker over 5 years ago

fix #7629 restricting new registrations to those which make sense in the current workingset

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/event/registration/RegistrationWorkingsetAction.java
10 10

  
11 11
import java.util.UUID;
12 12

  
13
import eu.etaxonomy.cdm.vaadin.view.registration.ExistingNameRegistrationType;
14

  
15 13
/**
16 14
 * @author a.kohlbecker
17 15
 * @since Mar 3, 2017
......
21 19

  
22 20
    private Action action;
23 21
    private UUID citationUuid = null;
24
    private ExistingNameRegistrationType type;
25 22

  
26 23
    /**
27 24
     *
28 25
     * @param citationID the id of a {@link Reference} denoting a
29 26
     * complete registration working set.
30 27
     */
31
    public RegistrationWorkingsetAction(UUID citationUuid, Action action, ExistingNameRegistrationType type){
28
    public RegistrationWorkingsetAction(UUID citationUuid, Action action){
32 29
        this.action = action;
33 30
        this.citationUuid = citationUuid;
34
        this.type = type;
35 31
    }
36 32

  
37 33
    /**
......
52 48
        return action.equals(Action.start);
53 49
    }
54 50

  
55
    public ExistingNameRegistrationType getType() {
56
        return type;
57
    }
58

  
59 51

  
60 52
    public enum Action {
61 53
        start, open;
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ExistingNameRegistrationType.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.registration;
10

  
11
public enum ExistingNameRegistrationType {
12
    NAME_TYPIFICATION("covering the name and typifications"),
13
    TYPIFICATION_ONLY("covering typifications only");
14

  
15
    private String caption;
16

  
17
    ExistingNameRegistrationType(String caption){
18
        this.caption = caption;
19
    }
20

  
21
    @Override
22
    public String toString() {
23
        return caption;
24
    }
25

  
26

  
27
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
174 174
    /**
175 175
     * Checks
176 176
     * <ol>
177
     * <li>if there is any registration for this name created in the current registration system</li>
177
     * <li>if there is NOT any registration for this name created in the current registration system</li>
178 178
     * <li>Checks if the name belongs to the current workingset</li>
179 179
     * </ol>
180 180
     * If both checks are successful the method returns <code>true</code>.
181 181
     */
182
    public boolean canCreateRegistrationForName(TaxonName name) {
183
        for(Registration reg : name.getRegistrations()){
184
            if(minter.isFromOwnRegistration(reg.getIdentifier())){
185
                return false;
186
            }
187
        }
182
    public boolean canCreateNameRegistrationFor(TaxonName name) {
183
        return !checkRegistrationExistsFor(name) && checkWokingsetContainsProtologe(name);
184
    }
185

  
186
    /**
187
     * @param name
188
     * @return
189
     */
190
    public boolean checkWokingsetContainsProtologe(TaxonName name) {
188 191
        Reference nomRef = name.getNomenclaturalReference();
189 192
        UUID citationUuid = workingset.getCitationUuid();
190 193
        // @formatter:off
......
197 200
        // @formatter:on
198 201
    }
199 202

  
203
    /**
204
     * @param name
205
     */
206
    public boolean checkRegistrationExistsFor(TaxonName name) {
207

  
208
        for(Registration reg : name.getRegistrations()){
209
            if(minter.isFromOwnRegistration(reg.getIdentifier())){
210
                return true;
211
            }
212
        }
213
        return false;
214
    }
215

  
216

  
200 217

  
201 218
    /**
202 219
     * @param taxonNameId
......
547 564
            // here we completely ignore the ExistingNameRegistrationType since the user should not have the choice
548 565
            // to create a typification only registration in the working (publication) set which contains
549 566
            // the protologe. This is known from the nomenclatural reference.
550
            if(canCreateRegistrationForName(typifiedName)){
551
                // the citation which is the base for workingset contains the protologe of the name and the name hast not
567
            if(canCreateNameRegistrationFor(typifiedName)){
568
                // the citation which is the base for workingset contains the protologe of the name and the name has not
552 569
                // been registered before:
553 570
                // create a registration for the name and the first typifications
554 571
                Registration newRegistrationWithExistingName = createNewRegistrationForName(typifiedName.getUuid());
555 572
                newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
556 573
                reloadWorkingSet = true;
557 574
            } else {
558
                // create a typification only registration
559
                // FIXME: this should not be possible if the names protologue is in the workingset --> #
560
                Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
561
                newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
575
                if(!checkWokingsetContainsProtologe(typifiedName)){
576
                    // create a typification only registration
577
                    Registration typificationOnlyRegistration = createNewRegistrationForName(null);
578
                    if(!checkRegistrationExistsFor(typifiedName)){
579
                        // oops, yet no registration for this name, so we create it as blocking registration:
580
                        Registration blockingNameRegistration = createNewRegistrationForName(typifiedName.getUuid());
581
                        typificationOnlyRegistration.getBlockedBy().add(blockingNameRegistration);
582
                    }
583
                    newRegistrationDTOWithExistingName = new RegistrationDTO(typificationOnlyRegistration, typifiedName, citation);
584
                }
562 585
            }
563 586
            workingset.add(newRegistrationDTOWithExistingName);
564 587
            // tell the view to update the workingset
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java
39 39
import com.vaadin.ui.GridLayout;
40 40
import com.vaadin.ui.HorizontalLayout;
41 41
import com.vaadin.ui.Label;
42
import com.vaadin.ui.ListSelect;
43 42
import com.vaadin.ui.Notification;
44 43
import com.vaadin.ui.Panel;
45 44
import com.vaadin.ui.UI;
......
88 87
public class RegistrationWorksetViewBean extends AbstractPageView<RegistrationWorkingsetPresenter>
89 88
    implements RegistrationWorkingsetView, View, AccessRestrictedView {
90 89

  
91
    /**
92
     *
93
     */
90

  
94 91
    private static final int COL_INDEX_STATE_LABEL = 0;
95 92

  
96
    /**
97
     *
98
     */
99 93
    private static final int COL_INDEX_REG_ITEM = 1;
100 94

  
101
    /**
102
     *
103
     */
104 95
    private static final int COL_INDEX_BUTTON_GROUP = 2;
105 96

  
106 97
    public static final String DOM_ID_WORKINGSET = "workingset";
107 98

  
99
    public static final String TEXT_NAME_TYPIFICATION = "covering the name and typifications";
100
    public static final String TEXT_TYPIFICATION_ONLY = "covering typifications only";
101

  
108 102
    private static final long serialVersionUID = -213040114015958970L;
109 103

  
110 104
    public static final String NAME = "workingset";
......
126 120

  
127 121
    private Button addExistingNameButton;
128 122

  
129
    private ListSelect existingNameRegistrationTypeSelect;
123
    private Label existingNameRegistrationTypeLabel;
130 124

  
131 125
    private RegistrationItem workingsetHeader;
132 126

  
......
253 247
        addNewNameRegistrationButton.addClickListener(
254 248
                e -> getViewEventBus().publish(this, new TaxonNameEditorAction(EditorActionType.ADD, null, addNewNameRegistrationButton, null, this)));
255 249

  
256
        existingNameRegistrationTypeSelect = new ListSelect(null, EnumSet.allOf(ExistingNameRegistrationType.class));
257
        existingNameRegistrationTypeSelect.setRows(1);
258
        existingNameRegistrationTypeSelect.setNullSelectionAllowed(true);
259
        existingNameRegistrationTypeSelect.setEnabled(false);
250
        existingNameRegistrationTypeLabel = new Label();
260 251
        addExistingNameButton = new Button("existing name:");
261 252
        addExistingNameButton.setEnabled(false);
262 253
        addExistingNameButton.addClickListener(
263 254
                e -> getViewEventBus().publish(this, new RegistrationWorkingsetAction(
264 255
                        citationUuid,
265
                        RegistrationWorkingsetAction.Action.start,
266
                        (ExistingNameRegistrationType)existingNameRegistrationTypeSelect.getValue())
256
                        RegistrationWorkingsetAction.Action.start
267 257
                )
268
             );
258
             )
259
                );
269 260

  
270 261
        existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
271 262
        existingNameCombobox.addValueChangeListener(
272 263
                e -> {
273 264
                    boolean selectionNotEmpty = e.getProperty().getValue() != null;
274
                    addExistingNameButton.setEnabled(selectionNotEmpty);
275
                    existingNameRegistrationTypeSelect.setEnabled(selectionNotEmpty);
265
                    addExistingNameButton.setEnabled(false);
266
                    existingNameRegistrationTypeLabel.setValue(null);
276 267
                    if(selectionNotEmpty){
277 268
                        TaxonName name = (TaxonName)e.getProperty().getValue();
278
                        if(getPresenter().canCreateRegistrationForName(name)){
279
                            existingNameRegistrationTypeSelect.setValue(ExistingNameRegistrationType.NAME_TYPIFICATION);
280
                            existingNameRegistrationTypeSelect.setEnabled(true);
281
                            existingNameRegistrationTypeSelect.setNullSelectionAllowed(false);
269
                        if(getPresenter().canCreateNameRegistrationFor(name)){
270
                            existingNameRegistrationTypeLabel.setValue(TEXT_NAME_TYPIFICATION);
271
                            addExistingNameButton.setEnabled(true);
282 272
                        } else {
283
                            existingNameRegistrationTypeSelect.setValue(ExistingNameRegistrationType.TYPIFICATION_ONLY);
284
                            existingNameRegistrationTypeSelect.setEnabled(false);
273
                            if(!getPresenter().checkWokingsetContainsProtologe(name)){
274
                                existingNameRegistrationTypeLabel.setValue(TEXT_TYPIFICATION_ONLY);
275
                                addExistingNameButton.setEnabled(true);
276
                            }
285 277
                        }
286 278
                    } else {
287
                        existingNameRegistrationTypeSelect.setNullSelectionAllowed(true);
288
                        existingNameRegistrationTypeSelect.clear();
289
                        existingNameRegistrationTypeSelect.setEnabled(false);
290

  
279
                        existingNameRegistrationTypeLabel.setValue(null);
291 280
                    }
292 281
                }
293 282
                );
......
298 287
                addRegistrationLabel_2,
299 288
                addExistingNameButton,
300 289
                existingNameCombobox,
301
                existingNameRegistrationTypeSelect
290
                existingNameRegistrationTypeLabel
302 291
                );
303 292
        buttonContainer.setSpacing(true);
304 293
//        buttonContainer.setWidth(100, Unit.PERCENTAGE);

Also available in: Unified diff