@Override public RetrieveAttributeResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, attributeValue, dittoHeaders); }
@Override public RetrieveAttributeResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, attributeValue, dittoHeaders); }
@Override public RetrieveAttributeResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, attributePointer, entity, getDittoHeaders()); }
@Override public RetrieveAttributeResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, attributePointer, entity, getDittoHeaders()); }
@Nonnull @Override public RetrieveAttributeResponse retrieved(final JsonValue attributeValue) { return RetrieveAttributeResponse.of(command.getThingId(), command.getAttributePointer(), attributeValue, command.getDittoHeaders()); }
@Nonnull @Override public RetrieveAttributeResponse retrieved(final JsonValue attributeValue) { return RetrieveAttributeResponse.of(command.getThingId(), command.getAttributePointer(), attributeValue, command.getDittoHeaders()); }
private Result getAttributeValueResult(final JsonObject attributes, final String thingId, final RetrieveAttribute command, @Nullable final Thing thing) { final JsonPointer attributePointer = command.getAttributePointer(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return attributes.getValue(attributePointer) .map(value -> RetrieveAttributeResponse.of(thingId, attributePointer, value, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.attributeNotFound(thingId, attributePointer, dittoHeaders))); }
private Result getAttributeValueResult(final JsonObject attributes, final String thingId, final RetrieveAttribute command, @Nullable final Thing thing) { final JsonPointer attributePointer = command.getAttributePointer(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return attributes.getValue(attributePointer) .map(value -> RetrieveAttributeResponse.of(thingId, attributePointer, value, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.attributeNotFound(thingId, attributePointer, dittoHeaders))); }
/** * Creates a response to a {@link RetrieveAttribute} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @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 RetrieveAttributeResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveAttributeResponse>(TYPE, jsonObject) .deserialize((statusCode) -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommandResponse.JsonFields.JSON_THING_ID); final String extractedPointerString = jsonObject.getValueOrThrow(JSON_ATTRIBUTE); final JsonPointer extractedPointer = JsonFactory.newPointer(extractedPointerString); final JsonValue extractedAttribute = jsonObject.getValueOrThrow(JSON_VALUE); return of(thingId, extractedPointer, extractedAttribute, dittoHeaders); }); }
/** * Creates a response to a {@link RetrieveAttribute} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @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 RetrieveAttributeResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveAttributeResponse>(TYPE, jsonObject) .deserialize((statusCode) -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommandResponse.JsonFields.JSON_THING_ID); final String extractedPointerString = jsonObject.getValueOrThrow(JSON_ATTRIBUTE); final JsonPointer extractedPointer = JsonFactory.newPointer(extractedPointerString); final JsonValue extractedAttribute = jsonObject.getValueOrThrow(JSON_VALUE); return of(thingId, extractedPointer, extractedAttribute, dittoHeaders); }); }
.of(thingIdFrom(adaptable), attributePointerFrom(adaptable), attributeValueFrom(adaptable), dittoHeadersFrom(adaptable)));
.of(thingIdFrom(adaptable), attributePointerFrom(adaptable), attributeValueFrom(adaptable), dittoHeadersFrom(adaptable)));