Project

General

Profile

« Previous | Next » 

Revision f6b17945

Added by Andreas Kohlbecker almost 12 years ago

fixing typo in language SPANISH_CASTILIAN & more tests for # 476: Implement free-text search methods for TaxonBase and TextData & indexing uuids

View differences:

.gitattributes
606 606
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/MultilanguageTextFieldBridge.java -text
607 607
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/PartialBridge.java -text
608 608
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/StripHtmlBridge.java -text
609
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java -text
609 610
cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmAccessor.java -text
610 611
cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmAccessorFactoryImpl.java -text
611 612
cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmNamespacePrefixMapper.java -text
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest.java
224 224
		assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);
225 225
		assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());
226 226
		language = textData.getMultilanguageText().keySet().iterator().next();
227
		assertEquals("Language should be Spanish", Language.SPANISH_CATALAN(), language);
227
		assertEquals("Language should be Spanish", Language.SPANISH_CASTILIAN(), language);
228 228
		text = textData.getText(language);
229 229
		assertEquals("Unexpected description text", expectedText, text);
230 230
		assertEquals("Number of source elements should be 1", 1, textData.getSources().size());
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java
1
/**
2
* Copyright (C) 2012 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

  
10
package eu.etaxonomy.cdm.hibernate.search;
11

  
12
import java.util.UUID;
13

  
14
import org.hibernate.search.bridge.StringBridge;
15

  
16
/**
17
 * @author andreas
18
 * @date Jun 19, 2012
19
 *
20
 */
21
public class UuidBridge implements StringBridge {
22

  
23
    @Override
24
    public String objectToString(Object object) {
25
        if(object != null) {
26
            return ((UUID)object).toString();
27
        }
28
        return null;
29
    }
30

  
31
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmBase.java
43 43
import org.hibernate.search.annotations.DocumentId;
44 44
import org.hibernate.search.annotations.Field;
45 45
import org.hibernate.search.annotations.FieldBridge;
46
import org.hibernate.search.annotations.Index;
47
import org.hibernate.search.annotations.Store;
46 48
import org.joda.time.DateTime;
47 49

  
48 50
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
49 51
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
52
import eu.etaxonomy.cdm.hibernate.search.UuidBridge;
50 53
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
51 54
import eu.etaxonomy.cdm.jaxb.UUIDAdapter;
52 55
import eu.etaxonomy.cdm.strategy.match.Match;
......
75 78
})
76 79
@MappedSuperclass
77 80
public abstract class CdmBase implements Serializable, ICdmBase, Cloneable{
78
	private static final long serialVersionUID = -3053225700018294809L;
79
	@SuppressWarnings("unused")
80
	private static final Logger logger = Logger.getLogger(CdmBase.class);
81
    private static final long serialVersionUID = -3053225700018294809L;
82
    @SuppressWarnings("unused")
83
    private static final Logger logger = Logger.getLogger(CdmBase.class);
81 84

  
82
	@Transient
83
	@XmlTransient
84
	private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
85
    @Transient
86
    @XmlTransient
87
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
85 88

  
86
	//@XmlAttribute(name = "id", required = true)
87
	@XmlTransient
88
	@Id
89
    //@XmlAttribute(name = "id", required = true)
90
    @XmlTransient
91
    @Id
89 92
//	@GeneratedValue(generator = "system-increment")
90 93
//	@GeneratedValue(generator = "enhanced-table")
91
	@GeneratedValue(generator = "custom-enhanced-table")
92
	@DocumentId
93
	@Match(MatchMode.IGNORE)
94
	@NotNull
95
	@Min(0)
96
	private int id;
97

  
98
	@XmlAttribute(required = true)
94
    @GeneratedValue(generator = "custom-enhanced-table")
95
    @DocumentId
96
    @Match(MatchMode.IGNORE)
97
    @NotNull
98
    @Min(0)
99
    private int id;
100

  
101
    @XmlAttribute(required = true)
99 102
    @XmlJavaTypeAdapter(UUIDAdapter.class)
100 103
    @Type(type="uuidUserType")
101
	@NaturalId // This has the effect of placing a "unique" constraint on the database column
102
	@XmlID
103
	@Column(length=36)
104
	@Match(MatchMode.IGNORE)
105
	@NotNull
106
	protected UUID uuid;
107

  
108
	@XmlElement (name = "Created", type= String.class)
109
	@XmlJavaTypeAdapter(DateTimeAdapter.class)
110
	@Type(type="dateTimeUserType")
111
	@Basic(fetch = FetchType.LAZY)
112
	@Match(MatchMode.IGNORE)
113
	@Field(index = org.hibernate.search.annotations.Index.UN_TOKENIZED)
114
	@FieldBridge(impl = DateTimeBridge.class)
115
	private DateTime created;
116

  
117
	@XmlElement (name = "CreatedBy")
118
	@XmlIDREF
119
	@XmlSchemaType(name = "IDREF")
120
	@ManyToOne(fetch=FetchType.LAZY)
104
    @NaturalId // This has the effect of placing a "unique" constraint on the database column
105
    @XmlID
106
    @Column(length=36)
107
    @Match(MatchMode.IGNORE)
108
    @NotNull
109
    @Field(store = Store.YES, index = Index.UN_TOKENIZED)
110
    @FieldBridge(impl = UuidBridge.class)
111
    protected UUID uuid;
112

  
113
    @XmlElement (name = "Created", type= String.class)
114
    @XmlJavaTypeAdapter(DateTimeAdapter.class)
115
    @Type(type="dateTimeUserType")
116
    @Basic(fetch = FetchType.LAZY)
117
    @Match(MatchMode.IGNORE)
118
    @Field(index = Index.UN_TOKENIZED)
119
    @FieldBridge(impl = DateTimeBridge.class)
120
    private DateTime created;
121

  
122
    @XmlElement (name = "CreatedBy")
123
    @XmlIDREF
124
    @XmlSchemaType(name = "IDREF")
125
    @ManyToOne(fetch=FetchType.LAZY)
121 126
    @Match(MatchMode.IGNORE)
122
	private User createdBy;
123

  
124
	/**
125
	 * Class constructor assigning a unique UUID and creation date.
126
	 * UUID can be changed later via setUuid method.
127
	 */
128
	public CdmBase() {
129
		this.uuid = UUID.randomUUID();
130
		this.created = new DateTime().withMillisOfSecond(0);
131
	}
132

  
133
	/**
134
	 * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
135
	 * @param listener
136
	 */
137
	public void addPropertyChangeListener(PropertyChangeListener listener) {
138
		propertyChangeSupport.addPropertyChangeListener(listener);
139
	}
140

  
141
	/**
142
	 * see {@link PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)}
143
	 */
144
	public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
145
		propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
146
	}
