From 09cb72ca173fbafdea8f0a7726e845ea80fcd0cc Mon Sep 17 00:00:00 2001 From: saipradeep_ravipati Date: Tue, 16 Apr 2024 08:48:35 +0530 Subject: [PATCH] Changes for Handling Retired Courses --- .../learner/util/ContentCacheHandler.java | 2 +- .../org/sunbird/learner/util/ContentUtil.java | 5 +++- .../enrolments/CourseEnrolmentActor.scala | 27 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentCacheHandler.java b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentCacheHandler.java index 32d79901d..957e8c894 100644 --- a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentCacheHandler.java +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentCacheHandler.java @@ -50,7 +50,7 @@ public static Map getContent(String id) { if(obj != null) return obj; else{ - contentMap.putAll(ContentUtil.getAllContent(Arrays.asList(id.split("")),Integer.parseInt(PropertiesCache.getInstance() + contentMap.putAll(ContentUtil.getAllContent(Arrays.asList(id),Integer.parseInt(PropertiesCache.getInstance() .getProperty(JsonKey.PAGE_SIZE_CONTENT_FETCH)))); return (Map)contentMap.get(id); } diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java index ceaa78cff..b2cdcd4e9 100644 --- a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java @@ -264,7 +264,10 @@ public static Map.Entry>> contents(List queryFields.addAll(Arrays.asList(queryFieldsParam.split(","))); searchDTO.setFields(queryFields); filters.put(JsonKey.MIME_TYPE, JsonKey.COLLECTION_MIME_TYPE); - filters.put(JsonKey.STATUS,JsonKey.LIVE); + List status = new ArrayList<>(); + status.add(JsonKey.LIVE); + status.add(JsonKey.RETIRED); + filters.put(JsonKey.STATUS,status); if(identifierList != null && identifierList.size() > 0) filters.put(JsonKey.IDENTIFIER,identifierList); searchDTO.getAdditionalProperties().put(JsonKey.FILTERS, filters); diff --git a/course-mw/enrolment-actor/src/main/scala/org/sunbird/enrolments/CourseEnrolmentActor.scala b/course-mw/enrolment-actor/src/main/scala/org/sunbird/enrolments/CourseEnrolmentActor.scala index 98d3df006..761186532 100644 --- a/course-mw/enrolment-actor/src/main/scala/org/sunbird/enrolments/CourseEnrolmentActor.scala +++ b/course-mw/enrolment-actor/src/main/scala/org/sunbird/enrolments/CourseEnrolmentActor.scala @@ -517,12 +517,28 @@ class CourseEnrolmentActor @Inject()(@Named("course-batch-notification-actor") c enrolmentData.setStatus(getCompletionStatus(enrolmentData.getProgress, leafNodesCount)) } - def addCourseDetails_v2(activeEnrolments: java.util.List[java.util.Map[String, AnyRef]]): java.util.List[java.util.Map[String, AnyRef]] = { + def getCourseContent(courseId: String): java.util.Map[String, AnyRef] = { val coursesMap = ContentCacheHandler.getContentMap.asInstanceOf[java.util.Map[String, java.util.Map[String, AnyRef]]] - activeEnrolments.map(enrolment => { - var courseContent = coursesMap.get(enrolment.get(JsonKey.COURSE_ID)) - if (courseContent == null || courseContent.size() < 1) - courseContent = ContentCacheHandler.getContent(enrolment.get(JsonKey.COURSE_ID).asInstanceOf[String]) + var courseContent = coursesMap.get(courseId) + if (courseContent == null || courseContent.size() < 1) + courseContent = ContentCacheHandler.getContent(courseId) + courseContent + } + + def isCourseEligible(enrolment: java.util.Map[String, AnyRef]): Boolean = { + val courseContent = getCourseContent(enrolment.get(JsonKey.COURSE_ID).asInstanceOf[String]) + if (null == courseContent || (!JsonKey.LIVE.equalsIgnoreCase(courseContent.get(JsonKey.STATUS).asInstanceOf[String]) + && !isRetiredCoursesIncludedInEnrolList)) { + false + } + else { + true + } + } + + def addCourseDetails_v2(activeEnrolments: java.util.List[java.util.Map[String, AnyRef]]): java.util.List[java.util.Map[String, AnyRef]] = { + activeEnrolments.filter(enrolment => isCourseEligible(enrolment)).map(enrolment => { + val courseContent = getCourseContent(enrolment.get(JsonKey.COURSE_ID).asInstanceOf[String]) enrolment.put(JsonKey.COURSE_NAME, courseContent.get(JsonKey.NAME)) enrolment.put(JsonKey.DESCRIPTION, courseContent.get(JsonKey.DESCRIPTION)) enrolment.put(JsonKey.LEAF_NODE_COUNT, courseContent.get(JsonKey.LEAF_NODE_COUNT)) @@ -533,6 +549,7 @@ class CourseEnrolmentActor @Inject()(@Named("course-batch-notification-actor") c enrolment }).toList.asJava } + def enrollProgram(request: Request): Unit = { val programId: String = request.get(JsonKey.PROGRAM_ID).asInstanceOf[String] val isAdminAPI: Boolean = request.get(JsonKey.IS_ADMIN_API).asInstanceOf[Boolean]