Search in sources :

Example 91 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode 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("$"))) {
                boolean t = false;
                if (svalue != null && svalue.length() == 0) {
                    // Technically "" is a member of any set, but ok, don't let it resolve true.
                    t = false;
                } else {
                    Object x = LookingGlass.get(sval);
                    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 SimpleSet) {
                        SimpleSet set = (SimpleSet) x;
                        t = set.getSet().contains(svalue);
                    } else {
                        // System.out.println("Error: ============> " + this.name + " DONT KNOW WHAT THIS IS: " + x);
                        t = false;
                    }
                }
                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 : SimpleSet(com.xrtb.blocks.SimpleSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) SimpleSet(com.xrtb.blocks.SimpleSet) 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 92 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode 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 can have protocol marker in the domain, need to strip it
    if (siteDomain != null) {
        siteDomain = siteDomain.replaceAll("http://", "");
        siteDomain = siteDomain.replaceAll("https://", "");
        JsonNode node = rootNode.get("site");
        if (node == null)
            node = rootNode.get("app");
        if (node.has("domain")) {
            ObjectNode n = (ObjectNode) node;
            n.remove("domain");
            n.put("domain", siteDomain);
        }
    }
    // 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 : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 93 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class Impression method doNative.

/**
 * Handle the native impression
 */
void doNative() {
    JsonNode node = rnode.get("native");
    if (node != null) {
        JsonNode child = null;
        nativead = true;
        nativePart = new NativePart();
        child = node.path("layout");
        if (child != null) {
            nativePart.layout = child.intValue();
        }
        if (node.path("assets") instanceof MissingNode == false) {
            ArrayNode array = (ArrayNode) node.path("assets");
            for (JsonNode x : array) {
                child = x.path("title");
                if (child instanceof MissingNode == false) {
                    nativePart.title = new Title();
                    nativePart.title.len = child.path("len").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.title.required = x.path("required").intValue();
                    }
                }
                child = x.path("img");
                if (child instanceof MissingNode == false) {
                    nativePart.img = new Img();
                    nativePart.img.w = child.path("w").intValue();
                    nativePart.img.h = child.path("h").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.img.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        if (child.path("mimes") instanceof TextNode) {
                            nativePart.img.mimes.add(child.get("mimes").asText());
                        } else {
                            array = (ArrayNode) child.path("mimes");
                            for (JsonNode nx : array) {
                                nativePart.img.mimes.add(nx.textValue());
                            }
                        }
                    }
                }
                child = x.path("video");
                if (child instanceof MissingNode == false) {
                    nativePart.video = new NativeVideo();
                    nativePart.video.linearity = child.path("linearity").intValue();
                    nativePart.video.minduration = child.path("minduration").intValue();
                    nativePart.video.maxduration = child.path("maxduration").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.video.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        array = (ArrayNode) child.path("protocols");
                        for (JsonNode nx : array) {
                            nativePart.video.protocols.add(nx.textValue());
                        }
                    }
                }
                child = x.path("data");
                if (child instanceof MissingNode == false) {
                    Data data = new Data();
                    if (x.path("required") instanceof MissingNode == false) {
                        data.required = x.path("required").intValue();
                    }
                    if (child.path("len") instanceof MissingNode == false) {
                        data.len = child.path("len").intValue();
                    }
                    data.type = child.path("type").intValue();
                    nativePart.data.add(data);
                }
            }
        }
    }
}
Also used : NativeVideo(com.xrtb.nativeads.creative.NativeVideo) Img(com.xrtb.nativeads.creative.Img) Title(com.xrtb.nativeads.creative.Title) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Data(com.xrtb.nativeads.creative.Data) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 94 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project OpenRefine by OpenRefine.

the class LoadLanguageCommand method doPost.

/**
 * POST is supported but does not actually change any state so we do
 * not add CSRF protection to it. This ensures existing extensions will not
 * have to be updated to add a CSRF token to their requests (2019-11-10)
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String modname = request.getParameter("module");
    if (modname == null) {
        modname = "core";
    }
    String[] langs = request.getParameterValues("lang");
    if (langs == null || "".equals(langs[0])) {
        PreferenceStore ps = ProjectManager.singleton.getPreferenceStore();
        if (ps != null) {
            langs = new String[] { (String) ps.get("userLang") };
        }
    }
    // Default language is English
    if (langs.length == 0 || langs[langs.length - 1] != "en") {
        langs = Arrays.copyOf(langs, langs.length + 1);
        langs[langs.length - 1] = "en";
    }
    ObjectNode translations = null;
    String bestLang = null;
    for (int i = langs.length - 1; i >= 0; i--) {
        if (langs[i] == null)
            continue;
        ObjectNode json = loadLanguage(this.servlet, modname, langs[i]);
        if (json != null) {
            bestLang = langs[i];
            if (translations == null) {
                translations = json;
            } else {
                translations = mergeLanguages(json, translations);
            }
        }
    }
    if (translations != null) {
        try {
            ObjectNode node = ParsingUtilities.mapper.createObjectNode();
            node.set("dictionary", translations);
            node.set("lang", new TextNode(bestLang));
            respondJSON(response, node);
        } catch (IOException e) {
            logger.error("Error writing language labels to response stream");
        }
    } else {
        logger.error("Failed to load any language files");
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) IOException(java.io.IOException) PreferenceStore(com.google.refine.preference.PreferenceStore)

Example 95 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project metacat by Netflix.

the class ConnectorTypeConverter method fromMetacatTypeToJson.

/**
 * Converts from Metacat type to JSON format.
 * @param type type
 * @return Type in JSON format
 */