147

  
148
	/**
149
	 * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
150
	 */
151
	public void removePropertyChangeListener(PropertyChangeListener listener) {
152
		propertyChangeSupport.removePropertyChangeListener(listener);
153
	}
154

  
155
	/**
156
	 * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)
157
	 */
158
	public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
159
		propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
160
	}
161

  
162
	public boolean hasListeners(String propertyName) {
163
		return propertyChangeSupport.hasListeners(propertyName);
164
	}
165

  
166
	public void firePropertyChange(String property, String oldval, String newval) {
167
		propertyChangeSupport.firePropertyChange(property, oldval, newval);
168
	}
169
	public void firePropertyChange(String property, int oldval, int newval) {
170
		propertyChangeSupport.firePropertyChange(property, oldval, newval);
171
	}
172
	public void firePropertyChange(String property, float oldval, float newval) {
173
		propertyChangeSupport.firePropertyChange(property, oldval, newval);
174
	}
175
	public void firePropertyChange(String property, boolean oldval, boolean newval) {
176
		propertyChangeSupport.firePropertyChange(property, oldval, newval);
177
	}
178
	public void firePropertyChange(String property, Object oldval, Object newval) {
179
		propertyChangeSupport.firePropertyChange(property, oldval, newval);
180
	}
181
	public void firePropertyChange(PropertyChangeEvent evt) {
182
		propertyChangeSupport.firePropertyChange(evt);
183
	}
184

  
185
	/* (non-Javadoc)
186
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
187
	 */
