.withSelectedFields(selectedFieldsFrom(adaptable)) .build());
/** * Returns a builder with a fluent API for an immutable {@code RetrieveThing} instance. * * @param thingId the ID of a single Thing to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return the builder. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws org.eclipse.ditto.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static Builder getBuilder(final CharSequence thingId, final DittoHeaders dittoHeaders) { ThingIdValidator.getInstance().accept(thingId, dittoHeaders); return new Builder(thingId.toString(), checkNotNull(dittoHeaders, "command headers")); }
.build(); final RetrieveThing retrieveThingV1 = RetrieveThing.getBuilder(retrieveThing.getThingId(), dittoHeaders) .withSelectedFields(jsonFieldSelectorBuilder.build()) .build(); PatternsCS.ask(thingsShardRegion, retrieveThingV1, getAskTimeout().toMillis()) .handleAsync((response, error) -> {
.withSelectedFields(selectedFieldsFrom(adaptable)) .build());
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); }
/** * Creates a new {@code RetrieveThing} 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 RetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveThing>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final Builder builder = getBuilder(thingId, dittoHeaders); jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .ifPresent(builder::withSelectedFields); jsonObject.getValue(JSON_SNAPSHOT_REVISION).ifPresent(builder::withSnapshotRevision); return builder.build(); }); }
/** * Creates a new {@code RetrieveThing} 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 RetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveThing>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final Builder builder = getBuilder(thingId, dittoHeaders); jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .ifPresent(builder::withSelectedFields); jsonObject.getValue(JSON_SNAPSHOT_REVISION).ifPresent(builder::withSnapshotRevision); return builder.build(); }); }
private Route thingsEntry(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return pathEndOrSingleSlash(() -> route( get(() -> // GET /things/things/<thingId>?fields=<fieldsString> parameterOptional(ThingsParameter.FIELDS.toString(), fieldsString -> handlePerRequest(ctx, RetrieveThing.getBuilder(thingId, dittoHeaders) .withSelectedFields(calculateSelectedFields(fieldsString).orElse(null)) .build()) ) ), put(() -> // PUT /things/things/<thingId> extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, thingJson -> ModifyThing.of(thingId, ThingsModelFactory.newThing( createThingJsonObjectForPut(thingJson, thingId)), createInlinePolicyJson(thingJson), getCopyPolicyFrom(thingJson), dittoHeaders)) ) ), delete(() -> // DELETE /things/things/<thingId> handlePerRequest(ctx, DeleteThing.of(thingId, dittoHeaders)) ) ) ); }
/** * Returns a Command for retrieving the Thing with the given ID. * * @param thingId the ID of a single Thing to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Thing with the {@code thingId} as its ID which is readable from the passed * authorization context. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws org.eclipse.ditto.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveThing of(final CharSequence thingId, final DittoHeaders dittoHeaders) { return getBuilder(thingId, dittoHeaders).build(); }
/** * Returns a builder with a fluent API for an immutable {@code RetrieveThing} instance. * * @param thingId the ID of a single Thing to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return the builder. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws org.eclipse.ditto.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static Builder getBuilder(final CharSequence thingId, final DittoHeaders dittoHeaders) { ThingIdValidator.getInstance().accept(thingId, dittoHeaders); return new Builder(thingId.toString(), checkNotNull(dittoHeaders, "command headers")); }
@Override public RetrieveThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { final RetrieveThing twinCommand = RetrieveThing.getBuilder(getThingId(), dittoHeaders) .withSelectedFields(getSelectedFields().orElse(null)) .build(); return of(twinCommand); }
@Override public RetrieveThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { final RetrieveThing twinCommand = RetrieveThing.getBuilder(getThingId(), dittoHeaders) .withSelectedFields(getSelectedFields().orElse(null)) .build(); return of(twinCommand); }
/** * Returns a Command for retrieving the Thing with the given ID. * * @param thingId the ID of a single Thing to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Thing with the {@code thingId} as its ID which is readable from the passed * authorization context. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. * @throws org.eclipse.ditto.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveThing of(final CharSequence thingId, final DittoHeaders dittoHeaders) { return getBuilder(thingId, dittoHeaders).build(); }
private CompletionStage<String> handleThingPolicyIdReference(final ReferencePlaceholder referencePlaceholder, final DittoHeaders dittoHeaders) { final RetrieveThing retrieveThingCommand = RetrieveThing.getBuilder(referencePlaceholder.getReferencedEntityId(), dittoHeaders) .withSelectedFields(referencePlaceholder.getReferencedField().toFieldSelector()) .build(); return PatternsCS.ask(conciergeForwarderActor, retrieveThingCommand, retrieveEntityTimeoutDuration) .thenApply(response -> this.handleRetrieveThingResponse(response, referencePlaceholder, dittoHeaders)); }
@Override public RetrieveThing setDittoHeaders(final DittoHeaders dittoHeaders) { return getBuilder(thingId, dittoHeaders) .withSelectedFields(selectedFields) .withSnapshotRevision(snapshotRevision) .build(); }
@Override public RetrieveThing setDittoHeaders(final DittoHeaders dittoHeaders) { return getBuilder(thingId, dittoHeaders) .withSelectedFields(selectedFields) .withSnapshotRevision(snapshotRevision) .build(); }