Skip to content

Commit d923517

Browse files
Sahil-tarentoshankaragoudabArpithaSureshappa
authored
4.8.27.2 dev v9 (#225)
* fix for the content state update issue (#220) * KB-11245 The email notification triggered and the course name is not … (#222) * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix added null check for recentLanguage (#224) * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix added null check for recentLanguage * KB-11245 The email notification triggered and the course name is not in a enrolled language issue fix added null check for recentLanguage --------- Co-authored-by: shankaragoudab <140387294+shankaragoudab@users.noreply.github.com> Co-authored-by: Arpitha <arpitha.sureshappa@tarento.com>
1 parent 3bf942e commit d923517

File tree

2 files changed

+73
-29
lines changed

2 files changed

+73
-29
lines changed

course-mw/course-actors/src/main/java/org/sunbird/learner/actors/coursebatch/CourseBatchNotificationActor.java

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.mashape.unirest.http.Unirest;
66
import com.mashape.unirest.http.exceptions.UnirestException;
77
import org.apache.commons.collections.CollectionUtils;
8+
import org.apache.commons.lang3.StringUtils;
89
import org.sunbird.actor.base.BaseActor;
910
import org.sunbird.common.Constants;
1011
import 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,

course-mw/enrolment-actor/src/main/scala/org/sunbird/enrolments/ExtendedCourseEnrollmentActor.scala

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
138138

139139
// Telemetry and notification
140140
generateTelemetryAudit(userId, courseId, batchId, data, "enrol", JsonKey.CREATE, request.getContext)
141-
notifyUser(userId, batchData, JsonKey.ADD)
141+
val recentLanguage = data.getOrDefault(JsonKey.RECENT_LANGUAGE, "").asInstanceOf[String]
142+
notifyUser(userId, batchData, JsonKey.ADD, recentLanguage)
142143
} else {
143144
ProjectCommonException.throwClientErrorException(ResponseCode.accessDeniedToEnrolOrUnenrolCourse, courseId)
144145
}
@@ -285,14 +286,15 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
285286
TelemetryUtil.telemetryProcessingCall(request, targetedObject, correlationObject, contextMap, "enrol")
286287
}
287288

288-
def notifyUser(userId: String, batchData: CourseBatch, operationType: String): Unit = {
289+
def notifyUser(userId: String, batchData: CourseBatch, operationType: String, recentLanguage: String): Unit = {
289290
val isNotifyUser = java.lang.Boolean.parseBoolean(PropertiesCache.getInstance().getProperty(JsonKey.SUNBIRD_COURSE_BATCH_NOTIFICATIONS_ENABLED))
290291
if (isNotifyUser) {
291292
val request = new Request()
292293
request.setOperation(ActorOperations.COURSE_BATCH_NOTIFICATION.getValue)
293294
request.put(JsonKey.USER_ID, userId)
294295
request.put(JsonKey.COURSE_BATCH, batchData)
295296
request.put(JsonKey.OPERATION_TYPE, operationType)
297+
request.put(JsonKey.RECENT_LANGUAGE, recentLanguage)
296298
courseBatchNotificationActorRef.tell(request, getSelf())
297299
}
298300
}
@@ -713,10 +715,16 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
713715

714716
def updateProgressData(enrolments: java.util.List[java.util.Map[String, AnyRef]], requestContext: RequestContext): util.List[java.util.Map[String, AnyRef]] = {
715717
enrolments.map { enrolment =>
716-
val leafNodesCount: Int = enrolment.getOrDefault("leafNodesCount", 0.asInstanceOf[AnyRef]).asInstanceOf[Int]
717-
val progress: Int = enrolment.getOrDefault("progress", 0.asInstanceOf[AnyRef]).asInstanceOf[Int]
718-
enrolment.put("status", getCompletionStatus(progress, leafNodesCount).asInstanceOf[AnyRef])
719-
enrolment.put("completionPercentage", getCompletionPerc(progress, leafNodesCount).asInstanceOf[AnyRef])
718+
val statusObj: Int = enrolment.getOrDefault("status", 0.asInstanceOf[AnyRef]).asInstanceOf[Int]
719+
if (statusObj.equals(2)) {
720+
enrolment.put("status", 2.asInstanceOf[AnyRef])
721+
enrolment.put("completionPercentage", 100.asInstanceOf[AnyRef])
722+
} else {
723+
val leafNodesCount: Int = enrolment.getOrDefault("leafNodesCount", 0.asInstanceOf[AnyRef]).asInstanceOf[Int]
724+
val progress: Int = enrolment.getOrDefault("progress", 0.asInstanceOf[AnyRef]).asInstanceOf[Int]
725+
enrolment.put("status", getCompletionStatus(progress, leafNodesCount).asInstanceOf[AnyRef])
726+
enrolment.put("completionPercentage", getCompletionPerc(progress, leafNodesCount).asInstanceOf[AnyRef])
727+
}
720728

721729
jsonFields.foreach { field =>
722730
if (enrolment.containsKey(field) && null != enrolment.get(field)) {
@@ -832,7 +840,8 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
832840
generatePreProcessorKafkaEvent(request,batchId, programId, userId)
833841
sender().tell(successResponse(), self)
834842
generateTelemetryAudit(userId, programId, batchId, data, "enrol", JsonKey.CREATE, request.getContext)
835-
notifyUser(userId, batchData, JsonKey.ADD)
843+
844+
notifyUser(userId, batchData, JsonKey.ADD, recentLanguage)
836845
cacheUtil.delete(getCacheBatchKey(batchId))
837846
}
838847

@@ -988,7 +997,7 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
988997
cacheUtil.delete(getCacheKey(userId))
989998
sender().tell(successResponse(), self)
990999
generateTelemetryAudit(userId, courseId, batchId, data, "enrol", JsonKey.CREATE, request.getContext)
991-
notifyUser(userId, batchData, JsonKey.ADD)
1000+
notifyUser(userId, batchData, JsonKey.ADD, courseLanguage)
9921001
val dataMap = new java.util.HashMap[String, AnyRef]
9931002
val requestMap = new java.util.HashMap[String, AnyRef]
9941003
requestMap.put(JsonKey.COURSE_ID,courseId)
@@ -1104,7 +1113,7 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
11041113
cacheUtil.delete(getCacheKey(userId))
11051114
generatePreProcessorKafkaEvent(request, batchId, programId, userId)
11061115
generateTelemetryAudit(userId, programId, batchId, data, "enrol", JsonKey.CREATE, request.getContext)
1107-
notifyUser(userId, batchData, JsonKey.ADD)
1116+
notifyUser(userId, batchData, JsonKey.ADD, courseLanguage)
11081117
status.put(JsonKey.STATUS, JsonKey.SUCCESS)
11091118
response.put(userId, status)
11101119
} catch {
@@ -1296,7 +1305,7 @@ class ExtendedCourseEnrollmentActor @Inject()(@Named("course-batch-notification-
12961305
logger.info(request.getRequestContext, "CourseEnrolmentActor :: enroll :: Deleting redis for key " + getCacheKey(userId))
12971306
cacheUtil.delete(getCacheKey(userId))
12981307
generateTelemetryAudit(userId, courseId, batchId, data, "enrol", JsonKey.CREATE, request.getContext)
1299-
notifyUser(userId, batchData, JsonKey.ADD)
1308+
notifyUser(userId, batchData, JsonKey.ADD , recentLanguage)
13001309
} catch {
13011310
case e: ProjectCommonException =>
13021311
if (ResponseCode.userAlreadyEnrolledCourse.getErrorMessage.equals(e.getMessage))

0 commit comments

Comments
 (0)