188
	public UUID getUuid() {
189
		return uuid;
190
	}
191
	/* (non-Javadoc)
192
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setUuid(java.util.UUID)
193
	 */
194
	public void setUuid(UUID uuid) {
195
		this.uuid = uuid;
196
	}
197

  
198
	/* (non-Javadoc)
199
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
200
	 */
201
	public int getId() {
202
		return this.id;
203
	}
204
	/* (non-Javadoc)
205
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
206
	 */
207
	public void setId(int id) {
208
		this.id = id;
209
	}
210

  
211
	/* (non-Javadoc)
212
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
213
	 */
214
	public DateTime getCreated() {
215
		return created;
216
	}
217
	/* (non-Javadoc)
218
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreated(java.util.Calendar)
219
	 */
220
	public void setCreated(DateTime created) {
221
		if (created != null){
222
			new DateTime();
223
			created = created.withMillisOfSecond(0);
224
			//created.set(Calendar.MILLISECOND, 0);  //old, can be deleted
225
		}
226
		this.created = created;
227
	}
228

  
229

  
230
	/* (non-Javadoc)
231
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
232
	 */
233
	public User getCreatedBy() {
234
		return this.createdBy;
235
	}
236
	/* (non-Javadoc)
237
	 * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreatedBy(eu.etaxonomy.cdm.model.agent.Person)
238
	 */
239
	public void setCreatedBy(User createdBy) {
240
		this.createdBy = createdBy;
241
	}
127
    private User createdBy;
128

  
129
    /**
130
     * Class constructor assigning a unique UUID and creation date.
131
     * UUID can be changed later via setUuid method.
132
     */
133
    public CdmBase() {
134
        this.uuid = UUID.randomUUID();
135
        this.created = new DateTime().withMillisOfSecond(0);
136
    }
137

  
138
    /**
139
     * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
140
     * @param listener
141
     */
142
    public void addPropertyChangeListener(PropertyChangeListener listener) {
143
        propertyChangeSupport.addPropertyChangeListener(listener);
144
    }
145

  
146
    /**
147
     * see {@link PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)}
148
     */
149
    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
150
        propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
151
    }
152

  
153
    /**
154
     * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
155
     */
156
    public void removePropertyChangeListener(PropertyChangeListener listener) {
157
        propertyChangeSupport.removePropertyChangeListener(listener);
158
    }
159

  
160
    /**
161
     * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)
162
     */
163
    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
164
        propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
165
    }
166

  
167
    public boolean hasListeners(String propertyName) {
168
        return propertyChangeSupport.hasListeners(propertyName);
169
    }
170

  
171
    public void firePropertyChange(String property, String oldval, String newval) {
172
        propertyChangeSupport.firePropertyChange(property, oldval, newval);
173
    }
174
    public void firePropertyChange(String property, int oldval, int newval) {
175
        propertyChangeSupport.firePropertyChange(property, oldval, newval);
176
    }
177
    public void firePropertyChange(String property, float oldval, float newval) {
178
        propertyChangeSupport.firePropertyChange(property, oldval, newval);
179
    }
180
    public void firePropertyChange(String property, boolean oldval, boolean newval) {
181
        propertyChangeSupport.firePropertyChange(property, oldval, newval);
182
    }
183
    public void firePropertyChange(String property, Object oldval, Object newval) {
184
        propertyChangeSupport.firePropertyChange(property, oldval, newval);
185
    }
186
    public void firePropertyChange(PropertyChangeEvent evt) {
187
        propertyChangeSupport.firePropertyChange(evt);
188
    }
189

  
190
    /* (non-Javadoc)
191
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
192
     */
193
    public UUID getUuid() {
194
        return uuid;
195
    }
196
    /* (non-Javadoc)
197
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setUuid(java.util.UUID)
198
     */
199
    public void setUuid(UUID uuid) {
200
        this.uuid = uuid;
201
    }
202

  
203
    /* (non-Javadoc)
204
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
205
     */
206
    public int getId() {
207
        return this.id;
208
    }
209
    /* (non-Javadoc)
210
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
211
     */
212
    public void setId(int id) {
213
        this.id = id;
214
    }
215

  
216
    /* (non-Javadoc)
217
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
218
     */
