Skip to content

Commit dc47aa5

Browse files
committed
Merge remote-tracking branch 'jlolling/master'
2 parents 8c9f0ef + 520f6da commit dc47aa5

File tree

1 file changed

+1
-135
lines changed

1 file changed

+1
-135
lines changed

src/main/java/de/jlo/talendcomp/google/analytics/ga4/v1/FilterExpressionBuilder.java

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import com.google.analytics.data.v1beta.Filter;
77
import com.google.analytics.data.v1beta.FilterExpression;
8-
import com.google.analytics.data.v1beta.FilterExpressionList;
98
import com.google.analytics.data.v1beta.NumericValue;
109
import com.google.analytics.data.v1beta.Filter.NumericFilter;
1110
import com.google.analytics.data.v1beta.Filter.StringFilter;
@@ -25,140 +24,7 @@ public class FilterExpressionBuilder {
2524
private static final String STRING_FILTER_OP_REGEX_INCL = "=~";
2625
private static final String STRING_FILTER_OP_REGEX_EXCL = "!~";
2726
private static final String STRING_FILTER_OP_CONTAINS = "=@";
28-
private static final String STRING_FILTER_OP_CONTAINS_NOT = "!@";
29-
30-
/**
31-
* Setup filter expressions in the UA style
32-
* Examples:
33-
* dim1==value1,dim2==value2,dim3!=value3
34-
* dim1==value1;dim2==value2;dim3!=value3
35-
*
36-
* comma means OR
37-
* semicolon means AND
38-
*
39-
* @param completeFilter
40-
* @param isNumericFilter if true, otherwise it is a String filter
41-
* @return FilterExpression object
42-
* @throws Exception
43-
*/
44-
public static FilterExpression buildCombinedFilterExpression(String completeFilter, boolean isNumericFilter) throws Exception {
45-
FilterExpression.Builder fb = FilterExpression.newBuilder();
46-
FilterExpressionList.Builder list = FilterExpressionList.newBuilder();
47-
boolean or = false;
48-
boolean and = false;
49-
StringBuilder oneFilterTerm = new StringBuilder();
50-
for (int i = 0, n = completeFilter.length(); i < n; i++) {
51-
char c = completeFilter.charAt(i);
52-
if (c == '(') {
53-
// start of group
54-
throw new Exception("Invalid filter: " + completeFilter + ". Groups are not allowed yet! Position: " + i);
55-
} else if (c == ')') {
56-
throw new Exception("Invalid filter: " + completeFilter + ". Groups are not allowed yet! Position: " + i);
57-
} else if (c == ',') {
58-
// OR found
59-
if (i == 0) {
60-
throw new Exception("Invalid filter: " + completeFilter + ". <,> cannot be the first char! Position: " + i);
61-
}
62-
if (and) {
63-
throw new Exception("Invalid filter: " + completeFilter + ". OR(,) found with previous AND. Within one filter you can only combine all with OR (,) or all with AND(;). Position: " + i);
64-
}
65-
if (oneFilterTerm.length() == 0) {
66-
throw new Exception("Invalid filter: " + completeFilter + ". OR(,) found but no filter term as operand before. Position: " + i);
67-
}
68-
or = true;
69-
String term = oneFilterTerm.toString();
70-
oneFilterTerm.setLength(0);
71-
if (isNumericFilter) {
72-
if (log.isDebugEnabled()) {
73-
log.debug("add numeric filter term: " + term);
74-
}
75-
list.addExpressions(buildNumericFilterExpression(term));
76-
} else {
77-
if (log.isDebugEnabled()) {
78-
log.debug("add string filter term: " + term);
79-
}
80-
list.addExpressions(buildStringFilterExpression(term));
81-
}
82-
} else if (c == ';') {
83-
// AND found
84-
if (i == 0) {
85-
throw new Exception("Invalid filter: " + completeFilter + ". <;> cannot be the first char! Position: " + i);
86-
}
87-
if (or) {
88-
throw new Exception("Invalid filter: " + completeFilter + ". AND(;) found with previous OR. Within one filter you can only combine all with OR (,) or all with AND(;). Position: " + i);
89-
}
90-
if (oneFilterTerm.length() == 0) {
91-
throw new Exception("Invalid filter: " + completeFilter + ". AND(;) found but no filter term as operand before. Position: " + i);
92-
}
93-
and = true;
94-
String term = oneFilterTerm.toString();
95-
oneFilterTerm.setLength(0);
96-
if (isNumericFilter) {
97-
if (log.isDebugEnabled()) {
98-
log.debug("add numeric filter term: " + term);
99-
}
100-
list.addExpressions(buildNumericFilterExpression(term));
101-
} else {
102-
if (log.isDebugEnabled()) {
103-
log.debug("add string filter term: " + term);
104-
}
105-
list.addExpressions(buildStringFilterExpression(term));
106-
}
107-
} else if (c == ' ') {
108-
// skip this
109-
continue;
110-
} else if (i == n-1) {
111-
// we are at the very last char
112-
if (oneFilterTerm.length() == 0) {
113-
throw new Exception("Invalid filter: " + completeFilter + ". Found end of filter but no filter term as operand before. Position: " + i);
114-
}
115-
if (and == false && or == false) {
116-
String term = oneFilterTerm.toString();
117-
oneFilterTerm.setLength(0);
118-
if (isNumericFilter) {
119-
if (log.isDebugEnabled()) {
120-
log.debug("add numeric filter term: " + term);
121-
}
122-
list.addExpressions(buildNumericFilterExpression(term));
123-
} else {
124-
if (log.isDebugEnabled()) {
125-
log.debug("add string filter term: " + term);
126-
}
127-
list.addExpressions(buildStringFilterExpression(term));
128-
}
129-
} else {
130-
String term = oneFilterTerm.toString();
131-
oneFilterTerm.setLength(0);
132-
if (isNumericFilter) {
133-
if (log.isDebugEnabled()) {
134-
log.debug("add numeric filter term: " + term);
135-
}
136-
list.addExpressions(buildNumericFilterExpression(term));
137-
} else {
138-
if (log.isDebugEnabled()) {
139-
log.debug("add string filter term: " + term);
140-
}
141-
list.addExpressions(buildStringFilterExpression(term));
142-
}
143-
if (and) {
144-
if (log.isDebugEnabled()) {
145-
log.debug("set AND filter list with count expressions: " + list.getExpressionsCount());
146-
}
147-
fb.setAndGroup(list);
148-
} else if (or) {
149-
if (log.isDebugEnabled()) {
150-
log.debug("set OR filter list with count expressions: " + list.getExpressionsCount());
151-
}
152-
fb.setOrGroup(list);
153-
}
154-
}
155-
} else {
156-
// we must be in a filter term
157-
oneFilterTerm.append(c);
158-
}
159-
}
160-
return fb.build();
161-
}
27+
private static final String STRING_FILTER_OP_CONTAINS_NOT = "!@";
16228

16329
public static FilterExpression buildStringFilterExpression(String oneFilterTerm) throws Exception {
16430
if (oneFilterTerm != null && oneFilterTerm.trim().isEmpty() == false) {

0 commit comments

Comments
 (0)