@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; } }
protected DittoProtocolAdapter(final AbstractErrorRegistry<DittoRuntimeException> errorRegistry, final HeaderTranslator headerTranslator) { this.errorRegistry = errorRegistry; this.messageCommandAdapter = MessageCommandAdapter.of(headerTranslator); this.messageCommandResponseAdapter = MessageCommandResponseAdapter.of(headerTranslator); this.thingModifyCommandAdapter = ThingModifyCommandAdapter.of(headerTranslator); this.thingModifyCommandResponseAdapter = ThingModifyCommandResponseAdapter.of(headerTranslator); this.thingQueryCommandAdapter = ThingQueryCommandAdapter.of(headerTranslator); this.thingQueryCommandResponseAdapter = ThingQueryCommandResponseAdapter.of(headerTranslator); this.thingEventAdapter = ThingEventAdapter.of(headerTranslator); this.headerTranslator = headerTranslator; }
@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 public Signal<?> fromAdaptable(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); if (TopicPath.Group.THINGS.equals(topicPath.getGroup())) { // /things final TopicPath.Channel channel = topicPath.getChannel(); if (channel.equals(TopicPath.Channel.LIVE)) { // /things/live return fromLiveAdaptable(adaptable); } else if (channel.equals(TopicPath.Channel.TWIN)) { // /things/twin return fromTwinAdaptable(adaptable); } } throw UnknownTopicPathException.newBuilder(topicPath).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 protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); if (topicPath.isWildcardTopic()) { return RetrieveThingsResponse.TYPE; } else { final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + ".responses:" + 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() + ".responses:" + commandName; }
private Signal<?> processCommandResponseSignalFromAdaptable(final Adaptable adaptable, final TopicPath topicPath) { final Optional<HttpStatusCode> status = adaptable.getPayload().getStatus(); final boolean isErrorResponse = status.isPresent() && status.get().toInt() >= HttpStatusCode.BAD_REQUEST.toInt(); if (TopicPath.Action.RETRIEVE.equals(topicPath.getAction().orElse(null))) { return isErrorResponse ? thingErrorResponseFromAdaptable(adaptable) : thingQueryCommandResponseAdapter.fromAdaptable(adaptable); } else { return isErrorResponse ? thingErrorResponseFromAdaptable(adaptable) : thingModifyCommandResponseAdapter.fromAdaptable(adaptable); } }
private Signal<?> fromTwinAdaptable(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final Signal<?> signal = signalFromAdaptable(adaptable, topicPath); // /things/twin/(commands|events) if (signal != null) { return signal; } else { throw UnknownTopicPathException.newBuilder(topicPath).build(); } }
/** * Returns a new {@code AdaptableBuilder} for the existing {@code existingAdaptable}. * * @param existingAdaptable the existingAdaptable to initialize the AdaptableBuilder with. * @return the builder. */ public static AdaptableBuilder newAdaptableBuilder(final Adaptable existingAdaptable) { return newAdaptableBuilder(existingAdaptable, existingAdaptable.getTopicPath()); }
/** * Creates a new {@code DittoProtocolAdapter} instance. * * @return the instance. */ public static DittoProtocolAdapter newInstance() { return new DittoProtocolAdapter(ProtocolAdapterErrorRegistry.newInstance(), headerTranslator()); }
@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(); 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 eventName = PathMatcher.match(path) + getActionNameWithFirstLetterUpperCase(topicPath); return topicPath.getGroup() + "." + topicPath.getCriterion() + ":" + eventName; }
@Override protected String getType(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); if (topicPath.isWildcardTopic()) { return RetrieveThingsResponse.TYPE; } else { final JsonPointer path = adaptable.getPayload().getPath(); final String commandName = getAction(topicPath) + upperCaseFirst(PathMatcher.match(path)); return topicPath.getGroup() + ".responses:" + 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() + ".responses:" + commandName; }
protected DittoProtocolAdapter(final AbstractErrorRegistry<DittoRuntimeException> errorRegistry, final HeaderTranslator headerTranslator) { this.errorRegistry = errorRegistry; this.messageCommandAdapter = MessageCommandAdapter.of(headerTranslator); this.messageCommandResponseAdapter = MessageCommandResponseAdapter.of(headerTranslator); this.thingModifyCommandAdapter = ThingModifyCommandAdapter.of(headerTranslator); this.thingModifyCommandResponseAdapter = ThingModifyCommandResponseAdapter.of(headerTranslator); this.thingQueryCommandAdapter = ThingQueryCommandAdapter.of(headerTranslator); this.thingQueryCommandResponseAdapter = ThingQueryCommandResponseAdapter.of(headerTranslator); this.thingEventAdapter = ThingEventAdapter.of(headerTranslator); this.headerTranslator = headerTranslator; }
private Signal<?> fromTwinAdaptable(final Adaptable adaptable) { final TopicPath topicPath = adaptable.getTopicPath(); final Signal<?> signal = signalFromAdaptable(adaptable, topicPath); // /things/twin/(commands|events) if (signal != null) { return signal; } else { throw UnknownTopicPathException.newBuilder(topicPath).build(); } }
/** * Returns a new {@code AdaptableBuilder} for the existing {@code existingAdaptable}. * * @param existingAdaptable the existingAdaptable to initialize the AdaptableBuilder with. * @return the builder. */ public static AdaptableBuilder newAdaptableBuilder(final Adaptable existingAdaptable) { return newAdaptableBuilder(existingAdaptable, existingAdaptable.getTopicPath()); }