219
    public DateTime getCreated() {
220
        return created;
221
    }
222
    /* (non-Javadoc)
223
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreated(java.util.Calendar)
224
     */
225
    public void setCreated(DateTime created) {
226
        if (created != null){
227
            new DateTime();
228
            created = created.withMillisOfSecond(0);
229
            //created.set(Calendar.MILLISECOND, 0);  //old, can be deleted
230
        }
231
        this.created = created;
232
    }
233

  
234

  
235
    /* (non-Javadoc)
236
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
237
     */
238
    public User getCreatedBy() {
239
        return this.createdBy;
240
    }
241
    /* (non-Javadoc)
242
     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreatedBy(eu.etaxonomy.cdm.model.agent.Person)
243
     */
244
    public void setCreatedBy(User createdBy) {
245
        this.createdBy = createdBy;
246
    }
242 247

  
243 248
// ************************** Hibernate proxies *******************/
244
	/**
245
	 * These methods are present due to HHH-1517 - that in a one-to-many
246
	 * relationship with a superclass at the "one" end, the proxy created
247
	 * by hibernate is the superclass, and not the subclass, resulting in
248
	 * a classcastexception when you try to cast it.
249
	 *
250
	 * Hopefully this will be resolved through improvements with the creation of
251
	 * proxy objects by hibernate and the following methods will become redundant,
252
	 * but for the time being . . .
253
	 * @param <T>
254
	 * @param object
255
	 * @param clazz
256
	 * @return
257
	 * @throws ClassCastException
258
	 */
259
	//non-static does not work because javassist already unwrapps the proxy before calling the method
260
	 public static <T extends CdmBase> T deproxy(Object object, Class<T> clazz) throws ClassCastException {
261
		 return HibernateProxyHelper.deproxy(object, clazz);
262
	 }
263

  
264
	 public boolean isInstanceOf(Class<? extends CdmBase> clazz) throws ClassCastException {
265
	     return HibernateProxyHelper.isInstanceOf(this, clazz);
266
	 }
249
    /**
250
     * These methods are present due to HHH-1517 - that in a one-to-many
251
     * relationship with a superclass at the "one" end, the proxy created
252
     * by hibernate is the superclass, and not the subclass, resulting in
253
     * a classcastexception when you try to cast it.
254
     *
255
     * Hopefully this will be resolved through improvements with the creation of
256
     * proxy objects by hibernate and the following methods will become redundant,
257
     * but for the time being . . .
258
     * @param <T>
259
     * @param object
260
     * @param clazz
261
     * @return
262
     * @throws ClassCastException
263
     */
264
    //non-static does not work because javassist already unwrapps the proxy before calling the method
265
     public static <T extends CdmBase> T deproxy(Object object, Class<T> clazz) throws ClassCastException {
266
         return HibernateProxyHelper.deproxy(object, clazz);
267
     }
268

  
269
     public boolean isInstanceOf(Class<? extends CdmBase> clazz) throws ClassCastException {
270
         return HibernateProxyHelper.isInstanceOf(this, clazz);
271
     }
267 272

  
268 273
// ************* Object overrides *************************/
269 274

  
270
	/**
271
	 * Is true if UUID is the same for the passed Object and this one.
272
	 * @see java.lang.Object#equals(java.lang.Object)
273
	 * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
274
	 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
275
	 * for more information about equals and hashcode.
276
	 */
277
	@Override
278
	public boolean equals(Object obj) {
279
		if (obj == this){
280
			return true;
281
		}
282
		if (obj == null){
283
			return false;
284
		}
285
		if (!CdmBase.class.isAssignableFrom(obj.getClass())){
286
			return false;
287
		}
288
		ICdmBase cdmObj = (ICdmBase)obj;
289
		boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
290
		boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
291
		if (! uuidEqual || !createdEqual){
292
				return false;
293
		}
294
		return true;
295
	}
296

  
297

  
298
	/** Overrides {@link java.lang.Object#hashCode()}
299
	 *  See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
300
	 * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
301
	 * for more information about equals and hashcode.
302
	 */
303
	@Override
