Search in sources :

Example 1 with InvalidAudienceCondition

use of com.optimizely.ab.internal.InvalidAudienceCondition 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;
}
Also used : EmptyCondition(com.optimizely.ab.config.audience.EmptyCondition) Condition(com.optimizely.ab.config.audience.Condition) NullCondition(com.optimizely.ab.config.audience.NullCondition) OrCondition(com.optimizely.ab.config.audience.OrCondition) NotCondition(com.optimizely.ab.config.audience.NotCondition) AndCondition(com.optimizely.ab.config.audience.AndCondition) InvalidAudienceCondition(com.optimizely.ab.internal.InvalidAudienceCondition) AudienceIdCondition(com.optimizely.ab.config.audience.AudienceIdCondition) EmptyCondition(com.optimizely.ab.config.audience.EmptyCondition) NotCondition(com.optimizely.ab.config.audience.NotCondition) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) NullCondition(com.optimizely.ab.config.audience.NullCondition) OrCondition(com.optimizely.ab.config.audience.OrCondition) AndCondition(com.optimizely.ab.config.audience.AndCondition)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 AndCondition (com.optimizely.ab.config.audience.AndCondition)1 AudienceIdCondition (com.optimizely.ab.config.audience.AudienceIdCondition)1 Condition (com.optimizely.ab.config.audience.Condition)1 EmptyCondition (com.optimizely.ab.config.audience.EmptyCondition)1 NotCondition (com.optimizely.ab.config.audience.NotCondition)1 NullCondition (com.optimizely.ab.config.audience.NullCondition)1 OrCondition (com.optimizely.ab.config.audience.OrCondition)1 InvalidAudienceCondition (com.optimizely.ab.internal.InvalidAudienceCondition)1 ArrayList (java.util.ArrayList)1