/** * Returns a Command for retrieving all Features of a Thing. * * @param thingId the ID of a Thing whose Features to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Features. * @throws NullPointerException if {@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 RetrieveFeatures of(final String thingId, final DittoHeaders dittoHeaders) { return of(thingId, null, dittoHeaders); }
/** * Returns a Command for retrieving all Features of a Thing. * * @param thingId the ID of a Thing whose Features to be retrieved by this command. * @param selectedFields defines the fields of the JSON representation of the Features to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Features. * @throws NullPointerException if {@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 RetrieveFeatures of(final String thingId, @Nullable final JsonFieldSelector selectedFields, final DittoHeaders dittoHeaders) { return new RetrieveFeatures(thingId, selectedFields, dittoHeaders); }
@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 RetrieveFeatures that = (RetrieveFeatures) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(selectedFields, that.selectedFields) && super.equals(that); }
private static JsonObject getFeaturesJson(final Features features, final RetrieveFeatures command) { return command.getSelectedFields() .map(selectedFields -> features.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> features.toJson(command.getImplementedSchemaVersion())); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatures command) { final String thingId = context.getThingId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return extractFeatures(thing) .map(features -> getFeaturesJson(features, command)) .map(featuresJson -> RetrieveFeaturesResponse.of(thingId, featuresJson, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featuresNotFound(thingId, dittoHeaders))); }
/** * Creates a new {@code RetrieveFeatures} 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 RetrieveFeatures fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
private static JsonObject getFeaturesJson(final Features features, final RetrieveFeatures command) { return command.getSelectedFields() .map(selectedFields -> features.toJson(command.getImplementedSchemaVersion(), selectedFields)) .orElseGet(() -> features.toJson(command.getImplementedSchemaVersion())); }
@Override protected Result doApply(final Context context, @Nullable final Thing thing, final long nextRevision, final RetrieveFeatures command) { final String thingId = context.getThingId(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); return extractFeatures(thing) .map(features -> getFeaturesJson(features, command)) .map(featuresJson -> RetrieveFeaturesResponse.of(thingId, featuresJson, dittoHeaders)) .map(response -> ResultFactory.newQueryResult(command, thing, response, this)) .orElseGet(() -> ResultFactory.newErrorResult(ExceptionFactory.featuresNotFound(thingId, dittoHeaders))); }
/** * Creates a new {@code RetrieveFeatures} 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 RetrieveFeatures fromJson(final String jsonString, final DittoHeaders dittoHeaders) { return fromJson(JsonFactory.newObject(jsonString), dittoHeaders); }
@Override public RetrieveFeatures setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, selectedFields, dittoHeaders); }
@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 RetrieveFeatures that = (RetrieveFeatures) obj; return that.canEqual(this) && Objects.equals(thingId, that.thingId) && Objects.equals(selectedFields, that.selectedFields) && super.equals(that); }
/** * Returns a Command for retrieving all Features of a Thing. * * @param thingId the ID of a Thing whose Features to be retrieved by this command. * @param selectedFields defines the fields of the JSON representation of the Features to retrieve. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Features. * @throws NullPointerException if {@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 RetrieveFeatures of(final String thingId, @Nullable final JsonFieldSelector selectedFields, final DittoHeaders dittoHeaders) { return new RetrieveFeatures(thingId, selectedFields, dittoHeaders); }
/** * Returns a Command for retrieving all Features of a Thing. * * @param thingId the ID of a Thing whose Features to be retrieved by this command. * @param dittoHeaders the headers of the command. * @return a Command for retrieving the Features. * @throws NullPointerException if {@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 RetrieveFeatures of(final String thingId, final DittoHeaders dittoHeaders) { return of(thingId, null, dittoHeaders); }
@Override public RetrieveFeatures setDittoHeaders(final DittoHeaders dittoHeaders) { return of(thingId, selectedFields, dittoHeaders); }
@Override public RetrieveFeaturesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveFeatures.of(getThingId(), getSelectedFields().orElse(null), dittoHeaders)); }
@Override public RetrieveFeaturesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { return of(RetrieveFeatures.of(getThingId(), getSelectedFields().orElse(null), dittoHeaders)); }
/** * Creates a new {@code RetrieveFeatures} 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.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveFeatures fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatures>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return of(thingId, extractedFieldSelector, dittoHeaders); }); }
/** * Creates a new {@code RetrieveFeatures} 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.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveFeatures fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatures>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return of(thingId, extractedFieldSelector, dittoHeaders); }); }
attributePointerFrom(adaptable), dittoHeadersFrom(adaptable))); mappingStrategies.put(RetrieveFeatures.TYPE, adaptable -> RetrieveFeatures.of(thingIdFrom(adaptable), selectedFieldsFrom(adaptable), dittoHeadersFrom(adaptable)));
attributePointerFrom(adaptable), dittoHeadersFrom(adaptable))); mappingStrategies.put(RetrieveFeatures.TYPE, adaptable -> RetrieveFeatures.of(thingIdFrom(adaptable), selectedFieldsFrom(adaptable), dittoHeadersFrom(adaptable)));