304
	public int hashCode() {
305
		   int hashCode = 7;
306
		   if(this.getUuid() != null) {
307
			   //this unfortunately leads to errors when loading maps via hibernate
308
			   //as hibernate computes hash values for CdmBase objects used as key at
309
			   // a time when the uuid is not yet loaded from the database. Therefore
310
			   //the hash values later change and give wrong results when retrieving
311
			   //data from the map (map.get(key) returns null, though there is an entry
312
			   //for key in the map.
313
			   //see further comments in #2114
314
		       int result = 29 * hashCode + this.getUuid().hashCode();
275
    /**
276
     * Is true if UUID is the same for the passed Object and this one.
277
     * @see java.lang.Object#equals(java.lang.Object)
278
     * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
279
     * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
280
     * for more information about equals and hashcode.
281
     */
282
    @Override
283
    public boolean equals(Object obj) {
284
        if (obj == this){
285
            return true;
286
        }
287
        if (obj == null){
288
            return false;
289
        }
290
        if (!CdmBase.class.isAssignableFrom(obj.getClass())){
291
            return false;
292
        }
293
        ICdmBase cdmObj = (ICdmBase)obj;
294
        boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
295
        boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
296
        if (! uuidEqual || !createdEqual){
297
                return false;
298
        }
299
        return true;
300
    }
301

  
302

  
303
    /** Overrides {@link java.lang.Object#hashCode()}
304
     *  See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
305
     * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
306
     * for more information about equals and hashcode.
307
     */
308
    @Override
309
    public int hashCode() {
310
           int hashCode = 7;
311
           if(this.getUuid() != null) {
312
               //this unfortunately leads to errors when loading maps via hibernate
313
               //as hibernate computes hash values for CdmBase objects used as key at
314
               // a time when the uuid is not yet loaded from the database. Therefore
315
               //the hash values later change and give wrong results when retrieving
316
               //data from the map (map.get(key) returns null, though there is an entry
317
               //for key in the map.
318
               //see further comments in #2114
319
               int result = 29 * hashCode + this.getUuid().hashCode();
315 320
//		       int shresult = 29 * hashCode + Integer.valueOf(this.getId()).hashCode();
316
			   return result;
317
		   } else {
318
			   return 29 * hashCode;
319
		   }
320
	}
321

  
322
	/**
323
	 * Overrides {@link java.lang.Object#toString()}.
324
	 * This returns an String that identifies the object well without beeing necessarily unique.
325
	 * Specification: This method should never call other object' methods so it can be well used for debugging
326
	 * without problems like lazy loading, unreal states etc.
327
	 * Note: If overriding this method's javadoc always copy or link the above requirement.
328
	 * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
329
	 * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
330
	 * @see java.lang.Object#toString()
331
	 */
332
	@Override
333
	public String toString() {
334
		return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
335
	}
321
               return result;
322
           } else {
323
               return 29 * hashCode;
324
           }
325
    }
326

  
327
    /**
328
     * Overrides {@link java.lang.Object#toString()}.
329
     * This returns an String that identifies the object well without beeing necessarily unique.
330
     * Specification: This method should never call other object' methods so it can be well used for debugging
331
     * without problems like lazy loading, unreal states etc.
332
     * Note: If overriding this method's javadoc always copy or link the above requirement.
333
     * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
334
     * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
335
     * @see java.lang.Object#toString()
336
     */
337
    @Override
338
    public String toString() {
339
        return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
340
    }
336 341

  
337 342
// **************** invoke methods **************************/
338 343

  
339
	protected void invokeSetMethod(Method method, Object object){
340
		try {
341
			method.invoke(object, this);
342
		} catch (Exception e) {
343
			e.printStackTrace();
344
			//TODO handle exceptioin;
345
		}
346
	}
347

  
348
	protected void invokeSetMethodWithNull(Method method, Object object){
349
		try {
350
			Object[] nul = new Object[]{null};
351
			method.invoke(object, nul);
352
		} catch (Exception e) {
353
			e.printStackTrace();
354
			//TODO handle exceptioin;
355
		}
356
	}
344
    protected void invokeSetMethod(Method method, Object object){
345
        try {
346
            method.invoke(object, this);
347
        } catch (Exception e) {
348
            e.printStackTrace();
349
            //TODO handle exceptioin;
350
        }
351
    }
