Skip to content

Commit ef14ad4

Browse files
committed
#1893 re-add deleted method
1 parent 083f412 commit ef14ad4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

internal/models/signalenrichment/src/main/java/org/eclipse/ditto/internal/models/signalenrichment/DittoCachingSignalEnrichmentFacade.java

+33
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
1616

17+
import java.util.Collection;
1718
import java.util.List;
1819
import java.util.Optional;
1920
import java.util.UUID;
2021
import java.util.concurrent.CompletableFuture;
2122
import java.util.concurrent.CompletionStage;
2223
import java.util.concurrent.Executor;
24+
import java.util.stream.Collectors;
2325

2426
import javax.annotation.Nullable;
2527

@@ -153,6 +155,37 @@ public CompletionStage<JsonObject> retrievePartialThing(final ThingId thingId,
153155
.thenApply(jsonObject -> applyJsonFieldSelector(jsonObject, jsonFieldSelector));
154156
}
155157

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+
156189
protected CompletionStage<JsonObject> doRetrievePartialThing(final EntityId thingId,
157190
final DittoHeaders dittoHeaders,
158191
@Nullable final DittoHeaders dittoHeadersNotAddedToCacheKey,

0 commit comments

Comments
 (0)