Skip to content

integrate user profile service #98

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 23 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a51c08c
add UserProfileService to Optimizely
wangjoshuah May 3, 2017
fd422da
start adding user profile service to decision service
wangjoshuah May 4, 2017
fa427ed
change storeVariation
wangjoshuah May 6, 2017
365df4b
start user UserProfileService.UserProfile
wangjoshuah May 8, 2017
596d159
user the new user profile class from the service interface
wangjoshuah May 9, 2017
32d5fa4
stash work to compile
wangjoshuah May 9, 2017
ebf82ef
we no longer clean the user profile for the developers
wangjoshuah May 9, 2017
67c6c63
get DecisionServiceTests to pass
wangjoshuah May 9, 2017
995f29b
Get all tests to pass.
wangjoshuah May 10, 2017
d80185d
test for catching save failure
wangjoshuah May 10, 2017
740a5a0
modify the User Profile Service Interface
wangjoshuah May 10, 2017
c3b638f
User the new structure for a decision map in decision service and tests
wangjoshuah May 10, 2017
fba3c0a
Add test checking for `getStoredVariation` returns null when a decisi…
wangjoshuah May 10, 2017
df639dd
Remove UserProfile.java, UserProfileUtils.java, ProjectValidationUtil…
wangjoshuah May 10, 2017
bd72858
Refactor UserProfileService to use objects instead of maps.
wangjoshuah May 15, 2017
112c9ba
revert to using Map instead of Object
wangjoshuah May 16, 2017
3b62f74
Make an Empty User Profile since the Service will return null for a n…
wangjoshuah May 16, 2017
db02770
Add some helpful comments.
wangjoshuah May 16, 2017
8895b99
Add extra logs
wangjoshuah May 16, 2017
d7b1189
modify decision service get variation logic slightly
wangjoshuah May 16, 2017
2bccdd9
remove unecessary parenthesis
wangjoshuah May 16, 2017
b292c99
respond to PR
wangjoshuah May 16, 2017
a91d2b1
change names, add new lines
wangjoshuah May 16, 2017
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
62 changes: 30 additions & 32 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
/**
*
* Copyright 2016-2017, Optimizely 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.
*/
/****************************************************************************
* Copyright 2016-2017, 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;

import com.optimizely.ab.annotations.VisibleForTesting;
import com.optimizely.ab.bucketing.Bucketer;
import com.optimizely.ab.bucketing.DecisionService;
import com.optimizely.ab.bucketing.UserProfile;
import com.optimizely.ab.bucketing.UserProfileService;
import com.optimizely.ab.config.Attribute;
import com.optimizely.ab.config.EventType;
import com.optimizely.ab.config.Experiment;
Expand All @@ -40,7 +39,6 @@
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
import com.optimizely.ab.internal.EventTagUtils;
import com.optimizely.ab.internal.ReservedEventKey;
import com.optimizely.ab.internal.UserProfileUtils;
import com.optimizely.ab.notification.NotificationBroadcaster;
import com.optimizely.ab.notification.NotificationListener;
import org.slf4j.Logger;
Expand Down Expand Up @@ -92,26 +90,26 @@ public class Optimizely {
@VisibleForTesting final EventHandler eventHandler;
@VisibleForTesting final ErrorHandler errorHandler;
@VisibleForTesting final NotificationBroadcaster notificationBroadcaster = new NotificationBroadcaster();
@Nullable private final UserProfile userProfile;
@Nullable private final UserProfileService userProfileService;

private Optimizely(@Nonnull ProjectConfig projectConfig,
@Nonnull DecisionService decisionService,
@Nonnull EventHandler eventHandler,
@Nonnull EventBuilder eventBuilder,
@Nonnull ErrorHandler errorHandler,
@Nullable UserProfile userProfile) {
@Nullable UserProfileService userProfileService) {
this.projectConfig = projectConfig;
this.decisionService = decisionService;
this.eventHandler = eventHandler;
this.eventBuilder = eventBuilder;
this.errorHandler = errorHandler;
this.userProfile = userProfile;
this.userProfileService = userProfileService;
}

// Do work here that should be done once per Optimizely lifecycle
@VisibleForTesting
void initialize() {
UserProfileUtils.cleanUserProfiles(userProfile, projectConfig);

}

//======== activate calls ========//
Expand Down Expand Up @@ -506,11 +504,10 @@ private static ProjectConfig getProjectConfig(String datafile) throws ConfigPars
}

@Nullable
public UserProfile getUserProfile() {
return userProfile;
public UserProfileService getUserProfileService() {
return userProfileService;
}


//======== Notification listeners ========//

/**
Expand Down Expand Up @@ -709,7 +706,7 @@ public static class Builder {
private ClientEngine clientEngine;
private String clientVersion;
private ProjectConfig projectConfig;
private UserProfile userProfile;
private UserProfileService userProfileService;

public Builder(@Nonnull String datafile,
@Nonnull EventHandler eventHandler) {
Expand All @@ -732,8 +729,8 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
return this;
}

public Builder withUserProfile(UserProfile userProfile) {
this.userProfile = userProfile;
public Builder withUserProfileService(UserProfileService userProfileService) {
this.userProfileService = userProfileService;
return this;
}

Expand Down Expand Up @@ -775,9 +772,6 @@ public Optimizely build() throws ConfigParseException {
clientVersion = BuildVersionInfo.VERSION;
}

if (decisionService == null) {
decisionService = new DecisionService(bucketer, projectConfig, userProfile);
}

if (eventBuilder == null) {
eventBuilder = new EventBuilderV2(clientEngine, clientVersion);
Expand All @@ -787,7 +781,11 @@ public Optimizely build() throws ConfigParseException {
errorHandler = new NoOpErrorHandler();
}

Optimizely optimizely = new Optimizely(projectConfig, decisionService, eventHandler, eventBuilder, errorHandler, userProfile);
if (decisionService == null) {
decisionService = new DecisionService(bucketer, errorHandler, projectConfig, userProfileService);
}

Optimizely optimizely = new Optimizely(projectConfig, decisionService, eventHandler, eventBuilder, errorHandler, userProfileService);
optimizely.initialize();
return optimizely;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class OptimizelyRuntimeException extends RuntimeException {

public OptimizelyRuntimeException() { }

public OptimizelyRuntimeException(Exception exception) {
super(exception);
}

public OptimizelyRuntimeException(String message) {
super(message);
}
Expand Down
58 changes: 58 additions & 0 deletions core-api/src/main/java/com/optimizely/ab/bucketing/Decision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/****************************************************************************
* Copyright 2017, 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.bucketing;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

/**
* A class representing a stored decision.
*/
public class Decision {

/** The ID of the {@link com.optimizely.ab.config.Variation} the user was bucketed into. */
@Nonnull public String variationId;

/**
* Initialize a Decision object.
* @param variationId The ID of the variation the user was bucketed into.
*/
public Decision(@Nonnull String variationId) {
this.variationId = variationId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Decision decision = (Decision) o;

return variationId.equals(decision.variationId);
}

@Override
public int hashCode() {
return variationId.hashCode();
}

public Map<String, String> toMap() {
Map<String, String> decisionMap = new HashMap<String, String>(1);
decisionMap.put(UserProfileService.variationIdKey, variationId);
return decisionMap;
}
}
Loading