Search in sources :

Example 1 with FilteredTopic

use of org.eclipse.ditto.connectivity.model.FilteredTopic in project ditto by eclipse.

the class SignalFilter method matchesFilterBeforeEnrichment.

private static boolean matchesFilterBeforeEnrichment(final FilteredTopic filteredTopic, final Signal<?> signal) {
    final Optional<String> filterOptional = filteredTopic.getFilter();
    if (filterOptional.isPresent()) {
        // match filter ignoring "extraFields"
        final TopicPath topicPath = DITTO_PROTOCOL_ADAPTER.toTopicPath(signal);
        final PlaceholderResolver<TopicPath> topicPathPlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(TOPIC_PATH_PLACEHOLDER, topicPath);
        final PlaceholderResolver<WithResource> resourcePlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(RESOURCE_PLACEHOLDER, signal);
        final PlaceholderResolver<Object> timePlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(TIME_PLACEHOLDER, new Object());
        final Criteria criteria = parseCriteria(filterOptional.get(), signal.getDittoHeaders(), topicPathPlaceholderResolver, resourcePlaceholderResolver, timePlaceholderResolver);
        final Set<JsonPointer> extraFields = filteredTopic.getExtraFields().map(JsonFieldSelector::getPointers).orElse(Collections.emptySet());
        if (signal instanceof ThingEvent) {
            return ThingEventToThingConverter.thingEventToThing((ThingEvent<?>) signal).filter(thing -> Thing3ValuePredicateVisitor.couldBeTrue(criteria, extraFields, thing, topicPathPlaceholderResolver, resourcePlaceholderResolver, timePlaceholderResolver)).isPresent();
        } else {
            final Thing emptyThing = Thing.newBuilder().build();
            return Thing3ValuePredicateVisitor.couldBeTrue(criteria, extraFields, emptyThing, topicPathPlaceholderResolver, resourcePlaceholderResolver, timePlaceholderResolver);
        }
    } else {
        return true;
    }
}
Also used : ThingEventToThingConverter(org.eclipse.ditto.things.model.signals.events.ThingEventToThingConverter) Command(org.eclipse.ditto.base.model.signals.commands.Command) PlaceholderResolver(org.eclipse.ditto.placeholders.PlaceholderResolver) Event(org.eclipse.ditto.base.model.signals.events.Event) Signal(org.eclipse.ditto.base.model.signals.Signal) AuthorizationContext(org.eclipse.ditto.base.model.auth.AuthorizationContext) ConnectionMonitor(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) PlaceholderFactory(org.eclipse.ditto.placeholders.PlaceholderFactory) Target(org.eclipse.ditto.connectivity.model.Target) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) WithEntityId(org.eclipse.ditto.base.model.entity.id.WithEntityId) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) Topic(org.eclipse.ditto.connectivity.model.Topic) COMMANDS(org.eclipse.ditto.protocol.TopicPath.Criterion.COMMANDS) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) PolicyAnnouncement(org.eclipse.ditto.policies.model.signals.announcements.PolicyAnnouncement) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) JsonPointer(org.eclipse.ditto.json.JsonPointer) Nullable(javax.annotation.Nullable) NamespaceReader(org.eclipse.ditto.base.model.namespaces.NamespaceReader) ConnectivityAnnouncement(org.eclipse.ditto.connectivity.model.signals.announcements.ConnectivityAnnouncement) Thing(org.eclipse.ditto.things.model.Thing) DittoProtocolAdapter(org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) MessageCommand(org.eclipse.ditto.messages.model.signals.commands.MessageCommand) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Predicate(java.util.function.Predicate) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic) Set(java.util.Set) TopicPath(org.eclipse.ditto.protocol.TopicPath) ThingId(org.eclipse.ditto.things.model.ThingId) Connection(org.eclipse.ditto.connectivity.model.Connection) Collectors(java.util.stream.Collectors) ConnectionMonitorRegistry(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitorRegistry) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) List(java.util.List) MessageCommandResponse(org.eclipse.ditto.messages.model.signals.commands.MessageCommandResponse) EVENTS(org.eclipse.ditto.protocol.TopicPath.Criterion.EVENTS) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) WithResource(org.eclipse.ditto.base.model.signals.WithResource) Collections(java.util.Collections) TopicPath(org.eclipse.ditto.protocol.TopicPath) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) JsonPointer(org.eclipse.ditto.json.JsonPointer) WithResource(org.eclipse.ditto.base.model.signals.WithResource) ThingEvent(org.eclipse.ditto.things.model.signals.events.ThingEvent) Thing(org.eclipse.ditto.things.model.Thing)

