@Override public Optional<JsonFieldSelector> getSelectedFields() { return thingQueryCommand.getSelectedFields(); }
@Override public Optional<JsonFieldSelector> getSelectedFields() { return thingQueryCommand.getSelectedFields(); }
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 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 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(); }
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(); }
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; }