-
Notifications
You must be signed in to change notification settings - Fork 32
feat: Integrated ODPManager with UserContext and Optimizely client #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
525ad99
5d3cb21
0a1bf21
0c74a18
42b2425
79263fc
e573a6a
6d88b86
68aa5ff
29f2b09
49a9686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package com.optimizely.ab; | ||
|
||
import com.optimizely.ab.config.Variation; | ||
import com.optimizely.ab.odp.ODPManager; | ||
import com.optimizely.ab.odp.ODPSegmentOption; | ||
import com.optimizely.ab.optimizelydecision.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -54,6 +56,15 @@ public OptimizelyUserContext(@Nonnull Optimizely optimizely, | |
@Nonnull Map<String, ?> attributes, | ||
@Nullable Map<String, OptimizelyForcedDecision> forcedDecisionsMap, | ||
@Nullable List<String> qualifiedSegments) { | ||
this(optimizely, userId, attributes, forcedDecisionsMap, qualifiedSegments, false); | ||
zashraf1985 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
public OptimizelyUserContext(@Nonnull Optimizely optimizely, | ||
@Nonnull String userId, | ||
@Nonnull Map<String, ?> attributes, | ||
@Nullable Map<String, OptimizelyForcedDecision> forcedDecisionsMap, | ||
@Nullable List<String> qualifiedSegments, | ||
@Nullable Boolean shouldIdentifyUser) { | ||
this.optimizely = optimizely; | ||
this.userId = userId; | ||
if (attributes != null) { | ||
|
@@ -66,6 +77,10 @@ public OptimizelyUserContext(@Nonnull Optimizely optimizely, | |
} | ||
|
||
this.qualifiedSegments = Collections.synchronizedList( qualifiedSegments == null ? new LinkedList<>(): qualifiedSegments); | ||
|
||
if (shouldIdentifyUser == null || shouldIdentifyUser) { | ||
optimizely.identifyUser(userId); | ||
} | ||
} | ||
|
||
public OptimizelyUserContext(@Nonnull Optimizely optimizely, @Nonnull String userId) { | ||
|
@@ -282,6 +297,36 @@ public void setQualifiedSegments(List<String> qualifiedSegments) { | |
this.qualifiedSegments.addAll(qualifiedSegments); | ||
} | ||
|
||
/** | ||
* Fetch all qualified segments for the user context. | ||
* | ||
* The segments fetched will be saved and can be accessed at any time by calling {@link #getQualifiedSegments()}. | ||
*/ | ||
public void fetchQualifiedSegments() { | ||
|
||
ODPManager odpManager = optimizely.getODPManager(); | ||
if (odpManager != null) { | ||
synchronized (odpManager) { | ||
setQualifiedSegments(odpManager.getSegmentManager().getQualifiedSegments(userId)); | ||
} | ||
} | ||
zashraf1985 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Fetch all qualified segments for the user context. | ||
* | ||
* The segments fetched will be saved and can be accessed at any time by calling {@link #getQualifiedSegments()}. | ||
* | ||
* @param segmentOptions A set of options for fetching qualified segments. | ||
*/ | ||
public void fetchQualifiedSegments(@Nonnull List<ODPSegmentOption> segmentOptions) { | ||
ODPManager odpManager = optimizely.getODPManager(); | ||
if (odpManager != null) { | ||
synchronized (odpManager) { | ||
setQualifiedSegments(odpManager.getSegmentManager().getQualifiedSegments(userId, segmentOptions)); | ||
} | ||
} | ||
} | ||
|
||
// Utils | ||
|
||
@Override | ||
|
@@ -309,5 +354,4 @@ public String toString() { | |
", attributes='" + attributes + '\'' + | ||
'}'; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import javax.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* ProjectConfig is an interface capturing the experiment, variation and feature definitions. | ||
|
@@ -69,6 +70,8 @@ Experiment getExperimentForKey(@Nonnull String experimentKey, | |
|
||
List<Experiment> getExperiments(); | ||
|
||
Set<String> getAllSegments(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if this addition to the interface will require changes to all existing customization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If users are using their own ProjectConfigManagers? yes! But this is the only way to add more functionality to ProjectConfig. I believe almost no one will be customizing the whole ProjectConfigManager. If there are a handful of customers who are even doing it, ATS will go out as a major version change anyway. We can mention this in the release notes as a breaking change. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zashraf1985 We'll go for a major version change if we have to. We better keep all the breaking changes required. |
||
|
||
List<Experiment> getExperimentsForEventKey(String eventKey); | ||
|
||
List<FeatureFlag> getFeatureFlags(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.