@Override public Stream<JsonField> stream() { return wrapped.stream(); }
@Override public Stream<JsonField> stream() { return wrapped.stream(); }
@Override public Stream<JsonField> stream() { return wrapped.stream(); }
@Override public Stream<JsonField> stream() { return wrapped.stream(); }
private static Map<String, Object> toJavaMap(final JsonObject jsonObject) { return jsonObject.stream() .collect(Collectors.toMap( JsonField::getKeyName, field -> toJavaObject(field.getValue()))); }
private static Map<String, Object> toJavaMap(final JsonObject jsonObject) { return jsonObject.stream() .collect(Collectors.toMap(JsonField::getKeyName, field -> toJavaObject(field.getValue()))); }
private static Map<String, String> getAliases() { final String configAliasesStr = System.getenv(ENV_CONFIG_ALIASES); if (configAliasesStr == null || configAliasesStr.isEmpty()) { LOGGER.info("Environment variable {} is not defined or empty, using default config aliases: {}", ENV_CONFIG_ALIASES, DEFAULT_CONFIG_ALIASES); return DEFAULT_CONFIG_ALIASES; } final Map<String, String> aliases = new HashMap<>(); final JsonObject configAliasesJsonObj = JsonFactory.newObject(configAliasesStr); configAliasesJsonObj.stream().forEach(jsonField -> { final String alias = jsonField.getKeyName(); final String originalPathStr = jsonField.getValue().asString(); aliases.put(alias, originalPathStr); }); LOGGER.info("Environment variable {} defines these config aliases: {}", ENV_CONFIG_ALIASES, aliases); return aliases; }
private static Map<String, String> getAliases() { final String configAliasesStr = System.getenv(ENV_CONFIG_ALIASES); if (configAliasesStr == null || configAliasesStr.isEmpty()) { LOGGER.info("Environment variable {} is not defined or empty, using default config aliases: {}", ENV_CONFIG_ALIASES, DEFAULT_CONFIG_ALIASES); return DEFAULT_CONFIG_ALIASES; } final Map<String, String> aliases = new HashMap<>(); final JsonObject configAliasesJsonObj = JsonFactory.newObject(configAliasesStr); configAliasesJsonObj.stream().forEach(jsonField -> { final String alias = jsonField.getKeyName(); final String originalPathStr = jsonField.getValue().asString(); aliases.put(alias, originalPathStr); }); LOGGER.info("Environment variable {} defines these config aliases: {}", ENV_CONFIG_ALIASES, aliases); return aliases; }
/** * Creates a new {@code HeaderMapping} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created. * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static HeaderMapping fromJson(final JsonObject jsonObject) { return new ImmutableHeaderMapping(jsonObject.stream() .filter(f -> f.getValue().isString()) .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString()))); }
/** * Returns a new immutable Iterable of Policy entries based on the given JSON object. * * @param jsonObject the JSON object representation of Policy entries. * @return the new initialised {@code Iterable} of {@code PolicyEntry}s. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.model.base.exceptions.DittoJsonException if {@code jsonObject} cannot be parsed to * {@link Iterable} of {@link PolicyEntry}s. */ public static Iterable<PolicyEntry> newPolicyEntries(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); return jsonObject.stream() .map(jsonField -> newPolicyEntry(jsonField.getKey(), jsonField.getValue())) .collect(Collectors.toSet()); }
/** * Creates a new {@code HeaderMapping} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created. * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static HeaderMapping fromJson(final JsonObject jsonObject) { return new ImmutableHeaderMapping(jsonObject.stream() .filter(f -> f.getValue().isString()) .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString()))); }
/** * Creates a new {@code TargetMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the TargetMetrics to be created. * @return a new TargetMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static TargetMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readPublishedMessages = jsonObject.getValueOrThrow(JsonFields.PUBLISHED_MESSAGES); return ImmutableTargetMetrics.of(readAddressMetrics, readPublishedMessages); }
/** * Creates a new {@code Resources} from the specified JSON object. * * @param jsonObject the JSON object of which a new Resources instance is to be created. * @return the {@code Resources} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'Resources' format. */ public static Resources fromJson(final JsonObject jsonObject) { final List<Resource> theResources = jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .map(field -> ImmutableResource.of(ResourceKey.newInstance(field.getKeyName()), field.getValue())) .collect(Collectors.toList()); return of(theResources); }
/** * Creates a new {@code TargetMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the TargetMetrics to be created. * @return a new TargetMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static TargetMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readPublishedMessages = jsonObject.getValueOrThrow(JsonFields.PUBLISHED_MESSAGES); return ImmutableTargetMetrics.of(readAddressMetrics, readPublishedMessages); }
/** * Creates a new {@code SourceMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created. * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static SourceMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES); return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages); }
/** * Creates a new {@code SourceMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created. * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static SourceMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES); return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages); }
/** * Creates a new {@code AclEntry} object from the specified JSON object. If, for any reason, the specified JSON * object contains more than one field with Authorization Subject/permissions pairs only the first field is used * while all remaining fields are ignored. * * @param jsonObject a JSON object which provides the data for the ACL entry to be created. * @return a new ACL entry which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} <ul> <li>is empty,</li> <li>contains only a field with the schema * version</li> <li>or it contains more than two fields.</li> </ul> */ public static AclEntry fromJson(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); return jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .findFirst() .map(field -> ImmutableAclEntry.of(field.getKey(), field.getValue())) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The JSON object for 'aclEntry' is missing.") .build())); }
private static boolean isJsonValueIllegal(final JsonValue entity) { final boolean result; if (entity.isArray()) { result = entity.asArray().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonValueIllegal); } else if (entity.isObject()) { result = entity.asObject().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonFieldIllegal); } else if (entity.isString()) { result = isStringIllegal(entity.asString()); } else { result = false; } return result; }
/** * Creates a new {@code MappingContext} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the MappingContext to be created. * @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static MappingContext fromJson(final JsonObject jsonObject) { final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE); final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream() .collect(Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString()) ); return of(mappingEngine, options); }
/** * Creates a new {@code MappingContext} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the MappingContext to be created. * @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static MappingContext fromJson(final JsonObject jsonObject) { final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE); final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream() .collect(Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString()) ); return of(mappingEngine, options); }