private Builder(final RetrieveThings retrieveThings) { this.thingIds = retrieveThings.getThingIds(); dittoHeaders = retrieveThings.getDittoHeaders(); selectedFields = retrieveThings.getSelectedFields().orElse(null); namespace = retrieveThings.getNamespace().orElse(null); }
/** * Builds an instance of {@code RetrieveThings} based on the provided values. * * @return a new instance of {@code RetrieveThings}. */ public RetrieveThings build() { return new RetrieveThings(this); }
private RetrieveThingsLiveCommandImpl(final RetrieveThings command) { super(command); thingIds = command.getThingIds(); namespace = command.getNamespace().orElse(null); }
private void retrieveThings(final RetrieveThings retrieveThings, final ActorRef resultReceiver) { final JsonFieldSelector selectedFields = retrieveThings.getSelectedFields().orElse(null); retrieveThingsAndSendResult(retrieveThings.getThingIds(), selectedFields, retrieveThings, resultReceiver); }
@Override public RetrieveThings setDittoHeaders(final DittoHeaders dittoHeaders) { return getBuilder(this).dittoHeaders(dittoHeaders).build(); }
private void handleRetrieveThings(final RetrieveThings rt, final Object msgToAsk) { LogUtil.enhanceLogWithCorrelationId(log, rt.getDittoHeaders().getCorrelationId()); log.info("Got '{}' message. Retrieving requested '{}' Things..", RetrieveThings.class.getSimpleName(), rt.getThingIds().size()); final ActorRef sender = getSender(); PatternsCS.ask(targetActor, msgToAsk, Duration.ofSeconds(ASK_TIMEOUT)) .thenAccept(sourceRef -> handleSourceRef((SourceRef) sourceRef, rt.getThingIds(), rt, sender) ); }
} else { thingPlainJsonSupplier = supplyPlainJsonFromRetrieveThingResponse(); final String namespace = ((RetrieveThings) originatingCommand).getNamespace().orElse(null); overallResponseSupplier = supplyRetrieveThingsResponse(originatingCommand.getDittoHeaders(), namespace);
@Override public RetrieveThings setDittoHeaders(final DittoHeaders dittoHeaders) { return getBuilder(this).dittoHeaders(dittoHeaders).build(); }
private RetrieveThingsLiveCommandImpl(final RetrieveThings command) { super(command); thingIds = command.getThingIds(); namespace = command.getNamespace().orElse(null); }
@Override public Receive createReceive() { return ReceiveBuilder.create() // # handle "RetrieveThings" command .match(RetrieveThings.class, rt -> { LogUtil.enhanceLogWithCorrelationId(log, rt.getDittoHeaders().getCorrelationId()); log.info("Got '{}' message. Retrieving requested '{}' Things..", RetrieveThings.class.getSimpleName(), rt.getThingIds().size()); retrieveThings(rt, getSender()); }) // # handle "SudoRetrieveThings" command .match(SudoRetrieveThings.class, rt -> { LogUtil.enhanceLogWithCorrelationId(log, rt.getDittoHeaders().getCorrelationId()); log.info("Got '{}' message. Retrieving requested '{}' Things..", SudoRetrieveThings.class.getSimpleName(), rt.getThingIds().size()); retrieveThings(rt, getSender()); }) // # handle unknown message .matchAny(m -> { log.warning("Got unknown message: {}", m); unhandled(m); }) // # build PartialFunction .build(); }
private Builder(final RetrieveThings retrieveThings) { this.thingIds = retrieveThings.getThingIds(); dittoHeaders = retrieveThings.getDittoHeaders(); selectedFields = retrieveThings.getSelectedFields().orElse(null); namespace = retrieveThings.getNamespace().orElse(null); }
@Override public RetrieveThingsLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { final RetrieveThings retrieveThingsCommand = RetrieveThings.getBuilder(getThingIds()) .dittoHeaders(dittoHeaders) .selectedFields(getSelectedFields().orElse(null)) .build(); return RetrieveThingsLiveCommandImpl.of(retrieveThingsCommand); }
/** * Builds an instance of {@code RetrieveThings} based on the provided values. * * @return a new instance of {@code RetrieveThings}. */ public RetrieveThings build() { return new RetrieveThings(this); }
private static Adaptable handleMultipleRetrieve(final RetrieveThings command, final TopicPath.Channel channel) { final String commandName = command.getClass().getSimpleName().toLowerCase(); if (!commandName.startsWith(TopicPath.Action.RETRIEVE.toString())) { throw UnknownCommandException.newBuilder(commandName).build(); } final String namespace = command.getNamespace().orElse("_"); final TopicPathBuilder topicPathBuilder = ProtocolFactory.newTopicPathBuilderFromNamespace(namespace); final CommandsTopicPathBuilder commandsTopicPathBuilder = fromTopicPathBuilderWithChannel(topicPathBuilder, channel); final PayloadBuilder payloadBuilder = Payload.newBuilder(command.getResourcePath()); command.getSelectedFields().ifPresent(payloadBuilder::withFields); payloadBuilder.withValue(createIdsPayload(command.getThingIds())); return Adaptable.newBuilder(commandsTopicPathBuilder.retrieve().build()) .withPayload(payloadBuilder.build()) .withHeaders(ProtocolFactory.newHeadersWithDittoContentType(command.getDittoHeaders())) .build(); }
@Override public RetrieveThingsLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { final RetrieveThings retrieveThingsCommand = RetrieveThings.getBuilder(getThingIds()) .dittoHeaders(dittoHeaders) .selectedFields(getSelectedFields().orElse(null)) .build(); return RetrieveThingsLiveCommandImpl.of(retrieveThingsCommand); }
/** * Creates a new {@code RetrieveThings} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveThings fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String namespace = jsonObject.getValue(JSON_NAMESPACE).orElse(null); final List<String> extractedThingIds = jsonObject.getValueOrThrow(JSON_THING_IDS) .stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toList()); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return new RetrieveThings(extractedThingIds, extractedFieldSelector, namespace, dittoHeaders); }
private static Adaptable handleMultipleRetrieve(final RetrieveThings command, final TopicPath.Channel channel) { final String commandName = command.getClass().getSimpleName().toLowerCase(); if (!commandName.startsWith(TopicPath.Action.RETRIEVE.toString())) { throw UnknownCommandException.newBuilder(commandName).build(); } final String namespace = command.getNamespace().orElse("_"); final TopicPathBuilder topicPathBuilder = ProtocolFactory.newTopicPathBuilderFromNamespace(namespace); final CommandsTopicPathBuilder commandsTopicPathBuilder = fromTopicPathBuilderWithChannel(topicPathBuilder, channel); final PayloadBuilder payloadBuilder = Payload.newBuilder(command.getResourcePath()); command.getSelectedFields().ifPresent(payloadBuilder::withFields); payloadBuilder.withValue(createIdsPayload(command.getThingIds())); return Adaptable.newBuilder(commandsTopicPathBuilder.retrieve().build()) .withPayload(payloadBuilder.build()) .withHeaders(ProtocolFactory.newHeadersWithDittoContentType(command.getDittoHeaders())) .build(); }
private Route buildRetrieveThingsRoute(final RequestContext ctx, final DittoHeaders dittoHeaders) { return parameter(ThingsParameter.IDS.toString(), idsString -> parameterOptional(ThingsParameter.FIELDS.toString(), fieldsString -> handlePerRequest(ctx, dittoHeaders, Source.empty(), emptyRequestBody -> RetrieveThings .getBuilder((idsString).isEmpty() ? new String[0] : idsString.split(",")) .selectedFields(calculateSelectedFields(fieldsString)) .dittoHeaders(dittoHeaders).build()) ) ); }
/** * Creates a new {@code RetrieveThings} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveThings fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String namespace = jsonObject.getValue(JSON_NAMESPACE).orElse(null); final List<String> extractedThingIds = jsonObject.getValueOrThrow(JSON_THING_IDS) .stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toList()); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return new RetrieveThings(extractedThingIds, extractedFieldSelector, namespace, dittoHeaders); }
.build()); mappingStrategies.put(RetrieveThings.TYPE, adaptable -> RetrieveThings.getBuilder(thingsIdsFrom(adaptable)) .dittoHeaders(dittoHeadersFrom(adaptable)) .namespace(namespaceFrom(adaptable))