Skip to content

Commit

Permalink
Fix for SB-29756 - content progress read issue in SB
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento authored May 6, 2022
1 parent f155175 commit dd100d9
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
private val assessmentAggregatorDBInfo = Util.dbInfoMap.get(JsonKey.ASSESSMENT_AGGREGATOR_DB)
private val enrolmentDBInfo = Util.dbInfoMap.get(JsonKey.LEARNER_COURSE_DB)
val dateFormatter = ProjectUtil.getDateFormatter

//Added default fields in env varible:
val defaultFields: Set[String] = if(ProjectUtil.getConfigValue("content.default.fields")!=null) ProjectUtil.getConfigValue("content.default.fields").split(",").toSet else Set[String]("contentid","userid","batchid","courseid","completedcount","completionpercentage","lastcompletedtime","status","viewcount")
val jsonFields = Set[String]("progressdetails")

override def onReceive(request: Request): Unit = {
Expand Down Expand Up @@ -174,7 +171,7 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
val courseId = if (entry._2.head.containsKey(JsonKey.COURSE_ID)) entry._2.head.getOrDefault(JsonKey.COURSE_ID, "").asInstanceOf[String] else entry._2.head.getOrDefault(JsonKey.COLLECTION_ID, "").asInstanceOf[String]
if(entry._2.head.containsKey(JsonKey.COLLECTION_ID)) entry._2.head.remove(JsonKey.COLLECTION_ID)
val contentIds = entry._2.map(e => e.getOrDefault(JsonKey.CONTENT_ID, "").asInstanceOf[String]).distinct.asJava
val existingContents = getContentsConsumption(userId, courseId, contentIds, batchId, defaultFields, requestContext).groupBy(x => x.get("contentId").asInstanceOf[String]).map(e => e._1 -> e._2.toList.head).toMap
val existingContents = getContentsConsumption(userId, courseId, contentIds, batchId, requestContext).groupBy(x => x.get("contentId").asInstanceOf[String]).map(e => e._1 -> e._2.toList.head).toMap
val contents:List[java.util.Map[String, AnyRef]] = entry._2.toList.map(inputContent => {
val existingContent = existingContents.getOrElse(inputContent.get("contentId").asInstanceOf[String], new java.util.HashMap[String, AnyRef])
CassandraUtil.changeCassandraColumnMapping(processContentConsumption(inputContent, existingContent, userId))
Expand Down Expand Up @@ -239,15 +236,15 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
}
}

def getContentsConsumption(userId: String, courseId : String, contentIds: java.util.List[String], batchId: String, fields: java.util.Set[String], requestContext: RequestContext):java.util.List[java.util.Map[String, AnyRef]] = {
def getContentsConsumption(userId: String, courseId : String, contentIds: java.util.List[String], batchId: String, requestContext: RequestContext):java.util.List[java.util.Map[String, AnyRef]] = {
val filters = new java.util.HashMap[String, AnyRef]() {{
put("userid", userId)
put("courseid", courseId)
put("batchid", batchId)
if(CollectionUtils.isNotEmpty(contentIds))
put("contentid", contentIds)
}}
val response = cassandraOperation.getRecords(requestContext, consumptionDBInfo.getKeySpace, consumptionDBInfo.getTableName, filters, fields.toList)
val response = cassandraOperation.getRecords(requestContext, consumptionDBInfo.getKeySpace, consumptionDBInfo.getTableName, filters)
response.getResult.getOrDefault(JsonKey.RESPONSE, new java.util.ArrayList[java.util.Map[String, AnyRef]]).asInstanceOf[java.util.List[java.util.Map[String, AnyRef]]]
}

Expand Down Expand Up @@ -370,15 +367,14 @@ class ContentConsumptionActor @Inject() extends BaseEnrolmentActor {
val courseId = request.get(JsonKey.COURSE_ID).asInstanceOf[String]
val contentIds = request.getRequest.getOrDefault(JsonKey.CONTENT_IDS, new java.util.ArrayList[String]()).asInstanceOf[java.util.List[String]]
val fields = request.getRequest.getOrDefault(JsonKey.FIELDS, new java.util.ArrayList[String](){{ add(JsonKey.PROGRESS) }}).asInstanceOf[java.util.List[String]]
val finalFields = defaultFields ++ fields
val contentsConsumed = getContentsConsumption(userId, courseId, contentIds, batchId, finalFields.asJava, request.getRequestContext)
val contentsConsumed = getContentsConsumption(userId, courseId, contentIds, batchId, request.getRequestContext)
val response = new Response
if(CollectionUtils.isNotEmpty(contentsConsumed)) {
val filteredContents = contentsConsumed.map(m => {
ProjectUtil.removeUnwantedFields(m, JsonKey.DATE_TIME, JsonKey.USER_ID, JsonKey.ADDED_BY, JsonKey.LAST_UPDATED_TIME, JsonKey.OLD_LAST_ACCESS_TIME, JsonKey.OLD_LAST_UPDATED_TIME, JsonKey.OLD_LAST_COMPLETED_TIME)
m.put(JsonKey.COLLECTION_ID, m.getOrDefault(JsonKey.COURSE_ID, ""))
jsonFields.foreach(field =>
if(fields.contains(field) && m.get(field) != null)
if(m.get(field) != null)
m.put(field, mapper.readTree(m.get(field).asInstanceOf[String]))
)
val formattedMap = JsonUtil.convertWithDateFormat(m, classOf[util.Map[String, Object]], dateFormatter)
Expand Down

0 comments on commit dd100d9

Please sign in to comment.