55import com .mashape .unirest .http .Unirest ;
66import com .mashape .unirest .http .exceptions .UnirestException ;
77import org .apache .commons .collections .CollectionUtils ;
8+ import org .apache .commons .lang3 .StringUtils ;
89import org .sunbird .actor .base .BaseActor ;
910import org .sunbird .common .Constants ;
1011import org .sunbird .common .models .util .ActorOperations ;
@@ -68,6 +69,9 @@ private void courseBatchNotification(Request request) throws Exception {
6869
6970 CourseBatch courseBatch = (CourseBatch ) requestMap .get (JsonKey .COURSE_BATCH );
7071 String authToken = (String ) request .getContext ().getOrDefault (JsonKey .X_AUTH_TOKEN , "" );
72+ String recentLanguage = StringUtils .defaultString (
73+ (String ) requestMap .get (JsonKey .RECENT_LANGUAGE ), ""
74+ );
7175
7276 String userId = (String ) requestMap .get (JsonKey .USER_ID );
7377 logger .info (request .getRequestContext (), "CourseBatchNotificationActor:courseBatchNotification: userId = " + userId );
@@ -83,6 +87,7 @@ private void courseBatchNotification(Request request) throws Exception {
8387 String template = JsonKey .OPEN_BATCH_LEARNER_UNENROL ;
8488 String subject = JsonKey .UNENROLL_FROM_COURSE_BATCH ;
8589
90+
8691 String operationType = (String ) requestMap .get (JsonKey .OPERATION_TYPE );
8792
8893 if (operationType .equals (JsonKey .ADD )) {
@@ -91,7 +96,7 @@ private void courseBatchNotification(Request request) throws Exception {
9196 }
9297
9398 triggerEmailNotification ( request .getRequestContext (),
94- Arrays .asList (userId ), courseBatch , subject , template , contentDetails , authToken );
99+ Arrays .asList (userId ), courseBatch , subject , template , contentDetails , authToken , recentLanguage );
95100
96101 } else {
97102 logger .info (request .getRequestContext (), "CourseBatchNotificationActor:courseBatchNotification: Invite only batch" );
@@ -104,13 +109,13 @@ private void courseBatchNotification(Request request) throws Exception {
104109 courseBatch ,
105110 JsonKey .COURSE_INVITATION ,
106111 JsonKey .BATCH_MENTOR_ENROL ,
107- contentDetails , authToken );
112+ contentDetails , authToken , recentLanguage );
108113 triggerEmailNotification (
109114 request .getRequestContext (), removedMentors ,
110115 courseBatch ,
111116 JsonKey .UNENROLL_FROM_COURSE_BATCH ,
112117 JsonKey .BATCH_MENTOR_UNENROL ,
113- contentDetails , authToken );
118+ contentDetails , authToken , recentLanguage );
114119
115120 List <String > addedParticipants = (List <String >) requestMap .get (JsonKey .ADDED_PARTICIPANTS );
116121 List <String > removedParticipants =
@@ -121,13 +126,13 @@ private void courseBatchNotification(Request request) throws Exception {
121126 courseBatch ,
122127 JsonKey .COURSE_INVITATION ,
123128 JsonKey .BATCH_LEARNER_ENROL ,
124- contentDetails , authToken );
129+ contentDetails , authToken , recentLanguage );
125130 triggerEmailNotification (
126131 request .getRequestContext (), removedParticipants ,
127132 courseBatch ,
128133 JsonKey .UNENROLL_FROM_COURSE_BATCH ,
129134 JsonKey .BATCH_LEARNER_UNENROL ,
130- contentDetails , authToken );
135+ contentDetails , authToken , recentLanguage );
131136 }
132137 }
133138
@@ -136,7 +141,7 @@ private void triggerEmailNotification(
136141 CourseBatch courseBatch ,
137142 String subject ,
138143 String template ,
139- Map <String , Object > contentDetails , String authToken ) throws Exception {
144+ Map <String , Object > contentDetails , String authToken , String recentLanguage ) throws Exception {
140145
141146 logger .debug (requestContext , "CourseBatchNotificationActor:triggerEmailNotification: userIdList = "
142147 + userIdList );
@@ -145,7 +150,7 @@ private void triggerEmailNotification(
145150
146151 for (String userId : userIdList ) {
147152 Map <String , Object > requestMap =
148- createEmailRequest (userId , courseBatch , contentDetails , subject , template );
153+ createEmailRequest (userId , courseBatch , contentDetails , subject , template , recentLanguage );
149154
150155 logger .info (requestContext , "CourseBatchNotificationActor:triggerEmailNotification: requestMap = " + requestMap );
151156 sendMail (requestContext , requestMap , authToken );
@@ -158,33 +163,63 @@ private Map<String, Object> createEmailRequest(
158163 CourseBatch courseBatch ,
159164 Map <String , Object > contentDetails ,
160165 String subject ,
161- String template ) throws Exception {
166+ String template ,
167+ String recentLanguage ) throws Exception {
162168 Map <String , Object > courseBatchObject = JsonUtil .convert (courseBatch , Map .class );
163169
164170 logger .info (null ,"Course Batch Details in email Request: " + courseBatchObject + ": contentDetails: " + contentDetails );
165171 Map <String , Object > request = new HashMap <>();
166172 Map <String , Object > requestMap = new HashMap <String , Object >();
173+ List <?> languageList = (List <?>) contentDetails .get (JsonKey .LANGUAGE );
174+ String langValue = (CollectionUtils .isNotEmpty (languageList ) && languageList .get (0 ) != null )
175+ ? languageList .get (0 ).toString ()
176+ : "" ;
177+ if (StringUtils .isNotBlank (recentLanguage ) && !recentLanguage .equalsIgnoreCase (langValue )) {
178+ Object langMapObj = contentDetails .get (JsonKey .LANGUAGE_MAP );
179+ if (langMapObj instanceof Map ) {
180+ Map <?, ?> langMap = (Map <?, ?>) langMapObj ;
181+ Object recentLangObj = langMap .get (recentLanguage );
182+ if (recentLangObj instanceof Map ) {
183+ Map <?, ?> recentLangMap = (Map <?, ?>) recentLangObj ;
184+ String id = recentLangMap .get (JsonKey .ID ).toString ();
185+ Map <String , Object > recentLangContentDetail = ContentUtil .getContent (id , Arrays .asList (JsonKey .APP_ICON , JsonKey .POSTER_IMAGE , JsonKey .NAME ));
186+ Map <String , Object > content = (Map <String , Object >) recentLangContentDetail .get (JsonKey .CONTENT );
187+ requestMap .put (JsonKey .COURSE_LOGO_URL , content .get (JsonKey .APP_ICON ));
188+ if (content .containsKey (JsonKey .POSTER_IMAGE )) {
189+ String posterImageUrl = (String ) content .get (JsonKey .POSTER_IMAGE );
190+ if (posterImageUrl .contains (staticHostUrl )) {
191+ String [] posterImageUrlArr = posterImageUrl .split ("/content/" );
192+ posterImageUrl = baseUrl + contentBucket + "/" + posterImageUrlArr [1 ];
193+ }
194+ requestMap .put (JsonKey .COURSE_POSTER_IMAGE , posterImageUrl );
195+ }
196+ requestMap .put (JsonKey .COURSE_NAME , content .get (JsonKey .NAME ));
197+ }
198+ }
199+ } else {
200+ requestMap .put (JsonKey .COURSE_LOGO_URL , contentDetails .get (JsonKey .APP_ICON ));
201+ if (contentDetails .containsKey (JsonKey .POSTER_IMAGE )) {
202+ String posterImageUrl = (String ) contentDetails .get (JsonKey .POSTER_IMAGE );
203+ if (posterImageUrl .contains (staticHostUrl )) {
204+ String [] posterImageUrlArr = posterImageUrl .split ("/content/" );
205+ posterImageUrl = baseUrl + contentBucket + "/" + posterImageUrlArr [1 ];
206+ }
207+ requestMap .put (JsonKey .COURSE_POSTER_IMAGE , posterImageUrl );
208+ }
209+ requestMap .put (JsonKey .COURSE_NAME , contentDetails .get (JsonKey .NAME ));
210+ }
167211
168212 requestMap .put (JsonKey .SUBJECT , subject );
169213 requestMap .put (JsonKey .EMAIL_TEMPLATE_TYPE , template );
170214 requestMap .put (JsonKey .BODY , "Notification mail Body" );
171215 requestMap .put (JsonKey .ORG_NAME , courseBatchObject .get (JsonKey .ORG_NAME ));
172- requestMap .put (JsonKey .COURSE_LOGO_URL , contentDetails .get (JsonKey .APP_ICON ));
173- if (contentDetails .containsKey (JsonKey .POSTER_IMAGE )) {
174- String posterImageUrl = (String ) contentDetails .get (JsonKey .POSTER_IMAGE );
175- if (posterImageUrl .contains (staticHostUrl )) {
176- String [] posterImageUrlArr = posterImageUrl .split ("/content/" );
177- posterImageUrl = baseUrl + contentBucket + "/" + posterImageUrlArr [1 ];
178- }
179- requestMap .put (JsonKey .COURSE_POSTER_IMAGE , posterImageUrl );
180- }
181- requestMap .put (JsonKey .PROVIDER_NAME , contentDetails .get (JsonKey .SOURCE ));
182216 requestMap .put (JsonKey .PROFILE_UPDATE_LINK , baseUrl + profileUpdateUrl );
217+ requestMap .put (JsonKey .PROVIDER_NAME , contentDetails .get (JsonKey .SOURCE ));
183218 requestMap .put (JsonKey .START_DATE , courseBatchObject .get (JsonKey .START_DATE ));
184219 requestMap .put (JsonKey .END_DATE , courseBatchObject .get (JsonKey .END_DATE ));
185220 requestMap .put (JsonKey .COURSE_ID , courseBatchObject .get (JsonKey .COURSE_ID ));
186221 requestMap .put (JsonKey .BATCH_NAME , courseBatch .getName ());
187- requestMap . put ( JsonKey . COURSE_NAME , contentDetails . get ( JsonKey . NAME ));
222+
188223 requestMap .put (JsonKey .MEETING_LINK , meetingLinkUrl );
189224 requestMap .put (
190225 JsonKey .COURSE_BATCH_URL ,
0 commit comments