|
3 | 3 | import static com.google.common.base.Preconditions.checkArgument; |
4 | 4 | import static com.google.common.base.Preconditions.checkNotNull; |
5 | 5 |
|
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; |
6 | 7 | import com.google.common.collect.Lists; |
7 | 8 | import io.getstream.core.http.Request; |
| 9 | +import java8.util.concurrent.CompletionException; |
| 10 | + |
| 11 | +import java.io.IOException; |
8 | 12 | import java.util.List; |
| 13 | +import java.util.Map; |
9 | 14 |
|
10 | 15 | public final class EnrichmentFlags implements RequestOption { |
11 | 16 | enum OpType { |
12 | 17 | OWN_CHILDREN("with_own_children"), |
13 | 18 | OWN_REACTIONS("with_own_reactions"), |
14 | 19 | REACTION_COUNTS("with_reaction_counts"), |
15 | | - // XXX: move it to a separate option??? |
16 | 20 | REACTION_KINDS("reaction_kinds_filter"), |
17 | 21 | RECENT_REACTIONS("with_recent_reactions"), |
18 | | - RECENT_REACTIONS_LIMIT("recent_reactions_limit"); |
| 22 | + RECENT_REACTIONS_LIMIT("recent_reactions_limit"), |
| 23 | + RANKING_VARS("ranking_vars"); |
19 | 24 |
|
20 | 25 | private String operator; |
21 | 26 |
|
@@ -91,6 +96,23 @@ public EnrichmentFlags withUserChildren(String userID) { |
91 | 96 | return this; |
92 | 97 | } |
93 | 98 |
|
| 99 | + public EnrichmentFlags rankingVars(Map<String, Object> externalVars) { |
| 100 | + checkNotNull(externalVars, "No external variables to filter by"); |
| 101 | + checkArgument(externalVars.size() > 0, "No external variables to filter by"); |
| 102 | + |
| 103 | + String rankingVarsJSON; |
| 104 | + try { |
| 105 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 106 | + rankingVarsJSON = objectMapper.writeValueAsString(externalVars); |
| 107 | + } |
| 108 | + catch (IOException e){ |
| 109 | + throw new CompletionException(e); |
| 110 | + } |
| 111 | + |
| 112 | + ops.add(new OpEntry(OpType.RANKING_VARS, rankingVarsJSON)); |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
94 | 116 | @Override |
95 | 117 | public void apply(Request.Builder builder) { |
96 | 118 | for (OpEntry op : ops) { |
|
0 commit comments