Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#isNull()

The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode#isNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestValidator.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
/**
 * Validates {@link ExtMediaTypePriceGranularity} if it's present.
 */
private void validateMediaTypePriceGranularity(ExtMediaTypePriceGranularity mediaTypePriceGranularity)
        throws ValidationException {
    if (mediaTypePriceGranularity != null) {
        final ObjectNode banner = mediaTypePriceGranularity.getBanner();
        final ObjectNode video = mediaTypePriceGranularity.getVideo();
        final ObjectNode xNative = mediaTypePriceGranularity.getXNative();
        final boolean isBannerNull = banner == null || banner.isNull();
        final boolean isVideoNull = video == null || video.isNull();
        final boolean isNativeNull = xNative == null || xNative.isNull();
        if (isBannerNull && isVideoNull && isNativeNull) {
            throw new ValidationException(
                    "Media type price granularity error: must have at least one media type present");
        }
        if (!isBannerNull) {
            validateExtPriceGranularity(banner, BidType.banner);
        }
        if (!isVideoNull) {
            validateExtPriceGranularity(video, BidType.video);
        }
        if (!isNativeNull) {
            validateExtPriceGranularity(xNative, BidType.xNative);
        }
    }
}
 
Example 2
Source File: ExchangeService.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts a map of bidders to their arguments from {@link ObjectNode} prebid.bidders.
 */
private static Map<String, JsonNode> bidderToPrebidBidders(ExtBidRequest requestExt) {
    final ExtRequestPrebid prebid = requestExt == null ? null : requestExt.getPrebid();
    final ObjectNode bidders = prebid == null ? null : prebid.getBidders();

    if (bidders == null || bidders.isNull()) {
        return Collections.emptyMap();
    }

    final Map<String, JsonNode> bidderToPrebidParameters = new HashMap<>();
    final Iterator<Map.Entry<String, JsonNode>> biddersToParams = bidders.fields();
    while (biddersToParams.hasNext()) {
        final Map.Entry<String, JsonNode> bidderToParam = biddersToParams.next();
        bidderToPrebidParameters.put(bidderToParam.getKey(), bidderToParam.getValue());
    }
    return bidderToPrebidParameters;
}
 
Example 3
Source File: LargeTextNodeRemover.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
private void handleObjectNode(final String table,
                              final String documentId,
                              ObjectNode objectNode) {
    if (objectNode == null || objectNode.isNull()) {
        return;
    }
    List<String> toBeRemoved = Lists.newArrayList();
    objectNode.fields().forEachRemaining(entry -> {
        val key = entry.getKey();
        val value = entry.getValue();
        if (value.isTextual()) {
            boolean removeEntry = evaluateForRemoval(table, documentId, key, value);
            if (removeEntry) {
                toBeRemoved.add(entry.getKey());
            }
        } else if (value.isArray()) {
            handleArrayNode(table, documentId, key, (ArrayNode) value);
        } else if (value.isObject()) {
            handleObjectNode(table, documentId, (ObjectNode) value);
        }
    });
    objectNode.remove(toBeRemoved);
}
 
Example 4
Source File: HGraphQLConverter.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private String langSTR(ObjectNode langArg) {

        if (langArg.isNull()) {
            return "";
        }
        final String LANGARG = "(lang:\"%s\")";
        return String.format(LANGARG, langArg.get("lang").asText());
    }
 
Example 5
Source File: BidResponseCreator.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a map of {@link BidType} to correspondent {@link TargetingKeywordsCreator}
 * extracted from {@link ExtRequestTargeting} if it exists.
 */
private Map<BidType, TargetingKeywordsCreator> keywordsCreatorByBidType(ExtRequestTargeting targeting,
                                                                        boolean isApp, Account account) {
    final ExtMediaTypePriceGranularity mediaTypePriceGranularity = targeting.getMediatypepricegranularity();

    if (mediaTypePriceGranularity == null) {
        return Collections.emptyMap();
    }

    final Map<BidType, TargetingKeywordsCreator> result = new HashMap<>();
    final int resolvedTruncateAttrChars = resolveTruncateAttrChars(targeting, account);

    final ObjectNode banner = mediaTypePriceGranularity.getBanner();
    final boolean isBannerNull = banner == null || banner.isNull();
    if (!isBannerNull) {
        result.put(BidType.banner, TargetingKeywordsCreator.create(parsePriceGranularity(banner),
                targeting.getIncludewinners(), targeting.getIncludebidderkeys(), isApp, resolvedTruncateAttrChars));
    }

    final ObjectNode video = mediaTypePriceGranularity.getVideo();
    final boolean isVideoNull = video == null || video.isNull();
    if (!isVideoNull) {
        result.put(BidType.video, TargetingKeywordsCreator.create(parsePriceGranularity(video),
                targeting.getIncludewinners(), targeting.getIncludebidderkeys(), isApp, resolvedTruncateAttrChars));
    }

    final ObjectNode xNative = mediaTypePriceGranularity.getXNative();
    final boolean isNativeNull = xNative == null || xNative.isNull();
    if (!isNativeNull) {
        result.put(BidType.xNative, TargetingKeywordsCreator.create(parsePriceGranularity(xNative),
                targeting.getIncludewinners(), targeting.getIncludebidderkeys(), isApp, resolvedTruncateAttrChars));
    }

    return result;
}
 
