@@ -74,7 +74,7 @@ public Mono<Void> publishFolderCommonEvent(String folderId, String folderName, E
74
74
75
75
return sessionUserService .getVisitorToken ()
76
76
.zipWith (sessionUserService .getVisitorOrgMemberCache ())
77
- .doOnNext (
77
+ .delayUntil (
78
78
tuple -> {
79
79
String token = tuple .getT1 ();
80
80
OrgMember orgMember = tuple .getT2 ();
@@ -87,8 +87,11 @@ public Mono<Void> publishFolderCommonEvent(String folderId, String folderName, E
87
87
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
88
88
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
89
89
.build ();
90
- event .populateDetails ();
91
- applicationEventPublisher .publishEvent (event );
90
+ return Mono .deferContextual (contextView -> {
91
+ event .populateDetails (contextView );
92
+ applicationEventPublisher .publishEvent (event );
93
+ return Mono .empty ();
94
+ });
92
95
})
93
96
.then ()
94
97
.onErrorResume (throwable -> {
@@ -151,7 +154,7 @@ public Mono<Void> publishApplicationCommonEvent(ApplicationView applicationView,
151
154
return Pair .of (category , description );
152
155
});
153
156
}), TupleUtils ::merge )
154
- .doOnNext (tuple -> {
157
+ .delayUntil (tuple -> {
155
158
OrgMember orgMember = tuple .getT1 ().getT1 ();
156
159
Optional <Folder > optional = tuple .getT1 ().getT2 ();
157
160
Optional <Folder > optionalFrom = tuple .getT1 ().getT3 ();
@@ -175,8 +178,11 @@ public Mono<Void> publishApplicationCommonEvent(ApplicationView applicationView,
175
178
.isAnonymous (anonymous )
176
179
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
177
180
.build ();
178
- event .populateDetails ();
179
- applicationEventPublisher .publishEvent (event );
181
+ return Mono .deferContextual (contextView -> {
182
+ event .populateDetails (contextView );
183
+ applicationEventPublisher .publishEvent (event );
184
+ return Mono .empty ();
185
+ });
180
186
})
181
187
.then ()
182
188
.onErrorResume (throwable -> {
@@ -188,7 +194,7 @@ public Mono<Void> publishApplicationCommonEvent(ApplicationView applicationView,
188
194
189
195
public Mono <Void > publishUserLoginEvent (String source ) {
190
196
return sessionUserService .getVisitorOrgMember ().zipWith (sessionUserService .getVisitorToken ())
191
- .doOnNext (tuple -> {
197
+ .delayUntil (tuple -> {
192
198
OrgMember orgMember = tuple .getT1 ();
193
199
String token = tuple .getT2 ();
194
200
UserLoginEvent event = UserLoginEvent .builder ()
@@ -198,8 +204,11 @@ public Mono<Void> publishUserLoginEvent(String source) {
198
204
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
199
205
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
200
206
.build ();
201
- event .populateDetails ();
202
- applicationEventPublisher .publishEvent (event );
207
+ return Mono .deferContextual (contextView -> {
208
+ event .populateDetails (contextView );
209
+ applicationEventPublisher .publishEvent (event );
210
+ return Mono .empty ();
211
+ });
203
212
})
204
213
.then ()
205
214
.onErrorResume (throwable -> {
@@ -211,7 +220,7 @@ public Mono<Void> publishUserLoginEvent(String source) {
211
220
public Mono <Void > publishUserLogoutEvent () {
212
221
return sessionUserService .getVisitorOrgMemberCache ()
213
222
.zipWith (sessionUserService .getVisitorToken ())
214
- .doOnNext (tuple -> {
223
+ .delayUntil (tuple -> {
215
224
OrgMember orgMember = tuple .getT1 ();
216
225
String token = tuple .getT2 ();
217
226
UserLogoutEvent event = UserLogoutEvent .builder ()
@@ -220,8 +229,11 @@ public Mono<Void> publishUserLogoutEvent() {
220
229
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
221
230
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
222
231
.build ();
223
- event .populateDetails ();
224
- applicationEventPublisher .publishEvent (event );
232
+ return Mono .deferContextual (contextView -> {
233
+ event .populateDetails (contextView );
234
+ applicationEventPublisher .publishEvent (event );
235
+ return Mono .empty ();
236
+ });
225
237
})
226
238
.then ()
227
239
.onErrorResume (throwable -> {
@@ -244,7 +256,7 @@ public Mono<Void> publishGroupCreateEvent(Group group) {
244
256
.isAnonymous (Authentication .isAnonymousUser (tuple .getT1 ().getUserId ()))
245
257
.sessionHash (Hashing .sha512 ().hashString (tuple .getT2 (), StandardCharsets .UTF_8 ).toString ())
246
258
.build ();
247
- event .populateDetails ();
259
+ event .populateDetails (contextView );
248
260
applicationEventPublisher .publishEvent (event );
249
261
return Mono .empty ();
250
262
}))
@@ -272,7 +284,7 @@ public Mono<Void> publishGroupUpdateEvent(boolean publish, Group previousGroup,
272
284
.isAnonymous (Authentication .isAnonymousUser (tuple .getT1 ().getUserId ()))
273
285
.sessionHash (Hashing .sha512 ().hashString (tuple .getT2 (), StandardCharsets .UTF_8 ).toString ())
274
286
.build ();
275
- event .populateDetails ();
287
+ event .populateDetails (contextView );
276
288
applicationEventPublisher .publishEvent (event );
277
289
return Mono .empty ();
278
290
}))
@@ -300,7 +312,7 @@ public Mono<Void> publishGroupDeleteEvent(boolean publish, Group previousGroup)
300
312
.isAnonymous (Authentication .isAnonymousUser (tuple .getT1 ().getUserId ()))
301
313
.sessionHash (Hashing .sha512 ().hashString (tuple .getT2 (), StandardCharsets .UTF_8 ).toString ())
302
314
.build ();
303
- event .populateDetails ();
315
+ event .populateDetails (contextView );
304
316
applicationEventPublisher .publishEvent (event );
305
317
return Mono .empty ();
306
318
}))
@@ -337,7 +349,7 @@ public Mono<Void> publishGroupMemberAddEvent(boolean publish, String groupId, Ad
337
349
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
338
350
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
339
351
.build ();
340
- event .populateDetails ();
352
+ event .populateDetails (contextView );
341
353
applicationEventPublisher .publishEvent (event );
342
354
return Mono .empty ();
343
355
}))
@@ -374,7 +386,7 @@ public Mono<Void> publishGroupMemberRoleUpdateEvent(boolean publish, String grou
374
386
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
375
387
.sessionHash (Hashing .sha512 ().hashString (tuple .getT4 (), StandardCharsets .UTF_8 ).toString ())
376
388
.build ();
377
- event .populateDetails ();
389
+ event .populateDetails (contextView );
378
390
applicationEventPublisher .publishEvent (event );
379
391
return Mono .empty ();
380
392
}))
@@ -410,7 +422,7 @@ public Mono<Void> publishGroupMemberLeaveEvent(boolean publish, GroupMember grou
410
422
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
411
423
.sessionHash (Hashing .sha512 ().hashString (tuple .getT4 (), StandardCharsets .UTF_8 ).toString ())
412
424
.build ();
413
- event .populateDetails ();
425
+ event .populateDetails (contextView );
414
426
applicationEventPublisher .publishEvent (event );
415
427
return Mono .empty ();
416
428
}))
@@ -446,7 +458,7 @@ public Mono<Void> publishGroupMemberRemoveEvent(boolean publish, GroupMember pre
446
458
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
447
459
.sessionHash (Hashing .sha512 ().hashString (tuple .getT4 (), StandardCharsets .UTF_8 ).toString ())
448
460
.build ();
449
- event .populateDetails ();
461
+ event .populateDetails (contextView );
450
462
applicationEventPublisher .publishEvent (event );
451
463
return Mono .empty ();
452
464
}))
@@ -484,9 +496,11 @@ public Mono<Void> publishDatasourceEvent(Datasource datasource, EventType eventT
484
496
.isAnonymous (Authentication .isAnonymousUser (tuple .getT1 ().getUserId ()))
485
497
.sessionHash (Hashing .sha512 ().hashString (tuple .getT2 (), StandardCharsets .UTF_8 ).toString ())
486
498
.build ();
487
- event .populateDetails ();
488
- applicationEventPublisher .publishEvent (event );
489
- return Mono .<Void > empty ();
499
+ return Mono .deferContextual (contextView -> {
500
+ event .populateDetails (contextView );
501
+ applicationEventPublisher .publishEvent (event );
502
+ return Mono .<Void >empty ();
503
+ });
490
504
})
491
505
.onErrorResume (throwable -> {
492
506
log .error ("publishDatasourceEvent error." , throwable );
@@ -535,9 +549,11 @@ public Mono<Void> publishDatasourcePermissionEvent(String datasourceId,
535
549
.isAnonymous (Authentication .isAnonymousUser (orgMember .getUserId ()))
536
550
.sessionHash (Hashing .sha512 ().hashString (tuple .getT3 (), StandardCharsets .UTF_8 ).toString ())
537
551
.build ();
538
- datasourcePermissionEvent .populateDetails ();
539
- applicationEventPublisher .publishEvent (datasourcePermissionEvent );
540
- return Mono .<Void > empty ();
552
+ return Mono .deferContextual (contextView -> {
553
+ datasourcePermissionEvent .populateDetails (contextView );
554
+ applicationEventPublisher .publishEvent (datasourcePermissionEvent );
555
+ return Mono .<Void >empty ();
556
+ });
541
557
})
542
558
.onErrorResume (throwable -> {
543
559
log .error ("publishDatasourcePermissionEvent error." , throwable );
@@ -552,7 +568,7 @@ public Mono<Void> publishLibraryQuery(LibraryQuery libraryQuery, EventType event
552
568
public Mono <Void > publishLibraryQueryEvent (String id , String name , EventType eventType ) {
553
569
return sessionUserService .getVisitorOrgMemberCache ()
554
570
.zipWith (sessionUserService .getVisitorToken ())
555
- .map (tuple -> {
571
+ .flatMap (tuple -> {
556
572
LibraryQueryEvent event = LibraryQueryEvent .builder ()
557
573
.userId (tuple .getT1 ().getUserId ())
558
574
.orgId (tuple .getT1 ().getOrgId ())
@@ -562,10 +578,12 @@ public Mono<Void> publishLibraryQueryEvent(String id, String name, EventType eve
562
578
.isAnonymous (Authentication .isAnonymousUser (tuple .getT1 ().getUserId ()))
563
579
.sessionHash (Hashing .sha512 ().hashString (tuple .getT2 (), StandardCharsets .UTF_8 ).toString ())
564
580
.build ();
565
- event .populateDetails ();
566
- return event ;
581
+ return Mono .deferContextual (contextView -> {
582
+ event .populateDetails (contextView );
583
+ applicationEventPublisher .publishEvent (event );
584
+ return Mono .<Void >empty ();
585
+ });
567
586
})
568
- .doOnNext (applicationEventPublisher ::publishEvent )
569
587
.then ()
570
588
.onErrorResume (throwable -> {
571
589
log .error ("publishLibraryQueryEvent error." , throwable );
0 commit comments