Project

General

Profile

Download (2.85 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2022 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.filter;
10

    
11
import java.io.Serializable;
12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import eu.etaxonomy.cdm.filter.LogicFilter.Op;
18
import eu.etaxonomy.cdm.model.term.TermType;
19
import eu.etaxonomy.cdm.model.term.TermVocabulary;
20

    
21
/**
22
 * Filter used e.g. for additivity ontology import. Should work similar to TaxonNodeFilter.
23
 *
24
 * @author a.mueller
25
 * @date 02.09.2022
26
 */
27
public class VocabularyFilter implements Serializable {
28

    
29
    private static final long serialVersionUID = -8054720226785479796L;
30

    
31
    private List<TermType> termTypes = new ArrayList<>();
32
    private List<LogicFilter<TermVocabulary>> termVocabularies = new ArrayList<>();
33

    
34
    private ORDER orderBy = null;
35

    
36
    public enum ORDER{
37
        ID("voc.id"),
38
//        TREEINDEX("tn.treeIndex"),
39
//        TREEINDEX_DESC("tn.treeIndex DESC")
40
        ;
41
        String hql;
42
        private ORDER(String hql){
43
            this.hql = hql;
44
        }
45
        public String getHql(){
46
            return hql;
47
        }
48
    }
49

    
50
// *************************** FACTORY ********************************/
51

    
52
    public static VocabularyFilter NewInstance(){
53
        return new VocabularyFilter();
54
    }
55

    
56
    public static VocabularyFilter NewTermTypeInstance(TermType termType){
57
        return new VocabularyFilter().orTermType(termType);
58
    }
59

    
60
// ******************** CONSTRUCTOR ************************/
61

    
62
    private VocabularyFilter() {
63
        reset();
64
    }
65

    
66
// ******************** reset *****************************/
67

    
68
    public void reset(){
69
        resetTermTypes();
70
        resetTermVocabularies();
71
    }
72

    
73
    private void resetTermTypes() {
74
        termTypes = new ArrayList<>();
75
    }
76

    
77
    private void resetTermVocabularies() {
78
        termVocabularies = new ArrayList<>();
79
    }
80

    
81
// ******************** OR, XXX ****************************************/
82

    
83
    public VocabularyFilter orTermType(TermType termType){
84
//        termTypes.add( new LogicFilter<>(termType, Op.OR));
85
        termTypes.add(termType);
86
        return this;
87
    }
88

    
89
    public VocabularyFilter orVocabulary(UUID uuid){
90
        termVocabularies.add( new LogicFilter<>(TermVocabulary.class, uuid, Op.OR));
91
        return this;
92
    }
93

    
94

    
95
    public List<LogicFilter<TermVocabulary>>getTermVocabulariesFilter(){
96
        return Collections.unmodifiableList(termVocabularies);
97
    }
98

    
99
    public List<TermType>getTermTypesFilter(){
100
        return Collections.unmodifiableList(termTypes);
101
    }
102

    
103
    public ORDER getOrderBy() {
104
        return orderBy;
105
    }
106
    public void setOrder(ORDER orderBy) {
107
        this.orderBy = orderBy;
108
    }
109
}
(3-3/3)