@@ -113,6 +113,9 @@ private Map<String, Object> retireContent(Map<String, Object> retirementRecord)
113113 result .put (Constants .RETIRED , true );
114114 result .put (Constants .MESSAGE , "Content retired successfully" );
115115
116+ LocalDate retirementDate = (LocalDate ) retirementRecord .get (Constants .RETIREMENT_DATE );
117+ validateAndSendInAppLearerNotification (contentId , Constants .CONTENT_RETIRED , retirementDate );
118+
116119 } else {
117120 log .warn ("Retirement API returned empty response for {}" , contentId );
118121
@@ -184,88 +187,8 @@ public void sendContentRetirementNotifications() {
184187 }
185188
186189 log .info ("Triggering {} notification for content {}" , notificationType , contentId );
190+ validateAndSendInAppLearerNotification (contentId , notificationType , retirementDate );
187191
188- Map <String , Object > content =
189- contentService .readContent (contentId , Arrays .asList ("name" , "batches" ));
190-
191- List <Map <String , Object >> batches =
192- (List <Map <String , Object >>) content .get ("batches" );
193-
194- if (CollectionUtils .isEmpty (batches )) {
195- log .info ("No batches found for content {}" , contentId );
196- continue ;
197- }
198-
199- for (Map <String , Object > batch : batches ) {
200-
201- String batchId = (String ) batch .get (Constants .BATCH_ID );
202-
203- List <Map <String , Object >> batchUsers =
204- cassandraOperation .getRecordsByProperties (
205- Constants .KEYSPACE_SUNBIRD_COURSE ,
206- Constants .ENROLLMENT_BATCH_LOOKUP ,
207- Map .of (Constants .BATCH_ID , batchId ),
208- Arrays .asList (Constants .USER_ID ),
209- null
210- );
211-
212- if (CollectionUtils .isEmpty (batchUsers )) {
213- continue ;
214- }
215-
216- for (Map <String , Object > batchUser : batchUsers ) {
217-
218- String userId = (String ) batchUser .get (Constants .USER_ID );
219- Map <String , Object > enrolmentProperties = Map .of (
220- Constants .USER_ID , userId ,
221- Constants .COURSE_ID , contentId ,
222- Constants .BATCH_ID , batchId
223- );
224-
225- List <Map <String , Object >> enrolment =
226- cassandraOperation .getRecordsByProperties (
227- Constants .KEYSPACE_SUNBIRD_COURSE ,
228- Constants .USER_ENROLMENTS_V2_TABLE ,
229- enrolmentProperties ,
230- null ,
231- null
232- );
233-
234- if (CollectionUtils .isEmpty (enrolment )) {
235- continue ;
236- }
237-
238- List <Map <String , Object >> eligibleEnrolments =
239- enrolment .stream ()
240- .filter (Objects ::nonNull )
241- .filter (e -> {
242- Object statusObj = e .get (Constants .STATUS );
243- Object activeObj = e .get (Constants .ACTIVE );
244- Object certificates = e .get (Constants .ISSUED_CERTIFICATES );
245-
246- return statusObj instanceof Integer
247- && activeObj instanceof Boolean
248- && !Objects .equals (statusObj , 2 )
249- && (certificates == null || ((List <?>) certificates ).isEmpty ())
250- && Boolean .TRUE .equals (activeObj );
251- })
252- .toList ();
253-
254-
255- if (CollectionUtils .isEmpty (eligibleEnrolments )) {
256- continue ;
257- }
258- String courseName = (String ) content .get (Constants .NAME );
259- notificationService .sendNotificationForContentRetirement (
260- contentId ,
261- courseName ,
262- retirementDate ,
263- List .of (userId ),
264- notificationType
265- );
266-
267- }
268- }
269192 }
270193 }
271194
@@ -399,5 +322,92 @@ private List<Map<String, String>> fetchSpvPublishers() {
399322 return publishers ;
400323 }
401324
325+ private void validateAndSendInAppLearerNotification (String contentId , String notificationType , LocalDate retirementDate ) {
326+ try {
327+ Map <String , Object > content =
328+ contentService .readContent (contentId , Arrays .asList ("name" , "batches" ));
329+
330+ List <Map <String , Object >> batches =
331+ (List <Map <String , Object >>) content .get ("batches" );
332+
333+ if (CollectionUtils .isEmpty (batches )) {
334+ log .info ("No batches found for content {}" , contentId );
335+ return ;
336+ }
337+
338+ for (Map <String , Object > batch : batches ) {
339+
340+ String batchId = (String ) batch .get (Constants .BATCH_ID );
341+
342+ List <Map <String , Object >> batchUsers =
343+ cassandraOperation .getRecordsByProperties (
344+ Constants .KEYSPACE_SUNBIRD_COURSE ,
345+ Constants .ENROLLMENT_BATCH_LOOKUP ,
346+ Map .of (Constants .BATCH_ID , batchId ),
347+ Arrays .asList (Constants .USER_ID ),
348+ null
349+ );
350+
351+ if (CollectionUtils .isEmpty (batchUsers )) {
352+ continue ;
353+ }
354+
355+ for (Map <String , Object > batchUser : batchUsers ) {
356+
357+ String userId = (String ) batchUser .get (Constants .USER_ID );
358+ Map <String , Object > enrolmentProperties = Map .of (
359+ Constants .USER_ID , userId ,
360+ Constants .COURSE_ID , contentId ,
361+ Constants .BATCH_ID , batchId
362+ );
363+
364+ List <Map <String , Object >> enrolment =
365+ cassandraOperation .getRecordsByProperties (
366+ Constants .KEYSPACE_SUNBIRD_COURSE ,
367+ Constants .USER_ENROLMENTS_V2_TABLE ,
368+ enrolmentProperties ,
369+ null ,
370+ null
371+ );
372+
373+ if (CollectionUtils .isEmpty (enrolment )) {
374+ continue ;
375+ }
376+
377+ List <Map <String , Object >> eligibleEnrolments =
378+ enrolment .stream ()
379+ .filter (Objects ::nonNull )
380+ .filter (e -> {
381+ Object statusObj = e .get (Constants .STATUS );
382+ Object activeObj = e .get (Constants .ACTIVE );
383+ Object certificates = e .get (Constants .ISSUED_CERTIFICATES );
384+
385+ return statusObj instanceof Integer
386+ && activeObj instanceof Boolean
387+ && !Objects .equals (statusObj , 2 )
388+ && (certificates == null || ((List <?>) certificates ).isEmpty ())
389+ && Boolean .TRUE .equals (activeObj );
390+ })
391+ .toList ();
392+
393+
394+ if (CollectionUtils .isEmpty (eligibleEnrolments )) {
395+ continue ;
396+ }
397+ String courseName = (String ) content .get (Constants .NAME );
398+ notificationService .sendNotificationForContentRetirement (
399+ contentId ,
400+ courseName ,
401+ retirementDate ,
402+ List .of (userId ),
403+ notificationType
404+ );
405+
406+ }
407+ }
408+ } catch (Exception e ) {
409+ log .error ("Error while sending in-app notification for content retirement" , e );
410+ }
411+ }
402412}
403413
0 commit comments