/** * Creates a response to a {@link RetrieveThings} command. * * @param thingsPlainJson the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final String thingsPlainJson, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, null, thingsPlainJson, namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param thingsPlainJson the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final String thingsPlainJson, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, null, thingsPlainJson, namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final JsonArray things, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, things, things.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final JsonArray things, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, things, things.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param thingsPlainJson the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<String> thingsPlainJson, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, null, thingsPlainJson.stream() .collect(Collectors.joining(",", "[", "]")), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param thingsPlainJson the retrieved Things. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<String> thingsPlainJson, @Nullable final String namespace, final DittoHeaders dittoHeaders) { return new RetrieveThingsResponse(HttpStatusCode.OK, null, thingsPlainJson.stream() .collect(Collectors.joining(",", "[", "]")), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param fieldSelector the JsonFieldSelector to apply to the passed things when transforming to JSON. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this retrieve things request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, @Nullable final JsonFieldSelector fieldSelector, @Nullable final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> getJsonFields(fieldSelector, predicate, dittoHeaders, thing)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param fieldSelector the JsonFieldSelector to apply to the passed things when transforming to JSON. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this retrieve things request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, @Nullable final JsonFieldSelector fieldSelector, @Nullable final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> getJsonFields(fieldSelector, predicate, dittoHeaders, thing)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> thing.toJson(dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST), predicate)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this search request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> thing.toJson(dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST), predicate)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @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 RetrieveThingsResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveThingsResponse>(TYPE, jsonObject) .deserialize(statusCode -> { final JsonArray thingsJsonArray = jsonObject.getValue(JSON_THINGS).orElse(null); final String plainJsonString = jsonObject.getValue(JSON_THINGS_PLAIN_JSON) .orElseGet(() -> thingsJsonArray != null ? thingsJsonArray.toString() : null); final String namespace = jsonObject.getValue(JSON_NAMESPACE).orElse(null); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsJsonArray, plainJsonString, namespace, dittoHeaders); }); }
/** * Creates a response to a {@link RetrieveThings} command from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the preceding command. * @return the response. * @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 RetrieveThingsResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveThingsResponse>(TYPE, jsonObject) .deserialize(statusCode -> { final JsonArray thingsJsonArray = jsonObject.getValue(JSON_THINGS).orElse(null); final String plainJsonString = jsonObject.getValue(JSON_THINGS_PLAIN_JSON) .orElseGet(() -> thingsJsonArray != null ? thingsJsonArray.toString() : null); final String namespace = jsonObject.getValue(JSON_NAMESPACE).orElse(null); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsJsonArray, plainJsonString, namespace, dittoHeaders); }); }