use of com.optimizely.ab.config.audience.Audience in project java-sdk by optimizely.
the class ProjectConfigGsonDeserializer method deserialize.
@Override
public ProjectConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
String accountId = jsonObject.get("accountId").getAsString();
String projectId = jsonObject.get("projectId").getAsString();
String revision = jsonObject.get("revision").getAsString();
String version = jsonObject.get("version").getAsString();
int datafileVersion = Integer.parseInt(version);
// generic list type tokens
Type groupsType = new TypeToken<List<Group>>() {
}.getType();
Type experimentsType = new TypeToken<List<Experiment>>() {
}.getType();
Type attributesType = new TypeToken<List<Attribute>>() {
}.getType();
Type eventsType = new TypeToken<List<EventType>>() {
}.getType();
Type audienceType = new TypeToken<List<Audience>>() {
}.getType();
List<Group> groups = context.deserialize(jsonObject.get("groups").getAsJsonArray(), groupsType);
List<Experiment> experiments = context.deserialize(jsonObject.get("experiments").getAsJsonArray(), experimentsType);
List<Attribute> attributes;
attributes = context.deserialize(jsonObject.get("attributes"), attributesType);
List<EventType> events = context.deserialize(jsonObject.get("events").getAsJsonArray(), eventsType);
List<Audience> audiences = context.deserialize(jsonObject.get("audiences").getAsJsonArray(), audienceType);
boolean anonymizeIP = false;
// live variables should be null if using V2
List<LiveVariable> liveVariables = null;
if (datafileVersion >= Integer.parseInt(ProjectConfig.Version.V3.toString())) {
Type liveVariablesType = new TypeToken<List<LiveVariable>>() {
}.getType();
liveVariables = context.deserialize(jsonObject.getAsJsonArray("variables"), liveVariablesType);
anonymizeIP = jsonObject.get("anonymizeIP").getAsBoolean();
}
List<FeatureFlag> featureFlags = null;
List<Rollout> rollouts = null;
if (datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString())) {
Type featureFlagsType = new TypeToken<List<FeatureFlag>>() {
}.getType();
featureFlags = context.deserialize(jsonObject.getAsJsonArray("featureFlags"), featureFlagsType);
Type rolloutsType = new TypeToken<List<Rollout>>() {
}.getType();
rollouts = context.deserialize(jsonObject.get("rollouts").getAsJsonArray(), rolloutsType);
}
return new ProjectConfig(accountId, anonymizeIP, projectId, revision, version, attributes, audiences, events, experiments, featureFlags, groups, liveVariables, rollouts);
}
use of com.optimizely.ab.config.audience.Audience in project java-sdk by optimizely.
the class ProjectConfigTestUtils method generateValidProjectConfigV2.
private static ProjectConfig generateValidProjectConfigV2() {
List<Experiment> experiments = asList(new Experiment("223", "etag1", "Running", "1", singletonList("100"), asList(new Variation("276", "vtag1"), new Variation("277", "vtag2")), Collections.singletonMap("testUser1", "vtag1"), asList(new TrafficAllocation("276", 3500), new TrafficAllocation("277", 9000)), ""), new Experiment("118", "etag2", "Not started", "2", singletonList("100"), asList(new Variation("278", "vtag3"), new Variation("279", "vtag4")), Collections.singletonMap("testUser3", "vtag3"), asList(new TrafficAllocation("278", 4500), new TrafficAllocation("279", 9000)), ""), new Experiment("119", "etag3", "Not started", null, singletonList("100"), asList(new Variation("280", "vtag5"), new Variation("281", "vtag6")), Collections.singletonMap("testUser4", "vtag5"), asList(new TrafficAllocation("280", 4500), new TrafficAllocation("281", 9000)), ""));
List<Attribute> attributes = singletonList(new Attribute("134", "browser_type"));
List<String> singleExperimentId = singletonList("223");
List<String> multipleExperimentIds = asList("118", "223");
List<EventType> events = asList(new EventType("971", "clicked_cart", singleExperimentId), new EventType("098", "Total Revenue", singleExperimentId), new EventType("099", "clicked_purchase", multipleExperimentIds), new EventType("100", "no_running_experiments", singletonList("118")));
List<Condition> userAttributes = new ArrayList<Condition>();
userAttributes.add(new UserAttribute("browser_type", "custom_dimension", "firefox"));
OrCondition orInner = new OrCondition(userAttributes);
NotCondition notCondition = new NotCondition(orInner);
List<Condition> outerOrList = new ArrayList<Condition>();
outerOrList.add(notCondition);
OrCondition orOuter = new OrCondition(outerOrList);
List<Condition> andList = new ArrayList<Condition>();
andList.add(orOuter);
AndCondition andCondition = new AndCondition(andList);
List<Audience> audiences = singletonList(new Audience("100", "not_firefox_users", andCondition));
Map<String, String> userIdToVariationKeyMap = new HashMap<String, String>();
userIdToVariationKeyMap.put("testUser1", "e1_vtag1");
userIdToVariationKeyMap.put("testUser2", "e1_vtag2");
List<Experiment> randomGroupExperiments = asList(new Experiment("301", "group_etag2", "Running", "3", singletonList("100"), asList(new Variation("282", "e2_vtag1"), new Variation("283", "e2_vtag2")), Collections.<String, String>emptyMap(), asList(new TrafficAllocation("282", 5000), new TrafficAllocation("283", 10000)), "42"), new Experiment("300", "group_etag1", "Running", "4", singletonList("100"), asList(new Variation("280", "e1_vtag1"), new Variation("281", "e1_vtag2")), userIdToVariationKeyMap, asList(new TrafficAllocation("280", 3000), new TrafficAllocation("281", 10000)), "42"));
List<Experiment> overlappingGroupExperiments = asList(new Experiment("302", "overlapping_etag1", "Running", "5", singletonList("100"), asList(new Variation("284", "e1_vtag1"), new Variation("285", "e1_vtag2")), userIdToVariationKeyMap, asList(new TrafficAllocation("284", 1500), new TrafficAllocation("285", 3000)), "43"));
Group randomPolicyGroup = new Group("42", "random", randomGroupExperiments, asList(new TrafficAllocation("300", 3000), new TrafficAllocation("301", 9000), new TrafficAllocation("", 10000)));
Group overlappingPolicyGroup = new Group("43", "overlapping", overlappingGroupExperiments, Collections.<TrafficAllocation>emptyList());
List<Group> groups = asList(randomPolicyGroup, overlappingPolicyGroup);
return new ProjectConfig("789", "1234", "2", "42", groups, experiments, attributes, events, audiences);
}
Aggregations