@Override public String getAddress() { return delegate.getAddress(); }
/** * Creates a new {@link Target} from existing target but different address. * * @param target the target * @param address the address where the signals will be published * @return the created {@link Target} */ public static Target newTarget(final Target target, final String address) { return newTarget(address, target.getAuthorizationContext(), target.getHeaderMapping().orElse(null), target.getTopics()); }
/** * Returns all non hidden marked fields of this {@code Connection}. * * @return a JSON object representation of this Target including only non hidden marked fields */ @Override default JsonObject toJson() { return toJson(FieldType.notHidden()); }
/** * Apply {@link ThingPlaceholder}s to the passed {@code targets} with the passed {@code thingId}. * * @param targets {@link Target}s to apply placeholder substitution in. * @param thingId the thing ID. * @param unresolvedPlaceholderListener callback to call with unresolved placeholders. * @return Targets as result of placeholder substitution. */ public static Set<Target> filterTargets(final Set<Target> targets, final String thingId, final Consumer<String> unresolvedPlaceholderListener) { // check if we have to replace anything at all if (targets.stream().map(Target::getAddress).noneMatch(Placeholders::containsAnyPlaceholder)) { return targets; } return targets.stream() .map(target -> { final String filtered = applyThingPlaceholder(target.getAddress(), thingId, unresolvedPlaceholderListener); return filtered != null ? target.withAddress(filtered) : null; }) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
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); })); }); }
@Override public Optional<HeaderMapping> getHeaderMapping() { return delegate.getHeaderMapping(); }
@Override public AuthorizationContext getAuthorizationContext() { return delegate.getAuthorizationContext(); }
@Override public Set<FilteredTopic> getTopics() { return delegate.getTopics(); }
@Override public Target withAddress(final String newAddress) { return new ImmutableMqttTarget(delegate.withAddress(newAddress), qos); }
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); })); }); }
@Override public Optional<HeaderMapping> getHeaderMapping() { return delegate.getHeaderMapping(); }
@Override public AuthorizationContext getAuthorizationContext() { return delegate.getAuthorizationContext(); }
@Override public Set<FilteredTopic> getTopics() { return delegate.getTopics(); }
@Override public Target withAddress(final String newAddress) { return new ImmutableMqttTarget(delegate.withAddress(newAddress), qos); }
@Override public String getAddress() { return delegate.getAddress(); }
/** * Creates a new {@link Target} from existing target but different address. * * @param target the target * @param address the address where the signals will be published * @return the created {@link Target} */ public static Target newTarget(final Target target, final String address) { return newTarget(address, target.getAuthorizationContext(), target.getHeaderMapping().orElse(null), target.getTopics()); }
@Override protected void validateTarget(final Target target, final DittoHeaders dittoHeaders, final Supplier<String> sourceDescription) { target.getHeaderMapping().ifPresent(mapping -> validateHeaderMapping(mapping, dittoHeaders)); }
/** * Returns all non hidden marked fields of this {@code Connection}. * * @return a JSON object representation of this Target including only non hidden marked fields */ @Override default JsonObject toJson() { return toJson(FieldType.notHidden()); }
private static boolean isTargetAuthorized(final Target target, final Signal<?> signal) { final Set<String> authorizedReadSubjects = signal.getDittoHeaders().getReadSubjects(); final AuthorizationContext authorizationContext = target.getAuthorizationContext(); final List<String> connectionSubjects = authorizationContext.getAuthorizationSubjectIds(); return !Collections.disjoint(authorizedReadSubjects, connectionSubjects); }
private boolean isTargetSubscribedForTopic(final Target target, final Signal<?> signal) { return target.getTopics().stream() .filter(applyTopicFilter(signal)) .filter(applyRqlFilter(signal)) .anyMatch(applyNamespaceFilter(signal)); }