private ObjectNode objectSchema(JsonNode exampleObject) { ObjectNode schema = this.objectMapper.createObjectNode(); schema.put("type", "object"); ObjectNode properties = this.objectMapper.createObjectNode(); for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext();) { String property = iter.next(); properties.set(property, schemaFromExample(exampleObject.get(property))); } schema.set("properties", properties); return schema; }
private void parseProps(JsonNode json) { for (Iterator<String> i = json.fieldNames(); i.hasNext();) { String p = i.next(); // add non-reserved as props if (!PROTOCOL_RESERVED.contains(p)) this.addProp(p, json.get(p)); } }
private void parseMessages(JsonNode json) { JsonNode defs = json.get("messages"); if (defs == null) return; // no messages defined for (Iterator<String> i = defs.fieldNames(); i.hasNext();) { String prop = i.next(); this.messages.put(prop, parseMessage(prop, defs.get(prop))); } }
private Map<String, JsonNode> buildDigests(final JsonNode schema) { final ImmutableMap.Builder<String, JsonNode> builder = ImmutableMap.builder(); final Map<String, Digester> map = Maps.newHashMap(digesterMap); map.keySet().retainAll(Sets.newHashSet(schema.fieldNames())); for (final Map.Entry<String, Digester> entry: map.entrySet()) builder.put(entry.getKey(), entry.getValue().digest(schema)); return builder.build(); }
private Map<String, String> _getJsonHomeRootEndpointMap(JsonNode jsonNode) { Map<String, String> resourcesMap = new TreeMap<>(); JsonNode resourcesJsonNode = jsonNode.findPath( JSONLDConstants.RESOURCES); Iterator<String> fieldNames = resourcesJsonNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode fieldValue = resourcesJsonNode.get(fieldName); if (fieldValue.has(JSONLDConstants.HREF)) { JsonNode hrefJsonNode = fieldValue.get(JSONLDConstants.HREF); resourcesMap.put(hrefJsonNode.asText(), fieldName); } } return resourcesMap; }
public SegmentZKMetadataCustomMapModifier(@Nonnull String jsonString) throws IOException { JsonNode jsonNode = JsonUtils.stringToJsonNode(jsonString); _modifyMode = ModifyMode.valueOf(jsonNode.get(MAP_MODIFY_MODE_KEY).asText()); JsonNode jsonMap = jsonNode.get(MAP_KEY); if (jsonMap == null || jsonMap.size() == 0) { _map = null; } else { _map = new HashMap<>(); Iterator<String> keys = jsonMap.fieldNames(); while (keys.hasNext()) { String key = keys.next(); _map.put(key, jsonMap.get(key).asText()); } } }
public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) { Iterator<String> fieldNames = updateNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode jsonNode = mainNode.get(fieldName); // if field exists and is an embedded object if (jsonNode != null && jsonNode.isObject()) { merge(jsonNode, updateNode.get(fieldName)); } else { if (mainNode instanceof ObjectNode) { // Overwrite field JsonNode value = updateNode.get(fieldName); ((ObjectNode) mainNode).put(fieldName, value); } } } return mainNode; }
@Override public JsonNode digest(final JsonNode schema) { // TODO: return an array directly (same for "required" in v4) final ObjectNode ret = FACTORY.objectNode(); final ArrayNode required = FACTORY.arrayNode(); ret.put("required", required); final JsonNode node = schema.get(keyword); final List<String> list = Lists.newArrayList(node.fieldNames()); Collections.sort(list); for (final String field: list) if (node.get(field).path("required").asBoolean(false)) required.add(field); return ret; } }
@Override public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray("value"); for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext();) { annotationValue.param(properties.next()); } }
@Override public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) { JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray("value"); for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext();) { annotationValue.param(properties.next()); } }
private void resolveObjectToColumns(Map<String, String> columnData, Object value) { if (value instanceof PdxInstance) { resolvePdxToColumns(columnData, (PdxInstance) value); } else if (value instanceof Struct) { resolveStructToColumns(columnData, (StructImpl) value); } else { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.valueToTree(value); node.fieldNames().forEachRemaining(field -> { try { columnData.put(field, mapper.writeValueAsString(node.get(field))); } catch (JsonProcessingException e) { columnData.put(field, e.getMessage()); } }); } }
JsonNode root = objectMapper.readTree(input); Iterator<String> keysIter = (fieldNames == null ? root.fieldNames() : fieldNames.iterator());
public Map<String, Set<String>> getAllMessageFieldsForIndices(final String[] writeIndexWildcards) { final String indices = String.join(",", writeIndexWildcards); final State request = new State.Builder() .indices(indices) .withMetadata() .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for indices " + indices); final JsonNode indicesJson = getClusterStateIndicesMetadata(jestResult.getJsonObject()); final ImmutableMap.Builder<String, Set<String>> fields = ImmutableMap.builder(); final Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); final String indexName = entry.getKey(); final Set<String> fieldNames = ImmutableSet.copyOf( entry.getValue() .path("mappings") .path(IndexMapping.TYPE_MESSAGE) .path("properties").fieldNames() ); if (!fieldNames.isEmpty()) { fields.put(indexName, fieldNames); } } return fields.build(); }
/** * Returns index names and their aliases. This only returns indices which actually have an alias. */ @NotNull public Map<String, Set<String>> getIndexNamesAndAliases(String indexPattern) { // only request indices matching the name or pattern in `indexPattern` and only get the alias names for each index, // not the settings or mappings final GetAliases request = new GetAliases.Builder() .addIndex(indexPattern) // ES 6 changed the "expand_wildcards" default value for the /_alias API from "open" to "all". // Since our code expects only open indices to be returned, we have to explicitly set the parameter now. .setParameter("expand_wildcards", "open") .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't collect aliases for index pattern " + indexPattern); final ImmutableMap.Builder<String, Set<String>> indexAliasesBuilder = ImmutableMap.builder(); final Iterator<Map.Entry<String, JsonNode>> it = jestResult.getJsonObject().fields(); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); final String indexName = entry.getKey(); final JsonNode aliasMetaData = entry.getValue().path("aliases"); if (aliasMetaData.isObject()) { final ImmutableSet<String> aliasNames = ImmutableSet.copyOf(aliasMetaData.fieldNames()); indexAliasesBuilder.put(indexName, aliasNames); } } return indexAliasesBuilder.build(); }
@Override public Object getField(String fieldName) { JsonNode fn = jn.get(fieldName); if (fn.isContainerNode()) { AtomicInteger idx = new AtomicInteger(0); List<Field> fields = Lists.newArrayList(fn.fieldNames()) .stream() .map(f -> new Field(f, idx.getAndIncrement())) .collect(Collectors.toList()); return new GenericJsonRecord(fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isInt()) { return fn.asInt(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isDouble()) { return fn.asDouble(); } else { return fn.asText(); } } }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final Set<String> set = Sets.newLinkedHashSet(required); set.removeAll(Sets.newHashSet(data.getInstance().getNode() .fieldNames())); if (!set.isEmpty()) report.error(newMsg(data, bundle, "err.common.object.missingMembers") .put("required", required) .putArgument("missing", toArrayNode(set))); }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final Set<String> set = Sets.newLinkedHashSet(required); set.removeAll(Sets.newHashSet(data.getInstance().getNode() .fieldNames())); if (!set.isEmpty()) report.error(newMsg(data, bundle, "err.common.object.missingMembers") .put("required", required) .putArgument("missing", toArrayNode(set))); }
private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException { final String indexSetId = indexSet.getConfig().id(); final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId); final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges(); final JsonNode indexStats = indices.getIndexStats(indexSet); final List<String> indexNames = new ArrayList<>(); indexStats.fieldNames().forEachRemaining(indexNames::add); final Map<String, Boolean> areReopened = indices.areReopened(indexNames); final Map<String, IndexSummary> indicesSummaries = buildIndexSummaries(deflectorSummary, indexSet, indexRanges, indexStats, areReopened); return IndexerOverview.create(deflectorSummary, IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()), countResource.total(indexSetId), indicesSummaries); }
/** * Check if a given name is an existing alias. * * @param alias Name of the alias to check presence for. * @return {@code true} if alias is an existing alias, {@code false} if it is non-existing or an index. */ public boolean aliasExists(String alias) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(alias).build()); return result.isSucceeded() && !Iterators.contains(result.getJsonObject().fieldNames(), alias); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of alias " + alias, e); } }
/** * Check if a given name is an existing index. * * @param indexName Name of the index to check presence for. * @return {@code true} if indexName is an existing index, {@code false} if it is non-existing or an alias. */ public boolean exists(String indexName) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(indexName).build()); return result.isSucceeded() && Iterators.contains(result.getJsonObject().fieldNames(), indexName); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of index " + indexName, e); } }