private static JsonObject getThingJson(final Thing thing, final ThingQueryCommand<RetrieveThing> command) { return command.getSelectedFields() .map(selectedFields -> thing.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> thing.toJson(command.getImplementedSchemaVersion())); }
private static ThingNotAccessibleException notAccessible(final ThingQueryCommand<?> command) { return new ThingNotAccessibleException(command.getThingId(), command.getDittoHeaders()); }
private static Adaptable handleSingleRetrieve(final ThingQueryCommand<?> command, final TopicPath.Channel channel) { final TopicPathBuilder topicPathBuilder = ProtocolFactory.newTopicPathBuilder(command.getThingId()); final CommandsTopicPathBuilder commandsTopicPathBuilder; commandsTopicPathBuilder = fromTopicPathBuilderWithChannel(topicPathBuilder, channel); final String commandName = command.getClass().getSimpleName().toLowerCase(); if (!commandName.startsWith(TopicPath.Action.RETRIEVE.toString())) { throw UnknownCommandException.newBuilder(commandName).build(); } final PayloadBuilder payloadBuilder = Payload.newBuilder(command.getResourcePath()); command.getSelectedFields().ifPresent(payloadBuilder::withFields); return Adaptable.newBuilder(commandsTopicPathBuilder.retrieve().build()) .withPayload(payloadBuilder.build()) .withHeaders(ProtocolFactory.newHeadersWithDittoContentType(command.getDittoHeaders())) .build(); }
@Override public Optional<JsonFieldSelector> getSelectedFields() { return thingQueryCommand.getSelectedFields(); }
@Override public String getThingId() { return thingQueryCommand.getThingId(); }
} else if (error != null) { reportUnexpectedError("before building JsonView", sender, error, commandWithReadSubjects.getDittoHeaders()); } else { reportUnknownResponse("before building JsonView", sender, response, commandWithReadSubjects.getDittoHeaders());
private static Adaptable handleSingleRetrieve(final ThingQueryCommand<?> command, final TopicPath.Channel channel) { final TopicPathBuilder topicPathBuilder = ProtocolFactory.newTopicPathBuilder(command.getThingId()); final CommandsTopicPathBuilder commandsTopicPathBuilder; commandsTopicPathBuilder = fromTopicPathBuilderWithChannel(topicPathBuilder, channel); final String commandName = command.getClass().getSimpleName().toLowerCase(); if (!commandName.startsWith(TopicPath.Action.RETRIEVE.toString())) { throw UnknownCommandException.newBuilder(commandName).build(); } final PayloadBuilder payloadBuilder = Payload.newBuilder(command.getResourcePath()); command.getSelectedFields().ifPresent(payloadBuilder::withFields); return Adaptable.newBuilder(commandsTopicPathBuilder.retrieve().build()) .withPayload(payloadBuilder.build()) .withHeaders(ProtocolFactory.newHeadersWithDittoContentType(command.getDittoHeaders())) .build(); }
@Override public Optional<JsonFieldSelector> getSelectedFields() { return thingQueryCommand.getSelectedFields(); }
@Override public String getThingId() { return thingQueryCommand.getThingId(); }
private static ThingNotAccessibleException notAccessible(final ThingQueryCommand<?> command) { return new ThingNotAccessibleException(command.getThingId(), command.getDittoHeaders()); }
private static JsonObject getThingJson(final Thing thing, final ThingQueryCommand<RetrieveThing> command) { return command.getSelectedFields() .map(selectedFields -> thing.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> thing.toJson(command.getImplementedSchemaVersion())); }
public S withSelectedFields(final JsonFieldSelector expectedSelectedFields) { isNotNull(); @SuppressWarnings("unchecked") final Optional<JsonFieldSelector> actualSelectedFields = actual.getSelectedFields(); if (null != expectedSelectedFields) { Assertions.assertThat(actualSelectedFields) .overridingErrorMessage("Expected Command to have selected fields\n<%s> but it had\n<%s>", expectedSelectedFields, actualSelectedFields.orElse(null)) .contains(expectedSelectedFields); } else { Assertions.assertThat(actualSelectedFields) .overridingErrorMessage("Expected Command not to have selected fields but it had\n<%s>", actualSelectedFields.orElse(null)) .isEmpty(); } return myself; }
private static WithDittoHeaders getRetrieveThingResponse(@Nullable final Thing thing, final ThingQueryCommand<RetrieveThing> command) { if (thing != null) { return RetrieveThingResponse.of(command.getThingId(), getThingJson(thing, command), command.getDittoHeaders()); } else { return notAccessible(command); } }
private static WithDittoHeaders getRetrieveThingResponse(@Nullable final Thing thing, final ThingQueryCommand<RetrieveThing> command) { if (thing != null) { return RetrieveThingResponse.of(command.getThingId(), getThingJson(thing, command), command.getDittoHeaders()); } else { return notAccessible(command); } }
/** * Report timeout of {@code ThingQueryCommand}. * * @param command the original command. * @param sender sender of the command. * @param askTimeoutException the timeout exception. */ private void reportTimeoutForThingQuery( final ThingQueryCommand command, final ActorRef sender, final AskTimeoutException askTimeoutException) { log(command).error(askTimeoutException, "Timeout before building JsonView"); replyToSender(ThingUnavailableException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build(), sender); }