use of com.optimizely.ab.config.audience.NotCondition in project java-sdk by optimizely.
the class DatafileProjectConfigTestUtils method generateValidProjectConfigV2.
private static ProjectConfig generateValidProjectConfigV2() {
List<Experiment> experiments = asList(new Experiment("223", "etag1", "Running", "1", singletonList("100"), null, 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"), null, 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"), null, 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_attribute", null, "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"), null, 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"), null, 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"), null, 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 DatafileProjectConfig("789", "1234", "2", "42", groups, experiments, attributes, events, audiences);
}
use of com.optimizely.ab.config.audience.NotCondition in project java-sdk by optimizely.
the class DatafileProjectConfigTestUtils method generateValidProjectConfigV3.
private static ProjectConfig generateValidProjectConfigV3() {
List<FeatureVariableUsageInstance> variationVtag1VariableUsageInstances = asList(new FeatureVariableUsageInstance("6", "True"), new FeatureVariableUsageInstance("2", "10"), new FeatureVariableUsageInstance("3", "string_var_vtag1"), new FeatureVariableUsageInstance("4", "5.3"));
List<FeatureVariableUsageInstance> variationVtag2VariableUsageInstances = asList(new FeatureVariableUsageInstance("6", "False"), new FeatureVariableUsageInstance("2", "20"), new FeatureVariableUsageInstance("3", "string_var_vtag2"), new FeatureVariableUsageInstance("4", "6.3"));
List<Experiment> experiments = asList(new Experiment("223", "etag1", "Running", "1", singletonList("100"), null, asList(new Variation("276", "vtag1", variationVtag1VariableUsageInstances), new Variation("277", "vtag2", variationVtag2VariableUsageInstances)), Collections.singletonMap("testUser1", "vtag1"), asList(new TrafficAllocation("276", 3500), new TrafficAllocation("277", 9000)), ""), new Experiment("118", "etag2", "Not started", "2", singletonList("100"), null, asList(new Variation("278", "vtag3", Collections.<FeatureVariableUsageInstance>emptyList()), new Variation("279", "vtag4", Collections.<FeatureVariableUsageInstance>emptyList())), Collections.singletonMap("testUser3", "vtag3"), asList(new TrafficAllocation("278", 4500), new TrafficAllocation("279", 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_attribute", null, "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"), null, asList(new Variation("282", "e2_vtag1", Collections.<FeatureVariableUsageInstance>emptyList()), new Variation("283", "e2_vtag2", Collections.<FeatureVariableUsageInstance>emptyList())), Collections.<String, String>emptyMap(), asList(new TrafficAllocation("282", 5000), new TrafficAllocation("283", 10000)), "42"), new Experiment("300", "group_etag1", "Running", "4", singletonList("100"), null, asList(new Variation("280", "e1_vtag1", Collections.singletonList(new FeatureVariableUsageInstance("7", "True"))), new Variation("281", "e1_vtag2", Collections.singletonList(new FeatureVariableUsageInstance("7", "False")))), userIdToVariationKeyMap, asList(new TrafficAllocation("280", 3000), new TrafficAllocation("281", 10000)), "42"));
List<Experiment> overlappingGroupExperiments = asList(new Experiment("302", "overlapping_etag1", "Running", "5", singletonList("100"), null, asList(new Variation("284", "e1_vtag1", Collections.<FeatureVariableUsageInstance>emptyList()), new Variation("285", "e1_vtag2", Collections.<FeatureVariableUsageInstance>emptyList())), 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 DatafileProjectConfig("789", "1234", "3", "42", groups, experiments, attributes, events, audiences, true);
}
use of com.optimizely.ab.config.audience.NotCondition in project java-sdk by optimizely.
the class JsonSimpleConfigParser method parseConditions.
private Condition parseConditions(JSONArray conditionJson) {
List<Condition> conditions = new ArrayList<Condition>();
String operand = (String) conditionJson.get(0);
for (int i = 1; i < conditionJson.size(); i++) {
Object obj = conditionJson.get(i);
if (obj instanceof JSONArray) {
conditions.add(parseConditions((JSONArray) conditionJson.get(i)));
} else {
JSONObject conditionMap = (JSONObject) obj;
conditions.add(new UserAttribute((String) conditionMap.get("name"), (String) conditionMap.get("type"), (String) conditionMap.get("value")));
}
}
Condition condition;
if (operand.equals("and")) {
condition = new AndCondition(conditions);
} else if (operand.equals("or")) {
condition = new OrCondition(conditions);
} else {
condition = new NotCondition(conditions.get(0));
}
return condition;
}
use of com.optimizely.ab.config.audience.NotCondition 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);
}
use of com.optimizely.ab.config.audience.NotCondition in project java-sdk by optimizely.
the class ConditionJacksonDeserializer method parseConditions.
protected static <T> Condition parseConditions(Class<T> clazz, ObjectMapper objectMapper, JsonNode conditionNode) throws JsonProcessingException, InvalidAudienceCondition {
if (conditionNode.isArray() && conditionNode.size() == 0) {
return new EmptyCondition();
}
List<Condition> conditions = new ArrayList<>();
int startingParsingIndex = 0;
JsonNode opNode = conditionNode.get(0);
String operand = operand(opNode);
if (operand == null) {
operand = "or";
} else {
// the operand is valid so move to the next node.
startingParsingIndex = 1;
}
for (int i = startingParsingIndex; i < conditionNode.size(); i++) {
JsonNode subNode = conditionNode.get(i);
conditions.add(ConditionJacksonDeserializer.<T>parseCondition(clazz, objectMapper, subNode));
}
Condition condition;
switch(operand) {
case "and":
condition = new AndCondition(conditions);
break;
case "not":
condition = new NotCondition(conditions.isEmpty() ? new NullCondition() : conditions.get(0));
break;
default:
condition = new OrCondition(conditions);
break;
}
return condition;
}
Aggregations