Example usage for com.fasterxml.jackson.databind JsonNode equals

List of usage examples for com.fasterxml.jackson.databind JsonNode equals

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode equals.

Prototype

public abstract boolean equals(Object paramObject);

Source Link

Usage

From source file:com.ikanow.aleph2.search_service.elasticsearch.services.ElasticsearchIndexService.java

/** Check if a new mapping based on a schema is equivalent to a mapping previously stored (from a schema) 
 * @param stored_mapping/*from   w  w w .  ja v  a 2s  .c o m*/
 * @param new_mapping
 * @param mapper
 * @return
 * @throws JsonProcessingException
 * @throws IOException
 */
protected static boolean mappingsAreEquivalent(final IndexTemplateMetaData stored_mapping,
        final JsonNode new_mapping, final ObjectMapper mapper) throws JsonProcessingException, IOException {

    final ObjectNode stored_json_mappings = StreamSupport.stream(stored_mapping.mappings().spliterator(), false)
            .reduce(mapper.createObjectNode(), Lambdas.wrap_u(
                    (acc, kv) -> (ObjectNode) acc.setAll((ObjectNode) mapper.readTree(kv.value.string()))),
                    (acc1, acc2) -> acc1); // (can't occur)

    final JsonNode new_json_mappings = Optional.ofNullable(new_mapping.get("mappings"))
            .orElse(mapper.createObjectNode());

    final JsonNode stored_json_settings = mapper.convertValue(Optional.ofNullable(stored_mapping.settings())
            .orElse(ImmutableSettings.settingsBuilder().build()).getAsMap(), JsonNode.class);

    final JsonNode new_json_settings = Optional.ofNullable(new_mapping.get("settings"))
            .orElse(mapper.createObjectNode());

    final ObjectNode stored_json_aliases = StreamSupport
            .stream(Optional.ofNullable(
                    stored_mapping.aliases()).orElse(
                            ImmutableOpenMap.of())
                    .spliterator(), false)
            .reduce(mapper.createObjectNode(), Lambdas.wrap_u((acc, kv) -> (ObjectNode) acc.set(kv.key,
                    kv.value.filteringRequired() ? mapper.createObjectNode().set("filter",
                            mapper.readTree(kv.value.filter().string())) : mapper.createObjectNode())),
                    (acc1, acc2) -> acc1); // (can't occur)

    final JsonNode new_json_aliases = Optional.ofNullable(new_mapping.get("aliases"))
            .orElse(mapper.createObjectNode());

    return stored_json_mappings.equals(new_json_mappings) && stored_json_settings.equals(new_json_settings)
            && stored_json_aliases.equals(new_json_aliases);
}

From source file:com.unboundid.scim2.common.utils.FilterEvaluator.java

/**
 * Evaluate a substring match filter./*from   w ww. j  a  va2s .  c  o  m*/
 *
 * @param filter The filter to operate on.
 * @param object The object to evaluate.
 * @return The return value from the operation.
 * @throws ScimException If an exception occurs during the operation.
 */
private boolean substringMatch(final Filter filter, final JsonNode object) throws ScimException {
    Iterable<JsonNode> nodes = getCandidateNodes(filter.getAttributePath(), object);
    for (JsonNode node : nodes) {
        if (node.isTextual() && filter.getComparisonValue().isTextual()) {
            AttributeDefinition attributeDefinition = getAttributeDefinition(filter.getAttributePath());
            String nodeValue = node.textValue();
            String comparisonValue = filter.getComparisonValue().textValue();
            if (attributeDefinition == null || !attributeDefinition.isCaseExact()) {
                nodeValue = StaticUtils.toLowerCase(nodeValue);
                comparisonValue = StaticUtils.toLowerCase(comparisonValue);
            }
            switch (filter.getFilterType()) {
            case CONTAINS:
                if (nodeValue.contains(comparisonValue)) {
                    return true;
                }
                break;
            case STARTS_WITH:
                if (nodeValue.startsWith(comparisonValue)) {
                    return true;
                }
                break;
            case ENDS_WITH:
                if (nodeValue.endsWith(comparisonValue)) {
                    return true;
                }
                break;
            }
        } else if (node.equals(filter.getComparisonValue())) {
            return true;
        }
    }
    return false;
}

From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java

public void updateEventType(int requestVersion, String accountName, String eventType, String body)
/*      */ {/*from   w ww  .j  av  a 2 s .  c om*/
    /*  239 */ eventType = this.indexNameResolver.resolveEventType(eventType);
    /*  240 */ accountName = AccountConfiguration.normalizeAccountName(accountName);
    /*      */
    /*      */
    /*  243 */ JsonNode existingEventType = getEventType(requestVersion, accountName, eventType);
    /*  244 */ if (existingEventType == null) {
        /*  245 */ throw new EventTypeMissingException(accountName, eventType);
        /*      */ }
    /*      */
    /*  248 */ ObjectNode bodyNode = ElasticSearchQueryHelper.parseJsonQueryToObjectModel(body);
    /*      */
    /*  250 */ mergeOrCopyObject(existingEventType, bodyNode, "metaData");
    /*      */
    /*  252 */ EventTypeMetaData metaData = preProcessBodyNodeAndReturnMetaData(requestVersion, accountName,
            eventType, bodyNode, null);
    /*      */
    /*      */
    /*      */
    /*  256 */ mergeOrCopyObject(existingEventType, bodyNode, "properties");
    /*      */
    /*      */
    /*      */
    /*  260 */ JsonNode newMergedEventType = existingEventType.deepCopy();
    /*      */
    /*  262 */ copyField("metaData", bodyNode, (ObjectNode) newMergedEventType);
    /*  263 */ copyField("properties", bodyNode, (ObjectNode) newMergedEventType);
    /*      */
    /*  265 */ EventTypeMetaData existingMetadataOnServer = getEventTypeMetaData(accountName, eventType);
    /*  266 */ int lifespan = getHotLifespanInDays(accountName, eventType, metaData);
    /*  267 */ metaData.setHotLifespanInDays(Integer.valueOf(lifespan));
    /*  268 */ if (log.isDebugEnabled()) {
        /*  269 */ log.debug(
                "\nEvent type old:\n[{}]\nEvent type new:\n[{}]\nMetadata old:\n[{}]\nMetadata new:\n[{}]",
                new Object[] { existingEventType, newMergedEventType, existingMetadataOnServer, metaData });
        /*      */ }
    /*      */
    /*      */
    /*  273 */ stripExplicitAnalyzedStrings(newMergedEventType);
    /*  274 */ if ((existingEventType.equals(newMergedEventType))
            && (existingMetadataOnServer.equals(metaData)))
    /*      */ {
        /*  276 */ log.info(
                "Update call to event type [{}] for account [{}] has been ignored as there is no change",
                eventType, accountName);
        /*      */ }
    /*      */ else {
        /*  279 */ upsertEventType(accountName, eventType, bodyNode, metaData);
        /*      */ }
    /*      */ }