use of com.optimizely.ab.config.TrafficAllocation in project java-sdk by optimizely.
the class JsonSimpleConfigParser method parseGroups.
private List<Group> parseGroups(JSONArray groupJson) {
List<Group> groups = new ArrayList<Group>(groupJson.size());
for (Object obj : groupJson) {
JSONObject groupObject = (JSONObject) obj;
String id = (String) groupObject.get("id");
String policy = (String) groupObject.get("policy");
List<Experiment> experiments = parseExperiments((JSONArray) groupObject.get("experiments"), id);
List<TrafficAllocation> trafficAllocations = parseTrafficAllocation((JSONArray) groupObject.get("trafficAllocation"));
groups.add(new Group(id, policy, experiments, trafficAllocations));
}
return groups;
}
use of com.optimizely.ab.config.TrafficAllocation in project java-sdk by optimizely.
the class JsonConfigParser method parseGroups.
private List<Group> parseGroups(JSONArray groupJson) {
List<Group> groups = new ArrayList<Group>(groupJson.length());
for (Object obj : groupJson) {
JSONObject groupObject = (JSONObject) obj;
String id = groupObject.getString("id");
String policy = groupObject.getString("policy");
List<Experiment> experiments = parseExperiments(groupObject.getJSONArray("experiments"), id);
List<TrafficAllocation> trafficAllocations = parseTrafficAllocation(groupObject.getJSONArray("trafficAllocation"));
groups.add(new Group(id, policy, experiments, trafficAllocations));
}
return groups;
}
use of com.optimizely.ab.config.TrafficAllocation in project java-sdk by optimizely.
the class JsonSimpleConfigParser method parseTrafficAllocation.
private List<TrafficAllocation> parseTrafficAllocation(JSONArray trafficAllocationJson) {
List<TrafficAllocation> trafficAllocation = new ArrayList<TrafficAllocation>(trafficAllocationJson.size());
for (Object obj : trafficAllocationJson) {
JSONObject allocationObject = (JSONObject) obj;
String entityId = (String) allocationObject.get("entityId");
long endOfRange = (Long) allocationObject.get("endOfRange");
trafficAllocation.add(new TrafficAllocation(entityId, (int) endOfRange));
}
return trafficAllocation;
}
use of com.optimizely.ab.config.TrafficAllocation in project java-sdk by optimizely.
the class GroupJacksonDeserializer method deserialize.
@Override
public Group deserialize(JsonParser parser, DeserializationContext context) throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = parser.getCodec().readTree(parser);
String id = node.get("id").textValue();
String policy = node.get("policy").textValue();
List<TrafficAllocation> trafficAllocations = mapper.readValue(node.get("trafficAllocation").toString(), new TypeReference<List<TrafficAllocation>>() {
});
JsonNode groupExperimentsJson = node.get("experiments");
List<Experiment> groupExperiments = new ArrayList<Experiment>();
if (groupExperimentsJson.isArray()) {
for (JsonNode groupExperimentJson : groupExperimentsJson) {
groupExperiments.add(parseExperiment(groupExperimentJson, id));
}
}
return new Group(id, policy, groupExperiments, trafficAllocations);
}
use of com.optimizely.ab.config.TrafficAllocation in project java-sdk by optimizely.
the class GroupJacksonDeserializer method parseExperiment.
private Experiment parseExperiment(JsonNode experimentJson, String groupId) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String id = experimentJson.get("id").textValue();
String key = experimentJson.get("key").textValue();
String status = experimentJson.get("status").textValue();
JsonNode layerIdJson = experimentJson.get("layerId");
String layerId = layerIdJson == null ? null : layerIdJson.textValue();
List<String> audienceIds = mapper.readValue(experimentJson.get("audienceIds").toString(), new TypeReference<List<String>>() {
});
List<Variation> variations = mapper.readValue(experimentJson.get("variations").toString(), new TypeReference<List<Variation>>() {
});
List<TrafficAllocation> trafficAllocations = mapper.readValue(experimentJson.get("trafficAllocation").toString(), new TypeReference<List<TrafficAllocation>>() {
});
Map<String, String> userIdToVariationKeyMap = mapper.readValue(experimentJson.get("forcedVariations").toString(), new TypeReference<Map<String, String>>() {
});
return new Experiment(id, key, status, layerId, audienceIds, variations, userIdToVariationKeyMap, trafficAllocations, groupId);
}
Aggregations