|
14 | 14 |
|
15 | 15 | import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
|
16 | 16 |
|
| 17 | +import java.util.Collection; |
17 | 18 | import java.util.List;
|
18 | 19 | import java.util.Optional;
|
19 | 20 | import java.util.UUID;
|
20 | 21 | import java.util.concurrent.CompletableFuture;
|
21 | 22 | import java.util.concurrent.CompletionStage;
|
22 | 23 | import java.util.concurrent.Executor;
|
| 24 | +import java.util.stream.Collectors; |
23 | 25 |
|
24 | 26 | import javax.annotation.Nullable;
|
25 | 27 |
|
@@ -153,6 +155,37 @@ public CompletionStage<JsonObject> retrievePartialThing(final ThingId thingId,
|
153 | 155 | .thenApply(jsonObject -> applyJsonFieldSelector(jsonObject, jsonFieldSelector));
|
154 | 156 | }
|
155 | 157 |
|
| 158 | + /** |
| 159 | + * Retrieve parts of a thing. |
| 160 | + * |
| 161 | + * @param thingId ID of the thing. |
| 162 | + * @param jsonFieldSelector the selected fields of the thing. |
| 163 | + * @param dittoHeaders Ditto headers containing authorization information. |
| 164 | + * @param concernedSignals the Signals which caused that this partial thing retrieval was triggered |
| 165 | + * (e.g. a {@code ThingEvent}) |
| 166 | + * @param minAcceptableSeqNr minimum sequence number of the concerned signals to not invalidate the cache. |
| 167 | + * @return future that completes with the parts of a thing or fails with an error. |
| 168 | + */ |
| 169 | + @SuppressWarnings({"java:S1612", "unused"}) |
| 170 | + public CompletionStage<JsonObject> retrievePartialThing(final EntityId thingId, |
| 171 | + final JsonFieldSelector jsonFieldSelector, |
| 172 | + final DittoHeaders dittoHeaders, |
| 173 | + final Collection<? extends Signal<?>> concernedSignals, |
| 174 | + final long minAcceptableSeqNr) { |
| 175 | + |
| 176 | + final List<ThingEvent<?>> thingEvents = concernedSignals.stream() |
| 177 | + .filter(signal -> signal instanceof ThingEvent && !Signal.isChannelLive(signal)) |
| 178 | + .map(signal -> (ThingEvent<?>) signal) |
| 179 | + .collect(Collectors.toList()); |
| 180 | + |
| 181 | + // as second step only return what was originally requested as fields: |
| 182 | + final var cachingParameters = |
| 183 | + new CachingParameters(jsonFieldSelector, thingEvents, true, minAcceptableSeqNr); |
| 184 | + |
| 185 | + return doRetrievePartialThing(thingId, dittoHeaders, null, cachingParameters) |
| 186 | + .thenApply(jsonObject -> applyJsonFieldSelector(jsonObject, jsonFieldSelector)); |
| 187 | + } |
| 188 | + |
156 | 189 | protected CompletionStage<JsonObject> doRetrievePartialThing(final EntityId thingId,
|
157 | 190 | final DittoHeaders dittoHeaders,
|
158 | 191 | @Nullable final DittoHeaders dittoHeadersNotAddedToCacheKey,
|
|
0 commit comments