Example 2 with FilteredTopic

use of org.eclipse.ditto.connectivity.model.FilteredTopic in project ditto by eclipse.

the class OutboundMappingProcessorActor method splitTargetsByExtraFields.

/**
 * Split the targets of an outbound signal into 2 parts: those without extra fields and those with.
 *
 * @param outboundSignal The outbound signal.
 * @return A pair of lists. The first list contains targets without matching extra fields.
 * The second list contains targets together with their extra fields matching the outbound signal.
 */
private static Pair<List<Target>, List<Pair<Target, FilteredTopic>>> splitTargetsByExtraFields(final OutboundSignal outboundSignal) {
    final Optional<StreamingType> streamingTypeOptional = StreamingType.fromSignal(outboundSignal.getSource());
    if (streamingTypeOptional.isPresent()) {
        // Find targets with a matching topic with extra fields
        final StreamingType streamingType = streamingTypeOptional.get();
        final List<Target> targetsWithoutExtraFields = new ArrayList<>(outboundSignal.getTargets().size());
        final List<Pair<Target, FilteredTopic>> targetsWithExtraFields = new ArrayList<>(outboundSignal.getTargets().size());
        for (final Target target : outboundSignal.getTargets()) {
            final Optional<FilteredTopic> matchingExtraFields = target.getTopics().stream().filter(filteredTopic -> filteredTopic.getExtraFields().isPresent() && streamingType == StreamingType.fromTopic(filteredTopic.getTopic().getPubSubTopic())).findAny();
            if (matchingExtraFields.isPresent()) {
                targetsWithExtraFields.add(Pair.create(target, matchingExtraFields.get()));
            } else {
                targetsWithoutExtraFields.add(target);
            }
        }
        return Pair.create(targetsWithoutExtraFields, targetsWithExtraFields);
    } else {
        // The outbound signal has no streaming type: Do not attach extra fields.
        return Pair.create(outboundSignal.getTargets(), Collections.emptyList());
    }
}
Also used : ThingEventToThingConverter(org.eclipse.ditto.things.model.signals.events.ThingEventToThingConverter) PFBuilder(akka.japi.pf.PFBuilder) PlaceholderResolver(org.eclipse.ditto.placeholders.PlaceholderResolver) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Signal(org.eclipse.ditto.base.model.signals.Signal) DittoHeaderDefinition(org.eclipse.ditto.base.model.headers.DittoHeaderDefinition) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) PlaceholderFactory(org.eclipse.ditto.placeholders.PlaceholderFactory) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) AcknowledgementRequest(org.eclipse.ditto.base.model.acks.AcknowledgementRequest) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ConnectionValidator(org.eclipse.ditto.connectivity.service.messaging.validation.ConnectionValidator) ActorRef(akka.actor.ActorRef) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) Mapped(org.eclipse.ditto.connectivity.api.OutboundSignal.Mapped) OutboundSignalFactory(org.eclipse.ditto.connectivity.api.OutboundSignalFactory) PrintWriter(java.io.PrintWriter) JsonValue(org.eclipse.ditto.json.JsonValue) DittoProtocolAdapter(org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter) LimitsConfig(org.eclipse.ditto.base.service.config.limits.LimitsConfig) LogCategory(org.eclipse.ditto.connectivity.model.LogCategory) PartialFunction(scala.PartialFunction) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Done(akka.Done) Predicate(java.util.function.Predicate) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic) Collection(java.util.Collection) MappingConfig(org.eclipse.ditto.connectivity.service.config.mapping.MappingConfig) Set(java.util.Set) ConnectivityMdcEntryKey(org.eclipse.ditto.connectivity.service.util.ConnectivityMdcEntryKey) Sink(akka.stream.javadsl.Sink) MetricDirection(org.eclipse.ditto.connectivity.model.MetricDirection) ThingId(org.eclipse.ditto.things.model.ThingId) Collectors(java.util.stream.Collectors) DROPPED(org.eclipse.ditto.connectivity.model.MetricType.DROPPED) Objects(java.util.Objects) ConnectionFailure(org.eclipse.ditto.connectivity.service.messaging.internal.ConnectionFailure) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ConnectivitySignalEnrichmentProvider(org.eclipse.ditto.connectivity.service.mapping.ConnectivitySignalEnrichmentProvider) InfoProviderFactory(org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.InfoProviderFactory) NotUsed(akka.NotUsed) ThingPredicateVisitor(org.eclipse.ditto.rql.query.things.ThingPredicateVisitor) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) WithResource(org.eclipse.ditto.base.model.signals.WithResource) MonitoringConfig(org.eclipse.ditto.connectivity.service.config.MonitoringConfig) SignalEnrichmentFacade(org.eclipse.ditto.internal.models.signalenrichment.SignalEnrichmentFacade) Props(akka.actor.Props) DittoAcknowledgementLabel(org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel) ThingNotAccessibleException(org.eclipse.ditto.things.model.signals.commands.exceptions.ThingNotAccessibleException) AbstractGraphActor(org.eclipse.ditto.internal.utils.akka.controlflow.AbstractGraphActor) ConnectivityConfig(org.eclipse.ditto.connectivity.service.config.ConnectivityConfig) DefaultConnectionMonitorRegistry(org.eclipse.ditto.connectivity.service.messaging.monitoring.DefaultConnectionMonitorRegistry) Flow(akka.stream.javadsl.Flow) Source(akka.stream.javadsl.Source) AcknowledgementLabel(org.eclipse.ditto.base.model.acks.AcknowledgementLabel) ConnectionMonitor(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor) CompletableFuture(java.util.concurrent.CompletableFuture) OutboundSignal(org.eclipse.ditto.connectivity.api.OutboundSignal) Target(org.eclipse.ditto.connectivity.model.Target) ArrayList(java.util.ArrayList) ErrorResponse(org.eclipse.ditto.base.model.signals.commands.ErrorResponse) JsonObject(org.eclipse.ditto.json.JsonObject) WithEntityId(org.eclipse.ditto.base.model.entity.id.WithEntityId) SignalEnrichmentFailedException(org.eclipse.ditto.base.model.exceptions.SignalEnrichmentFailedException) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) EntityId(org.eclipse.ditto.base.model.entity.id.EntityId) Nullable(javax.annotation.Nullable) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) JsonSchemaVersion(org.eclipse.ditto.base.model.json.JsonSchemaVersion) StringWriter(java.io.StringWriter) BoxedUnit(scala.runtime.BoxedUnit) TopicPath(org.eclipse.ditto.protocol.TopicPath) Connection(org.eclipse.ditto.connectivity.model.Connection) Pair(akka.japi.Pair) Acknowledgements(org.eclipse.ditto.base.model.signals.acks.Acknowledgements) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) MetricType(org.eclipse.ditto.connectivity.model.MetricType) LogType(org.eclipse.ditto.connectivity.model.LogType) Status(akka.actor.Status) ConditionChecker.checkNotEmpty(org.eclipse.ditto.base.model.common.ConditionChecker.checkNotEmpty) MappingOutcome(org.eclipse.ditto.connectivity.service.messaging.mappingoutcome.MappingOutcome) JsonField(org.eclipse.ditto.json.JsonField) Collections(java.util.Collections) MAPPED(org.eclipse.ditto.connectivity.model.MetricType.MAPPED) Target(org.eclipse.ditto.connectivity.model.Target) ArrayList(java.util.ArrayList) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic) Pair(akka.japi.Pair)

