/** * @return whether this FilteredTopic has a filter to apply or not */ default boolean hasFilter() { return getFilter().isPresent(); }
/** * @return whether this FilteredTopic has a filter to apply or not */ default boolean hasFilter() { return getFilter().isPresent(); }
private Predicate<FilteredTopic> applyRqlFilter(final Signal<?> signal) { return t -> !t.hasFilter() || t.getFilter().filter(f -> matchesFilter(f, signal)).isPresent(); }
private Predicate<FilteredTopic> applyRqlFilter(final Signal<?> signal) { return t -> !t.hasFilter() || t.getFilter().filter(f -> matchesFilter(f, signal)).isPresent(); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
@Test public void fromStringParsesAsExpectedWithOnlyFilter() { final String filterTopicString = "_/_/things/live/events?filter=" + FILTER_EXAMPLE; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEmpty(); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.LIVE_EVENTS); assertThat(filteredTopic.getFilter()).contains(FILTER_EXAMPLE); }
@Test public void fromStringParsesAsExpected() { final String filterTopicString = "_/_/things/twin/events"; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEmpty(); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.TWIN_EVENTS); assertThat(filteredTopic.getFilter()).isEmpty(); }
@Test public void fromStringParsesAsExpectedWithFilterAndNamespaces() { final String filterTopicString = "_/_/things/twin/events?namespaces=foo,bar&filter=" + FILTER_EXAMPLE; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEqualTo(Arrays.asList("foo", "bar")); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.TWIN_EVENTS); assertThat(filteredTopic.getFilter()).contains(FILTER_EXAMPLE); }