private RetrieveFeatureDefinitionLiveCommandImpl(final RetrieveFeatureDefinition command) { super(command); featureId = command.getFeatureId(); }
/** * Returns a Command for retrieving a Feature's Definition on a Thing. * * @param thingId the {@code Thing}'s ID whose {@code Feature}'s Definition to retrieve. * @param featureId the {@code Feature}'s ID whose Definition to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Definition of the specified Feature. * @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 RetrieveFeatureDefinition of(final String thingId, final String featureId, final DittoHeaders dittoHeaders) { return new RetrieveFeatureDefinition(thingId, featureId, dittoHeaders); }
@SuppressWarnings("squid:S1067") @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveFeatureDefinition that = (RetrieveFeatureDefinition) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(featureId, that.featureId) && super.equals(that); }
@Override public RetrieveFeatureDefinitionLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveFeatureDefinition.of(getThingId(), getFeatureId(), dittoHeaders)); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatureDefinition command) { final String thingId = context.getThingId(); final String featureId = command.getFeatureId(); return extractFeature(command, thing) .map(feature -> getFeatureDefinition(feature, thingId, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(thingId, featureId, command.getDittoHeaders()))); }
private Result getFeatureDefinition(final Feature feature, final String thingId, final RetrieveFeatureDefinition command, @Nullable final Thing thing) { final String featureId = feature.getId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return feature.getDefinition() .map(featureDefinition -> RetrieveFeatureDefinitionResponse.of(thingId, featureId, featureDefinition, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureDefinitionNotFound(thingId, featureId, dittoHeaders))); }
/** * Creates a new {@code RetrieveFeatureProperties} 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.json.JsonMissingFieldException if the parsed {@code jsonString} did not contain any of * the required fields * <ul> * <li>{@link ThingQueryCommand.JsonFields#JSON_THING_ID} or</li> * <li>{@link #JSON_FEATURE_ID}.</li> * </ul> * @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 RetrieveFeatureDefinition fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveFeatureDefinitionLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveFeatureDefinition.of(getThingId(), getFeatureId(), dittoHeaders)); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatureDefinition command) { final String thingId = context.getThingId(); final String featureId = command.getFeatureId(); return extractFeature(command, thing) .map(feature -> getFeatureDefinition(feature, thingId, command, thing)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featureNotFound(thingId, featureId, command.getDittoHeaders()))); }
private Result getFeatureDefinition(final Feature feature, final String thingId, final RetrieveFeatureDefinition command, @Nullable final Thing thing) { final String featureId = feature.getId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return feature.getDefinition() .map(featureDefinition -> RetrieveFeatureDefinitionResponse.of(thingId, featureId, featureDefinition, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult( ExceptionFactory.featureDefinitionNotFound(thingId, featureId, dittoHeaders))); }
/** * Creates a new {@code RetrieveFeatureProperties} 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.json.JsonMissingFieldException if the parsed {@code jsonString} did not contain any of * the required fields * <ul> * <li>{@link ThingQueryCommand.JsonFields#JSON_THING_ID} or</li> * <li>{@link #JSON_FEATURE_ID}.</li> * </ul> * @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 RetrieveFeatureDefinition fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
/** * Creates a new {@code RetrieveFeatureProperties} 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.json.JsonMissingFieldException if {@code jsonObject} did not contain any of the * required fields * <ul> * <li>{@link ThingQueryCommand.JsonFields#JSON_THING_ID} or</li> * <li>{@link #JSON_FEATURE_ID}.</li> * </ul> * @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 RetrieveFeatureDefinition fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatureDefinition>(TYPE, jsonObject).deserialize(() -> { final String extractedThingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JSON_FEATURE_ID); return of(extractedThingId, extractedFeatureId, dittoHeaders); }); }
private RetrieveFeatureDefinitionLiveCommandImpl(final RetrieveFeatureDefinition command) { super(command); featureId = command.getFeatureId(); }
@Override public RetrieveFeatureDefinition setDittoHeaders(final DittoHeaders dittoHeaders) { return new RetrieveFeatureDefinition(thingId, featureId, dittoHeaders); }
@SuppressWarnings("squid:S1067") @Override public boolean equals(@Nullable final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final RetrieveFeatureDefinition that = (RetrieveFeatureDefinition) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(featureId, that.featureId) && super.equals(that); }
/** * Creates a new {@code RetrieveFeatureProperties} 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.json.JsonMissingFieldException if {@code jsonObject} did not contain any of the * required fields * <ul> * <li>{@link ThingQueryCommand.JsonFields#JSON_THING_ID} or</li> * <li>{@link #JSON_FEATURE_ID}.</li> * </ul> * @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 RetrieveFeatureDefinition fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatureDefinition>(TYPE, jsonObject).deserialize(() -> { final String extractedThingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JSON_FEATURE_ID); return of(extractedThingId, extractedFeatureId, dittoHeaders); }); }
private Optional<Feature> extractFeature(final RetrieveFeatureDefinition command, final @Nullable Thing thing) { return getThingOrThrow(thing).getFeatures() .flatMap(features -> features.getFeature(command.getFeatureId())); }
@Override public RetrieveFeatureDefinition setDittoHeaders(final DittoHeaders dittoHeaders) { return new RetrieveFeatureDefinition(thingId, featureId, dittoHeaders); }
RetrieveFeatureDefinition.of(thingIdFrom(adaptable), featureIdFrom(adaptable), dittoHeadersFrom(adaptable)));
private Optional<Feature> extractFeature(final RetrieveFeatureDefinition command, final @Nullable Thing thing) { return getThingOrThrow(thing).getFeatures() .flatMap(features -> features.getFeature(command.getFeatureId())); }