Search in sources :

Example 11 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project XRTB by benmfaul.

the class Node method testInternal.

/**
	 * Internal version of test() when recursion is required (NOT_* form)
	 * 
	 * @param value.
	 *            Object. Converts the value of the bid request field (Jackson)
	 *            to the appropriate Java object.
	 * @return boolean. Returns true if the operation succeeded.
	 * @throws Exception
	 *             if the value is not recognized or is not compatible with
	 *             this.value.
	 */
public boolean testInternal(Object value) throws Exception {
    if (value == null || value instanceof MissingNode == true) {
        // request.
        if (!(operator == EXISTS || operator == NOT_EXISTS)) {
            if (notPresentOk)
                return true;
            return false;
        }
    }
    Number nvalue = null;
    String svalue = null;
    //	Set qvalue = null;
    Set qval = null;
    if (value instanceof String)
        svalue = (String) value;
    if (value instanceof IntNode) {
        IntNode n = (IntNode) value;
        nvalue = n.numberValue();
    } else if (value instanceof TextNode) {
        TextNode tn = (TextNode) value;
        svalue = tn.textValue();
    } else if (value instanceof ArrayNode) {
        List list = traverse((ArrayNode) value);
        qvalue = new TreeSet(list);
    } else if (value instanceof ObjectNode) {
        ObjectNode n = (ObjectNode) value;
        mvalue = iterateObject(n);
    } else if (value instanceof Double) {
        // (Node) value;
        DoubleNode n = new DoubleNode((Double) value);
        nvalue = n.numberValue();
    } else if (value instanceof DoubleNode) {
        DoubleNode n = (DoubleNode) value;
        n.asDouble();
        // (Node) value;
        DoubleNode nn = new DoubleNode(n.asDouble());
        nvalue = nn.numberValue();
    } else if (value instanceof Integer) {
        // (Node) value;
        IntNode n = new IntNode((Integer) value);
        nvalue = n.numberValue();
    } else if (value instanceof Collection) {
        qvalue = new TreeSet();
        qvalue.addAll((Collection) value);
    }
    switch(operator) {
        case QUERY:
            return true;
        case EQUALS:
            return processEquals(ival, nvalue, sval, svalue, qval, qvalue);
        case NOT_EQUALS:
            return !processEquals(ival, nvalue, sval, svalue, qval, qvalue);
        case STRINGIN:
            if (lval != null) {
                boolean member = false;
                for (int i = 0; i < lval.size(); i++) {
                    Object test = lval.get(i);
                    if (test instanceof String) {
                        String testS = (String) test;
                        member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
                    }
                }
                return member;
            }
            return processStringin(ival, nvalue, sval, svalue, qval, qvalue);
        case NOT_STRINGIN:
            if (lval != null) {
                boolean member = false;
                for (int i = 0; i < lval.size(); i++) {
                    Object test = lval.get(i);
                    if (test instanceof String) {
                        String testS = (String) test;
                        member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
                    }
                }
                return !member;
            }
            return !processStringin(ival, nvalue, sval, svalue, qval, qvalue);
        case REGEX:
        case NOT_REGEX:
            boolean member = true;
            if (svalue != null) {
                member = processRegex(ival, nvalue, sval, svalue, qval, qvalue);
            }
            if (operator == NOT_REGEX)
                return !member;
            else
                return member;
        case MEMBER:
        case NOT_MEMBER:
            if (sval != null && (sval.startsWith("@") || sval.startsWith("$"))) {
                Object x = LookingGlass.get(sval);
                boolean t = false;
                if (x instanceof NavMap) {
                    NavMap nm = (NavMap) x;
                    t = nm.contains(svalue);
                } else if (x instanceof BloomFilter) {
                    BloomFilter b = (BloomFilter) x;
                    t = b.mightContain(svalue);
                } else if (x instanceof Set) {
                    Set set = (Set) x;
                    t = set.contains(svalue);
                }
                if (operator == NOT_MEMBER)
                    return !t;
                else
                    return t;
            }
            if (qvalue == null) {
                if (lval != null)
                    qvalue = new HashSet(lval);
                else {
                    qvalue = new HashSet();
                    if (svalue == null)
                        qvalue.addAll((Collection) value);
                    else
                        qvalue.add(svalue);
                }
            }
            if (nvalue == null && svalue == null) {
                if (this.value instanceof String)
                    svalue = (String) this.value;
                else {
                    try {
                        nvalue = (Integer) this.value;
                    } catch (Exception error) {
                        return false;
                    //System.out.println("QVALUE: " + qvalue);
                    //System.out.println("THIS VALUE: " + this.value);
                    //System.out.println("VALUE: " + value);
                    }
                }
            }
            boolean test = false;
            test = processMember(nvalue, svalue, qvalue);
            if (operator == MEMBER)
                return test;
            else
                return !test;
        case INTERSECTS:
        case NOT_INTERSECTS:
            if (qvalue == null) {
                if (lval != null)
                    qvalue = new TreeSet(lval);
            }
            if (qval == null) {
                if (svalue != null) {
                    qval = new TreeSet();
                    qval.add(svalue);
                } else {
                    if (nvalue != null) {
                        qval = new TreeSet();
                        qval.add(nvalue);
                    } else if (lval != null) {
                        qval = new TreeSet(lval);
                    }
                }
            } else {
                if (svalue != null) {
                    qval.add(svalue);
                } else {
                    if (nvalue != null) {
                        qval.add(nvalue.intValue());
                    }
                }
            }
            if (qval == null)
                qval = new TreeSet(lval);
            boolean xxx = processIntersects(qval, qvalue);
            if (operator == INTERSECTS)
                return xxx;
            return !xxx;
        case INRANGE:
            return computeInRange(mvalue, lval);
        case NOT_INRANGE:
            return !computeInRange(mvalue, lval);
        case DOMAIN:
            return computeInDomain(nvalue, lval);
        case NOT_DOMAIN:
            return !computeInDomain(nvalue, lval);
        case LESS_THAN:
        case LESS_THAN_EQUALS:
        case GREATER_THAN:
        case GREATER_THAN_EQUALS:
            return processLTE(operator, ival, nvalue, sval, svalue, qval, qvalue);
        case EXISTS:
        case NOT_EXISTS:
            boolean rc = false;
            if (value == null)
                rc = false;
            else
                rc = value instanceof ObjectNode;
            if (operator == EXISTS)
                return rc;
            return !rc;
        default:
            return false;
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) BloomFilter(com.google.common.hash.BloomFilter) IntNode(com.fasterxml.jackson.databind.node.IntNode) TreeSet(java.util.TreeSet) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NavMap(com.xrtb.blocks.NavMap) HashSet(java.util.HashSet)

Example 12 with MissingNode

use of com.fasterxml.jackson.databind.node.MissingNode in project XRTB by benmfaul.

the class C1X method parseSpecial.

/**
         * Process special C1X stuff, sets the exchange name. Sets encoding.
         */
@Override
public boolean parseSpecial() {
    setExchange("c1x");
    usesEncodedAdm = false;
    // C1X uses ISO2 country codes, we can't digest that with our campaign processor, so we
    // will convert it for them and patch the bid request.
    // Use a cache of country codes to keep from creating a lot of objects to be later garbage collected.
    Object o = this.database.get("device.geo.country");
    if (o instanceof MissingNode) {
        return true;
    }
    TextNode country = (TextNode) o;
    TextNode test = null;
    if (country != null) {
        test = cache.get(country.asText());
        if (test == null) {
            String iso3 = isoMap.query(country.asText());
            test = new TextNode(iso3);
        }
        if (test != country)
            database.put("device.geo.country", test);
    }
    return true;
}
Also used : MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

MissingNode (com.fasterxml.jackson.databind.node.MissingNode)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 IntNode (com.fasterxml.jackson.databind.node.IntNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)2 NativeVideo (com.xrtb.nativeads.creative.NativeVideo)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SecurityQuestionsAuthenticationContext (com.evolveum.midpoint.model.api.context.SecurityQuestionsAuthenticationContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)1 SecurityQuestionDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 BloomFilter (com.google.common.hash.BloomFilter)1 NavMap (com.xrtb.blocks.NavMap)1