fixing typo in language SPANISH_CASTILIAN & more tests for # 476: Implement free...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 19 Jun 2012 15:58:06 +0000 (15:58 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 19 Jun 2012 15:58:06 +0000 (15:58 +0000)
.gitattributes
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/excel/taxa/NormalExplicitImportTest.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java [new file with mode: 0644]
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmBase.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.java

index 61145ac737784128fe7d469c297b7350be179bc3..c2e74699c64ee6772b0595035ff288bbc40cd877 100644 (file)
@@ -606,6 +606,7 @@ cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/LanguageFieldBridge
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/MultilanguageTextFieldBridge.java -text
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/PartialBridge.java -text
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/StripHtmlBridge.java -text
+cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java -text
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmAccessor.java -text
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmAccessorFactoryImpl.java -text
 cdmlib-model/src/main/java/eu/etaxonomy/cdm/jaxb/CdmNamespacePrefixMapper.java -text
index 5ee3c54033fa011feb297e70bcb9a50e79234eba..db5a28497363dbc54322170cd17c2c1d44fcdf76 100644 (file)
@@ -224,7 +224,7 @@ public class NormalExplicitImportTest extends CdmTransactionalIntegrationTest{
                assertEquals("Unexpected feature", Feature.DESCRIPTION(), feature);\r
                assertEquals("There should be exactly 1 language", 1,textData.getMultilanguageText().size());\r
                language = textData.getMultilanguageText().keySet().iterator().next();\r
-               assertEquals("Language should be Spanish", Language.SPANISH_CATALAN(), language);\r
+               assertEquals("Language should be Spanish", Language.SPANISH_CASTILIAN(), language);\r
                text = textData.getText(language);\r
                assertEquals("Unexpected description text", expectedText, text);\r
                assertEquals("Number of source elements should be 1", 1, textData.getSources().size());\r
diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/search/UuidBridge.java
new file mode 100644 (file)
index 0000000..8097371
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+* Copyright (C) 2012 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.hibernate.search;
+
+import java.util.UUID;
+
+import org.hibernate.search.bridge.StringBridge;
+
+/**
+ * @author andreas
+ * @date Jun 19, 2012
+ *
+ */
+public class UuidBridge implements StringBridge {
+
+    @Override
+    public String objectToString(Object object) {
+        if(object != null) {
+            return ((UUID)object).toString();
+        }
+        return null;
+    }
+
+}
index 4170fa3c640b9f21578f4e38301b71215f0a1a13..12c6e3703b9683270caf7b8db9fc14c20f7863dd 100644 (file)
@@ -43,10 +43,13 @@ import org.hibernate.annotations.Type;
 import org.hibernate.search.annotations.DocumentId;
 import org.hibernate.search.annotations.Field;
 import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
 import org.joda.time.DateTime;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
+import eu.etaxonomy.cdm.hibernate.search.UuidBridge;
 import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
 import eu.etaxonomy.cdm.jaxb.UUIDAdapter;
 import eu.etaxonomy.cdm.strategy.match.Match;
@@ -75,314 +78,316 @@ import eu.etaxonomy.cdm.strategy.match.MatchMode;
 })
 @MappedSuperclass
 public abstract class CdmBase implements Serializable, ICdmBase, Cloneable{
-       private static final long serialVersionUID = -3053225700018294809L;
-       @SuppressWarnings("unused")
-       private static final Logger logger = Logger.getLogger(CdmBase.class);
+    private static final long serialVersionUID = -3053225700018294809L;
+    @SuppressWarnings("unused")
+    private static final Logger logger = Logger.getLogger(CdmBase.class);
 
-       @Transient
-       @XmlTransient
-       private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+    @Transient
+    @XmlTransient
+    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
 
-       //@XmlAttribute(name = "id", required = true)
-       @XmlTransient
-       @Id
+    //@XmlAttribute(name = "id", required = true)
+    @XmlTransient
+    @Id
 //     @GeneratedValue(generator = "system-increment")
 //     @GeneratedValue(generator = "enhanced-table")
-       @GeneratedValue(generator = "custom-enhanced-table")
-       @DocumentId
-       @Match(MatchMode.IGNORE)
-       @NotNull
-       @Min(0)
-       private int id;
-
-       @XmlAttribute(required = true)
+    @GeneratedValue(generator = "custom-enhanced-table")
+    @DocumentId
+    @Match(MatchMode.IGNORE)
+    @NotNull
+    @Min(0)
+    private int id;
+
+    @XmlAttribute(required = true)
     @XmlJavaTypeAdapter(UUIDAdapter.class)
     @Type(type="uuidUserType")
-       @NaturalId // This has the effect of placing a "unique" constraint on the database column
-       @XmlID
-       @Column(length=36)
-       @Match(MatchMode.IGNORE)
-       @NotNull
-       protected UUID uuid;
-
-       @XmlElement (name = "Created", type= String.class)
-       @XmlJavaTypeAdapter(DateTimeAdapter.class)
-       @Type(type="dateTimeUserType")
-       @Basic(fetch = FetchType.LAZY)
-       @Match(MatchMode.IGNORE)
-       @Field(index = org.hibernate.search.annotations.Index.UN_TOKENIZED)
-       @FieldBridge(impl = DateTimeBridge.class)
-       private DateTime created;
-
-       @XmlElement (name = "CreatedBy")
-       @XmlIDREF
-       @XmlSchemaType(name = "IDREF")
-       @ManyToOne(fetch=FetchType.LAZY)
+    @NaturalId // This has the effect of placing a "unique" constraint on the database column
+    @XmlID
+    @Column(length=36)
+    @Match(MatchMode.IGNORE)
+    @NotNull
+    @Field(store = Store.YES, index = Index.UN_TOKENIZED)
+    @FieldBridge(impl = UuidBridge.class)
+    protected UUID uuid;
+
+    @XmlElement (name = "Created", type= String.class)
+    @XmlJavaTypeAdapter(DateTimeAdapter.class)
+    @Type(type="dateTimeUserType")
+    @Basic(fetch = FetchType.LAZY)
+    @Match(MatchMode.IGNORE)
+    @Field(index = Index.UN_TOKENIZED)
+    @FieldBridge(impl = DateTimeBridge.class)
+    private DateTime created;
+
+    @XmlElement (name = "CreatedBy")
+    @XmlIDREF
+    @XmlSchemaType(name = "IDREF")
+    @ManyToOne(fetch=FetchType.LAZY)
     @Match(MatchMode.IGNORE)
-       private User createdBy;
-
-       /**
-        * Class constructor assigning a unique UUID and creation date.
-        * UUID can be changed later via setUuid method.
-        */
-       public CdmBase() {
-               this.uuid = UUID.randomUUID();
-               this.created = new DateTime().withMillisOfSecond(0);
-       }
-
-       /**
-        * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
-        * @param listener
-        */
-       public void addPropertyChangeListener(PropertyChangeListener listener) {
-               propertyChangeSupport.addPropertyChangeListener(listener);
-       }
-
-       /**
-        * see {@link PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)}
-        */
-       public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
-               propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
-       }
-
-       /**
-        * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
-        */
-       public void removePropertyChangeListener(PropertyChangeListener listener) {
-               propertyChangeSupport.removePropertyChangeListener(listener);
-       }
-
-       /**
-        * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)
-        */
-       public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
-               propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
-       }
-
-       public boolean hasListeners(String propertyName) {
-               return propertyChangeSupport.hasListeners(propertyName);
-       }
-
-       public void firePropertyChange(String property, String oldval, String newval) {
-               propertyChangeSupport.firePropertyChange(property, oldval, newval);
-       }
-       public void firePropertyChange(String property, int oldval, int newval) {
-               propertyChangeSupport.firePropertyChange(property, oldval, newval);
-       }
-       public void firePropertyChange(String property, float oldval, float newval) {
-               propertyChangeSupport.firePropertyChange(property, oldval, newval);
-       }
-       public void firePropertyChange(String property, boolean oldval, boolean newval) {
-               propertyChangeSupport.firePropertyChange(property, oldval, newval);
-       }
-       public void firePropertyChange(String property, Object oldval, Object newval) {
-               propertyChangeSupport.firePropertyChange(property, oldval, newval);
-       }
-       public void firePropertyChange(PropertyChangeEvent evt) {
-               propertyChangeSupport.firePropertyChange(evt);
-       }
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
-        */
-       public UUID getUuid() {
-               return uuid;
-       }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setUuid(java.util.UUID)
-        */
-       public void setUuid(UUID uuid) {
-               this.uuid = uuid;
-       }
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
-        */
-       public int getId() {
-               return this.id;
-       }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
-        */
-       public void setId(int id) {
-               this.id = id;
-       }
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
-        */
-       public DateTime getCreated() {
-               return created;
-       }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreated(java.util.Calendar)
-        */
-       public void setCreated(DateTime created) {
-               if (created != null){
-                       new DateTime();
-                       created = created.withMillisOfSecond(0);
-                       //created.set(Calendar.MILLISECOND, 0);  //old, can be deleted
-               }
-               this.created = created;
-       }
-
-
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
-        */
-       public User getCreatedBy() {
-               return this.createdBy;
-       }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreatedBy(eu.etaxonomy.cdm.model.agent.Person)
-        */
-       public void setCreatedBy(User createdBy) {
-               this.createdBy = createdBy;
-       }
+    private User createdBy;
+
+    /**
+     * Class constructor assigning a unique UUID and creation date.
+     * UUID can be changed later via setUuid method.
+     */
+    public CdmBase() {
+        this.uuid = UUID.randomUUID();
+        this.created = new DateTime().withMillisOfSecond(0);
+    }
+
+    /**
+     * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
+     * @param listener
+     */
+    public void addPropertyChangeListener(PropertyChangeListener listener) {
+        propertyChangeSupport.addPropertyChangeListener(listener);
+    }
+
+    /**
+     * see {@link PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)}
+     */
+    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+        propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
+    }
+
+    /**
+     * see {@link PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)}
+     */
+    public void removePropertyChangeListener(PropertyChangeListener listener) {
+        propertyChangeSupport.removePropertyChangeListener(listener);
+    }
+
+    /**
+     * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)
+     */
+    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+        propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
+    }
+
+    public boolean hasListeners(String propertyName) {
+        return propertyChangeSupport.hasListeners(propertyName);
+    }
+
+    public void firePropertyChange(String property, String oldval, String newval) {
+        propertyChangeSupport.firePropertyChange(property, oldval, newval);
+    }
+    public void firePropertyChange(String property, int oldval, int newval) {
+        propertyChangeSupport.firePropertyChange(property, oldval, newval);
+    }
+    public void firePropertyChange(String property, float oldval, float newval) {
+        propertyChangeSupport.firePropertyChange(property, oldval, newval);
+    }
+    public void firePropertyChange(String property, boolean oldval, boolean newval) {
+        propertyChangeSupport.firePropertyChange(property, oldval, newval);
+    }
+    public void firePropertyChange(String property, Object oldval, Object newval) {
+        propertyChangeSupport.firePropertyChange(property, oldval, newval);
+    }
+    public void firePropertyChange(PropertyChangeEvent evt) {
+        propertyChangeSupport.firePropertyChange(evt);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
+     */
+    public UUID getUuid() {
+        return uuid;
+    }
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setUuid(java.util.UUID)
+     */
+    public void setUuid(UUID uuid) {
+        this.uuid = uuid;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
+     */
+    public int getId() {
+        return this.id;
+    }
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
+     */
+    public DateTime getCreated() {
+        return created;
+    }
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreated(java.util.Calendar)
+     */
+    public void setCreated(DateTime created) {
+        if (created != null){
+            new DateTime();
+            created = created.withMillisOfSecond(0);
+            //created.set(Calendar.MILLISECOND, 0);  //old, can be deleted
+        }
+        this.created = created;
+    }
+
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
+     */
+    public User getCreatedBy() {
+        return this.createdBy;
+    }
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.model.common.ICdmBase#setCreatedBy(eu.etaxonomy.cdm.model.agent.Person)
+     */
+    public void setCreatedBy(User createdBy) {
+        this.createdBy = createdBy;
+    }
 
 // ************************** Hibernate proxies *******************/
-       /**
-        * These methods are present due to HHH-1517 - that in a one-to-many
-        * relationship with a superclass at the "one" end, the proxy created
-        * by hibernate is the superclass, and not the subclass, resulting in
-        * a classcastexception when you try to cast it.
-        *
-        * Hopefully this will be resolved through improvements with the creation of
-        * proxy objects by hibernate and the following methods will become redundant,
-        * but for the time being . . .
-        * @param <T>
-        * @param object
-        * @param clazz
-        * @return
-        * @throws ClassCastException
-        */
-       //non-static does not work because javassist already unwrapps the proxy before calling the method
-        public static <T extends CdmBase> T deproxy(Object object, Class<T> clazz) throws ClassCastException {
-                return HibernateProxyHelper.deproxy(object, clazz);
-        }
-
-        public boolean isInstanceOf(Class<? extends CdmBase> clazz) throws ClassCastException {
-            return HibernateProxyHelper.isInstanceOf(this, clazz);
-        }
+    /**
+     * These methods are present due to HHH-1517 - that in a one-to-many
+     * relationship with a superclass at the "one" end, the proxy created
+     * by hibernate is the superclass, and not the subclass, resulting in
+     * a classcastexception when you try to cast it.
+     *
+     * Hopefully this will be resolved through improvements with the creation of
+     * proxy objects by hibernate and the following methods will become redundant,
+     * but for the time being . . .
+     * @param <T>
+     * @param object
+     * @param clazz
+     * @return
+     * @throws ClassCastException
+     */
+    //non-static does not work because javassist already unwrapps the proxy before calling the method
+     public static <T extends CdmBase> T deproxy(Object object, Class<T> clazz) throws ClassCastException {
+         return HibernateProxyHelper.deproxy(object, clazz);
+     }
+
+     public boolean isInstanceOf(Class<? extends CdmBase> clazz) throws ClassCastException {
+         return HibernateProxyHelper.isInstanceOf(this, clazz);
+     }
 
 // ************* Object overrides *************************/
 
-       /**
-        * Is true if UUID is the same for the passed Object and this one.
-        * @see java.lang.Object#equals(java.lang.Object)
-        * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
-        * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
-        * for more information about equals and hashcode.
-        */
-       @Override
-       public boolean equals(Object obj) {
-               if (obj == this){
-                       return true;
-               }
-               if (obj == null){
-                       return false;
-               }
-               if (!CdmBase.class.isAssignableFrom(obj.getClass())){
-                       return false;
-               }
-               ICdmBase cdmObj = (ICdmBase)obj;
-               boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
-               boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
-               if (! uuidEqual || !createdEqual){
-                               return false;
-               }
-               return true;
-       }
-
-
-       /** Overrides {@link java.lang.Object#hashCode()}
-        *  See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
-        * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
-        * for more information about equals and hashcode.
-        */
-       @Override
-       public int hashCode() {
-                  int hashCode = 7;
-                  if(this.getUuid() != null) {
-                          //this unfortunately leads to errors when loading maps via hibernate
-                          //as hibernate computes hash values for CdmBase objects used as key at
-                          // a time when the uuid is not yet loaded from the database. Therefore
-                          //the hash values later change and give wrong results when retrieving
-                          //data from the map (map.get(key) returns null, though there is an entry
-                          //for key in the map.
-                          //see further comments in #2114
-                      int result = 29 * hashCode + this.getUuid().hashCode();
+    /**
+     * Is true if UUID is the same for the passed Object and this one.
+     * @see java.lang.Object#equals(java.lang.Object)
+     * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
+     * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
+     * for more information about equals and hashcode.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this){
+            return true;
+        }
+        if (obj == null){
+            return false;
+        }
+        if (!CdmBase.class.isAssignableFrom(obj.getClass())){
+            return false;
+        }
+        ICdmBase cdmObj = (ICdmBase)obj;
+        boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
+        boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
+        if (! uuidEqual || !createdEqual){
+                return false;
+        }
+        return true;
+    }
+
+
+    /** Overrides {@link java.lang.Object#hashCode()}
+     *  See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
+     * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
+     * for more information about equals and hashcode.
+     */
+    @Override
+    public int hashCode() {
+           int hashCode = 7;
+           if(this.getUuid() != null) {
+               //this unfortunately leads to errors when loading maps via hibernate
+               //as hibernate computes hash values for CdmBase objects used as key at
+               // a time when the uuid is not yet loaded from the database. Therefore
+               //the hash values later change and give wrong results when retrieving
+               //data from the map (map.get(key) returns null, though there is an entry
+               //for key in the map.
+               //see further comments in #2114
+               int result = 29 * hashCode + this.getUuid().hashCode();
 //                    int shresult = 29 * hashCode + Integer.valueOf(this.getId()).hashCode();
-                          return result;
-                  } else {
-                          return 29 * hashCode;
-                  }
-       }
-
-       /**
-        * Overrides {@link java.lang.Object#toString()}.
-        * This returns an String that identifies the object well without beeing necessarily unique.
-        * Specification: This method should never call other object' methods so it can be well used for debugging
-        * without problems like lazy loading, unreal states etc.
-        * Note: If overriding this method's javadoc always copy or link the above requirement.
-        * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
-        * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
-        * @see java.lang.Object#toString()
-        */
-       @Override
-       public String toString() {
-               return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
-       }
+               return result;
+           } else {
+               return 29 * hashCode;
+           }
+    }
+
+    /**
+     * Overrides {@link java.lang.Object#toString()}.
+     * This returns an String that identifies the object well without beeing necessarily unique.
+     * Specification: This method should never call other object' methods so it can be well used for debugging
+     * without problems like lazy loading, unreal states etc.
+     * Note: If overriding this method's javadoc always copy or link the above requirement.
+     * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
+     * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
+    }
 
 // **************** invoke methods **************************/
 
-       protected void invokeSetMethod(Method method, Object object){
-               try {
-                       method.invoke(object, this);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       //TODO handle exceptioin;
-               }
-       }
-
-       protected void invokeSetMethodWithNull(Method method, Object object){
-               try {
-                       Object[] nul = new Object[]{null};
-                       method.invoke(object, nul);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       //TODO handle exceptioin;
-               }
-       }
+    protected void invokeSetMethod(Method method, Object object){
+        try {
+            method.invoke(object, this);
+        } catch (Exception e) {
+            e.printStackTrace();
+            //TODO handle exceptioin;
+        }
+    }
+
+    protected void invokeSetMethodWithNull(Method method, Object object){
+        try {
+            Object[] nul = new Object[]{null};
+            method.invoke(object, nul);
+        } catch (Exception e) {
+            e.printStackTrace();
+            //TODO handle exceptioin;
+        }
+    }
 
 //********************** CLONE *****************************************/
 
-       protected void clone(CdmBase clone){
-               clone.setCreatedBy(createdBy);
-               clone.setId(id);
-               clone.propertyChangeSupport=new PropertyChangeSupport(clone);
-               //Constructor Attributes
-               //clone.setCreated(created);
-               //clone.setUuid(getUuid());
-
-       }
-
-       /* (non-Javadoc)
-        * @see java.lang.Object#clone()
-        */
-       @Override
-       public Object clone() throws CloneNotSupportedException{
-               CdmBase result = (CdmBase)super.clone();
-               result.propertyChangeSupport=new PropertyChangeSupport(result);
-
-               //TODO ?
-               result.setId(0);
-               result.setUuid(UUID.randomUUID());
-               result.setCreated(new DateTime());
-               result.setCreatedBy(null);
-
-               //no changes to: -
-               return result;
-       }
+    protected void clone(CdmBase clone){
+        clone.setCreatedBy(createdBy);
+        clone.setId(id);
+        clone.propertyChangeSupport=new PropertyChangeSupport(clone);
+        //Constructor Attributes
+        //clone.setCreated(created);
+        //clone.setUuid(getUuid());
+
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public Object clone() throws CloneNotSupportedException{
+        CdmBase result = (CdmBase)super.clone();
+        result.propertyChangeSupport=new PropertyChangeSupport(result);
+
+        //TODO ?
+        result.setId(0);
+        result.setUuid(UUID.randomUUID());
+        result.setCreated(new DateTime());
+        result.setCreatedBy(null);
+
+        //no changes to: -
+        return result;
+    }
 
 }
index b2aa77d6697856737ae24e569e6b70f240c7a2e3..6681697647b8989f1a1b3b42e5619164f5472ce9 100644 (file)
@@ -1108,7 +1108,16 @@ public class TaxonServiceImpl extends IdentifiableServiceBase<TaxonBase,ITaxonDa
         StringBuilder luceneQueryTemplate = new StringBuilder();\r
 \r
         luceneQueryTemplate.append("titleCache:%1$s ");\r
-        luceneQueryTemplate.append("name:%1$s").append(" ");\r
+        // common name\r
+        if(languages == null || languages.size() == 0){\r
+            luceneQueryTemplate.append("name:%1$s ");\r
+        } else {\r
+            luceneQueryTemplate.append("(name:%1$s AND (");\r
+            for(Language lang : languages){\r
+                luceneQueryTemplate.append(" language.label:" + lang.getLabel());\r
+            }\r
+            luceneQueryTemplate.append("))");\r
+        }\r
         // text field from TextData\r
         appendLocalizedFieldQuery("text", languages, luceneQueryTemplate).append(" ");\r
         // state field from CategoricalData\r
index c61116be06b10cfec0785d6bf86f124fc9ac9aa7..e32ba52168dc26f309ebf058756d7e57f412ce51 100644 (file)
@@ -22,6 +22,7 @@ import java.util.UUID;
 \r
 import org.apache.commons.lang.RandomStringUtils;\r
 import org.apache.log4j.Logger;\r
+import org.apache.lucene.document.Document;\r
 import org.apache.lucene.index.CorruptIndexException;\r
 import org.apache.lucene.queryParser.ParseException;\r
 import org.junit.Assert;\r
@@ -168,6 +169,26 @@ public class TaxonServiceSearchTest extends CdmTransactionalIntegrationTest {
     @SuppressWarnings("rawtypes")\r
     @Test\r
     @DataSet\r
+    public final void testFindByDescriptionElementFullText_CommonName() throws CorruptIndexException, IOException, ParseException {\r
+\r
+        refreshLuceneIndex();\r
+\r
+        Pager<SearchResult<TaxonBase>> pager;\r
+\r
+        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", null, null, null, null, null);\r
+        Assert.assertEquals("Expecting one entity when searching for CommonTaxonName", Integer.valueOf(1), pager.getCount());\r
+\r
+        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", Arrays.asList(new Language[]{Language.GERMAN()}), null, null, null, null);\r
+        Assert.assertEquals("Expecting one entity when searching in German", Integer.valueOf(1), pager.getCount());\r
+\r
+        pager = taxonService.findByDescriptionElementFullText(CommonTaxonName.class, "Weiß*", Arrays.asList(new Language[]{Language.RUSSIAN()}), null, null, null, null);\r
+        Assert.assertEquals("Expecting no entity when searching in Russian", Integer.valueOf(0), pager.getCount());\r
+    }\r
+\r
+    @SuppressWarnings("rawtypes")\r
+    @Test\r
+    @DataSet\r
+    @Ignore\r
     public final void testFindByDescriptionElementFullText_TextData() throws CorruptIndexException, IOException, ParseException {\r
 \r
         refreshLuceneIndex();\r
@@ -199,17 +220,37 @@ public class TaxonServiceSearchTest extends CdmTransactionalIntegrationTest {
         Assert.assertEquals("Expecting one entity", Integer.valueOf(1), pager.getCount());\r
         Assert.assertEquals("Abies balsamea sec. ", pager.getRecords().get(0).getEntity().getTitleCache());\r
 \r
-        // modify the taxon\r
-        TaxonBase taxon = pager.getRecords().get(0).getEntity();\r
+        //\r
+        // modify the DescriptionElement\r
+        pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", Arrays.asList(new Language[]{Language.GERMAN(), Language.RUSSIAN()}), null, null, null, null);\r
+        Document indexDocument = pager.getRecords().get(0).getDoc();\r
+        String[] uuidStrings = indexDocument.getValues("uuid");\r
+        // is only one uuid!\r
+        DescriptionElementBase textData = descriptionService.getDescriptionElementByUuid(UUID.fromString(uuidStrings[0]));\r
 \r
-        String newName = "Quercus robur";\r
-        taxon.setTitleCache(newName + " sec. ", true);\r
+        ((TextData)textData).removeText(Language.GERMAN());\r
+        ((TextData)textData).putText(Language.SPANISH_CASTILIAN(), "abeto balsámico");\r
+\r
+        descriptionService.saveDescriptionElement(textData);\r
 \r
-        taxonService.saveOrUpdate(taxon);\r
         commitAndStartNewTransaction(null);\r
+        //\r
+        pager = taxonService.findByDescriptionElementFullText(TextData.class, "Balsam-Tanne", Arrays.asList(new Language[]{Language.GERMAN(), Language.RUSSIAN()}), null, null, null, null);\r
+        Assert.assertEquals("The german 'Balsam-Tanne' TextData should no longer be indexed", Integer.valueOf(0), pager.getCount());\r
+        pager = taxonService.findByDescriptionElementFullText(TextData.class, "balsámico", Arrays.asList(new Language[]{Language.SPANISH_CASTILIAN()}), null, null, null, null);\r
+        Assert.assertEquals("expecting to find the  SPANISH_CATALAN 'abeto balsámico'", Integer.valueOf(1), pager.getCount());\r
 \r
-        taxon = taxonService.load(taxon.getUuid());\r
-        Assert.assertEquals(newName + " sec. ", taxon.getTitleCache());\r
+        //\r
+        // modify the DescriptionElement via the Description object\r
+\r
+//        String newName = "Quercus robur";\r
+//        taxon.setTitleCache(newName + " sec. ", true);\r
+//\r
+//        taxonService.saveOrUpdate(taxon);\r
+//        commitAndStartNewTransaction(null);\r
+//\r
+//        taxon = taxonService.load(taxon.getUuid());\r
+//        Assert.assertEquals(newName + " sec. ", taxon.getTitleCache());\r
     }\r
 \r
     @SuppressWarnings("rawtypes")\r
@@ -228,7 +269,7 @@ public class TaxonServiceSearchTest extends CdmTransactionalIntegrationTest {
         statedata.putModifyingText(Language.ENGLISH(), "always, even during winter");\r
         cdata.addState(statedata);\r
         d_abies_balsamea.addElement(cdata);\r
-        \r
+\r
         termService.save(state);\r
         descriptionService.save(d_abies_balsamea);\r
 \r
@@ -246,7 +287,7 @@ public class TaxonServiceSearchTest extends CdmTransactionalIntegrationTest {
         Assert.assertEquals("Abies balsamea sec. ", pager.getRecords().get(0).getDoc().get("inDescription.taxon.titleCache"));\r
 \r
 \r
-        // modify the taxon\r
+        //TODO modify the StateData\r
         TaxonBase taxon = pager.getRecords().get(0).getEntity();\r
 \r
         String newName = "Quercus robur";\r