|
16 | 16 | */
|
17 | 17 | package com.optimizely.ab.bucketing;
|
18 | 18 |
|
| 19 | +import java.util.HashMap; |
19 | 20 | import java.util.Map;
|
20 | 21 |
|
21 | 22 | /**
|
|
25 | 26 | */
|
26 | 27 | public interface UserProfileService {
|
27 | 28 |
|
| 29 | + /** |
| 30 | + * A class representing a user's profile. |
| 31 | + */ |
| 32 | + class UserProfile { |
| 33 | + |
| 34 | + /** A user's ID. */ |
| 35 | + public final String userId; |
| 36 | + /** The bucketing decisions of the user. */ |
| 37 | + public final Map<String, String> decisions; |
| 38 | + |
| 39 | + /** |
| 40 | + * Construct a User Profile instance from explicit components. |
| 41 | + * @param userId The ID of the user. |
| 42 | + * @param decisions The bucketing decisions of the user. |
| 43 | + */ |
| 44 | + public UserProfile(String userId, Map<String, String> decisions) { |
| 45 | + this.userId = userId; |
| 46 | + this.decisions = decisions; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Construct a User Profile instance from a Map. |
| 51 | + * @param userProfileMap A {@code Map<String, Object>} containing the properties of the user profile. |
| 52 | + */ |
| 53 | + @SuppressWarnings("unchecked") |
| 54 | + public UserProfile(Map<String, Object> userProfileMap) { |
| 55 | + this((String) userProfileMap.get(userIdKey), (Map<String, String>) userProfileMap.get(decisionsKey)); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Convert a User Profile instance to a Map. |
| 60 | + * @return A map representation of the user profile instance. |
| 61 | + */ |
| 62 | + Map<String, Object> toMap() { |
| 63 | + Map<String, Object> userProfileMap = new HashMap<String, Object>(2); |
| 64 | + userProfileMap.put(userIdKey, userId); |
| 65 | + userProfileMap.put(decisionsKey, decisions); |
| 66 | + return userProfileMap; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /** The key for the user ID. Returns a String.*/ |
| 71 | + String userIdKey = "user_id"; |
| 72 | + /** The key for the decisions Map. Returns a {@code Map<String, String>}.*/ |
| 73 | + String decisionsKey = "decisions"; |
| 74 | + |
28 | 75 | /**
|
29 | 76 | * Fetch the user profile map for the user ID.
|
30 | 77 | *
|
31 | 78 | * @param userId The ID of the user whose profile will be retrieved.
|
32 | 79 | * @return a Map representing the user's profile.
|
33 |
| - * @throws Exception |
| 80 | + * The returned {@code Map<String, Object>} of the user profile will have the following structure. |
| 81 | + * { |
| 82 | + * userIdKey : String userId, |
| 83 | + * decisionsKey : {@code Map<String, String>} decisions { |
| 84 | + * String experimentId : String variationId |
| 85 | + * } |
| 86 | + * } |
| 87 | + * @throws Exception Passes on whatever exceptions the implementation may throw. |
34 | 88 | */
|
35 | 89 | Map<String, Object> lookup(String userId) throws Exception;
|
36 | 90 |
|
|
0 commit comments