352

  
353
    protected void invokeSetMethodWithNull(Method method, Object object){
354
        try {
355
            Object[] nul = new Object[]{null};
356
            method.invoke(object, nul);
357
        } catch (Exception e) {
358
            e.printStackTrace();
359
            //TODO handle exceptioin;
360
        }
361
    }
357 362

  
358 363
//********************** CLONE *****************************************/
359 364

  
360
	protected void clone(CdmBase clone){
361
		clone.setCreatedBy(createdBy);
362
		clone.setId(id);
363
		clone.propertyChangeSupport=new PropertyChangeSupport(clone);
364
		//Constructor Attributes
365
		//clone.setCreated(created);
366
		//clone.setUuid(getUuid());
367

  
368
	}
369

  
370
	/* (non-Javadoc)
371
	 * @see java.lang.Object#clone()
372
	 */
373
	@Override
374
	public Object clone() throws CloneNotSupportedException{
375
		CdmBase result = (CdmBase)super.clone();
376
		result.propertyChangeSupport=new PropertyChangeSupport(result);
377

  
378
		//TODO ?
379
		result.setId(0);
380
		result.setUuid(UUID.randomUUID());
381
		result.setCreated(new DateTime());
382
		result.setCreatedBy(null);
383

  
384
		//no changes to: -
385
		return result;
386
	}
365
    protected void clone(CdmBase clone){
366
        clone.setCreatedBy(createdBy);
367
        clone.setId(id);
368
        clone.propertyChangeSupport=new PropertyChangeSupport(clone);
369
        //Constructor Attributes
370
        //clone.setCreated(created);
371
        //clone.setUuid(getUuid());
372

  
373
    }
374

  
375
    /* (non-Javadoc)
376
     * @see java.lang.Object#clone()
377
     */
378
    @Override
379
    public Object clone() throws CloneNotSupportedException{
380
        CdmBase result = (CdmBase)super.clone();
381
        result.propertyChangeSupport=new PropertyChangeSupport(result);
382

  
383
        //TODO ?
384
        result.setId(0);
385
        result.setUuid(UUID.randomUUID());
386
        result.setCreated(new DateTime());
387
        result.setCreatedBy(null);
388

  
389
        //no changes to: -
390
        return result;
391
    }
387 392

  
388 393
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
1108 1108
        StringBuilder luceneQueryTemplate = new StringBuilder();
1109 1109

  
1110 1110
        luceneQueryTemplate.append("titleCache:%1$s ");
1111
        luceneQueryTemplate.append("name:%1$s").append(" ");
1111
        // common name
1112
        if(languages == null || languages.size() == 0){
1113
            luceneQueryTemplate.append("name:%1$s ");
1114
        } else {
1115
            luceneQueryTemplate.append("(name:%1$s AND (");
1116
            for(Language lang : languages){
1117
                luceneQueryTemplate.append(" language.label:" + lang.getLabel());
1118
            }
1119
            luceneQueryTemplate.append("))");
1120
        }
1112 1121
        // text field from TextData
1113 1122
        appendLocalizedFieldQuery("text", languages, luceneQueryTemplate).append(" ");
1114 1123
        // state field from CategoricalData
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.java
22 22

  
23 23
import org.apache.commons.lang.RandomStringUtils;
24 24
import org.apache.log4j.Logger;
25
import org.apache.lucene.document.Document;
25 26
import org.apache.lucene.index.CorruptIndexException;
26 27
import org.apache.lucene.queryParser.ParseException;
27 28
import org.junit.Assert;
......
168 169
    @SuppressWarnings("rawtypes")
169 170
    @Test
170 171
    @DataSet
172
    public final void testFindByDescriptionElementFullText_CommonName() throws CorruptIndexException, IOException, ParseException {
173

  
174
        refreshLuceneIndex();
175

  
176
        Pager<SearchResult<TaxonBase>> pager;
177

  
178
        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", null, null, null, null, null);
179
        Assert.assertEquals("Expecting one entity when searching for CommonTaxonName", Integer.valueOf(1), pager.getCount());
180

  
181
        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", Arrays.asList(new Language[]{Language.GERMAN()}), null, null, null, null);
182
        Assert.assertEquals("Expecting one entity when searching in German", Integer.valueOf(1), pager.getCount());
183

  
184
        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", Arrays.asList(new Language[]{Language.RUSSIAN()}), null, null, null, null);
185
        Assert.assertEquals("Expecting no entity when searching in Russian", Integer.valueOf(0), pager.getCount());
186
    }
