@Override public RetrieveAttributeResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, attributeValue, dittoHeaders); }
/** * Creates a response to a {@link RetrieveAttribute} command. * * @param thingId the Thing ID of the retrieved attribute. * @param attributePointer the JSON pointer of the attribute to retrieve. * @param attributeValue the retrieved Attribute value. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveAttributeResponse of(final String thingId, final JsonPointer attributePointer, final JsonValue attributeValue, final DittoHeaders dittoHeaders) { return new RetrieveAttributeResponse(thingId, attributePointer, attributeValue, HttpStatusCode.OK, dittoHeaders); }
@Override public boolean equals(@Nullable final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final RetrieveAttributeResponse that = (RetrieveAttributeResponse) o; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(attributePointer, that.attributePointer) && Objects.equals(attributeValue, that.attributeValue) && super.equals(o); }
@Override public RetrieveAttributeResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, attributePointer, entity, getDittoHeaders()); }
/** * Creates a response to a {@link RetrieveAttribute} command from a JSON string. * * @param jsonString the JSON string of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if {@code jsonString} is {@code null}. * @throws IllegalArgumentException if {@code jsonString} is empty. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonString} was not in the expected * format. */ public static RetrieveAttributeResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveAttributeResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, attributePointer, entity, getDittoHeaders()); }
/** * Creates a response to a {@link RetrieveAttribute} command from a JSON string. * * @param jsonString the JSON string of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if {@code jsonString} is {@code null}. * @throws IllegalArgumentException if {@code jsonString} is empty. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonString} was not in the expected * format. */ public static RetrieveAttributeResponse fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveAttributeResponse setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, attributeValue, dittoHeaders); }
@Override public boolean equals(@Nullable final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final RetrieveAttributeResponse that = (RetrieveAttributeResponse) o; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(attributePointer, that.attributePointer) && Objects.equals(attributeValue, that.attributeValue) && super.equals(o); }
/** * Creates a response to a {@link RetrieveAttribute} command. * * @param thingId the Thing ID of the retrieved attribute. * @param attributePointer the JSON pointer of the attribute to retrieve. * @param attributeValue the retrieved Attribute value. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveAttributeResponse of(final String thingId, final JsonPointer attributePointer, final JsonValue attributeValue, final DittoHeaders dittoHeaders) { return new RetrieveAttributeResponse(thingId, attributePointer, attributeValue, HttpStatusCode.OK, dittoHeaders); }
@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)));