Example 3 with FilteredTopic

use of org.eclipse.ditto.connectivity.model.FilteredTopic in project ditto by eclipse.

the class OutboundMappingProcessorActor method enrichAndFilterSignal.

// Called inside stream; must be thread-safe
// precondition: whenever filteredTopic != null, it contains an extra fields
private CompletionStage<Collection<OutboundSignalWithSender>> enrichAndFilterSignal(final Pair<OutboundSignalWithSender, FilteredTopic> outboundSignalWithExtraFields) {
    final OutboundSignalWithSender outboundSignal = outboundSignalWithExtraFields.first();
    final FilteredTopic filteredTopic = outboundSignalWithExtraFields.second();
    final Optional<JsonFieldSelector> extraFieldsOptional = Optional.ofNullable(filteredTopic).flatMap(FilteredTopic::getExtraFields);
    if (extraFieldsOptional.isEmpty()) {
        return CompletableFuture.completedFuture(Collections.singletonList(outboundSignal));
    }
    final JsonFieldSelector extraFields = extraFieldsOptional.get();
    final Target target = outboundSignal.getTargets().get(0);
    final DittoHeaders headers = DittoHeaders.newBuilder().authorizationContext(target.getAuthorizationContext()).schemaVersion(JsonSchemaVersion.LATEST).build();
    return extractEntityId(outboundSignal.delegate.getSource()).filter(ThingId.class::isInstance).map(ThingId.class::cast).map(thingId -> signalEnrichmentFacade.retrievePartialThing(thingId, extraFields, headers, outboundSignal.getSource())).map(partialThingCompletionStage -> partialThingCompletionStage.thenApply(outboundSignal::setExtra)).orElse(CompletableFuture.completedStage(outboundSignal)).thenApply(outboundSignalWithExtra -> applyFilter(outboundSignalWithExtra, filteredTopic)).exceptionally(error -> {
        logger.withCorrelationId(outboundSignal.getSource()).warning("Could not retrieve extra data due to: {} {}", error.getClass().getSimpleName(), error.getMessage());
        // recover from all errors to keep message-mapping-stream running despite enrichment failures
        return recoverFromEnrichmentError(outboundSignal, target, error);
    });
}
Also used : ThingEventToThingConverter(org.eclipse.ditto.things.model.signals.events.ThingEventToThingConverter) PFBuilder(akka.japi.pf.PFBuilder) PlaceholderResolver(org.eclipse.ditto.placeholders.PlaceholderResolver) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Signal(org.eclipse.ditto.base.model.signals.Signal) DittoHeaderDefinition(org.eclipse.ditto.base.model.headers.DittoHeaderDefinition) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) PlaceholderFactory(org.eclipse.ditto.placeholders.PlaceholderFactory) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) AcknowledgementRequest(org.eclipse.ditto.base.model.acks.AcknowledgementRequest) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ConnectionValidator(org.eclipse.ditto.connectivity.service.messaging.validation.ConnectionValidator) ActorRef(akka.actor.ActorRef) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) Mapped(org.eclipse.ditto.connectivity.api.OutboundSignal.Mapped) OutboundSignalFactory(org.eclipse.ditto.connectivity.api.OutboundSignalFactory) PrintWriter(java.io.PrintWriter) JsonValue(org.eclipse.ditto.json.JsonValue) DittoProtocolAdapter(org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter) LimitsConfig(org.eclipse.ditto.base.service.config.limits.LimitsConfig) LogCategory(org.eclipse.ditto.connectivity.model.LogCategory) PartialFunction(scala.PartialFunction) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Done(akka.Done) Predicate(java.util.function.Predicate) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic) Collection(java.util.Collection) MappingConfig(org.eclipse.ditto.connectivity.service.config.mapping.MappingConfig) Set(java.util.Set) ConnectivityMdcEntryKey(org.eclipse.ditto.connectivity.service.util.ConnectivityMdcEntryKey) Sink(akka.stream.javadsl.Sink) MetricDirection(org.eclipse.ditto.connectivity.model.MetricDirection) ThingId(org.eclipse.ditto.things.model.ThingId) Collectors(java.util.stream.Collectors) DROPPED(org.eclipse.ditto.connectivity.model.MetricType.DROPPED) Objects(java.util.Objects) ConnectionFailure(org.eclipse.ditto.connectivity.service.messaging.internal.ConnectionFailure) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ConnectivitySignalEnrichmentProvider(org.eclipse.ditto.connectivity.service.mapping.ConnectivitySignalEnrichmentProvider) InfoProviderFactory(org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.InfoProviderFactory) NotUsed(akka.NotUsed) ThingPredicateVisitor(org.eclipse.ditto.rql.query.things.ThingPredicateVisitor) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) WithResource(org.eclipse.ditto.base.model.signals.WithResource) MonitoringConfig(org.eclipse.ditto.connectivity.service.config.MonitoringConfig) SignalEnrichmentFacade(org.eclipse.ditto.internal.models.signalenrichment.SignalEnrichmentFacade) Props(akka.actor.Props) DittoAcknowledgementLabel(org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel) ThingNotAccessibleException(org.eclipse.ditto.things.model.signals.commands.exceptions.ThingNotAccessibleException) AbstractGraphActor(org.eclipse.ditto.internal.utils.akka.controlflow.AbstractGraphActor) ConnectivityConfig(org.eclipse.ditto.connectivity.service.config.ConnectivityConfig) DefaultConnectionMonitorRegistry(org.eclipse.ditto.connectivity.service.messaging.monitoring.DefaultConnectionMonitorRegistry) Flow(akka.stream.javadsl.Flow) Source(akka.stream.javadsl.Source) AcknowledgementLabel(org.eclipse.ditto.base.model.acks.AcknowledgementLabel) ConnectionMonitor(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor) CompletableFuture(java.util.concurrent.CompletableFuture) OutboundSignal(org.eclipse.ditto.connectivity.api.OutboundSignal) Target(org.eclipse.ditto.connectivity.model.Target) ArrayList(java.util.ArrayList) ErrorResponse(org.eclipse.ditto.base.model.signals.commands.ErrorResponse) JsonObject(org.eclipse.ditto.json.JsonObject) WithEntityId(org.eclipse.ditto.base.model.entity.id.WithEntityId) SignalEnrichmentFailedException(org.eclipse.ditto.base.model.exceptions.SignalEnrichmentFailedException) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) EntityId(org.eclipse.ditto.base.model.entity.id.EntityId) Nullable(javax.annotation.Nullable) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) JsonSchemaVersion(org.eclipse.ditto.base.model.json.JsonSchemaVersion) StringWriter(java.io.StringWriter) BoxedUnit(scala.runtime.BoxedUnit) TopicPath(org.eclipse.ditto.protocol.TopicPath) Connection(org.eclipse.ditto.connectivity.model.Connection) Pair(akka.japi.Pair) Acknowledgements(org.eclipse.ditto.base.model.signals.acks.Acknowledgements) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) MetricType(org.eclipse.ditto.connectivity.model.MetricType) LogType(org.eclipse.ditto.connectivity.model.LogType) Status(akka.actor.Status) ConditionChecker.checkNotEmpty(org.eclipse.ditto.base.model.common.ConditionChecker.checkNotEmpty) MappingOutcome(org.eclipse.ditto.connectivity.service.messaging.mappingoutcome.MappingOutcome) JsonField(org.eclipse.ditto.json.JsonField) Collections(java.util.Collections) MAPPED(org.eclipse.ditto.connectivity.model.MetricType.MAPPED) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) Target(org.eclipse.ditto.connectivity.model.Target) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ThingId(org.eclipse.ditto.things.model.ThingId) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic)

