hide term vocabulary constructors and create factory methods instead
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / TermVocabulary.java
index a71dbfa7901eabc8b9d50a0eea911bbc6b881b5f..de46f8749b5b8b6102fcdc8e1687f82e0cee707c 100644 (file)
@@ -38,6 +38,9 @@ import org.hibernate.annotations.Cascade;
 import org.hibernate.annotations.CascadeType;
 import org.hibernate.annotations.Type;
 import org.hibernate.envers.Audited;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
 
 
 /**
@@ -54,6 +57,7 @@ import org.hibernate.envers.Audited;
 })
 @XmlRootElement(name = "TermVocabulary")
 @Entity
+@Indexed(index = "eu.etaxonomy.cdm.model.common.TermVocabulary")
 @Audited
 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
 public class TermVocabulary<T extends DefinedTermBase> extends TermBase implements Iterable<T> {
@@ -65,6 +69,7 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
        // Software can go and grap these terms incl labels and description. 
        // UUID needed? Further vocs can be setup through our own ontology.
        @XmlElement(name = "TermSourceURI")
+       @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED)
        private String termSourceUri;
        
 
@@ -76,8 +81,28 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
     @OneToMany(mappedBy="vocabulary", fetch=FetchType.LAZY, targetEntity = DefinedTermBase.class)
        @Type(type="DefinedTermBase")
        @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
+       @IndexedEmbedded(depth = 2)
        protected Set<T> terms = getNewTermSet();
        
+// ********************************* FACTORY METHODS *****************************************/
+
+       public static TermVocabulary NewInstance(String description, String label, String abbrev, String termSourceUri){
+               return new TermVocabulary(description, label, abbrev, termSourceUri);
+       }
+       
+// ************************* CONSTRUCTOR *************************************************     
+
+       protected TermVocabulary() {
+       }
+       
+       protected TermVocabulary(String term, String label, String labelAbbrev, String termSourceUri) {
+               super(term, label, labelAbbrev);
+               setTermSourceUri(termSourceUri);
+       }
+       
+
+// ******************* METHODS *************************************************/      
+       
        public T findTermByUuid(UUID uuid){
                for(T t : terms) {
                        if(t.getUuid().equals(uuid)) {
@@ -87,15 +112,6 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
                return null;
        }
 
-       public TermVocabulary(String term, String label, String labelAbbrev, String termSourceUri) {
-               super(term, label, labelAbbrev);
-               setTermSourceUri(termSourceUri);
-       }
-       
-       public TermVocabulary() {
-               // TODO Auto-generated constructor stub
-       }
-       
        @Transient
        Set<T> getNewTermSet() {
                return new HashSet<T>();
@@ -110,8 +126,8 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
                this.terms.add(term);
        }
        public void removeTerm(T term) {
-               term.setVocabulary(null);
                this.terms.remove(term);
+               term.setVocabulary(null);
        }
 
        public String getTermSourceUri() {
@@ -122,24 +138,6 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
        }
        
        
-//     // inner iterator class for the iterable interface
-//     private class TermIterator<T> implements Iterator<T> {
-//                // FIXME: using a list here is probably not safe. Sth passed by value, an array, would be better
-//                // but arrays cause generics problems: http://forum.java.sun.com/thread.jspa?threadID=651276&messageID=3832182
-//                // hack for now ;(
-//                private Set<T> array;
-//                private int i= 0;
-//                // ctor
-//                public TermIterator(Set<T> array) {
-//                   // check for null being passed in etc.
-//                   this.array= array;
-//                }
-//                // interface implementation
-//                public boolean hasNext() { return i < array.size(); }
-//                public T next() { return array.get(i++); }
-//                public void remove() { throw new UnsupportedOperationException(); }
-//     }
-
        public Iterator<T> iterator() {
                return terms.iterator();  // OLD: new TermIterator<T>(this.terms);
        }
@@ -169,7 +167,7 @@ public class TermVocabulary<T extends DefinedTermBase> extends TermBase implemen
         * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.util.List)
         */
        public TermVocabulary<T> readCsvLine(List<String> csvLine) {
-               return readCsvLine(csvLine, Language.ENGLISH());
+               return readCsvLine(csvLine, Language.CSV_LANGUAGE());
        }
        
        public TermVocabulary<T> readCsvLine(List<String> csvLine, Language lang) {