@Nullable private Signal<?> signalFromAdaptable(final Adaptable adaptable, final TopicPath topicPath) { if (TopicPath.Criterion.COMMANDS.equals(topicPath.getCriterion())) { if (adaptable.getPayload().getStatus().isPresent()) { // this was a command response: return processCommandResponseSignalFromAdaptable(adaptable, topicPath); } else if (TopicPath.Action.RETRIEVE.equals(topicPath.getAction().orElse(null))) { return thingQueryCommandAdapter.fromAdaptable(adaptable); } else { return thingModifyCommandAdapter.fromAdaptable(adaptable); } } else if (TopicPath.Criterion.EVENTS.equals(topicPath.getCriterion())) { return thingEventAdapter.fromAdaptable(adaptable); } else if (TopicPath.Criterion.ERRORS.equals(topicPath.getCriterion())) { return thingErrorResponseFromAdaptable(adaptable); } return null; }
@Nullable private Signal<?> signalFromAdaptable(final Adaptable adaptable, final TopicPath topicPath) { if (TopicPath.Criterion.COMMANDS.equals(topicPath.getCriterion())) { if (adaptable.getPayload().getStatus().isPresent()) { // this was a command response: return processCommandResponseSignalFromAdaptable(adaptable, topicPath); } else if (TopicPath.Action.RETRIEVE.equals(topicPath.getAction().orElse(null))) { return thingQueryCommandAdapter.fromAdaptable(adaptable); } else { return thingModifyCommandAdapter.fromAdaptable(adaptable); } } else if (TopicPath.Criterion.EVENTS.equals(topicPath.getCriterion())) { return thingEventAdapter.fromAdaptable(adaptable); } else if (TopicPath.Criterion.ERRORS.equals(topicPath.getCriterion())) { return thingErrorResponseFromAdaptable(adaptable); } return null; }
return Optional.of(topicPath.getChannel().getName()); case CRITERION_PLACEHOLDER: return Optional.of(topicPath.getCriterion().getName()); case ACTION_PLACEHOLDER: return topicPath.getAction().map(TopicPath.Action::getName);
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final JsonPointer path = adaptable.getPayload().getPath(); final String eventName = PathMatcher.match(path) + getActionNameWithFirstLetterUpperCase(topicPath); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + eventName; }
@Override public Optional<ExternalMessage> map(final Adaptable adaptable) { final Map<String, String> headers = new LinkedHashMap<>(adaptable.getHeaders().orElse(DittoHeaders.empty())); final String jsonString = ProtocolFactory.wrapAsJsonifiableAdaptable(adaptable).toJsonString(); final boolean isError = TopicPath.Criterion.ERRORS.equals(adaptable.getTopicPath().getCriterion()); final boolean isResponse = adaptable.getPayload().getStatus().isPresent(); return Optional.of( ExternalMessageFactory.newExternalMessageBuilder(headers) .withTopicPath(adaptable.getTopicPath()) .withText(jsonString) .asResponse(isResponse) .asError(isError) .build()); }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final JsonPointer path = adaptable.getPayload().getPath(); final String eventName = PathMatcher.match(path) + getActionNameWithFirstLetterUpperCase(topicPath); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + eventName; }
@Override public Optional<ExternalMessage> map(final Adaptable adaptable) { final Map<String, String> headers = new LinkedHashMap<>(adaptable.getHeaders().orElse(DittoHeaders.empty())); final String jsonString = ProtocolFactory.wrapAsJsonifiableAdaptable(adaptable).toJsonString(); final boolean isError = TopicPath.Criterion.ERRORS.equals(adaptable.getTopicPath().getCriterion()); final boolean isResponse = adaptable.getPayload().getStatus().isPresent(); return Optional.of( ExternalMessageFactory.newExternalMessageBuilder(headers) .withTopicPath(adaptable.getTopicPath()) .withText(jsonString) .asResponse(isResponse) .asError(isError) .build()); }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + commandName; }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + commandName; }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); if (topicPath.isWildcardTopic()) { return RetrieveThings.TYPE; } else { final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + commandName; } }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); if (topicPath.isWildcardTopic()) { return RetrieveThings.TYPE; } else { final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + commandName; } }
private Signal<?> fromLiveAdaptable(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final Signal<?> liveSignal; if (TopicPath.Criterion.MESSAGES.equals(topicPath.getCriterion())) { // /things/live/messages final boolean isResponse = adaptable.getPayload().getStatus().isPresent(); if (isResponse) { liveSignal = messageCommandResponseAdapter.fromAdaptable(adaptable); } else { liveSignal = messageCommandAdapter.fromAdaptable(adaptable); } } else { liveSignal = signalFromAdaptable(adaptable, topicPath); // /things/live/(commands|events) } if (liveSignal != null) { final DittoHeadersBuilder enhancedHeadersBuilder = liveSignal.getDittoHeaders() .toBuilder() .channel(TopicPath.Channel.LIVE.getName()); return liveSignal.setDittoHeaders(enhancedHeadersBuilder.build()); } else { throw UnknownTopicPathException.newBuilder(topicPath).build(); } }
private Signal<?> fromLiveAdaptable(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final Signal<?> liveSignal; if (TopicPath.Criterion.MESSAGES.equals(topicPath.getCriterion())) { // /things/live/messages final boolean isResponse = adaptable.getPayload().getStatus().isPresent(); if (isResponse) { liveSignal = messageCommandResponseAdapter.fromAdaptable(adaptable); } else { liveSignal = messageCommandAdapter.fromAdaptable(adaptable); } } else { liveSignal = signalFromAdaptable(adaptable, topicPath); // /things/live/(commands|events) } if (liveSignal != null) { final DittoHeadersBuilder enhancedHeadersBuilder = liveSignal.getDittoHeaders() .toBuilder() .channel(TopicPath.Channel.LIVE.getName()); return liveSignal.setDittoHeaders(enhancedHeadersBuilder.build()); } else { throw UnknownTopicPathException.newBuilder(topicPath).build(); } }