Project

General

Profile

Revision 18dfe77e

ID18dfe77e69ad8ad52689f0835c15888b6bd6cbbe
Parent 502547d1
Child ec978653

Added by Andreas Müller 12 months ago

ref #6794 move term relations down to TermCollection

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/ITermGraph.java
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.model.term;
10

  
11
import java.util.Set;
12

  
13
/**
14
 * @author a.mueller
15
 * @since 11.03.2019
16
 *
17
 */
18
public interface ITermGraph<TERM extends DefinedTermBase, REL extends TermRelationBase> {
19

  
20
    /**
21
     * @return
22
     */
23
    Set<REL> getTermRelations();
24

  
25
    //not yet pulic
26
//    /**
27
//     * @param termRelations
28
//     */
29
//    void setTermRelations(Set<REL> termRelations);
30

  
31
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/OrderedTermVocabulary.java
37 37
@XmlRootElement(name = "OrderedTermVocabulary")
38 38
@Entity
39 39
@Audited
40
public class OrderedTermVocabulary<T extends OrderedTermBase> extends TermVocabulary<T> {
40
public class OrderedTermVocabulary<T extends OrderedTermBase>
41
        extends TermVocabulary<T>
42
        implements ITermGraph<T, TermTreeNode>    {
43

  
44

  
41 45
	private static final long serialVersionUID = 7871741306306371242L;
42 46
	@SuppressWarnings("unused")
43 47
	private static final Logger logger = Logger.getLogger(OrderedTermVocabulary.class);
......
296 300
		return sortedSet;
297 301
	}
298 302

  
303
    @Override
304
    public Set<TermTreeNode> getTermRelations() {
305
        return super.termRelations();
306
    }
307
    /**
308
     * For now protected to avoid type checking etc. Might become
309
     * public in future
310
     * @param termRelations
311
     */
312
//    @Override  //not yet public
313
    protected void setTermRelations(Set<TermTreeNode> termRelations) {
314
        super.termRelations(termRelations);
315
    }
316

  
299 317
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermCollection.java
8 8
*/
9 9
package eu.etaxonomy.cdm.model.term;
10 10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
11 14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
12 16
import javax.persistence.Inheritance;
13 17
import javax.persistence.InheritanceType;
18
import javax.persistence.OneToMany;
14 19
import javax.persistence.Table;
15 20
import javax.xml.bind.annotation.XmlAccessType;
16 21
import javax.xml.bind.annotation.XmlAccessorType;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlElementWrapper;
24
import javax.xml.bind.annotation.XmlIDREF;
25
import javax.xml.bind.annotation.XmlSchemaType;
17 26
import javax.xml.bind.annotation.XmlType;
18 27

  
28
import org.hibernate.annotations.Cascade;
29
import org.hibernate.annotations.CascadeType;
19 30
import org.hibernate.envers.Audited;
31
import org.hibernate.search.annotations.IndexedEmbedded;
20 32

  
21 33
/**
22 34
 * @author a.mueller
......
24 36
 */
25 37
@XmlAccessorType(XmlAccessType.FIELD)
26 38
@XmlType(name = "TermCollection", propOrder = {
27
//    "termSourceUri",
28
//    "terms"
39
        "termRelations",
40
        "allowDuplicates",
41
        "orderRelevant",
42
        "isFlat"
29 43
})
30 44
@Entity
31 45
@Audited
32 46
@Table(name="TermCollection")
33 47
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
34
public abstract class TermCollection<T extends DefinedTermBase>
48
public abstract class TermCollection<TERM extends DefinedTermBase, REL extends TermRelationBase>
35 49
            extends TermBase{
36 50

  
37 51
    private static final long serialVersionUID = 6102175902060054329L;
38 52

  
53

  
54
    @XmlElementWrapper(name = "TermRelations")
55
    @XmlElement(name = "TermRelation")
56
    @XmlIDREF
57
    @XmlSchemaType(name = "IDREF")
58
    @OneToMany(mappedBy="graph", fetch=FetchType.LAZY, targetEntity = TermRelationBase.class)
59
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
60
    @IndexedEmbedded(depth = 2)
61
    private Set<REL> termRelations = new HashSet<>();
62

  
63
    //#7372 indicates if this tree/graph allows duplicated terms/features
64
    private boolean allowDuplicates = false;
65

  
66
    private boolean orderRelevant = false;
67

  
68
    private boolean isFlat = false;
69

  
70

  
71
//*************************** CONSTRUCTOR *************************************/
72

  
39 73
    @SuppressWarnings("deprecation")
40 74
    protected TermCollection(){}
41 75

  
......
46 80
    protected TermCollection(TermType type, String term, String label, String labelAbbrev) {
47 81
        super(type, term, label, labelAbbrev);
48 82
    }
83

  
84
// ****************** GETTER / SETTER **********************************/
85

  
86
    public boolean isAllowDuplicates() {
87
        return allowDuplicates;
88
    }
89
    public void setAllowDuplicates(boolean allowDuplicates) {
90
        this.allowDuplicates = allowDuplicates;
91
    }
92

  
93
    public boolean isOrderRelevant() {
94
        return orderRelevant;
95
    }
96
    public void setOrderRelevant(boolean orderRelevant) {
97
        this.orderRelevant = orderRelevant;
98
    }
99

  
100
    public boolean isFlat() {
101
        return isFlat;
102
    }
103
    public void setFlat(boolean isFlat) {
104
        this.isFlat = isFlat;
105
    }
106

  
107
    /**
108
     * @Deprecated for use by defined subclasses only
109
     */
110
    @Deprecated
111
    protected Set<REL> termRelations() {
112
        return termRelations;
113
    }
114
    /**
115
     * @Deprecated for use by defined subclasses only
116
     */
117
    @Deprecated
118
    protected void termRelations(Set<REL> termRelations) {
119
        this.termRelations = termRelations;
120
    }
121

  
122

  
123

  
49 124
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermGraphBase.java
8 8
*/
9 9
package eu.etaxonomy.cdm.model.term;
10 10

  
11
import java.util.HashSet;
12 11
import java.util.Set;
13 12

  
14 13
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.OneToMany;
17 14
import javax.xml.bind.annotation.XmlAccessType;
18 15
import javax.xml.bind.annotation.XmlAccessorType;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlElementWrapper;
21
import javax.xml.bind.annotation.XmlIDREF;
22
import javax.xml.bind.annotation.XmlSchemaType;
23 16
import javax.xml.bind.annotation.XmlType;
24 17

  
25 18
import org.apache.log4j.Logger;
26
import org.hibernate.annotations.Cascade;
27
import org.hibernate.annotations.CascadeType;
28 19
import org.hibernate.envers.Audited;
29
import org.hibernate.search.annotations.IndexedEmbedded;
30 20

  
31 21
/**
32 22
 * @author a.mueller
......
34 24
 */
35 25
@XmlAccessorType(XmlAccessType.FIELD)
36 26
@XmlType(name = "TermGraph", propOrder = {
37
      "allowDuplicates",
38
      "orderRelevant",
39
      "isFlat"
27

  
40 28
})
41 29
@Entity
42 30
@Audited
43 31
public abstract class TermGraphBase<TERM extends DefinedTermBase, REL extends TermRelationBase> //<TERM, REL, TermGraphBase>
44
            extends TermCollection<TERM> {
32
            extends TermCollection<TERM, REL>
33
            implements ITermGraph<TERM, REL>{
45 34

  
46 35
    private static final long serialVersionUID = -704169783744494023L;
47 36

  
......
49 38
    private static final Logger logger = Logger.getLogger(TermGraphBase.class);
50 39

  
51 40

  
52
    @XmlElementWrapper(name = "TermRelations")
53
    @XmlElement(name = "TermRelation")
54
    @XmlIDREF
55
    @XmlSchemaType(name = "IDREF")
56
    @OneToMany(mappedBy="graph", fetch=FetchType.LAZY, targetEntity = TermRelationBase.class)
57
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
58
    @IndexedEmbedded(depth = 2)
59
    private Set<REL> termRelations = new HashSet<>();
60

  
61
    //#7372 indicates if this tree/graph allows duplicated terms/features
62
    private boolean allowDuplicates = false;
63

  
64
    private boolean orderRelevant = false;
65

  
66
    private boolean isFlat = false;
67 41

  
68 42
 // ******************** CONSTRUCTOR *************************************/
69 43

  
......
74 48
        super(termType);
75 49
    }
76 50

  
77
 // ****************** GETTER / SETTER **********************************/
78

  
79
    public boolean isAllowDuplicates() {
80
        return allowDuplicates;
81
    }
82
    public void setAllowDuplicates(boolean allowDuplicates) {
83
        this.allowDuplicates = allowDuplicates;
84
    }
85

  
86
    public boolean isOrderRelevant() {
87
        return orderRelevant;
88
    }
89
    public void setOrderRelevant(boolean orderRelevant) {
90
        this.orderRelevant = orderRelevant;
91
    }
92

  
93
    public boolean isFlat() {
94
        return isFlat;
95
    }
96
    public void setFlat(boolean isFlat) {
97
        this.isFlat = isFlat;
98
    }
99

  
100

  
101 51

  
52
    @Override
102 53
    public Set<REL> getTermRelations() {
103
        return termRelations;
54
        return super.termRelations();
104 55
    }
105 56
    /**
106 57
     * For now protected to avoid type checking etc. Might become
107 58
     * public in future
108 59
     * @param termRelations
109 60
     */
61
//    @Override  //not yet public
110 62
    protected void setTermRelations(Set<REL> termRelations) {
111
        this.termRelations = termRelations;
63
        super.termRelations(termRelations);
112 64
    }
113 65

  
66

  
114 67
    public abstract Set<TERM> getDistinctTerms();
115 68
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermRelationBase.java
41 41
 */
42 42
@XmlAccessorType(XmlAccessType.FIELD)
43 43
@XmlType(name = "TermRelationBase", propOrder = {
44
        "termTree",
44
        "graph",
45 45
        "termType",
46 46
        "term"
47 47
})
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermVocabulary.java
12 12

  
13 13
import java.net.URI;
14 14
import java.util.HashSet;
15
import java.util.Iterator;
16 15
import java.util.List;
17 16
import java.util.Set;
18 17
import java.util.SortedSet;
......
61 60
//@Indexed(index = "eu.etaxonomy.cdm.model.term.TermVocabulary")
62 61
@Audited
63 62
public class TermVocabulary<T extends DefinedTermBase>
64
        extends TermCollection<T>
65
        implements Iterable<T> {
63
        extends TermCollection<T,TermTreeNode> {
66 64

  
67 65
    private static final long serialVersionUID = 1925052321596648672L;
68 66
	private static final Logger logger = Logger.getLogger(TermVocabulary.class);
......
171 169
        return null;
172 170
    }
173 171

  
174
	@Override
175
    public Iterator<T> iterator() {
176
		return terms.iterator();  // OLD: new TermIterator<T>(this.terms);
177
	}
178

  
179 172
	public int size(){
180 173
		return terms.size();
181 174
	}
182 175

  
183

  
184 176
	/**
185 177
	 * Returns all terms of this vocabulary sorted by their representation defined by the given language.
186 178
	 * If such an representation does not exist, the representation of the default language is testing instead for ordering.
......
188 180
	 * @return
189 181
	 */
190 182
	public SortedSet<T> getTermsOrderedByLabels(Language language){
191
		TermLanguageComparator<T> comp = new TermLanguageComparator<T>();
183
		TermLanguageComparator<T> comp = new TermLanguageComparator<>();
192 184
		comp.setCompareLanguage(language);
193 185

  
194
		SortedSet<T> result = new TreeSet<T>(comp);
186
		SortedSet<T> result = new TreeSet<>(comp);
195 187
		result.addAll(getTerms());
196 188
		return result;
197 189
	}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)