Project

General

Profile

Revision 592b9851

ID592b9851f97ad3bd5734275477e8bcc142777247
Parent 3c6137bf
Child 2bcb1498

Added by Andreas Kohlbecker over 1 year ago

ref #8107 getFieldGroup() returns Optional to avoid NPEs and logging errors before rethrowing as PopupEditorException

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java
12 12
import java.util.Arrays;
13 13
import java.util.Collection;
14 14
import java.util.List;
15
import java.util.Optional;
15 16

  
16 17
import org.vaadin.viritin.FilterableListContainer;
17 18

  
......
140 141
     * {@inheritDoc}
141 142
     */
142 143
    @Override
143
    public FieldGroup getFieldGroup() {
144
        // holds a Container instead // TODO can this cause a NPE?
145
        return null;
144
    public Optional<FieldGroup> getFieldGroup() {
145
        // holds a Container instead
146
        return Optional.empty();
146 147
    }
147 148

  
148 149
    @Override
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/GeoLocationField.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.component.common;
10 10

  
11
import java.util.Optional;
12

  
11 13
import org.apache.commons.lang3.StringUtils;
12 14
import org.apache.log4j.Logger;
13 15
import org.vaadin.addon.leaflet.LCircle;
......
220 222
     * {@inheritDoc}
221 223
     */
222 224
    @Override
223
    public FieldGroup getFieldGroup() {
224
        return fieldGroup;
225
    public Optional<FieldGroup> getFieldGroup() {
226
        return Optional.of(fieldGroup);
225 227
    }
226 228

  
227 229
    public ListSelect getReferenceSystemSelect() {
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java
10 10

  
11 11
import java.util.EnumSet;
12 12
import java.util.List;
13
import java.util.Optional;
13 14
import java.util.regex.Pattern;
14 15

  
15 16
import org.vaadin.teemu.switchui.Switch;
......
325 326
     * {@inheritDoc}
326 327
     */
327 328
    @Override
328
    public FieldGroup getFieldGroup() {
329
        return fieldGroup;
329
    public Optional<FieldGroup> getFieldGroup() {
330
        return Optional.of(fieldGroup);
330 331
    }
331 332

  
332 333

  
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
11 11
import java.util.Arrays;
12 12
import java.util.EnumSet;
13 13
import java.util.List;
14
import java.util.Optional;
14 15

  
15 16
import org.apache.log4j.Logger;
16 17
import org.vaadin.viritin.fields.LazyComboBox;
......
262 263
     * {@inheritDoc}
263 264
     */
264 265
    @Override
265
    public FieldGroup getFieldGroup() {
266
        return fieldGroup;
266
    public Optional<FieldGroup> getFieldGroup() {
267
        return Optional.of(fieldGroup);
267 268
    }
268 269

  
269 270
    public Component[] getCachFields(){
src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java
12 12
import java.util.Arrays;
13 13
import java.util.Collection;
14 14
import java.util.List;
15
import java.util.Optional;
15 16

  
16 17
import com.vaadin.data.fieldgroup.FieldGroup;
17 18
import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;
......
60 61
        @Override
61 62
        public void preCommit(CommitEvent commitEvent) throws CommitException {
62 63
            // commit the nested bean(s) first
63
            if(getFieldGroup() != null){
64
                getFieldGroup().commit();
64
            if(getFieldGroup().isPresent()){
65
                getFieldGroup().get().commit();
65 66
            }
66 67
        }
67 68

  
......
181 182
     * @return
182 183
     */
183 184
    @Override
184
    public abstract FieldGroup getFieldGroup();
185
    public abstract Optional<FieldGroup> getFieldGroup();
185 186

  
186 187
    /**
187
     * @return true if all fields having the value <code>null</code>
188
     * @return true if all fields having the value <code>null</code> and if there is no fieldgroup at all for this component.
188 189
     */
189 190
    @SuppressWarnings("rawtypes")
190 191
    public boolean hasNullContent() {
191 192
        Collection<Field> nullValueCheckIgnore = nullValueCheckIgnoreFields();
192
        return getFieldGroup().getFields().stream()
193
        if(!getFieldGroup().isPresent()){
194
            return true;
195
        }
196
        return getFieldGroup().get().getFields().stream()
193 197
                .filter(
194 198
                        f -> !nullValueCheckIgnore.contains(f)
195 199
                )
src/main/java/eu/etaxonomy/vaadin/component/NameRelationField.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
12

  
11 13
import com.vaadin.data.fieldgroup.BeanFieldGroup;
12 14
import com.vaadin.data.fieldgroup.FieldGroup;
13 15
import com.vaadin.ui.Button;
......
99 101
     * {@inheritDoc}
100 102
     */
101 103
    @Override
102
    public FieldGroup getFieldGroup() {
103
        return fieldGroup;
104
    public Optional<FieldGroup> getFieldGroup() {
105
        return Optional.of(fieldGroup);
104 106
    }
105 107

  
106 108
    /**
......
176 178
        newValue = HibernateProxyHelper.deproxy(newValue);
177 179
        if(newValue != null) {
178 180
            compositeWrapper.addComponent(grid);
179
            getFieldGroup().bind(relatedNameComboBox, "otherName");
180
            getFieldGroup().bind(citationMicroReferenceField, "citationMicroReference");
181
            getFieldGroup().bind(citatonComboBox, "citation");
182
            getFieldGroup().bind(ruleConsideredField, "ruleConsidered");
181
            fieldGroup.bind(relatedNameComboBox, "otherName");
182
            fieldGroup.bind(citationMicroReferenceField, "citationMicroReference");
183
            fieldGroup.bind(citatonComboBox, "citation");
184
            fieldGroup.bind(ruleConsideredField, "ruleConsidered");
183 185

  
184 186
            fieldGroup.setItemDataSource(newValue);
185 187
        } else {
186 188
            if(oldValue != null){
187 189
                compositeWrapper.removeComponent(grid);
188
                getFieldGroup().unbind(relatedNameComboBox);
189
                getFieldGroup().unbind(citationMicroReferenceField);
190
                getFieldGroup().unbind(citatonComboBox);
191
                getFieldGroup().unbind(ruleConsideredField);
190
                fieldGroup.unbind(relatedNameComboBox);
191
                fieldGroup.unbind(citationMicroReferenceField);
192
                fieldGroup.unbind(citatonComboBox);
193
                fieldGroup.unbind(ruleConsideredField);
192 194

  
193 195
                fieldGroup.setItemDataSource(newValue);
194 196
            }
src/main/java/eu/etaxonomy/vaadin/component/NestedFieldGroup.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
12

  
11 13
import com.vaadin.data.fieldgroup.FieldGroup;
12 14

  
13 15
/**
......
22 24
     *
23 25
     * @return the FieldGroup, may be <code>null</code>.
24 26
     */
25
    public abstract FieldGroup getFieldGroup();
27
    public abstract Optional<FieldGroup> getFieldGroup();
26 28

  
27 29
    public abstract void registerParentFieldGroup(FieldGroup parent);
28 30

  
src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
12

  
11 13
import org.vaadin.teemu.switchui.Switch;
12 14

  
13 15
import com.vaadin.data.fieldgroup.FieldGroup;
......
116 118
     * {@inheritDoc}
117 119
     */
118 120
    @Override
119
    public FieldGroup getFieldGroup() {
120
        return null;
121
    public Optional<FieldGroup> getFieldGroup() {
122
        return Optional.empty();
121 123
    }
122 124

  
123 125
    /**
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesListSelect.java
13 13
import java.util.Collections;
14 14
import java.util.HashSet;
15 15
import java.util.List;
16
import java.util.Optional;
16 17
import java.util.Set;
17 18

  
18 19
import org.apache.log4j.Logger;
......
553 554
     * <p>
554 555
     */
555 556
    @Override
556
    public FieldGroup getFieldGroup() {
557
        return null;
557
    public Optional<FieldGroup> getFieldGroup() {
558
        return Optional.empty();
558 559
    }
559 560

  
560 561
    /**
src/main/java/eu/etaxonomy/vaadin/component/ToOneRelatedEntityCombobox.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
12

  
11 13
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
12 14
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
13 15

  
......
100 102
     * {@inheritDoc}
101 103
     */
102 104
    @Override
103
    public FieldGroup getFieldGroup() {
104
        return null;
105
    public Optional<FieldGroup> getFieldGroup() {
106
        return Optional.empty();
105 107
    }
106 108

  
107 109
    /**
src/main/java/eu/etaxonomy/vaadin/component/ToOneRelatedEntityListSelect.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
12

  
11 13
import com.vaadin.data.Container;
12 14
import com.vaadin.data.Property;
13 15
import com.vaadin.data.fieldgroup.FieldGroup;
......
83 85
     * {@inheritDoc}
84 86
     */
85 87
    @Override
86
    public FieldGroup getFieldGroup() {
87
        return null;
88
    public Optional<FieldGroup> getFieldGroup() {
89
        return Optional.empty();
88 90
    }
89 91

  
90 92
    /**
src/main/java/eu/etaxonomy/vaadin/component/WeaklyRelatedEntityCombobox.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.component;
10 10

  
11
import java.util.Optional;
11 12
import java.util.UUID;
12 13

  
13 14
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
......
102 103
     * {@inheritDoc}
103 104
     */
104 105
    @Override
105
    public FieldGroup getFieldGroup() {
106
        return null;
106
    public Optional<FieldGroup> getFieldGroup() {
107
        return Optional.empty();
107 108
    }
108 109

  
109 110
    /**
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
13 13
import java.util.HashSet;
14 14
import java.util.List;
15 15
import java.util.Map;
16
import java.util.Optional;
16 17
import java.util.Set;
17 18
import java.util.Stack;
18 19

  
......
22 23

  
23 24
import com.vaadin.data.Validator.InvalidValueException;
24 25
import com.vaadin.data.fieldgroup.BeanFieldGroup;
26
import com.vaadin.data.fieldgroup.FieldGroup;
25 27
import com.vaadin.data.fieldgroup.FieldGroup.CommitEvent;
26 28
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
27 29
import com.vaadin.data.fieldgroup.FieldGroup.CommitHandler;
......
445 447
            }
446 448
            if(cause == null){
447 449
                // no known exception type found
450
                logger.error("Unhandled exception", e);
448 451
                throw new PopupEditorException("Error saving popup editor", this, e);
449 452
            }
450 453

  
......
594 597
            while(parentComponent != null){
595 598
                logger.debug("parentComponent: " + parentComponent.getClass().getSimpleName());
596 599
                if(NestedFieldGroup.class.isAssignableFrom(parentComponent.getClass()) && AbstractField.class.isAssignableFrom(parentComponent.getClass())){
597
                    Object propId = ((NestedFieldGroup)parentComponent).getFieldGroup().getPropertyId(parentField);
598
                    if(propId != null){
599
                        logger.debug("propId: " + propId.toString());
600
                        nestedPropertyIds.addParent(propId);
600
                    Optional<FieldGroup> parentFieldGroup = ((NestedFieldGroup)parentComponent).getFieldGroup();
601
                    if(parentFieldGroup.isPresent()){
602
                        Object propId = parentFieldGroup.get().getPropertyId(parentField);
603
                        if(propId != null){
604
                            logger.debug("propId: " + propId.toString());
605
                            nestedPropertyIds.addParent(propId);
606
                        }
607
                        logger.debug("parentField: " + parentField.getClass().getSimpleName());
608
                        parentField = (Field)parentComponent;
609
                    } else {
610
                        logger.debug("parentFieldGroup is null, continuing ...");
601 611
                    }
602
                    logger.debug("parentField: " + parentField.getClass().getSimpleName());
603
                    parentField = (Field)parentComponent;
604 612
                } else if(parentComponent == this) {
605 613
                    // we reached the editor itself
606 614
                    Object propId = fieldGroup.getPropertyId(parentField);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)