Example 4 with FilteredTopic

use of org.eclipse.ditto.connectivity.model.FilteredTopic in project ditto by eclipse.

the class OutboundMappingProcessorActor method applyFilter.

private Collection<OutboundSignalWithSender> applyFilter(final OutboundSignalWithSender outboundSignalWithExtra, final FilteredTopic filteredTopic) {
    final Optional<String> filter = filteredTopic.getFilter();
    final Optional<JsonFieldSelector> extraFields = filteredTopic.getExtraFields();
    if (filter.isPresent() && extraFields.isPresent()) {
        // evaluate filter criteria again if signal enrichment is involved.
        final Signal<?> signal = outboundSignalWithExtra.getSource();
        final TopicPath topicPath = DITTO_PROTOCOL_ADAPTER.toTopicPath(signal);
        final PlaceholderResolver<TopicPath> topicPathPlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(TOPIC_PATH_PLACEHOLDER, topicPath);
        final PlaceholderResolver<WithResource> resourcePlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(RESOURCE_PLACEHOLDER, signal);
        final PlaceholderResolver<Object> timePlaceholderResolver = PlaceholderFactory.newPlaceholderResolver(TIME_PLACEHOLDER, new Object());
        final DittoHeaders dittoHeaders = signal.getDittoHeaders();
        final Criteria criteria = QueryFilterCriteriaFactory.modelBased(RqlPredicateParser.getInstance(), topicPathPlaceholderResolver, resourcePlaceholderResolver, timePlaceholderResolver).filterCriteria(filter.get(), dittoHeaders);
        return outboundSignalWithExtra.getExtra().flatMap(extra -> ThingEventToThingConverter.mergeThingWithExtraFields(signal, extraFields.get(), extra).filter(ThingPredicateVisitor.apply(criteria, topicPathPlaceholderResolver, resourcePlaceholderResolver, timePlaceholderResolver)).map(thing -> outboundSignalWithExtra)).map(Collections::singletonList).orElse(List.of());
    } else {
        // no signal enrichment: filtering is already done in SignalFilter since there is no ignored field
        return Collections.singletonList(outboundSignalWithExtra);
    }
}
Also used : ThingEventToThingConverter(org.eclipse.ditto.things.model.signals.events.ThingEventToThingConverter) PFBuilder(akka.japi.pf.PFBuilder) PlaceholderResolver(org.eclipse.ditto.placeholders.PlaceholderResolver) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Signal(org.eclipse.ditto.base.model.signals.Signal) DittoHeaderDefinition(org.eclipse.ditto.base.model.headers.DittoHeaderDefinition) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) PlaceholderFactory(org.eclipse.ditto.placeholders.PlaceholderFactory) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) AcknowledgementRequest(org.eclipse.ditto.base.model.acks.AcknowledgementRequest) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) ConnectionValidator(org.eclipse.ditto.connectivity.service.messaging.validation.ConnectionValidator) ActorRef(akka.actor.ActorRef) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) Mapped(org.eclipse.ditto.connectivity.api.OutboundSignal.Mapped) OutboundSignalFactory(org.eclipse.ditto.connectivity.api.OutboundSignalFactory) PrintWriter(java.io.PrintWriter) JsonValue(org.eclipse.ditto.json.JsonValue) DittoProtocolAdapter(org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter) LimitsConfig(org.eclipse.ditto.base.service.config.limits.LimitsConfig) LogCategory(org.eclipse.ditto.connectivity.model.LogCategory) PartialFunction(scala.PartialFunction) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Done(akka.Done) Predicate(java.util.function.Predicate) FilteredTopic(org.eclipse.ditto.connectivity.model.FilteredTopic) Collection(java.util.Collection) MappingConfig(org.eclipse.ditto.connectivity.service.config.mapping.MappingConfig) Set(java.util.Set) ConnectivityMdcEntryKey(org.eclipse.ditto.connectivity.service.util.ConnectivityMdcEntryKey) Sink(akka.stream.javadsl.Sink) MetricDirection(org.eclipse.ditto.connectivity.model.MetricDirection) ThingId(org.eclipse.ditto.things.model.ThingId) Collectors(java.util.stream.Collectors) DROPPED(org.eclipse.ditto.connectivity.model.MetricType.DROPPED) Objects(java.util.Objects) ConnectionFailure(org.eclipse.ditto.connectivity.service.messaging.internal.ConnectionFailure) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ConnectivitySignalEnrichmentProvider(org.eclipse.ditto.connectivity.service.mapping.ConnectivitySignalEnrichmentProvider) InfoProviderFactory(org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.InfoProviderFactory) NotUsed(akka.NotUsed) ThingPredicateVisitor(org.eclipse.ditto.rql.query.things.ThingPredicateVisitor) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) WithResource(org.eclipse.ditto.base.model.signals.WithResource) MonitoringConfig(org.eclipse.ditto.connectivity.service.config.MonitoringConfig) SignalEnrichmentFacade(org.eclipse.ditto.internal.models.signalenrichment.SignalEnrichmentFacade) Props(akka.actor.Props) DittoAcknowledgementLabel(org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel) ThingNotAccessibleException(org.eclipse.ditto.things.model.signals.commands.exceptions.ThingNotAccessibleException) AbstractGraphActor(org.eclipse.ditto.internal.utils.akka.controlflow.AbstractGraphActor) ConnectivityConfig(org.eclipse.ditto.connectivity.service.config.ConnectivityConfig) DefaultConnectionMonitorRegistry(org.eclipse.ditto.connectivity.service.messaging.monitoring.DefaultConnectionMonitorRegistry) Flow(akka.stream.javadsl.Flow) Source(akka.stream.javadsl.Source) AcknowledgementLabel(org.eclipse.ditto.base.model.acks.AcknowledgementLabel) ConnectionMonitor(org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor) CompletableFuture(java.util.concurrent.CompletableFuture) OutboundSignal(org.eclipse.ditto.connectivity.api.OutboundSignal) Target(org.eclipse.ditto.connectivity.model.Target) ArrayList(java.util.ArrayList) ErrorResponse(org.eclipse.ditto.base.model.signals.commands.ErrorResponse) JsonObject(org.eclipse.ditto.json.JsonObject) WithEntityId(org.eclipse.ditto.base.model.entity.id.WithEntityId) SignalEnrichmentFailedException(org.eclipse.ditto.base.model.exceptions.SignalEnrichmentFailedException) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) EntityId(org.eclipse.ditto.base.model.entity.id.EntityId) Nullable(javax.annotation.Nullable) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) JsonSchemaVersion(org.eclipse.ditto.base.model.json.JsonSchemaVersion) StringWriter(java.io.StringWriter) BoxedUnit(scala.runtime.BoxedUnit) TopicPath(org.eclipse.ditto.protocol.TopicPath) Connection(org.eclipse.ditto.connectivity.model.Connection) Pair(akka.japi.Pair) Acknowledgements(org.eclipse.ditto.base.model.signals.acks.Acknowledgements) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) MetricType(org.eclipse.ditto.connectivity.model.MetricType) LogType(org.eclipse.ditto.connectivity.model.LogType) Status(akka.actor.Status) ConditionChecker.checkNotEmpty(org.eclipse.ditto.base.model.common.ConditionChecker.checkNotEmpty) MappingOutcome(org.eclipse.ditto.connectivity.service.messaging.mappingoutcome.MappingOutcome) JsonField(org.eclipse.ditto.json.JsonField) Collections(java.util.Collections) MAPPED(org.eclipse.ditto.connectivity.model.MetricType.MAPPED) JsonFieldSelector(org.eclipse.ditto.json.JsonFieldSelector) TopicPath(org.eclipse.ditto.protocol.TopicPath) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) WithResource(org.eclipse.ditto.base.model.signals.WithResource) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) JsonObject(org.eclipse.ditto.json.JsonObject)

Aggregations

Collections (java.util.Collections)4 List (java.util.List)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Predicate (java.util.function.Predicate)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 WithEntityId (org.eclipse.ditto.base.model.entity.id.WithEntityId)4 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)4 Signal (org.eclipse.ditto.base.model.signals.Signal)4 WithResource (org.eclipse.ditto.base.model.signals.WithResource)4 CommandResponse (org.eclipse.ditto.base.model.signals.commands.CommandResponse)4 Connection (org.eclipse.ditto.connectivity.model.Connection)4 FilteredTopic (org.eclipse.ditto.connectivity.model.FilteredTopic)4 Target (org.eclipse.ditto.connectivity.model.Target)4 ConnectionMonitor (org.eclipse.ditto.connectivity.service.messaging.monitoring.ConnectionMonitor)4 JsonFieldSelector (org.eclipse.ditto.json.JsonFieldSelector)4 PlaceholderFactory (org.eclipse.ditto.placeholders.PlaceholderFactory)4 PlaceholderResolver (org.eclipse.ditto.placeholders.PlaceholderResolver)4 TimePlaceholder (org.eclipse.ditto.placeholders.TimePlaceholder)4