Skip to content

Commit

Permalink
Added desiredProperty to filterBy.
Browse files Browse the repository at this point in the history
Part of issue #697

Signed-off-by: David Joos <david.joos@bosch.io>
  • Loading branch information
David Joos committed Nov 4, 2020
1 parent c28f22b commit 06db7fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -58,11 +58,16 @@ public FilterFieldExpression filterBy(final String propertyNameWithOptionalLeadi

final Supplier<FilterFieldExpression> defaultSupplier = () -> (FilterFieldExpression) common(propertyName);
return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName))
.<FilterFieldExpression>flatMap(f -> f.getProperty()
.flatMap(property ->
.<FilterFieldExpression>flatMap(f ->
f.getProperty().isPresent()
? f.getProperty().flatMap(property ->
// we have a feature id and a property path
f.getFeatureId().map(id -> new FeatureIdPropertyExpressionImpl(id, property))
)
: f.getDesiredProperty().flatMap(desiredProperty ->
f.getFeatureId()
.map(id -> new FeatureIdDesiredPropertyExpressionImpl(id, desiredProperty))
)
)
.orElseGet(defaultSupplier);
}
Expand Down
Expand Up @@ -145,6 +145,15 @@ public void filterByFeatureIdAndProperty() {
assertThat(fieldExpression).isEqualTo(expected);
}

@Test
public void filterByFeatureIdAndDesiredProperty() {
final FilterFieldExpression fieldExpression = ef.filterByFeatureDesiredProperty(KNOWN_FEATURE_ID, KNOWN_STRING);

final FilterFieldExpression expected =
new FeatureIdDesiredPropertyExpressionImpl(KNOWN_FEATURE_ID, KNOWN_STRING);
assertThat(fieldExpression).isEqualTo(expected);
}

@Test
public void sortByFeatureProperty() {
final SortFieldExpression fieldExpression = ef.sortByFeatureProperty(KNOWN_FEATURE_ID, KNOWN_STRING);
Expand Down
Expand Up @@ -94,7 +94,6 @@ public Bson visitFeatureIdDesiredProperty(final String featureId, final String d
return matchKeyValue(FIELD_FEATURES_PATH + featureId + DESIRED_PROPERTIES + desiredProperty);
}


@Override
Bson visitPointer(final String pointer) {
return matchKeyValue(pointer);
Expand Down

0 comments on commit 06db7fc

Please sign in to comment.