Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue KN-972 feat : Added code for generic implementation for setting… #778

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait FrameworkDataEnrichment {
//private val fwMetaFields = List("boardIds", "subjectIds", "mediumIds", "topicsIds", "gradeLevelIds", "targetBoardIds", "targetSubjectIds", "targetMediumIds", "targetTopicIds", "targetGradeLevelIds")
//private val fwMetaMap = Map(("se_boardIds", "se_boards") -> List("boardIds", "targetBoardIds"), ("se_subjectIds", "se_subjects") -> List("subjectIds", "targetSubjectIds"), ("se_mediumIds", "se_mediums") -> List("mediumIds", "targetMediumIds"), ("se_topicIds", "se_topics") -> List("topicsIds", "targetTopicIds"), ("se_gradeLevelIds", "se_gradeLevels") -> List("gradeLevelIds", "targetGradeLevelIds"))

private val frameworkCategorySearchMetadataMapping: HashMap[String, String] = HashMap[String, String]("se_boards" -> "board", "se_subjects"-> "subject", "se_mediums" -> "medium", "se_topics"-> "topic", "se_gradeLevels"-> "gradeLevel")
// private val frameworkCategorySearchMetadataMapping: HashMap[String, String] = HashMap[String, String]("se_boards" -> "board", "se_subjects"-> "subject", "se_mediums" -> "medium", "se_topics"-> "topic", "se_gradeLevels"-> "gradeLevel")

def enrichFrameworkData(obj: ObjectData)(implicit neo4JUtil: Neo4JUtil, config: PublishConfig): ObjectData = {
val (fwMetaFields, fwMetaMap) : (List[String], Map[(String, String), List[String]]) =
Expand All @@ -45,10 +45,19 @@ trait FrameworkDataEnrichment {
}
}

private def revalidateFrameworkCategoryMetadata(obj: ObjectData, enMetadata: Map[String, AnyRef]) : Map[String, AnyRef] = {
private def revalidateFrameworkCategoryMetadata(obj: ObjectData, enMetadata: Map[String, AnyRef])(implicit neo4JUtil: Neo4JUtil) : Map[String, AnyRef] = {

val masterCategories: List[Map[String, AnyRef]] = getMasterCategory("domain", "Category")
val frameworkCategorySearchMetadataMapping: Map[String, String] = masterCategories.flatMap(category =>
Map(category.getOrElse("searchLabelFieldName", "").asInstanceOf[String] ->
category.getOrElse("code", "").asInstanceOf[String])).toMap

logger.info("frameworkCategorySearchMetadataMapping:: " + frameworkCategorySearchMetadataMapping)

val updatedFwData: immutable.Iterable[(String, AnyRef)] = frameworkCategorySearchMetadataMapping.map(category => {
val data: AnyRef = obj.metadata.getOrElse(category._2, null)
if(data != null) Map(category._1 -> getList(data)) else Map.empty
val se_data: AnyRef = enMetadata.getOrElse(category._1, null)
if(se_data == null && data != null) Map(category._1 -> getList(data)) else Map.empty
}).filter(rec => rec.nonEmpty).flatten

enMetadata ++ updatedFwData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class FrameworkDataEnrichmentTestSpec extends FlatSpec with BeforeAndAfterAll wi
}

"enrichFrameworkData with board, medium, gradeLevel and subject " should "enrich se_boards, se_mediums, se_gradeLevels and se_subjects" in {
enrichFrameworkMasterCategoryMap()
val data = new ObjectData("do_123", Map[String, AnyRef]("name" -> "Content Name", "identifier" -> "do_123", "IL_UNIQUE_ID" -> "do_123", "pkgVersion" -> 0.0.asInstanceOf[AnyRef], "framework" -> "NCF", "board" -> "some board", "medium" -> List("some medium 1", "some_medium_2").asJava))
when(mockNeo4JUtil.getNodesName(ArgumentMatchers.anyObject())).thenReturn(Map[String, String]("ncf_medium_telugu" -> "Telugu", "ncf_medium_english" -> "English", "ncf_board_cbse" -> "CBSE", "ncfcopy_board_ncert" -> "NCERT"))
val obj = new TestFrameworkDataEnrichment()
Expand Down
Loading