Project

General

Profile

Revision fd48f996

IDfd48f9961b4794ba5b6cb3422320a851dc42b752
Parent f1ec80f5
Child cf6be9f8, a7d31c5a

Added by Andreas Müller almost 4 years ago

ref #7080 fix potential other isEmpty issues for @Embeddable classes

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/Contact.java
12 12
import java.io.Serializable;
13 13
import java.net.URI;
14 14
import java.util.ArrayList;
15
import java.util.Collection;
15 16
import java.util.HashSet;
16 17
import java.util.List;
17 18
import java.util.Set;
......
21 22
import javax.persistence.Embeddable;
22 23
import javax.persistence.FetchType;
23 24
import javax.persistence.OneToMany;
25
import javax.persistence.Transient;
24 26
import javax.xml.bind.annotation.XmlAccessType;
25 27
import javax.xml.bind.annotation.XmlAccessorType;
26 28
import javax.xml.bind.annotation.XmlElement;
......
204 206
		}
205 207
	}
206 208

  
207

  
208
	/**
209
    /**
210
     * True, if no contact data exists in any of the lists (email, phone, ...).
211
     */
212
    @Transient
213
    public boolean isEmpty(){
214
        if (isEmpty(emailAddresses) && isEmpty(faxNumbers) && isEmpty(phoneNumbers)
215
                && isEmpty(urls) && isEmpty(addresses)){
216
            return true;
217
        }else{
218
            return false;
219
        }
220
    }
221

  
222
    private boolean isEmpty(Collection<? extends Object> collection) {
223
        return collection == null || collection.isEmpty();
224
    }
225

  
226
    /**
209 227
	 * Returns the set of postal {@link Address addresses} belonging to <i>this</i> contact.
210 228
	 * A {@link Person person} or an {@link Institution institution} cannot have more than one contact,
211 229
	 * but a contact may include several postal addresses.
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/LSID.java
160 160
			return false;
161 161
		}
162 162
	}
163
	
164
	
163

  
164
    /**
165
     * <code>true</code>, if all of the LSID parts are
166
     * empty or <code>null</code>.
167
     */
168
    @Transient
169
    public boolean isEmpty(){
170
        if (isEmpty(authority) && isEmpty(lsid) &&
171
                isEmpty(namespace) && isEmpty(object) &&
172
                isEmpty(revision)){
173
            return true;
174
        }else{
175
            return false;
176
        }
177
    }
178
    private boolean isEmpty(String str) {
179
        return str == null || str.isEmpty();
180
    }
181

  
165 182
	/**
166 183
	 * return the string representation
167 184
	 * @return String
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/Point.java
554 554

  
555 555
    }
556 556

  
557
    /**
558
     * <code>true</code>, if none of the attributes (lat, long, errRadius, refSys) is set.
559
     */
560
    @Transient
561
    public boolean isEmpty(){
562
        if (errorRadius == null && latitude == null && longitude == null
563
                && referenceSystem == null){
564
            return true;
565
        }else{
566
            return false;
567
        }
568
    }
569

  
557 570
// ******************** GETTER / SETTER ********************************
558 571

  
559 572
    public ReferenceSystem getReferenceSystem(){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/molecular/SequenceString.java
12 12

  
13 13
import javax.persistence.Embeddable;
14 14
import javax.persistence.Lob;
15
import javax.persistence.Transient;
15 16
import javax.xml.bind.annotation.XmlAccessType;
16 17
import javax.xml.bind.annotation.XmlAccessorType;
17 18
import javax.xml.bind.annotation.XmlElement;
......
113 114
	}
114 115

  
115 116

  
117
    /**
118
     * <code>true</code>, if none of the attributes (string, length) is set.
119
     */
120
    @Transient
121
    public boolean isEmpty(){
122
        if ((string == null || string.isEmpty())
123
                && length == null){
124
            return true;
125
        }else{
126
            return false;
127
        }
128
    }
129

  
130

  
116 131
	// ********************* CLONE ********************/
117 132

  
118 133
	/**
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/match/DefaultMatchStrategy.java
31 31
import eu.etaxonomy.cdm.common.DOI;
32 32
import eu.etaxonomy.cdm.common.DoubleResult;
33 33
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
34
import eu.etaxonomy.cdm.model.agent.Contact;
34 35
import eu.etaxonomy.cdm.model.common.CdmBase;
36
import eu.etaxonomy.cdm.model.common.LSID;
35 37
import eu.etaxonomy.cdm.model.common.TimePeriod;
38
import eu.etaxonomy.cdm.model.location.Point;
39
import eu.etaxonomy.cdm.model.molecular.SequenceString;
36 40
import eu.etaxonomy.cdm.strategy.StrategyBase;
37 41
import eu.etaxonomy.cdm.strategy.match.Match.ReplaceMode;
38 42

  
......
303 307
		    if ( ((TimePeriod)object).isEmpty()){
304 308
		        return null;
305 309
		    }
306
		}
310
		}else if (object instanceof Contact){
311
            if ( ((Contact)object).isEmpty()){
312
                return null;
313
            }
314
        }else if (object instanceof Point){
315
            if ( ((Point)object).isEmpty()){
316
                return null;
317
            }
318
        }else if (object instanceof SequenceString){
319
            if ( ((SequenceString)object).isEmpty()){
320
                return null;
321
            }
322
        }else if (object instanceof LSID){
323
            if ( ((LSID)object).isEmpty()){
324
                return null;
325
            }
326
        }
307 327
		return HibernateProxyHelper.deproxy(object);
308 328
	}
309 329

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)