private Result getFeatureResult(final Features features, final String thingId, final RetrieveFeature command, @Nullable final Thing thing) { final String featureId = command.getFeatureId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return features.getFeature(featureId) .map(feature -> getFeatureJson(feature, command)) .map(featureJson -> RetrieveFeatureResponse.of(thingId, featureId, featureJson, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureNotFound(thingId, featureId, dittoHeaders))); }
private Result getFeatureResult(final Features features, final String thingId, final RetrieveFeature command, @Nullable final Thing thing) { final String featureId = command.getFeatureId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return features.getFeature(featureId) .map(feature -> getFeatureJson(feature, command)) .map(featureJson -> RetrieveFeatureResponse.of(thingId, featureId, featureJson, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureNotFound(thingId, featureId, dittoHeaders))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeature command) { final String thingId = context.getThingId(); return extractFeatures(thing) .map(features -> getFeatureResult(features, thingId, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(thingId, command.getFeatureId(), command.getDittoHeaders()))); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeature command) { final String thingId = context.getThingId(); return extractFeatures(thing) .map(features -> getFeatureResult(features, thingId, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(thingId, command.getFeatureId(), command.getDittoHeaders()))); }