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))); }
@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()))); }
@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()))); }