@@ -61,6 +61,7 @@ public final class SubscribeForPersistedEvents extends AbstractStreamingSubscrip
61
61
@ Nullable private final Instant fromHistoricalTimestamp ;
62
62
@ Nullable private final Instant toHistoricalTimestamp ;
63
63
@ Nullable private final String prefix ;
64
+ @ Nullable private final String filter ;
64
65
65
66
private SubscribeForPersistedEvents (final EntityId entityId ,
66
67
final JsonPointer resourcePath ,
@@ -69,6 +70,7 @@ private SubscribeForPersistedEvents(final EntityId entityId,
69
70
@ Nullable final Instant fromHistoricalTimestamp ,
70
71
@ Nullable final Instant toHistoricalTimestamp ,
71
72
@ Nullable final String prefix ,
73
+ @ Nullable final CharSequence filter ,
72
74
final DittoHeaders dittoHeaders ) {
73
75
74
76
super (TYPE , entityId , resourcePath , dittoHeaders );
@@ -77,6 +79,7 @@ private SubscribeForPersistedEvents(final EntityId entityId,
77
79
this .fromHistoricalTimestamp = fromHistoricalTimestamp ;
78
80
this .toHistoricalTimestamp = toHistoricalTimestamp ;
79
81
this .prefix = prefix ;
82
+ this .filter = filter != null ? filter .toString () : null ;
80
83
}
81
84
82
85
/**
@@ -89,7 +92,9 @@ private SubscribeForPersistedEvents(final EntityId entityId,
89
92
* @param dittoHeaders the command headers of the request.
90
93
* @return the command.
91
94
* @throws NullPointerException if any non-nullable argument is {@code null}.
95
+ * @deprecated since 3.5.0, use {@link #of(EntityId, JsonPointer, long, long, CharSequence, DittoHeaders)}
92
96
*/
97
+ @ Deprecated
93
98
public static SubscribeForPersistedEvents of (final EntityId entityId ,
94
99
final JsonPointer resourcePath ,
95
100
final long fromHistoricalRevision ,
@@ -103,6 +108,38 @@ public static SubscribeForPersistedEvents of(final EntityId entityId,
103
108
null ,
104
109
null ,
105
110
null ,
111
+ null ,
112
+ dittoHeaders );
113
+ }
114
+
115
+ /**
116
+ * Creates a new {@code SudoStreamSnapshots} command based on "from" and "to" {@code long} revisions.
117
+ *
118
+ * @param entityId the entityId that should be streamed.
119
+ * @param resourcePath the resource path for which to stream events.
120
+ * @param fromHistoricalRevision the revision to start the streaming from.
121
+ * @param toHistoricalRevision the revision to stop the streaming at.
122
+ * @param dittoHeaders the command headers of the request.
123
+ * @param filter the optional RQL filter to apply for persisted events before publishing to the stream
124
+ * @return the command.
125
+ * @throws NullPointerException if any non-nullable argument is {@code null}.
126
+ * @since 3.5.0
127
+ */
128
+ public static SubscribeForPersistedEvents of (final EntityId entityId ,
129
+ final JsonPointer resourcePath ,
130
+ final long fromHistoricalRevision ,
131
+ final long toHistoricalRevision ,
132
+ @ Nullable final CharSequence filter ,
133
+ final DittoHeaders dittoHeaders ) {
134
+
135
+ return new SubscribeForPersistedEvents (entityId ,
136
+ resourcePath ,
137
+ fromHistoricalRevision ,
138
+ toHistoricalRevision ,
139
+ null ,
140
+ null ,
141
+ null ,
142
+ filter ,
106
143
dittoHeaders );
107
144
}
108
145
@@ -116,7 +153,9 @@ public static SubscribeForPersistedEvents of(final EntityId entityId,
116
153
* @param dittoHeaders the command headers of the request.
117
154
* @return the command.
118
155
* @throws NullPointerException if any non-nullable argument is {@code null}.
156
+ * @deprecated since 3.5.0, use {@link #of(EntityId, JsonPointer, Instant, Instant, CharSequence, DittoHeaders)}
119
157
*/
158
+ @ Deprecated
120
159
public static SubscribeForPersistedEvents of (final EntityId entityId ,
121
160
final JsonPointer resourcePath ,
122
161
@ Nullable final Instant fromHistoricalTimestamp ,
@@ -130,6 +169,72 @@ public static SubscribeForPersistedEvents of(final EntityId entityId,
130
169
fromHistoricalTimestamp ,
131
170
toHistoricalTimestamp ,
132
171
null ,
172
+ null ,
173
+ dittoHeaders );
174
+ }
175
+
176
+ /**
177
+ * Creates a new {@code SudoStreamSnapshots} command based on "from" and "to" {@code Instant} timestamps.
178
+ *
179
+ * @param entityId the entityId that should be streamed.
180
+ * @param resourcePath the resource path for which to stream events.
181
+ * @param fromHistoricalTimestamp the timestamp to start the streaming from.
182
+ * @param toHistoricalTimestamp the timestamp to stop the streaming at.
183
+ * @param dittoHeaders the command headers of the request.
184
+ * @param filter the optional RQL filter to apply for persisted events before publishing to the stream
185
+ * @return the command.
186
+ * @throws NullPointerException if any non-nullable argument is {@code null}.
187
+ * @since 3.5.0
188
+ */
189
+ public static SubscribeForPersistedEvents of (final EntityId entityId ,
190
+ final JsonPointer resourcePath ,
191
+ @ Nullable final Instant fromHistoricalTimestamp ,
192
+ @ Nullable final Instant toHistoricalTimestamp ,
193
+ @ Nullable final CharSequence filter ,
194
+ final DittoHeaders dittoHeaders ) {
195
+
196
+ return new SubscribeForPersistedEvents (entityId ,
197
+ resourcePath ,
198
+ 0L ,
199
+ Long .MAX_VALUE ,
200
+ fromHistoricalTimestamp ,
201
+ toHistoricalTimestamp ,
202
+ null ,
203
+ filter ,
204
+ dittoHeaders );
205
+ }
206
+
207
+ /**
208
+ * Creates a new {@code SudoStreamSnapshots} command based on "from" and "to" {@code Instant} timestamps.
209
+ *
210
+ * @param entityId the entityId that should be streamed.
211
+ * @param resourcePath the resource path for which to stream events.
212
+ * @param fromHistoricalRevision the revision to start the streaming from.
213
+ * @param toHistoricalRevision the revision to stop the streaming at.
214
+ * @param fromHistoricalTimestamp the timestamp to start the streaming from.
215
+ * @param toHistoricalTimestamp the timestamp to stop the streaming at.
216
+ * @param dittoHeaders the command headers of the request.
217
+ * @return the command.
218
+ * @throws NullPointerException if any non-nullable argument is {@code null}.
219
+ * @deprecated since 3.5.0, use {@link #of(EntityId, JsonPointer, Long, Long, Instant, Instant, CharSequence, DittoHeaders)}
220
+ */
221
+ @ Deprecated
222
+ public static SubscribeForPersistedEvents of (final EntityId entityId ,
223
+ final JsonPointer resourcePath ,
224
+ @ Nullable final Long fromHistoricalRevision ,
225
+ @ Nullable final Long toHistoricalRevision ,
226
+ @ Nullable final Instant fromHistoricalTimestamp ,
227
+ @ Nullable final Instant toHistoricalTimestamp ,
228
+ final DittoHeaders dittoHeaders ) {
229
+
230
+ return new SubscribeForPersistedEvents (entityId ,
231
+ resourcePath ,
232
+ null != fromHistoricalRevision ? fromHistoricalRevision : 0L ,
233
+ null != toHistoricalRevision ? toHistoricalRevision : Long .MAX_VALUE ,
234
+ fromHistoricalTimestamp ,
235
+ toHistoricalTimestamp ,
236
+ null ,
237
+ null ,
133
238
dittoHeaders );
134
239
}
135
240
@@ -142,16 +247,19 @@ public static SubscribeForPersistedEvents of(final EntityId entityId,
142
247
* @param toHistoricalRevision the revision to stop the streaming at.
143
248
* @param fromHistoricalTimestamp the timestamp to start the streaming from.
144
249
* @param toHistoricalTimestamp the timestamp to stop the streaming at.
250
+ * @param filter the optional RQL filter to apply for persisted events before publishing to the stream
145
251
* @param dittoHeaders the command headers of the request.
146
252
* @return the command.
147
253
* @throws NullPointerException if any non-nullable argument is {@code null}.
254
+ * @since 3.5.0
148
255
*/
149
256
public static SubscribeForPersistedEvents of (final EntityId entityId ,
150
257
final JsonPointer resourcePath ,
151
258
@ Nullable final Long fromHistoricalRevision ,
152
259
@ Nullable final Long toHistoricalRevision ,
153
260
@ Nullable final Instant fromHistoricalTimestamp ,
154
261
@ Nullable final Instant toHistoricalTimestamp ,
262
+ @ Nullable final CharSequence filter ,
155
263
final DittoHeaders dittoHeaders ) {
156
264
157
265
return new SubscribeForPersistedEvents (entityId ,
@@ -161,6 +269,7 @@ public static SubscribeForPersistedEvents of(final EntityId entityId,
161
269
fromHistoricalTimestamp ,
162
270
toHistoricalTimestamp ,
163
271
null ,
272
+ filter ,
164
273
dittoHeaders );
165
274
}
166
275
@@ -182,6 +291,7 @@ public static SubscribeForPersistedEvents fromJson(final JsonObject jsonObject,
182
291
jsonObject .getValue (JsonFields .JSON_FROM_HISTORICAL_TIMESTAMP ).map (Instant ::parse ).orElse (null ),
183
292
jsonObject .getValue (JsonFields .JSON_TO_HISTORICAL_TIMESTAMP ).map (Instant ::parse ).orElse (null ),
184
293
jsonObject .getValue (JsonFields .PREFIX ).orElse (null ),
294
+ jsonObject .getValue (JsonFields .FILTER ).orElse (null ),
185
295
dittoHeaders
186
296
);
187
297
}
@@ -195,7 +305,7 @@ public static SubscribeForPersistedEvents fromJson(final JsonObject jsonObject,
195
305
*/
196
306
public SubscribeForPersistedEvents setPrefix (@ Nullable final String prefix ) {
197
307
return new SubscribeForPersistedEvents (entityId , resourcePath , fromHistoricalRevision , toHistoricalRevision ,
198
- fromHistoricalTimestamp , toHistoricalTimestamp , prefix , getDittoHeaders ());
308
+ fromHistoricalTimestamp , toHistoricalTimestamp , prefix , filter , getDittoHeaders ());
199
309
}
200
310
201
311
/**
@@ -244,6 +354,14 @@ public Optional<String> getPrefix() {
244
354
return Optional .ofNullable (prefix );
245
355
}
246
356
357
+ /**
358
+ * @return the optional RQL filter to apply for persisted events before publishing to the stream
359
+ * @since 3.5.0
360
+ */
361
+ public Optional <String > getFilter () {
362
+ return Optional .ofNullable (filter );
363
+ }
364
+
247
365
@ Override
248
366
protected void appendPayload (final JsonObjectBuilder jsonObjectBuilder ,
249
367
final JsonSchemaVersion schemaVersion ,
@@ -263,6 +381,7 @@ protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder,
263
381
jsonObjectBuilder .set (JsonFields .JSON_TO_HISTORICAL_TIMESTAMP , toHistoricalTimestamp .toString (), predicate );
264
382
}
265
383
getPrefix ().ifPresent (thePrefix -> jsonObjectBuilder .set (JsonFields .PREFIX , thePrefix ));
384
+ getFilter ().ifPresent (theFilter -> jsonObjectBuilder .set (JsonFields .FILTER , theFilter ));
266
385
}
267
386
268
387
@ Override
@@ -273,13 +392,13 @@ public String getTypePrefix() {
273
392
@ Override
274
393
public SubscribeForPersistedEvents setDittoHeaders (final DittoHeaders dittoHeaders ) {
275
394
return new SubscribeForPersistedEvents (entityId , resourcePath , fromHistoricalRevision , toHistoricalRevision ,
276
- fromHistoricalTimestamp , toHistoricalTimestamp , prefix , dittoHeaders );
395
+ fromHistoricalTimestamp , toHistoricalTimestamp , prefix , filter , dittoHeaders );
277
396
}
278
397
279
398
@ Override
280
399
public int hashCode () {
281
400
return Objects .hash (super .hashCode (), entityId , resourcePath , fromHistoricalRevision , toHistoricalRevision ,
282
- fromHistoricalTimestamp , toHistoricalTimestamp , prefix );
401
+ fromHistoricalTimestamp , toHistoricalTimestamp , prefix , filter );
283
402
}
284
403
285
404
@ Override
@@ -297,7 +416,8 @@ public boolean equals(@Nullable final Object obj) {
297
416
toHistoricalRevision == that .toHistoricalRevision &&
298
417
Objects .equals (fromHistoricalTimestamp , that .fromHistoricalTimestamp ) &&
299
418
Objects .equals (toHistoricalTimestamp , that .toHistoricalTimestamp ) &&
300
- Objects .equals (prefix , that .prefix );
419
+ Objects .equals (prefix , that .prefix ) &&
420
+ Objects .equals (filter , that .filter );
301
421
}
302
422
303
423
@ Override
@@ -313,6 +433,7 @@ public String toString() {
313
433
+ ", fromHistoricalTimestamp=" + fromHistoricalTimestamp
314
434
+ ", toHistoricalTimestamp=" + toHistoricalTimestamp
315
435
+ ", prefix=" + prefix
436
+ + ", filter=" + filter
316
437
+ "]" ;
317
438
}
318
439
@@ -339,6 +460,9 @@ private JsonFields() {
339
460
340
461
static final JsonFieldDefinition <String > PREFIX =
341
462
JsonFactory .newStringFieldDefinition ("prefix" , REGULAR , V_2 );
463
+
464
+ public static final JsonFieldDefinition <String > FILTER =
465
+ JsonFactory .newStringFieldDefinition ("filter" , REGULAR , V_2 );
342
466
}
343
467
344
468
}
0 commit comments