-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathRuleBasedSegmentParser.java
More file actions
54 lines (45 loc) · 2.15 KB
/
RuleBasedSegmentParser.java
File metadata and controls
54 lines (45 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package io.split.engine.experiments;
import com.google.common.collect.Lists;
import io.split.client.dtos.Condition;
import io.split.client.dtos.RuleBasedSegment;
import io.split.engine.matchers.CombiningMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static io.split.engine.experiments.ParserUtils.checkUnsupportedMatcherExist;
import static io.split.engine.experiments.ParserUtils.getTemplateCondition;
import static io.split.engine.experiments.ParserUtils.toMatcher;
public final class RuleBasedSegmentParser {
private static final Logger _log = LoggerFactory.getLogger(RuleBasedSegmentParser.class);
public RuleBasedSegmentParser() {
}
public ParsedRuleBasedSegment parse(RuleBasedSegment ruleBasedSegment) {
try {
return parseWithoutExceptionHandling(ruleBasedSegment);
} catch (Throwable t) {
_log.error("Could not parse rule based segment: " + ruleBasedSegment, t);
return null;
}
}
private ParsedRuleBasedSegment parseWithoutExceptionHandling(RuleBasedSegment ruleBasedSegment) {
List<ParsedCondition> parsedConditionList = Lists.newArrayList();
for (Condition condition : ruleBasedSegment.conditions) {
if (checkUnsupportedMatcherExist(condition.matcherGroup.matchers)) {
_log.error("Unsupported matcher type found for rule based segment: " + ruleBasedSegment.name +
" , will revert to default template matcher.");
parsedConditionList.clear();
parsedConditionList.add(getTemplateCondition());
break;
}
CombiningMatcher matcher = toMatcher(condition.matcherGroup);
parsedConditionList.add(new ParsedCondition(condition.conditionType, matcher, null, condition.label));
}
return new ParsedRuleBasedSegment(
ruleBasedSegment.name,
parsedConditionList,
ruleBasedSegment.trafficTypeName,
ruleBasedSegment.changeNumber,
ruleBasedSegment.excluded.keys,
ruleBasedSegment.excluded.segments);
}
}