default JsonNode fromMetacatTypeToJson(Type type) {
    final MetacatJsonLocator json = new MetacatJsonLocator();
    JsonNode result = null;
    final TypeEnum base = type.getTypeSignature().getBase();
    if (!base.isParametricType()) {
        result = new TextNode(fromMetacatType(type));
    } else if (type instanceof DecimalType || type instanceof CharType || type instanceof VarcharType || type instanceof VarbinaryType) {
        final ObjectNode node = json.emptyObjectNode();
        final String typeText = fromMetacatType(type);
        final int index = typeText.indexOf('(');
        if (index == -1) {
            node.put("type", typeText);
        } else {
            node.put("type", typeText.substring(0, index));
            if (type instanceof DecimalType) {
                node.put("precision", ((DecimalType) type).getPrecision());
                node.put("scale", ((DecimalType) type).getScale());
            } else if (type instanceof CharType) {
                node.put("length", ((CharType) type).getLength());
            } else if (type instanceof VarcharType) {
                node.put("length", ((VarcharType) type).getLength());
            } else {
                node.put("length", ((VarbinaryType) type).getLength());
            }
        }
        result = node;
    } else if (base.equals(TypeEnum.MAP)) {
        final MapType mapType = (MapType) type;
        final ObjectNode node = json.emptyObjectNode();
        node.put("type", TypeEnum.MAP.getType());
        node.set("keyType", fromMetacatTypeToJson(mapType.getKeyType()));
        node.set("valueType", fromMetacatTypeToJson(mapType.getValueType()));
        result = node;
    } else if (base.equals(TypeEnum.ROW)) {
        final RowType rowType = (RowType) type;
        final ObjectNode node = json.emptyObjectNode();
        final ArrayNode fieldsNode = node.arrayNode();
        rowType.getFields().forEach(f -> {
            final ObjectNode fieldNode = json.emptyObjectNode();
            fieldNode.put("name", f.getName());
            fieldNode.set("type", fromMetacatTypeToJson(f.getType()));
            fieldsNode.add(fieldNode);
        });
        node.put("type", TypeEnum.ROW.getType());
        node.set("fields", fieldsNode);
        result = node;
    } else if (base.equals(TypeEnum.ARRAY)) {
        final ObjectNode node = json.emptyObjectNode();
        node.put("type", TypeEnum.ARRAY.getType());
        ((ParametricType) type).getParameters().stream().findFirst().ifPresent(t -> node.set("elementType", fromMetacatTypeToJson(t)));
        result = node;
    }
    return result;
}
Also used : DecimalType(com.netflix.metacat.common.type.DecimalType) VarbinaryType(com.netflix.metacat.common.type.VarbinaryType) Type(com.netflix.metacat.common.type.Type) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) CharType(com.netflix.metacat.common.type.CharType) VarcharType(com.netflix.metacat.common.type.VarcharType) JsonNode(com.fasterxml.jackson.databind.JsonNode) RowType(com.netflix.metacat.common.type.RowType) TypeEnum(com.netflix.metacat.common.type.TypeEnum) MapType(com.netflix.metacat.common.type.MapType) ParametricType(com.netflix.metacat.common.type.ParametricType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VarcharType(com.netflix.metacat.common.type.VarcharType) RowType(com.netflix.metacat.common.type.RowType) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) MapType(com.netflix.metacat.common.type.MapType) VarbinaryType(com.netflix.metacat.common.type.VarbinaryType) TypeEnum(com.netflix.metacat.common.type.TypeEnum) DecimalType(com.netflix.metacat.common.type.DecimalType) CharType(com.netflix.metacat.common.type.CharType) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)140 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)48 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)37 Test (org.junit.Test)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 IntNode (com.fasterxml.jackson.databind.node.IntNode)16 ArrayList (java.util.ArrayList)16 Test (org.junit.jupiter.api.Test)15 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)12 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 TreeNode (com.fasterxml.jackson.core.TreeNode)11 HashMap (java.util.HashMap)11 List (java.util.List)11 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 Map (java.util.Map)10