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;
/**
})
@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> {
// 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;
@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)) {
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>();
this.terms.add(term);
}
public void removeTerm(T term) {
- term.setVocabulary(null);
this.terms.remove(term);
+ term.setVocabulary(null);
}
public String getTermSourceUri() {
}
-// // 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);
}
* @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) {