Skip to content

Commit

Permalink
method for updating the score in batch user mapping table
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbowade committed Feb 2, 2024
1 parent bd9e47a commit 6006dd3
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.sunbird.common.models.util._
import org.sunbird.common.request.{Request, RequestContext}
import org.sunbird.common.responsecode.ResponseCode
import org.sunbird.helper.ServiceFactory
import org.sunbird.keys.SunbirdKey
import org.sunbird.learner.actors.coursebatch.dao.impl.{BatchUserDaoImpl, CourseBatchDaoImpl, CourseUserDaoImpl, UserCoursesDaoImpl}
import org.sunbird.learner.actors.coursebatch.dao.{BatchUserDao, CourseBatchDao, CourseUserDao, UserCoursesDao}
import org.sunbird.learner.actors.coursebatch.service.UserCoursesService
Expand Down Expand Up @@ -673,6 +674,25 @@ class CourseEnrolmentActor @Inject()(@Named("course-batch-notification-actor") c
resp
}

private def getScoreDetails(batchId: String, userIds: util.List[String], courseId: String, request: Request, x: Int) = {
val scoreListResponse = groupDao.readEntries("Course", util.Arrays.asList(userIds.get(x)), util.Arrays.asList(courseId), request.getRequestContext)
val scoreList: java.util.List[java.util.Map[String, AnyRef]] = scoreListResponse.get(SunbirdKey.RESPONSE).asInstanceOf[java.util.List[java.util.Map[String, AnyRef]]]
val matchedScore = scoreList.find(score =>
score.get("activity_id") == courseId &&
score.get("context_id").toString.replaceFirst("cb:", "") == batchId &&
score.get("user_id") == userIds.get(x)
)
val batchMap = new util.HashMap[String, Object]()
batchMap.put(JsonKey.USER_ID, userIds.get(x))
batchMap.put(JsonKey.BATCH_ID, batchId)
val scoreFromAggregates: java.util.Map[String, Double] = matchedScore.get("aggregates").asInstanceOf[java.util.Map[String, Double]]
val keyStartingWithScore = scoreFromAggregates.keys.find(_.startsWith("score:"))
val scoreValue = scoreFromAggregates.get(keyStartingWithScore.get).toString
batchMap.put(JsonKey.SCORE, scoreValue.asInstanceOf[AnyRef])
val batchdata = CassandraUtil.changeCassandraColumnMapping(batchMap)
batchUserDao.update(request.getRequestContext, batchId, userIds.get(x), batchdata)
}

// TODO: to be removed once all are in scala.
def setDao(courseDao: CourseBatchDao, userDao: UserCoursesDao, groupDao: GroupDaoImpl) = {
courseBatchDao = courseDao
Expand Down Expand Up @@ -729,7 +749,8 @@ class CourseEnrolmentActor @Inject()(@Named("course-batch-notification-actor") c
} else {
saveUserEnrolmentComment(request, courseId, userIds, batchId, statusCode, x, nodalFeedback, nodalFeedback)
}
}
getScoreDetails(batchId,userIds,courseId,request,x)
}

private def saveUserEnrolmentComment(request: Request, courseId: String, userIds: util.List[String], batchId: String, statusCode: Integer, x: Int,
enrolmentDataComment: util.Map[String, String],
Expand Down

0 comments on commit 6006dd3

Please sign in to comment.