Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jdk:
install: true
script:
- "./gradlew clean"
- "./gradlew exhaustiveTest"
- "if [[ -n $TRAVIS_TAG ]]; then
./gradlew ship;
else
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.6.0

March 17, 2017

- Add event tags to `track` API and include in the event payload
- Deprecates the `eventValue` parameter from the `track` method. Should use event tags to pass in event value instead
- Gracefully handle a null attributes parameter
- Gracefully handle a null/empty datafile when using the Gson parser

## 1.5.0

February 16, 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
115 changes: 44 additions & 71 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down Expand Up @@ -38,7 +38,9 @@
import com.optimizely.ab.event.internal.EventBuilderV1;
import com.optimizely.ab.event.internal.EventBuilderV2;
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
import com.optimizely.ab.internal.EventTagUtils;
import com.optimizely.ab.internal.ProjectValidationUtils;
import com.optimizely.ab.internal.ReservedEventKey;
import com.optimizely.ab.notification.NotificationListener;
import com.optimizely.ab.notification.NotificationBroadcaster;

Expand Down Expand Up @@ -117,22 +119,9 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
return activate(experimentKey, userId, Collections.<String, String>emptyMap());
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@CheckForNull String sessionId) throws UnknownExperimentException {
return activate(experimentKey, userId, Collections.<String, String>emptyMap(), sessionId);
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) throws UnknownExperimentException {
return activate(experimentKey, userId, attributes, null);
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) throws UnknownExperimentException {

if (!validateUserId(userId)) {
logger.info("Not activating user for experiment \"{}\".", experimentKey);
Expand All @@ -148,42 +137,27 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
return null;
}

return activate(currentConfig, experiment, userId, attributes, sessionId);
return activate(currentConfig, experiment, userId, attributes);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId) {
return activate(experiment, userId, Collections.<String, String>emptyMap());
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@CheckForNull String sessionId) {
return activate(experiment, userId, Collections.<String, String>emptyMap(), sessionId);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) {

return activate(experiment, userId, attributes, null);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) {

ProjectConfig currentConfig = getProjectConfig();

return activate(currentConfig, experiment, userId, attributes, sessionId);
return activate(currentConfig, experiment, userId, attributes);
}

private @Nullable Variation activate(@Nonnull ProjectConfig projectConfig,
@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) {
@Nonnull Map<String, String> attributes) {
// determine whether all the given attributes are present in the project config. If not, filter out the unknown
// attributes.
attributes = filterAttributes(projectConfig, attributes);
Expand All @@ -202,7 +176,7 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,

if (experiment.isRunning()) {
LogEvent impressionEvent = eventBuilder.createImpressionEvent(projectConfig, experiment, variation, userId,
attributes, sessionId);
attributes);
logger.info("Activating user \"{}\" in experiment \"{}\".", userId, experiment.getKey());
logger.debug(
"Dispatching impression event to URL {} with params {} and payload \"{}\".",
Expand All @@ -225,61 +199,39 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,

public void track(@Nonnull String eventName,
@Nonnull String userId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), null, null);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), null, sessionId);
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) throws UnknownEventTypeException {
track(eventName, userId, attributes, null, null);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, attributes, null, sessionId);
track(eventName, userId, attributes, Collections.<String, String>emptyMap());
}

/**
* @deprecated see {@link #track(String, String, Map)} and pass in the revenue value as an event tag instead.
*/
public void track(@Nonnull String eventName,
@Nonnull String userId,
long eventValue) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue, sessionId);
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.singletonMap(
ReservedEventKey.REVENUE.toString(), eventValue));
}

/**
* @deprecated see {@link #track(String, String, Map, long)} and pass in the revenue value as an event tag instead.
*/
public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
long eventValue) throws UnknownEventTypeException {
track(eventName, userId, attributes, (Long)eventValue, null);
track(eventName, userId, attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, attributes, (Long)eventValue, sessionId);
}

private void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull Long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
@Nonnull Map<String, ?> eventTags) throws UnknownEventTypeException {

ProjectConfig currentConfig = getProjectConfig();

Expand All @@ -294,10 +246,18 @@ private void track(@Nonnull String eventName,
// attributes.
attributes = filterAttributes(currentConfig, attributes);

Long eventValue = null;
if (eventTags == null) {
logger.warn("Event tags is null when non-null was expected. Defaulting to an empty event tags map.");
eventTags = Collections.<String, String>emptyMap();
} else {
eventValue = EventTagUtils.getRevenueValue(eventTags);
}

// create the conversion event request parameters, then dispatch
LogEvent conversionEvent = eventBuilder.createConversionEvent(currentConfig, bucketer, userId,
eventType.getId(), eventType.getKey(), attributes,
eventValue, sessionId);
eventTags);

if (conversionEvent == null) {
logger.info("There are no valid experiments for event \"{}\" to track.", eventName);
Expand Down Expand Up @@ -498,6 +458,13 @@ private void track(@Nonnull String eventName,
* @return a {@link ProjectConfig} instance given a json string
*/
private static ProjectConfig getProjectConfig(String datafile) throws ConfigParseException {
if (datafile == null) {
throw new ConfigParseException("Unable to parse null datafile.");
}
if (datafile.length() == 0) {
throw new ConfigParseException("Unable to parse empty datafile.");
}

return DefaultConfigParser.getInstance().parseProjectConfig(datafile);
}

Expand Down Expand Up @@ -624,10 +591,16 @@ private LiveVariable getLiveVariableOrThrow(ProjectConfig projectConfig, String
*
* @param projectConfig the current project config
* @param attributes the attributes map to validate and potentially filter
* @return the filtered attributes map (containing only attributes that are present in the project config)
*
* @return the filtered attributes map (containing only attributes that are present in the project config) or an
* empty map if a null attributes object is passed in
*/
private Map<String, String> filterAttributes(ProjectConfig projectConfig, Map<String, String> attributes) {
private Map<String, String> filterAttributes(@Nonnull ProjectConfig projectConfig,
@Nonnull Map<String, String> attributes) {
if (attributes == null) {
logger.warn("Attributes is null when non-null was expected. Defaulting to an empty attributes map.");
return Collections.<String, String>emptyMap();
}

List<String> unknownAttributes = null;

Map<String, Attribute> attributeKeyMapping = projectConfig.getAttributeKeyMapping();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
2 changes: 1 addition & 1 deletion core-api/src/main/java/com/optimizely/ab/config/Group.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* 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.
Expand Down
Loading