@Override public JsonFieldSelector toFieldSelector() { return JsonFactory.newFieldSelector(this); }
/** * Returns a new JSON field selector which is based on the given {@link JsonPointer}(s). * * @param pointerString representation of a JSON pointer of the field selector to be created. * @param furtherPointerStrings additional representations of JSON pointers to form the field selector to be created * by this method. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ static JsonFieldSelector newInstance(final CharSequence pointerString, final CharSequence... furtherPointerStrings) { return JsonFactory.newFieldSelector(pointerString, furtherPointerStrings); }
@Override public JsonFieldSelector toFieldSelector() { return JsonFactory.newFieldSelector(this); }
/** * Returns a new JSON field selector which is based on the given {@link JsonPointer}(s). * * @param pointerString representation of a JSON pointer of the field selector to be created. * @param furtherPointerStrings additional representations of JSON pointers to form the field selector to be created * by this method. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ static JsonFieldSelector newInstance(final CharSequence pointerString, final CharSequence... furtherPointerStrings) { return JsonFactory.newFieldSelector(pointerString, furtherPointerStrings); }
/** * Calculates a JsonFieldSelector from the passed {@code fieldsString}. * * @param fieldsString the fields as string. * @return the Optional JsonFieldSelector */ protected static Optional<JsonFieldSelector> calculateSelectedFields(final Optional<String> fieldsString) { return fieldsString.map(fs -> JsonFactory.newFieldSelector(fs, JSON_FIELD_SELECTOR_PARSE_OPTIONS)); }
@Override public JsonFieldSelectorBuilder addFieldSelectorString(@Nullable final String fieldSelectorString, final JsonParseOptions options) { requireNonNull(options, "The JSON parse options must not be null!"); if (null == fieldSelectorString || fieldSelectorString.isEmpty()) { return this; } final JsonFieldSelector fieldSelector = JsonFactory.newFieldSelector(fieldSelectorString, options); final boolean arePointersInitiallyEmpty = pointers.isEmpty(); addPointers(fieldSelector); if (arePointersInitiallyEmpty) { // We can only set the field selector string if there were no other pointers beforehand. jsonFieldSelectorString = fieldSelectorString; } return this; }
@Override public JsonFieldSelectorBuilder addFieldSelectorString(@Nullable final String fieldSelectorString, final JsonParseOptions options) { requireNonNull(options, "The JSON parse options must not be null!"); if (null == fieldSelectorString || fieldSelectorString.isEmpty()) { return this; } final JsonFieldSelector fieldSelector = JsonFactory.newFieldSelector(fieldSelectorString, options); final boolean arePointersInitiallyEmpty = pointers.isEmpty(); addPointers(fieldSelector); if (arePointersInitiallyEmpty) { // We can only set the field selector string if there were no other pointers beforehand. jsonFieldSelectorString = fieldSelectorString; } return this; }
/** * Returns a new JSON field selector which is based on pointers of the given {@link JsonFieldDefinition}(s). * * @param fieldDefinition the JSON field definition of the returned field selector. * @param furtherFieldDefinitions additional JSON field definitions of the returned field selector. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ public static JsonFieldSelector newFieldSelector(final JsonFieldDefinition fieldDefinition, final JsonFieldDefinition... furtherFieldDefinitions) { requireNonNull(fieldDefinition, "The JSON field definition must not be null!"); requireNonNull(furtherFieldDefinitions, "The optional JSON field definitions must not be null!"); final Collection<JsonPointer> pointers = new LinkedHashSet<>(1 + furtherFieldDefinitions.length); pointers.add(fieldDefinition.getPointer()); for (final JsonFieldDefinition furtherFieldDefinition : furtherFieldDefinitions) { pointers.add(furtherFieldDefinition.getPointer()); } return newFieldSelector(pointers); }
/** * Returns a new JSON field selector which is based on pointers of the given {@link JsonFieldDefinition}(s). * * @param fieldDefinition the JSON field definition of the returned field selector. * @param furtherFieldDefinitions additional JSON field definitions of the returned field selector. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ public static JsonFieldSelector newFieldSelector(final JsonFieldDefinition fieldDefinition, final JsonFieldDefinition... furtherFieldDefinitions) { requireNonNull(fieldDefinition, "The JSON field definition must not be null!"); requireNonNull(furtherFieldDefinitions, "The optional JSON field definitions must not be null!"); final Collection<JsonPointer> pointers = new LinkedHashSet<>(1 + furtherFieldDefinitions.length); pointers.add(fieldDefinition.getPointer()); for (final JsonFieldDefinition furtherFieldDefinition : furtherFieldDefinitions) { pointers.add(furtherFieldDefinition.getPointer()); } return newFieldSelector(pointers); }
/** * Creates a new {@code SudoRetrieveThings} from a JSON object. * * @param jsonObject the JSON string of which a new SudoRetrieveThings is to be created. * @param dittoHeaders the optional command headers of the request. * @return the SudoRetrieveThings which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static SudoRetrieveThings fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final List<String> extractedThingIds = jsonObject.getValueOrThrow(JSON_THING_IDS) .stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toList()); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return SudoRetrieveThings.of(extractedThingIds, extractedFieldSelector, dittoHeaders); }
/** * Creates a new {@code SudoRetrieveThings} from a JSON object. * * @param jsonObject the JSON string of which a new SudoRetrieveThings is to be created. * @param dittoHeaders the optional command headers of the request. * @return the SudoRetrieveThings which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static SudoRetrieveThings fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final List<String> extractedThingIds = jsonObject.getValueOrThrow(JSON_THING_IDS) .stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toList()); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return SudoRetrieveThings.of(extractedThingIds, extractedFieldSelector, dittoHeaders); }
/** * Creates a new {@code SudoRetrieveThing} from a JSON object. * * @param jsonObject the JSON string of which a new SudoRetrieveThing is to be created. * @param dittoHeaders the optional command headers of the request. * @return the SudoRetrieveThing which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static SudoRetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String readThingId = jsonObject.getValueOrThrow(SudoCommand.JsonFields.JSON_THING_ID); final JsonFieldSelector readFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build()) ) .orElse(null); final boolean isUseOriginalSchemaVersion = jsonObject.getValue(JSON_USE_ORIGINAL_SCHEMA_VERSION).orElse(false); return new SudoRetrieveThing(readThingId, readFieldSelector, dittoHeaders, isUseOriginalSchemaVersion); }
/** * Creates a new {@code SudoRetrieveThing} from a JSON object. * * @param jsonObject the JSON string of which a new SudoRetrieveThing is to be created. * @param dittoHeaders the optional command headers of the request. * @return the SudoRetrieveThing which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the passed in {@code jsonObject} was not in the * expected format. */ public static SudoRetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String readThingId = jsonObject.getValueOrThrow(SudoCommand.JsonFields.JSON_THING_ID); final JsonFieldSelector readFieldSelector = jsonObject.getValue(SudoCommand.JsonFields.SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build()) ) .orElse(null); final boolean isUseOriginalSchemaVersion = jsonObject.getValue(JSON_USE_ORIGINAL_SCHEMA_VERSION).orElse(false); return new SudoRetrieveThing(readThingId, readFieldSelector, dittoHeaders, isUseOriginalSchemaVersion); }
/** * Creates a new {@code RetrieveAttributes} 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 RetrieveAttributes fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveAttributes>(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 RetrieveAttributes} 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 RetrieveAttributes fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveAttributes>(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); }); }
/** * Creates a new {@code RetrieveThing} 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 {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveThing fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveThing>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final Builder builder = getBuilder(thingId, dittoHeaders); jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .ifPresent(builder::withSelectedFields); jsonObject.getValue(JSON_SNAPSHOT_REVISION).ifPresent(builder::withSnapshotRevision); return builder.build(); }); }
/** * 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.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveFeatureProperties fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatureProperties>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JSON_FEATURE_ID); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return of(thingId, extractedFeatureId, extractedFieldSelector, dittoHeaders); }); }
/** * Creates a new {@code RetrieveFeature} 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 RetrieveFeature fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeature>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JSON_FEATURE_ID); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return of(thingId, extractedFeatureId, extractedFieldSelector, 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.model.things.ThingIdInvalidException if the parsed thing ID did not comply to {@link * org.eclipse.ditto.model.things.Thing#ID_REGEX}. */ public static RetrieveFeatureProperties fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveFeatureProperties>(TYPE, jsonObject).deserialize(() -> { final String thingId = jsonObject.getValueOrThrow(ThingQueryCommand.JsonFields.JSON_THING_ID); final String extractedFeatureId = jsonObject.getValueOrThrow(JSON_FEATURE_ID); final JsonFieldSelector extractedFieldSelector = jsonObject.getValue(JSON_SELECTED_FIELDS) .map(str -> JsonFactory.newFieldSelector(str, JsonFactory.newParseOptionsBuilder() .withoutUrlDecoding() .build())) .orElse(null); return of(thingId, extractedFeatureId, extractedFieldSelector, dittoHeaders); }); }