1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.filter;
|
11
|
|
12
|
import java.io.Serializable;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
16
|
import eu.etaxonomy.cdm.model.common.ITreeNode;
|
17
|
|
18
|
/**
|
19
|
* Preliminary class which represents a filter for an export on a CdmBase object, combined
|
20
|
* with a logical operation.
|
21
|
* Added to an existing filter it may e.g. allow operations like "filter1 or filter(TaxonNode:123)"
|
22
|
* It includes the logical operators as enums.
|
23
|
*
|
24
|
* @author a.mueller
|
25
|
*
|
26
|
*/
|
27
|
public class LogicFilter<T extends CdmBase> implements Serializable{
|
28
|
|
29
|
private static final long serialVersionUID = 802334066143796153L;
|
30
|
|
31
|
public enum Op{
|
32
|
OR, AND, NOT;
|
33
|
// OR(" OR "), AND(" AND "), NOT(" NOT ");
|
34
|
// String str;
|
35
|
//
|
36
|
// private Op(String opStr){
|
37
|
// str = opStr;
|
38
|
// }
|
39
|
}
|
40
|
|
41
|
private static final Op defaultOperator = Op.OR;
|
42
|
|
43
|
private Op operator = defaultOperator;
|
44
|
|
45
|
private UUID uuid;
|
46
|
private String treeIndex;
|
47
|
private Class<? extends T> clazz;
|
48
|
|
49
|
// private boolean hasUncheckedUuid = false;
|
50
|
|
51
|
|
52
|
|
53
|
public LogicFilter(T cdmBase){
|
54
|
this(cdmBase, defaultOperator);
|
55
|
}
|
56
|
|
57
|
public LogicFilter(Class<? extends T> clazz, UUID uuid, Op operator) {
|
58
|
// hasUncheckedUuid = true;
|
59
|
if (uuid == null){
|
60
|
throw new IllegalArgumentException("Null uuid not allowed as filter criteria");
|
61
|
}
|
62
|
if (operator == null){
|
63
|
operator = defaultOperator;
|
64
|
}
|
65
|
|
66
|
this.uuid = uuid;
|
67
|
this.operator = operator;
|
68
|
this.clazz = clazz;
|
69
|
|
70
|
}
|
71
|
|
72
|
public <S extends T> LogicFilter(S cdmBase, Op operator){
|
73
|
if (cdmBase == null){
|
74
|
throw new IllegalArgumentException("Null object not allowed as filter criteria");
|
75
|
}
|
76
|
if (operator == null){
|
77
|
operator = defaultOperator;
|
78
|
}
|
79
|
cdmBase = CdmBase.deproxy(cdmBase);
|
80
|
|
81
|
this.uuid = cdmBase.getUuid();
|
82
|
this.operator = operator;
|
83
|
this.clazz = (Class)cdmBase.getClass();
|
84
|
if (cdmBase instanceof ITreeNode){
|
85
|
this.treeIndex = ((ITreeNode<?>)cdmBase).treeIndex();
|
86
|
}
|
87
|
}
|
88
|
|
89
|
|
90
|
|
91
|
public Op getOperator() {
|
92
|
return operator;
|
93
|
}
|
94
|
|
95
|
public UUID getUuid() {
|
96
|
return uuid;
|
97
|
}
|
98
|
|
99
|
public String getTreeIndex() {
|
100
|
return treeIndex;
|
101
|
}
|
102
|
|
103
|
public Class<? extends T> getClazz() {
|
104
|
return clazz;
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* TODO try to remove public setter
|
109
|
* @deprecated for internal use only
|
110
|
*/
|
111
|
|
112
|
@Deprecated
|
113
|
public void setTreeIndex(String treeIndex) {
|
114
|
this.treeIndex = treeIndex;
|
115
|
}
|
116
|
|
117
|
// **************************** to String *******************************************/
|
118
|
|
119
|
@Override
|
120
|
public String toString() {
|
121
|
return "LogicFilter [operator=" + operator + ", uuid=" + uuid + ", treeIndex=" + treeIndex + ", clazz=" + clazz
|
122
|
+ "]";
|
123
|
}
|
124
|
|
125
|
|
126
|
}
|
127
|
|