@Override public RetrieveFeature setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, featureId, selectedFields, dittoHeaders); }
private RetrieveFeatureLiveCommandImpl(final RetrieveFeature command) { super(command); featureId = command.getFeatureId(); }
/** * Returns a Command for retrieving a Feature with the given ID of a Thing. * * @param thingId the ID of a Thing whose Feature to be retrieved by this command. * @param featureId the ID of the a single Feature to be retrieved by this command. * @param selectedFields defines the fields of the JSON representation of the Feature to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Feature with the {@code featureId} as its ID. * @throws NullPointerException if {@code featureId} or {@code dittoHeaders} 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 RetrieveFeature of(final String thingId, final String featureId, @Nullable final JsonFieldSelector selectedFields, final DittoHeaders dittoHeaders) { return new RetrieveFeature(thingId, featureId, selectedFields, dittoHeaders); }
private static JsonObject getFeatureJson(final Feature feature, final RetrieveFeature command) { return command.getSelectedFields() .map(selectedFields -> feature.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> feature.toJson(command.getImplementedSchemaVersion())); }
@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()))); }
@SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "OverlyComplexMethod"}) @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveFeature that = (RetrieveFeature) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(featureId, that.featureId) && Objects.equals(selectedFields, that.selectedFields) && super.equals(that); }
/** * Creates a new {@code RetrieveFeature} 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 RetrieveFeature fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), 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()))); }
private static JsonObject getFeatureJson(final Feature feature, final RetrieveFeature command) { return command.getSelectedFields() .map(selectedFields -> feature.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> feature.toJson(command.getImplementedSchemaVersion())); }
@SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067", "OverlyComplexMethod"}) @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveFeature that = (RetrieveFeature) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(featureId, that.featureId) && Objects.equals(selectedFields, that.selectedFields) && super.equals(that); }
/** * Creates a new {@code RetrieveFeature} 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 RetrieveFeature fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveFeature setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, featureId, selectedFields, 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))); }
private RetrieveFeatureLiveCommandImpl(final RetrieveFeature command) { super(command); featureId = command.getFeatureId(); }
/** * Returns a Command for retrieving a Feature with the given ID of a Thing. * * @param thingId the ID of a Thing whose Feature to be retrieved by this command. * @param featureId the ID of the a single Feature to be retrieved by this command. * @param selectedFields defines the fields of the JSON representation of the Feature to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Feature with the {@code featureId} as its ID. * @throws NullPointerException if {@code featureId} or {@code dittoHeaders} 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 RetrieveFeature of(final String thingId, final String featureId, @Nullable final JsonFieldSelector selectedFields, final DittoHeaders dittoHeaders) { return new RetrieveFeature(thingId, featureId, selectedFields, dittoHeaders); }
/** * Returns a Command for retrieving a Feature with the given ID of a Thing. * * @param thingId the ID of a Thing whose Feature to be retrieved by this command. * @param featureId the ID of the a single Feature to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Feature with the {@code featureId} as its ID. * @throws NullPointerException if any argument but {@code dittoHeaders} 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 RetrieveFeature of(final String thingId, final String featureId, final DittoHeaders dittoHeaders) { return of(thingId, featureId, null, 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 public Optional<Feature> determineETagEntity(final RetrieveFeature command, @Nullable final Thing thing) { return extractFeatures(thing) .flatMap(features -> features.getFeature(command.getFeatureId())); } }
/** * Returns a Command for retrieving a Feature with the given ID of a Thing. * * @param thingId the ID of a Thing whose Feature to be retrieved by this command. * @param featureId the ID of the a single Feature to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Feature with the {@code featureId} as its ID. * @throws NullPointerException if any argument but {@code dittoHeaders} 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 RetrieveFeature of(final String thingId, final String featureId, final DittoHeaders dittoHeaders) { return of(thingId, featureId, null, dittoHeaders); }
@Override public Optional<Feature> determineETagEntity(final RetrieveFeature command, @Nullable final Thing thing) { return extractFeatures(thing) .flatMap(features -> features.getFeature(command.getFeatureId())); } }