-
Notifications
You must be signed in to change notification settings - Fork 31
(feat): Feature Management Activate and GetVariation Listener #272
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1f8838d
Added New Listener of activate in OnDecision and depreciated old one
mnoman09 d909fb1
Changed OnDecision enum to Decision
mnoman09 d2b7861
passing empty attributes instead of passing null in decision listener
mnoman09 5dff7b7
Did suggested name changes
mnoman09 035bc0a
Merge branch 'master' into mnoman/ActivateVarNewListener
mfahadahmed 45994d1
Nit fix and verified that listener is getting called
mnoman09 617f848
nit fix
mnoman09 4b95211
Merge branch 'master' into mnoman/ActivateVarNewListener
mnoman09 39113f6
Refactored and added builder Pattern
mnoman09 b6600fb
Merge branch 'master' into mnoman/ActivateVarNewListener
aliabbasrizvi 634a037
Merge branch 'master' into mnoman/ActivateVarNewListener
mnoman09 f6335c5
Merge branch 'master' into mnoman/ActivateVarNewListener
mnoman09 511c6e9
Feat: Updated Activate/Variation notification listener implementation…
mnoman09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
core-api/src/main/java/com/optimizely/ab/notification/DecisionNotification.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2019, Optimizely, Inc. and contributors * | ||
| * * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| * you may not use this file except in compliance with the License. * | ||
| * You may obtain a copy of the License at * | ||
| * * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| * * | ||
| * Unless required by applicable law or agreed to in writing, software * | ||
| * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| * See the License for the specific language governing permissions and * | ||
| * limitations under the License. * | ||
| ***************************************************************************/ | ||
|
|
||
| package com.optimizely.ab.notification; | ||
|
|
||
|
|
||
| import com.optimizely.ab.bucketing.FeatureDecision; | ||
| import com.optimizely.ab.config.FeatureVariable; | ||
| import com.optimizely.ab.config.Variation; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class DecisionNotification { | ||
| protected String type; | ||
| protected String userId; | ||
| protected Map<String, ?> attributes; | ||
| protected Map<String, ?> decisionInfo; | ||
|
|
||
| protected DecisionNotification() { | ||
| } | ||
|
|
||
| protected DecisionNotification(@Nonnull String type, | ||
| @Nonnull String userId, | ||
| @Nullable Map<String, ?> attributes, | ||
| @Nonnull Map<String, ?> decisionInfo) { | ||
| this.type = type; | ||
| this.userId = userId; | ||
| if (attributes == null) { | ||
| attributes = new HashMap<>(); | ||
| } | ||
| this.attributes = attributes; | ||
| this.decisionInfo = decisionInfo; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public String getUserId() { | ||
| return userId; | ||
| } | ||
|
|
||
| public Map<String, ?> getAttributes() { | ||
| return attributes; | ||
| } | ||
|
|
||
| public Map<String, ?> getDecisionInfo() { | ||
| return decisionInfo; | ||
| } | ||
|
|
||
| public static ExperimentDecisionNotificationBuilder newExperimentDecisionNotificationBuilder() { | ||
| return new ExperimentDecisionNotificationBuilder(); | ||
| } | ||
|
|
||
| public static class ExperimentDecisionNotificationBuilder { | ||
| public final static String EXPERIMENT_KEY = "experiment_key"; | ||
| public final static String VARIATION_KEY = "variation_key"; | ||
|
|
||
| private String type; | ||
| private String experimentKey; | ||
| private Variation variation; | ||
| private String userId; | ||
| private Map<String, ?> attributes; | ||
| private Map<String, Object> decisionInfo; | ||
|
|
||
| public ExperimentDecisionNotificationBuilder withUserId(String userId) { | ||
| this.userId = userId; | ||
| return this; | ||
| } | ||
|
|
||
| public ExperimentDecisionNotificationBuilder withAttributes(Map<String, ?> attributes) { | ||
| this.attributes = attributes; | ||
| return this; | ||
| } | ||
|
|
||
| public ExperimentDecisionNotificationBuilder withExperimentKey(String experimentKey) { | ||
| this.experimentKey = experimentKey; | ||
| return this; | ||
| } | ||
|
|
||
| public ExperimentDecisionNotificationBuilder withType(String type) { | ||
| this.type = type; | ||
| return this; | ||
| } | ||
|
|
||
| public ExperimentDecisionNotificationBuilder withVariation(Variation variation) { | ||
| this.variation = variation; | ||
| return this; | ||
| } | ||
|
|
||
| public DecisionNotification build() { | ||
| decisionInfo = new HashMap<>(); | ||
| decisionInfo.put(EXPERIMENT_KEY, experimentKey); | ||
| decisionInfo.put(VARIATION_KEY, variation != null ? variation.getKey() : null); | ||
|
|
||
| return new DecisionNotification( | ||
| type, | ||
| userId, | ||
| attributes, | ||
| decisionInfo); | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
core-api/src/main/java/com/optimizely/ab/notification/DecisionNotificationListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /**************************************************************************** | ||
| * Copyright 2019, Optimizely, Inc. and contributors * | ||
| * * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| * you may not use this file except in compliance with the License. * | ||
| * You may obtain a copy of the License at * | ||
| * * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| * * | ||
| * Unless required by applicable law or agreed to in writing, software * | ||
| * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| * See the License for the specific language governing permissions and * | ||
| * limitations under the License. * | ||
| ***************************************************************************/ | ||
|
|
||
| package com.optimizely.ab.notification; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| public interface DecisionNotificationListener { | ||
|
|
||
| /** | ||
| * onDecision called when an activate was triggered | ||
| * | ||
| * @param decisionNotification - The decision notification object containing: | ||
| * type - The notification type. | ||
| * userId - The userId passed to the API. | ||
| * attributes - The attribute map passed to the API. | ||
| * decisionInfo - The decision information containing all parameters passed in API. | ||
| */ | ||
| void onDecision(@Nonnull DecisionNotification decisionNotification); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this should be
withVariationKey. Just seems inconsistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I am passing variation here so that on build we can verify null check before getting key from its object