private RetrieveFeaturePropertyLiveCommandImpl(final RetrieveFeatureProperty command) { super(command); featureId = command.getFeatureId(); propertyPointer = command.getPropertyPointer(); }
private RetrieveFeaturePropertyLiveCommandImpl(final RetrieveFeatureProperty command) { super(command); featureId = command.getFeatureId(); propertyPointer = command.getPropertyPointer(); }
private Optional<Feature> extractFeature(final RetrieveFeatureProperty command, final @Nullable Thing thing) { return getThingOrThrow(thing).getFeatures() .flatMap(features -> features.getFeature(command.getFeatureId())); }
private Optional<Feature> extractFeature(final RetrieveFeatureProperty command, final @Nullable Thing thing) { return getThingOrThrow(thing).getFeatures() .flatMap(features -> features.getFeature(command.getFeatureId())); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatureProperty command) { final String featureId = command.getFeatureId(); return extractFeature(command, thing) .map(feature -> getRetrieveFeaturePropertyResult(feature, context, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(context.getThingId(), featureId, command.getDittoHeaders()))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatureProperty command) { final String featureId = command.getFeatureId(); return extractFeature(command, thing) .map(feature -> getRetrieveFeaturePropertyResult(feature, context, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(context.getThingId(), featureId, command.getDittoHeaders()))); }
private Result getRetrieveFeaturePropertyResult(final JsonObject featureProperties, final Context context, final RetrieveFeatureProperty command, @Nullable final Thing thing) { final String featureId = command.getFeatureId(); final JsonPointer propertyPointer = command.getPropertyPointer(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return featureProperties.getValue(propertyPointer) .map(featureProperty -> RetrieveFeaturePropertyResponse.of(context.getThingId(), featureId, propertyPointer, featureProperty, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertyNotFound(context.getThingId(), featureId, propertyPointer, dittoHeaders))); }
private Result getRetrieveFeaturePropertyResult(final JsonObject featureProperties, final Context context, final RetrieveFeatureProperty command, @Nullable final Thing thing) { final String featureId = command.getFeatureId(); final JsonPointer propertyPointer = command.getPropertyPointer(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return featureProperties.getValue(propertyPointer) .map(featureProperty -> RetrieveFeaturePropertyResponse.of(context.getThingId(), featureId, propertyPointer, featureProperty, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featurePropertyNotFound(context.getThingId(), featureId, propertyPointer, dittoHeaders))); }