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 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 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 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 Optional<JsonField> getField(final Iterable<JsonField> jsonFields, final JsonKey key) { return StreamSupport.stream(jsonFields.spliterator(), false) .filter(jsonField -> Objects.equals(jsonField.getKey(), key)) .findAny(); }
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 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(); }
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 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 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(); }
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; }
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; }
private static Collection<ResourcePermissions> createEntriesForAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(3); if (attributeValue.isObject() && !attributeValue.isNull()) { final JsonObject jsonObject = attributeValue.asObject(); // Recursion! jsonObject.forEach( subField -> result.addAll(createEntriesForAttribute(attributePointer.addLeaf(subField.getKey()), subField.getValue(), policyEnforcer))); } else { result.add(AttributeResourcePermissions.getInstance(attributePointer, attributeValue, policyEnforcer)); } return result; }
private static void compareFieldDefinitions(final JsonField expectedField, final JsonField actualField) { final Optional<JsonFieldDefinition> expectedFieldDefinition = expectedField.getDefinition(); final Optional<JsonFieldDefinition> actualFieldDefinition = actualField.getDefinition(); if (expectedFieldDefinition.isPresent()) { Assertions.assertThat(actualFieldDefinition) .overridingErrorMessage("Expected JsonField <%s> to have definition <%s> but it had " + "none", expectedField.getKey(), expectedFieldDefinition.get()) .isPresent(); Assertions.assertThat(expectedFieldDefinition) .as("Definitions of JsonField <%s> are equal", expectedField.getKey()) .contains(actualFieldDefinition.get()); } }
/** * Maps the specified JsonObject to a {@link com.mongodb.BasicDBObject} which can be stored in MongoDB. * * @param jsonObject the object to be mapped. * @return {@code jsonObject} as BasicDBObject. * @throws NullPointerException if {@code jsonObject} is {@code null}. */ private BasicDBObject mapJsonObjectToBasicDBObject(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object to be mapped"); final BasicDBObject result = new BasicDBObject(jsonObject.getSize()); jsonObject.forEach(jsonField -> result.put(reviseKeyName(jsonField.getKey()), mapJsonValueToJavaObject(jsonField.getValue()))); return result; }
private static void compareFieldValues(final JsonField expectedField, final JsonField actualField, final boolean compareFieldDefinitions) { compareValuesWithFieldKey(expectedField.getKey(), expectedField.getValue(), actualField.getValue(), compareFieldDefinitions); }