Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public boolean isStandard() {
public boolean isRuleBased() {
return RULE_BASED_TYPE.equals(type);
}

public String getSegmentName(){
return name;
}
}
18 changes: 16 additions & 2 deletions client/src/main/java/io/split/client/dtos/RuleBasedSegment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.split.client.dtos;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

public class RuleBasedSegment {
Expand All @@ -17,7 +17,21 @@ public String toString() {
"name='" + name + '\'' +
", status=" + status +
", trafficTypeName='" + trafficTypeName + '\'' +
", changeNumber=" + changeNumber +
", changeNumber=" + changeNumber + '\'' +
excludedToString() + '\'' +
'}';
}

public String excludedToString() {
Excluded ts = excluded != null ? excluded : new Excluded();
if (ts.keys == null) {
ts.keys = new ArrayList<>();
}

if (ts.segments == null) {
ts.segments = new ArrayList<>();
}

return ", excludedKeys=" + ts.keys + '\'' + ", excludedSegments=" + ts.segments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ public String toString() {
}

public Set<String> getSegmentsNames() {
return parsedConditions().stream()
Set<String> segmentNames = excludedSegments()
.stream()
.filter(ExcludedSegments::isStandard)
.map(ExcludedSegments::getSegmentName)
.collect(Collectors.toSet());

segmentNames.addAll(parsedConditions().stream()
.flatMap(parsedCondition -> parsedCondition.matcher().attributeMatchers().stream())
.filter(ParsedRuleBasedSegment::isSegmentMatcher)
.map(ParsedRuleBasedSegment::asSegmentMatcherForEach)
.map(UserDefinedSegmentMatcher::getSegmentName)
.collect(Collectors.toSet());
.collect(Collectors.toSet()));

return segmentNames;
}

private static boolean isSegmentMatcher(AttributeMatcher attributeMatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void works() {
Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")), "user",
123, Lists.newArrayList("mauro@test.io", "gaston@test.io"), excludedSegments);

Assert.assertEquals(Sets.newHashSet("employees"), parsedRuleBasedSegment.getSegmentsNames());
Assert.assertEquals(Sets.newHashSet("segment2", "segment1", "employees"), parsedRuleBasedSegment.getSegmentsNames());
Assert.assertEquals("another_rule_based_segment", parsedRuleBasedSegment.ruleBasedSegment());
Assert.assertEquals(Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")),
parsedRuleBasedSegment.parsedConditions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public void testMultipleSegment(){

ruleBasedSegmentCache.update(Lists.newArrayList(parsedRuleBasedSegment1, parsedRuleBasedSegment2), null, 123);
assertEquals(Lists.newArrayList("another_rule_based_segment", "sample_rule_based_segment"), ruleBasedSegmentCache.ruleBasedSegmentNames());
assertEquals(Sets.newHashSet("employees"), ruleBasedSegmentCache.getSegments());
assertEquals(Sets.newHashSet("segment2", "segment1", "employees"), ruleBasedSegmentCache.getSegments());
}
}