@Override public RetrieveAttribute setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, dittoHeaders); }
private RetrieveAttributeLiveCommandImpl(final RetrieveAttribute command) { super(command); attributePointer = command.getAttributePointer(); }
/** * Returns a command for retrieving an attribute of a Thing with the given ID. * * @param thingId the ID of a single Thing from which a single attribute will be retrieved by this command. * @param attributeJsonPointer defines one JSON pointer of the attribute to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving a single attribute of the Thing with the {@code thingId} as its ID which is * readable from the passed authorization context. * @throws NullPointerException if any argument but {@code thingId} 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 RetrieveAttribute of(final String thingId, final JsonPointer attributeJsonPointer, final DittoHeaders dittoHeaders) { return new RetrieveAttribute(attributeJsonPointer, thingId, 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))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveAttribute command) { return extractAttributes(thing) .map(attributes -> getAttributeValueResult(attributes, context.getThingId(), command, thing)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.attributesNotFound(context.getThingId(), command.getDittoHeaders()))); }
@SuppressWarnings("squid:MethodCyclomaticComplexity") @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveAttribute that = (RetrieveAttribute) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(attributePointer, that.attributePointer) && super.equals(that); }
/** * Creates a new {@code RetrieveAttribute} from a JSON string. * * @param jsonString the JSON string of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if any argument 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. * @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 RetrieveAttribute fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), 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))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveAttribute command) { return extractAttributes(thing) .map(attributes -> getAttributeValueResult(attributes, context.getThingId(), command, thing)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.attributesNotFound(context.getThingId(), command.getDittoHeaders()))); }
@SuppressWarnings("squid:MethodCyclomaticComplexity") @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveAttribute that = (RetrieveAttribute) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(attributePointer, that.attributePointer) && super.equals(that); }
/** * Creates a new {@code RetrieveAttribute} from a JSON string. * * @param jsonString the JSON string of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if any argument 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. * @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 RetrieveAttribute fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveAttribute setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, attributePointer, dittoHeaders); }
private RetrieveAttributeLiveCommandImpl(final RetrieveAttribute command) { super(command); attributePointer = command.getAttributePointer(); }
/** * Returns a command for retrieving an attribute of a Thing with the given ID. * * @param thingId the ID of a single Thing from which a single attribute will be retrieved by this command. * @param attributeJsonPointer defines one JSON pointer of the attribute to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving a single attribute of the Thing with the {@code thingId} as its ID which is * readable from the passed authorization context. * @throws NullPointerException if any argument but {@code thingId} 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 RetrieveAttribute of(final String thingId, final JsonPointer attributeJsonPointer, final DittoHeaders dittoHeaders) { return new RetrieveAttribute(attributeJsonPointer, thingId, dittoHeaders); }
@Override public RetrieveAttributeLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveAttribute.of(getThingId(), getAttributePointer(), dittoHeaders)); }
@Override public Optional<JsonValue> determineETagEntity(final RetrieveAttribute command, @Nullable final Thing thing) { return extractAttributes(thing) .flatMap(attributes -> attributes.getValue(command.getAttributePointer())); } }
@Override public RetrieveAttributeLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveAttribute.of(getThingId(), getAttributePointer(), dittoHeaders)); }
@Override public Optional<JsonValue> determineETagEntity(final RetrieveAttribute command, @Nullable final Thing thing) { return extractAttributes(thing) .flatMap(attributes -> attributes.getValue(command.getAttributePointer())); } }
/** * Creates a new {@code RetrieveAttribute} 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 any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. * @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 RetrieveAttribute fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveAttribute>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedPointerString = jsonObject.getValueOrThrow(JSON_ATTRIBUTE); final JsonPointer extractedPointer = JsonFactory.newPointer(extractedPointerString); return of(thingId, extractedPointer, dittoHeaders); }); }
/** * Creates a new {@code RetrieveAttribute} 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 any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. * @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 RetrieveAttribute fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveAttribute>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedPointerString = jsonObject.getValueOrThrow(JSON_ATTRIBUTE); final JsonPointer extractedPointer = JsonFactory.newPointer(extractedPointerString); return of(thingId, extractedPointer, dittoHeaders); }); }