/** * 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 RetrieveFeatures setDittoHeaders(final DittoHeaders dittoHeaders) { return of(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 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)));
private Route features(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return pathEndOrSingleSlash(() -> Directives.route( get(() -> // GET /features?fields=<fieldsString> parameterOptional(ThingsParameter.FIELDS.toString(), fieldsString -> handlePerRequest(ctx, RetrieveFeatures .of(thingId, calculateSelectedFields(fieldsString).orElse( null), dittoHeaders)) ) ), put(() -> // PUT /features extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, featuresJson -> ModifyFeatures .of(thingId, ThingsModelFactory.newFeatures( featuresJson), dittoHeaders)) ) ), delete(() -> // DELETE /features handlePerRequest(ctx, DeleteFeatures.of(thingId, dittoHeaders)) ) ) ); }