Example 6
Source File: AppnexusBidder.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
private ObjectNode updatedBidRequestExt(BidRequest bidRequest) {
    final ObjectNode requestExt = bidRequest.getExt();
    if (requestExt != null && !requestExt.isNull()) {
        final AppnexusReqExt appnexusReqExt = parseRequestExt(requestExt);
        if (isIncludeBrandCategory(appnexusReqExt)) {
            final AppnexusReqExt updateAppnexusReqExt =
                    AppnexusReqExt.of(AppnexusReqExtAppnexus.of(true, true), appnexusReqExt.getPrebid());
            return mapper.mapper().valueToTree(updateAppnexusReqExt);
        }
    }
    return null;
}
 
Example 7
Source File: HGraphQLConverter.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private String langSTR(ObjectNode langArg) {

        if (langArg.isNull()) {
            return "";
        }
        final String LANGARG = "(lang:\"%s\")";
        return String.format(LANGARG, langArg.get("lang").asText());
    }
 
Example 8
Source File: UpdateMessagePatchConverter.java    From james-project with Apache License 2.0 5 votes vote down vote up
public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) {
    if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) {
        throw new IllegalArgumentException("updatePatchNode");
    }
    if (! validator.isValid(updatePatchNode)) {
        return UpdateMessagePatch.builder()
                .validationResult(validator.validate(updatePatchNode))
                .build();
    }
    try {
        return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: ViewFieldsCollector.java    From tasmo with Apache License 2.0 5 votes vote down vote up
public boolean add(ViewDescriptor viewDescriptor,
        ModelPath modelPath,
        Id[] modelPathIds,
        String[] viewPathClasses,
        ViewValue viewValue,
        Long timestamp) throws IOException {

    byte[] value = (viewValue == null) ? null : viewValue.getValue();
    viewSizeInBytes += (value == null) ? 0 : value.length;
    if (viewSizeInBytes > viewMaxSizeInBytes) {
        LOG.error("ViewDescriptor:" + viewDescriptor + " is larger than viewMaxReadableBytes:" + viewMaxSizeInBytes);
        return false;
    }

    if (viewValue == null || viewValue.getValue() == null || viewValue.getValue().length == 0) {
        return false;
    }
    ObjectNode valueObject = merger.toObjectNode(viewValue.getValue());
    if (valueObject == null || valueObject.isNull() || valueObject.size() == 0) {
        return false;
    }

    ObjectId[] modelPathInstanceIds = modelPathInstanceIds(modelPathIds, viewPathClasses, modelPath.getPathMembers());

    LOG.debug("Read view path -> with id={} instance ids={} value={} timestamp={}", new Object[]{modelPath.getId(), modelPathIds, viewValue, timestamp});

    if (treeRoot == null) {
        treeRoot = new MapTreeNode(modelPathInstanceIds[0]);
    }
    treeRoot.add(modelPath.getPathMembers().toArray(new ModelPathStep[modelPath.getPathMemberSize()]), modelPathInstanceIds, viewValue, timestamp);
    return true;
}
 
Example 10
Source File: ViewFieldsCollector.java    From tasmo with Apache License 2.0 5 votes vote down vote up
public boolean add(ViewDescriptor viewDescriptor,
        ModelPath modelPath,
        Id[] modelPathIds,
        String[] viewPathClasses,
        ViewValue viewValue,
        Long timestamp) throws IOException {

    byte[] value = (viewValue == null) ? null : viewValue.getValue();
    viewSizeInBytes += (value == null) ? 0 : value.length;
    if (viewSizeInBytes > viewMaxSizeInBytes) {
        LOG.error("ViewDescriptor:" + viewDescriptor + " is larger than viewMaxReadableBytes:" + viewMaxSizeInBytes);
        return false;
    }

    if (viewValue == null || viewValue.getValue() == null || viewValue.getValue().length == 0) {
        return false;
    }
    ObjectNode valueObject = merger.toObjectNode(viewValue.getValue());
    if (valueObject == null || valueObject.isNull() || valueObject.size() == 0) {
        return false;
    }

    ObjectId[] modelPathInstanceIds = modelPathInstanceIds(modelPathIds, viewPathClasses, modelPath.getPathMembers());

    LOG.debug("Read view path -> with id={} instance ids={} value={} timestamp={}", new Object[]{modelPath.getId(), modelPathIds, viewValue, timestamp});

    if (treeRoot == null) {
        treeRoot = new MapTreeNode(modelPathInstanceIds[0]);
    }
    treeRoot.add(modelPath.getPathMembers().toArray(new ModelPathStep[modelPath.getPathMemberSize()]), modelPathInstanceIds, viewValue, timestamp);
    return true;
}
 
Example 11
Source File: EventModel.java    From tasmo with Apache License 2.0 4 votes vote down vote up
public EventModel build() {
    String eventClass = eventHelper.getInstanceClassName(eventNode);
    Map<String, ValueType> eventFields = new HashMap<>();

    ObjectNode instanceNode = eventHelper.getInstanceNode(eventNode, eventClass);

    if (instanceNode == null || instanceNode.isNull()) {
        throw new IllegalArgumentException("Events must contain a populated instance node");
    }

    for (Iterator<String> eventFieldNames = instanceNode.fieldNames(); eventFieldNames.hasNext();) {
        String eventFieldName = eventFieldNames.next();
        JsonNode exampleValue = instanceNode.get(eventFieldName);

        if (isExampleEvent && (exampleValue == null || exampleValue.isNull())) {
            throw new IllegalArgumentException("Example event fields must contain a valid value. " + eventFieldName + " does not");
        }

        if (exampleValue.isTextual() && ObjectId.isStringForm(exampleValue.textValue())) {
            eventFields.put(eventFieldName, ValueType.ref);
        } else if (exampleValue.isArray()) {
            ArrayNode exampleArray = (ArrayNode) exampleValue;
            if (isExampleEvent && (exampleArray.size() != 1)) {
                throw new IllegalArgumentException("Array values in example events must contain one element. "
                        + "The array value for field " + eventFieldName + " has " + exampleArray.size() + " elements.");
            }

            if (exampleArray.size() > 0) {
                JsonNode element = exampleArray.get(0);

                if (element.isNull()) {
                    if (isExampleEvent) {
                        throw new IllegalArgumentException("Elements in event field value arrays can't be null. "
                                + "The " + eventFieldName + " field holds an array with an empty json node as the sole element.");
                    } else {
                        eventFields.put(eventFieldName, ValueType.unknown);
                    }
                } else {
                    if (element.isTextual() && ObjectId.isStringForm(element.textValue())) {
                        eventFields.put(eventFieldName, ValueType.refs);
                    } else {
                        eventFields.put(eventFieldName, ValueType.value);
                    }
                }
            } else {
                eventFields.put(eventFieldName, ValueType.unknown);
            }

        } else {
            eventFields.put(eventFieldName, ValueType.value);
        }
    }
    return new EventModel(eventClass, eventFields);
}
 
Example 12
Source File: EventModel.java    From tasmo with Apache License 2.0 4 votes vote down vote up
public EventModel build() {
    String eventClass = eventHelper.getInstanceClassName(eventNode);
    Map<String, ValueType> eventFields = new HashMap<>();

    ObjectNode instanceNode = eventHelper.getInstanceNode(eventNode, eventClass);

    if (instanceNode == null || instanceNode.isNull()) {
        throw new IllegalArgumentException("Events must contain a populated instance node");
    }

    for (Iterator<String> eventFieldNames = instanceNode.fieldNames(); eventFieldNames.hasNext();) {
        String eventFieldName = eventFieldNames.next();
        JsonNode exampleValue = instanceNode.get(eventFieldName);

        if (isExampleEvent && (exampleValue == null || exampleValue.isNull())) {
            throw new IllegalArgumentException("Example event fields must contain a valid value. " + eventFieldName + " does not");
        }

        if (exampleValue.isTextual() && ObjectId.isStringForm(exampleValue.textValue())) {
            eventFields.put(eventFieldName, ValueType.ref);
        } else if (exampleValue.isArray()) {
            ArrayNode exampleArray = (ArrayNode) exampleValue;
            if (isExampleEvent && (exampleArray.size() != 1)) {
                throw new IllegalArgumentException("Array values in example events must contain one element. "
                        + "The array value for field " + eventFieldName + " has " + exampleArray.size() + " elements.");
            }

            if (exampleArray.size() > 0) {
                JsonNode element = exampleArray.get(0);

                if (element.isNull()) {
                    if (isExampleEvent) {
                        throw new IllegalArgumentException("Elements in event field value arrays can't be null. "
                                + "The " + eventFieldName + " field holds an array with an empty json node as the sole element.");
                    } else {
                        eventFields.put(eventFieldName, ValueType.unknown);
                    }
                } else {
                    if (element.isTextual() && ObjectId.isStringForm(element.textValue())) {
                        eventFields.put(eventFieldName, ValueType.refs);
                    } else {
                        eventFields.put(eventFieldName, ValueType.value);
                    }
                }
            } else {
                eventFields.put(eventFieldName, ValueType.unknown);
            }

        } else {
            eventFields.put(eventFieldName, ValueType.value);
        }
    }
    return new EventModel(eventClass, eventFields);
}