@Override public final boolean isNull() { return value.isMissingNode() || value.isNull(); }
@Override public final boolean isNull() { return value.isMissingNode() || value.isNull(); }
@Override public boolean isNull() { return value.isMissingNode() || value.isNull(); }
private String serializedConfiguration(JsonNode config) throws JsonProcessingException{ ObjectMapper mapper = new ObjectMapper(); ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); return config.isMissingNode() ? null : writer.writeValueAsString(config); }
protected boolean isEqualToCurrentLocalizationValue(String language, String id, String propertyName, String propertyValue, ObjectNode infoNode) { boolean isEqual = false; JsonNode localizationNode = infoNode.path("localization").path(language).path(id).path(propertyName); if (!localizationNode.isMissingNode() && !localizationNode.isNull() && localizationNode.asText().equals(propertyValue)) { isEqual = true; } return isEqual; }
protected JsonNode findJsonNode(JsonNode resource, String nodeName) { JsonNode jsonNode = resource.path(nodeName); if (_log.isDebugEnabled()) { if (jsonNode.isMissingNode()) { _log.debug("Unable to find the \"{}\" node", nodeName); } if (jsonNode.isArray() && (jsonNode.size() == 0)) { _log.debug("The \"{}\" array node is empty", jsonNode); } } return jsonNode; }
private static JsonNode _findJsonNode(JsonNode resource, String nodeName) { JsonNode jsonNode = resource.path(nodeName); if (_log.isDebugEnabled()) { if (jsonNode.isMissingNode()) { _log.debug("Unable to find the \"{}\" node", nodeName); } if (jsonNode.isArray() && (jsonNode.size() == 0)) { _log.debug("The \"{}\" array node is empty", jsonNode); } } return jsonNode; }
private AuthConfig authConfigUsingStore(final JsonNode config, final String reposName) throws Exception { final JsonNode credsStoreNode = config.get("credsStore"); if (credsStoreNode != null && !credsStoreNode.isMissingNode() && credsStoreNode.isTextual()) { final String credsStore = credsStoreNode.asText(); return runCredentialProvider(reposName, credsStore); } return null; }
private void _validateSingleModel() throws IOException { JsonNode contextJsonNode = getContextJsonNode(); if (contextJsonNode.isMissingNode()) { throw new IOException( "The given resource does not have context node"); } }
private JsonNode getJsonNode(String rentalString, String jsonParsePath) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(rentalString); if (!jsonParsePath.equals("")) { String delimiter = "/"; String[] parseElement = jsonParsePath.split(delimiter); for (int i = 0; i < parseElement.length; i++) { rootNode = rootNode.path(parseElement[i]); } if (rootNode.isMissingNode()) { throw new IllegalArgumentException( "Could not find jSON elements " + jsonParsePath); } } return rootNode; }
public Optional<IndexStatistics> getIndexStats(String index) { final JsonNode indexStats = indexStatsWithShardLevel(index); return indexStats.isMissingNode() ? Optional.empty() : Optional.of(buildIndexStatistics(index, indexStats)); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); ret.put("itemsSize", 0); ret.put("itemsIsArray", false); final JsonNode itemsNode = schema.path("items"); final JsonNode additionalNode = schema.path("additionalItems"); final boolean hasItems = !itemsNode.isMissingNode(); final boolean hasAdditional = additionalNode.isObject(); ret.put("hasItems", hasItems); ret.put("hasAdditional", hasAdditional); if (itemsNode.isArray()) { ret.put("itemsIsArray", true); ret.put("itemsSize", itemsNode.size()); } return ret; } }
/** Create a BucketConfig from a JSON configuration node. */ public static S3BucketConfig fromConfig(JsonNode config) { if (config == null || config.isMissingNode()) { /* No configuration was specified, nothing should be downloaded from S3. */ return null; } S3BucketConfig bucketConfig = new S3BucketConfig(); try { bucketConfig.accessKey = config.get("accessKey").asText(); bucketConfig.secretKey = config.get("secretKey").asText(); bucketConfig.bucketName = config.get("bucketName").asText(); } catch (NullPointerException ex) { LOG.error("You must specify an accessKey, a secretKey, and a bucketName when configuring S3 download."); throw ex; } return bucketConfig; }
/** * Helper method to create a Claim representation from the given JsonNode. * * @param node the JsonNode to convert into a Claim. * @return a valid Claim instance. If the node is null or missing, a NullClaim will be returned. */ static Claim claimFromNode(JsonNode node, ObjectReader objectReader) { if (node == null || node.isNull() || node.isMissingNode()) { return new NullClaim(); } return new JsonNodeClaim(node, objectReader); }
/** * Parses the given jsonNode (Resource Collection) e.g people, blog-postings * and returns the name of the resource element fields based on the first * entry * * @return <code>List<String></code> Name of the resource fields, empty * collection otherwise * @review */ public List<String> getResourceElementFieldNames() { JsonNode firstEntryJsonNode = getFirstEntryJsonNode(); if (firstEntryJsonNode.isMissingNode() || firstEntryJsonNode.isNull()) { return Collections.emptyList(); } List<String> fieldNames = new ArrayList<>(); Iterator<String> iterator = firstEntryJsonNode.fieldNames(); while (iterator.hasNext()) { fieldNames.add(iterator.next()); } return fieldNames; }
if (hostNode.isMissingNode()) { log.warn(prefix + "is missing mandatory \"host\" field."); } else { if (!shortMessageNode.isMissingNode()) { if (!shortMessageNode.isTextual()) { throw new IllegalArgumentException(prefix + "has invalid \"short_message\": " + shortMessageNode.asText()); throw new IllegalArgumentException(prefix + "has empty mandatory \"short_message\" field."); } else if (!messageNode.isMissingNode()) { if (!messageNode.isTextual()) { throw new IllegalArgumentException(prefix + "has invalid \"message\": " + messageNode.asText());
public static JsonNode searchJson(JsonNode tree, String searchKey) throws JsonProcessingException, IOException { if (tree == null) { return null; } if(tree.has(searchKey)) { return tree.get(searchKey); } if(tree.isContainerNode()) { for(JsonNode branch: tree) { JsonNode branchResult = searchJson(branch, searchKey); if (branchResult != null && !branchResult.isMissingNode()) { return branchResult; } } } return null; }
private Set<String> getReopenedIndices(final Collection<String> indices) { final Version elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version.")); final String indexList = String.join(",", indices); final State request = new State.Builder().withMetadata().indices(indexList).build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for reopened indices " + indices); final JsonNode clusterStateJson = jestResult.getJsonObject(); final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices"); final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder(); if (indicesJson.isMissingNode()) { LOG.error("Retrieved cluster state is invalid (no metadata.indices key)."); LOG.debug("Received cluster state was: {}", clusterStateJson.toString()); return Collections.emptySet(); } for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) { final Map.Entry<String, JsonNode> entry = it.next(); final String indexName = entry.getKey(); final JsonNode value = entry.getValue(); final JsonNode indexSettings = value.path("settings"); if (indexSettings.isMissingNode()) { LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName); LOG.debug("Index metadata was: {}", value.toString()); continue; } if (checkForReopened(indexSettings, elasticsearchVersion)) { LOG.debug("Adding {} to list of indices to be migrated.", indexName); reopenedIndices.add(indexName); } } return reopenedIndices.build(); }
@Override public Object apply(JsonNode node) { if (node == null || node.isMissingNode() || node.isNull()) { return null; } if (node.isIntegralNumber()) { if (node.canConvertToLong()) { return node.asLong(); } else { return node.asDouble(); } } if (node.isFloatingPointNumber()) { return node.asDouble(); } final String s = node.asText(); final CharsetEncoder enc = StandardCharsets.UTF_8.newEncoder(); if (s != null && !enc.canEncode(s)) { // Some whacky characters are in this string (e.g. \uD900). These are problematic because they are decodeable // by new String(...) but will not encode into the same character. This dance here will replace these // characters with something more sane. return StringUtils.fromUtf8(StringUtils.toUtf8(s)); } else { return s; } } };
/** * Build a {@link JsonSchema} instance * * @param schema the schema * @param pointer the pointer into the schema * @return a new {@link JsonSchema} * @throws ProcessingException resolving the pointer against the schema * leads to a {@link MissingNode} * @throws NullPointerException the schema or pointer is null */ JsonSchema buildJsonSchema(final JsonNode schema, final JsonPointer pointer) throws ProcessingException { final SchemaTree tree = loader.load(schema).setPointer(pointer); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }