Skip to content

Commit

Permalink
Issue KN-970 fix: categories filter issue fix (#1048)
Browse files Browse the repository at this point in the history
* Issue KN-970 fix: categories filter issue fix

* Issue KN-970 fix: categories filter issue fix

* Issue KN-970 fix: unit test fixes
  • Loading branch information
pallakartheekreddy authored Feb 13, 2024
1 parent 157f5c6 commit a9fa6d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ object FrameworkManager {

def filterFrameworkCategories(framework: util.Map[String, AnyRef], categoryNames: util.List[String]): Map[String, AnyRef] = {
val categories = framework.getOrDefault("categories", new util.ArrayList[util.Map[String, AnyRef]]).asInstanceOf[util.List[util.Map[String, AnyRef]]]
if (!categories.isEmpty && !categoryNames.isEmpty) {
val newCategoryNames = categoryNames.map(_.toLowerCase)
if (!categories.isEmpty && !newCategoryNames.isEmpty) {
val filteredCategories = categories.filter(category => {
val name = category.get("name").asInstanceOf[String]
categoryNames.contains(name.toLowerCase())
val code = category.get("code").asInstanceOf[String]
newCategoryNames.contains(code.toLowerCase())
}).toList.asJava
val filteredData = framework.-("categories") ++ Map("categories" -> filteredCategories)
val finalCategories = removeAssociations(filteredData.toMap, categoryNames)
val finalCategories = removeAssociations(filteredData.toMap, newCategoryNames)
(filteredData.-("categories") ++ Map("categories" -> finalCategories)).toMap
} else {
framework.toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class FrameworkManagerTest extends FlatSpec with Matchers with MockFactory{

val category1 = new util.HashMap[String, AnyRef]()
category1.put("name", "Subject")
category1.put("code", "subject")
val category2 = new util.HashMap[String, AnyRef]()
category2.put("name", "Grade")
category2.put("code", "grade")
val categories = new util.ArrayList[util.Map[String, AnyRef]]()
categories.add(category1)
categories.add(category2)
Expand All @@ -42,6 +44,7 @@ class FrameworkManagerTest extends FlatSpec with Matchers with MockFactory{

val term1 = new util.HashMap[String, AnyRef]()
term1.put("name", "Term1")
term1.put("code", "term1")
val associations1 = new util.ArrayList[util.Map[String, AnyRef]]()
val association1 = new util.HashMap[String, AnyRef]()
association1.put("category", "Category1")
Expand All @@ -50,6 +53,7 @@ class FrameworkManagerTest extends FlatSpec with Matchers with MockFactory{

val term2 = new util.HashMap[String, AnyRef]()
term2.put("name", "Term2")
term2.put("code", "term2")
val associations2 = new util.ArrayList[util.Map[String, AnyRef]]()
val association2 = new util.HashMap[String, AnyRef]()
association2.put("category", "Category2")
Expand Down

0 comments on commit a9fa6d9

Please sign in to comment.