187

  
188
    @SuppressWarnings("rawtypes")
189
    @Test
190
    @DataSet
191
    @Ignore
171 192
    public final void testFindByDescriptionElementFullText_TextData() throws CorruptIndexException, IOException, ParseException {
172 193

  
173 194
        refreshLuceneIndex();
......
199 220
        Assert.assertEquals("Expecting one entity", Integer.valueOf(1), pager.getCount());
200 221
        Assert.assertEquals("Abies balsamea sec. ", pager.getRecords().get(0).getEntity().getTitleCache());
201 222

  
202
        // modify the taxon
203
        TaxonBase taxon = pager.getRecords().get(0).getEntity();
223
        //
224
        // modify the DescriptionElement
225
        pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", Arrays.asList(new Language[]{Language.GERMAN(), Language.RUSSIAN()}), null, null, null, null);
226
        Document indexDocument = pager.getRecords().get(0).getDoc();
227
        String[] uuidStrings = indexDocument.getValues("uuid");
228
        // is only one uuid!
229
        DescriptionElementBase textData = descriptionService.getDescriptionElementByUuid(UUID.fromString(uuidStrings[0]));
204 230

  
205
        String newName = "Quercus robur";
206
        taxon.setTitleCache(newName + " sec. ", true);
231
        ((TextData)textData).removeText(Language.GERMAN());
232
        ((TextData)textData).putText(Language.SPANISH_CASTILIAN(), "abeto balsámico");
233

  
234
        descriptionService.saveDescriptionElement(textData);
207 235

  
208
        taxonService.saveOrUpdate(taxon);
209 236
        commitAndStartNewTransaction(null);
237
        //
238
        pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", Arrays.asList(new Language[]{Language.GERMAN(), Language.RUSSIAN()}), null, null, null, null);
239
        Assert.assertEquals("The german 'Balsam-Tanne' TextData should no longer be indexed", Integer.valueOf(0), pager.getCount());
240
        pager = taxonService.findByDescriptionElementFullText(TextData.class, "balsámico", Arrays.asList(new Language[]{Language.SPANISH_CASTILIAN()}), null, null, null, null);
241
        Assert.assertEquals("expecting to find the  SPANISH_CATALAN 'abeto balsámico'", Integer.valueOf(1), pager.getCount());
210 242

  
211
        taxon = taxonService.load(taxon.getUuid());
212
        Assert.assertEquals(newName + " sec. ", taxon.getTitleCache());
243
        //
244
        // modify the DescriptionElement via the Description object
245

  
246
//        String newName = "Quercus robur";
247
//        taxon.setTitleCache(newName + " sec. ", true);
248
//
249
//        taxonService.saveOrUpdate(taxon);
250
//        commitAndStartNewTransaction(null);
251
//
252
//        taxon = taxonService.load(taxon.getUuid());
253
//        Assert.assertEquals(newName + " sec. ", taxon.getTitleCache());
213 254
    }
214 255

  
215 256
    @SuppressWarnings("rawtypes")
......
228 269
        statedata.putModifyingText(Language.ENGLISH(), "always, even during winter");
229 270
        cdata.addState(statedata);
230 271
        d_abies_balsamea.addElement(cdata);
231
        
272

  
232 273
        termService.save(state);
233 274
        descriptionService.save(d_abies_balsamea);
234 275

  
......
246 287
        Assert.assertEquals("Abies balsamea sec. ", pager.getRecords().get(0).getDoc().get("inDescription.taxon.titleCache"));
247 288

  
248 289

  
249
        // modify the taxon
290
        //TODO modify the StateData
250 291
        TaxonBase taxon = pager.getRecords().get(0).getEntity();
251 292

  
252 293
        String newName = "Quercus robur";

Also available in: Unified diff