/** * Creates a new {@code SudoRetrieveThing}. * * @param thingId the ID of the Thing to be retrieved. * @param dittoHeaders the command headers of the request. * @return a command for retrieving a Thing without authorization. * @throws NullPointerException if any argument is {@code null}. */ public static SudoRetrieveThing of(final String thingId, final DittoHeaders dittoHeaders) { return of(thingId, null, dittoHeaders); }
/** * Creates a new {@code SudoRetrieveThing}. * * @param thingId the ID of the Thing to be retrieved. * @param dittoHeaders the command headers of the request. * @return a command for retrieving a Thing without authorization. * @throws NullPointerException if any argument is {@code null}. */ public static SudoRetrieveThing of(final String thingId, final DittoHeaders dittoHeaders) { return of(thingId, null, dittoHeaders); }
private void retrieveThingsAndSendResult(final List<String> thingIds, @Nullable final JsonFieldSelector selectedFields, final Command<?> command, final ActorRef resultReceiver) { final DittoHeaders dittoHeaders = command.getDittoHeaders(); final CompletionStage<?> commandResponseSource = Source.from(thingIds) .filter(Objects::nonNull) .filterNot(String::isEmpty) .filter(thingId -> THING_ID_PATTERN.matcher(thingId).matches()) .map(thingId -> { final Command<?> toBeWrapped; if (command instanceof RetrieveThings) { toBeWrapped = Optional.ofNullable(selectedFields) .map(sf -> RetrieveThing.getBuilder(thingId, dittoHeaders) .withSelectedFields(sf) .build()) .orElse(RetrieveThing.of(thingId, dittoHeaders)); } else { toBeWrapped = Optional.ofNullable(selectedFields) .map(sf -> SudoRetrieveThing.of(thingId, sf, dittoHeaders)) .orElse(SudoRetrieveThing.of(thingId, dittoHeaders)); } return ConciergeWrapper.wrapForEnforcer(toBeWrapped); }) .ask(calculateParallelism(thingIds), targetActor, Jsonifiable.class, Timeout.apply(retrieveSingleThingTimeout.toMillis(), TimeUnit.MILLISECONDS)) .log("command-response", log) .runWith(StreamRefs.sourceRef(), actorMaterializer); PatternsCS.pipe(commandResponseSource, aggregatorDispatcher) .to(resultReceiver); }