private Optional<JsonValue> getValueForKey(final CharSequence key) { final JsonField jsonField = fields.get(key.toString()); return null != jsonField ? Optional.of(jsonField.getValue()) : Optional.empty(); }
/** * Returns a {@code Predicate} for testing if the value of a JSON field is null. * * @return the predicate. * @see JsonValue#isNull() */ static Predicate<JsonField> isValueNonNull() { return jsonField -> !jsonField.getValue().isNull(); }
/** * Returns a {@code Predicate} for testing if the value of a JSON field is null. * * @return the predicate. * @see JsonValue#isNull() */ static Predicate<JsonField> isValueNonNull() { return jsonField -> !jsonField.getValue().isNull(); }
private static Map<String, String> getSpecificConfiguration(final JsonObject jsonObject) { return jsonObject.getValue(JsonFields.SPECIFIC_CONFIG) .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(JsonObject::stream) .map(jsonFields -> jsonFields.collect(Collectors.toMap(JsonField::getKeyName, f -> f.getValue().isString() ? f.getValue().asString() : f.getValue().toString()))) .orElse(Collections.emptyMap()); }
private static List<Document> createInternalAttributes(final Iterable<JsonField> attributes) { final List<Document> internalFlatList = new ArrayList<>(); for (final JsonField attribute : attributes) { final JsonValue value = attribute.getValue(); final JsonKey key = attribute.getKey(); internalFlatList.addAll(toFlatAttributesList(PersistenceConstants.SLASH + key, value, new ArrayList<>())); } return internalFlatList; }
private static List<Document> createInternalAttributes(final Iterable<JsonField> attributes) { final List<Document> internalFlatList = new ArrayList<>(); for (final JsonField attribute : attributes) { final JsonValue value = attribute.getValue(); final JsonKey key = attribute.getKey(); internalFlatList.addAll(toFlatAttributesList(PersistenceConstants.SLASH + key, value, new ArrayList<>())); } return internalFlatList; }
@Nullable private JsonValue getViewForJsonFieldOrNull(final JsonField jsonField, final PolicyTrie defaultPolicyTrie, final Set<String> subjectIds, final Permissions permissions) { final PolicyTrie relevantTrie = children.getOrDefault(jsonField.getKey(), defaultPolicyTrie); return relevantTrie.getViewForJsonValueOrNull(jsonField.getValue(), subjectIds, permissions); }
private static List<Document> createFlatFeaturesRepresentation(final Iterable<JsonField> properties, final String featureId) { final List<Document> flatFeatures = new ArrayList<>(); properties.forEach(field -> toFlatFeaturesList(PersistenceConstants.SLASH + field.getKeyName(), featureId, field.getValue(), flatFeatures)); return flatFeatures; }
private static void handleObject(final String path, final Iterable<JsonField> jsonObject, final String featureId, final List<Document> flatAttributes) { jsonObject.forEach(jsonField -> { final String newPath = path + PersistenceConstants.SLASH + jsonField.getKey(); final JsonValue innerValue = jsonField.getValue(); toFlatFeaturesList(newPath, featureId, innerValue, flatAttributes); }); }
private static Collection<ResourcePermissions> createEntriesForAttributes(final Attributes attributes, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(); attributes.forEach(attribute -> result.addAll( createEntriesForAttribute(JsonFactory.newPointer(attribute.getKey()), attribute.getValue(), policyEnforcer))); return result; }
private Set<JsonField> calculateThresholdViolations(final String featureId, final FeatureProperties featureProperties) { return featureProperties.stream() .filter(field -> violatesThreshold( field.getKey().asPointer(), field.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
private static Collection<ResourcePermissions> createEntriesForAttributes(final Attributes attributes, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(); attributes.forEach(attribute -> result.addAll( createEntriesForAttribute(JsonFactory.newPointer(attribute.getKey()), attribute.getValue(), policyEnforcer))); return result; }
private Set<JsonField> calculateThresholdViolations(final Attributes attributes) { return attributes .stream() .filter(field -> violatesThreshold(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
private Set<JsonField> calculateThresholdViolations(final String featureId, final FeatureProperties featureProperties) { return featureProperties.stream() .filter(field -> violatesThreshold( field.getKey().asPointer(), field.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
@Override protected String createStringRepresentation() { final com.eclipsesource.json.JsonObject minJsonObject = new com.eclipsesource.json.JsonObject(); fields.values().forEach(field -> minJsonObject.add(field.getKeyName(), JsonFactory.convert(field.getValue()))); return minJsonObject.toString(); }
private static Collection<ResourcePermissions> createEntriesForFeature(final Feature feature, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(); result.add(FeatureResourcePermissions.getInstance(feature, policyEnforcer)); final FeatureProperties featureProperties = feature.getProperties().orElseGet( ThingsModelFactory::emptyFeatureProperties); featureProperties.forEach(featureProperty -> result.addAll( createEntriesForFeatureProperty(feature.getId(), JsonFactory.newPointer(featureProperty.getKey()), featureProperty.getValue(), policyEnforcer))); return result; }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }
private Attributes fixViolations(final Set<JsonField> exceededAttributes, final Attributes attributes) { final AttributesBuilder builder = attributes.toBuilder(); exceededAttributes.forEach(field -> builder.set( field.getKey().toString(), fixViolation(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH))); return builder.build(); }