From f8e10bea3324c8c04dc73baade8113b2ea57a10b Mon Sep 17 00:00:00 2001 From: Rahu Date: Wed, 14 Oct 2026 12:41:27 +0530 Subject: [PATCH 1/3] fix(graph-engine): handle legacy comma-joined array values in resetJsonProperties Migrated nodes store array props as plain strings (e.g. ownershipType=createdFor), which failed JSON parsing and made content update return 500. These are now converted to lists. --- .../scala/org/sunbird/graph/schema/DefinitionDTO.scala | 2 ++ .../org/sunbird/graph/schema/DefinitionNode.scala | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionDTO.scala b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionDTO.scala index 6443a46ab..bb2531187 100644 --- a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionDTO.scala +++ b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionDTO.scala @@ -47,6 +47,8 @@ class DefinitionDTO(graphId: String, schemaName: String, version: String = "1.0" jsonProps.toList } + def fetchArrayProps(): List[String] = schemaValidator.getArrayProps.asScala.toList + def getInRelations(): List[Map[String, AnyRef]] = { if (schemaValidator.getConfig.hasPath("relations")) schemaValidator.getConfig diff --git a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala index 9b54c24f2..d78a8291d 100644 --- a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala +++ b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala @@ -219,12 +219,18 @@ object DefinitionNode { } def resetJsonProperties(node: Node, graphId: String, version: String, schemaName: String, ocd: ObjectCategoryDefinition = ObjectCategoryDefinition())(implicit ec: ExecutionContext, oec: OntologyEngineContext): Node = { - val jsonPropList = fetchJsonProps(graphId, version, schemaName, ocd) + val definition = DefinitionFactory.getDefinition(graphId, schemaName, version, ocd) + val jsonPropList = definition.fetchJsonProps() if (!jsonPropList.isEmpty) { + lazy val arrayPropList = definition.fetchArrayProps() node.getMetadata.entrySet().asScala.map(entry => { if (jsonPropList.contains(entry.getKey)) { entry.getValue match { - case value: String => entry.setValue(JsonUtils.deserialize(value.asInstanceOf[String], classOf[Object])) + // Data migrated from Neo4j can hold array properties as plain comma-joined strings + // (e.g. ownershipType=createdFor, keywords=a,b) which are not valid JSON. + case value: String if !StringUtils.startsWithAny(value.trim, "[", "{", "\"") && arrayPropList.contains(entry.getKey) => + entry.setValue(new util.ArrayList[String](value.split(",").map(_.trim).filter(StringUtils.isNotEmpty).toList.asJava)) + case value: String => entry.setValue(JsonUtils.deserialize(value, classOf[Object])) case _ => entry } } From 033d3448756477d6be56e96a9625fdae88eb4f91 Mon Sep 17 00:00:00 2001 From: Rahu Date: Wed, 14 Oct 2026 13:05:47 +0530 Subject: [PATCH 2/3] fix(graph-engine): try JSON parse first, fall back to list only for legacy array values --- .../scala/org/sunbird/graph/schema/DefinitionNode.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala index d78a8291d..c2acb0bcb 100644 --- a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala +++ b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala @@ -228,9 +228,12 @@ object DefinitionNode { entry.getValue match { // Data migrated from Neo4j can hold array properties as plain comma-joined strings // (e.g. ownershipType=createdFor, keywords=a,b) which are not valid JSON. - case value: String if !StringUtils.startsWithAny(value.trim, "[", "{", "\"") && arrayPropList.contains(entry.getKey) => - entry.setValue(new util.ArrayList[String](value.split(",").map(_.trim).filter(StringUtils.isNotEmpty).toList.asJava)) - case value: String => entry.setValue(JsonUtils.deserialize(value, classOf[Object])) + case value: String => + try entry.setValue(JsonUtils.deserialize(value, classOf[Object])) + catch { + case _: Exception if !StringUtils.startsWithAny(value.trim, "[", "{") && arrayPropList.contains(entry.getKey) => + entry.setValue(new util.ArrayList[String](value.split(",").map(_.trim).filter(StringUtils.isNotEmpty).toList.asJava)) + } case _ => entry } } From 8c961bed0e63d2dccbd4f7954f7ac42c36e9476c Mon Sep 17 00:00:00 2001 From: Rahu Date: Wed, 14 Oct 2026 15:26:11 +0530 Subject: [PATCH 3/3] fix(graph-engine): convert legacy comma-joined values for all array props --- .../sunbird/graph/schema/DefinitionNode.scala | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala index c2acb0bcb..25faf1f78 100644 --- a/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala +++ b/ontology-engine/graph-engine_2.13/src/main/scala/org/sunbird/graph/schema/DefinitionNode.scala @@ -221,24 +221,24 @@ object DefinitionNode { def resetJsonProperties(node: Node, graphId: String, version: String, schemaName: String, ocd: ObjectCategoryDefinition = ObjectCategoryDefinition())(implicit ec: ExecutionContext, oec: OntologyEngineContext): Node = { val definition = DefinitionFactory.getDefinition(graphId, schemaName, version, ocd) val jsonPropList = definition.fetchJsonProps() - if (!jsonPropList.isEmpty) { - lazy val arrayPropList = definition.fetchArrayProps() - node.getMetadata.entrySet().asScala.map(entry => { - if (jsonPropList.contains(entry.getKey)) { - entry.getValue match { - // Data migrated from Neo4j can hold array properties as plain comma-joined strings - // (e.g. ownershipType=createdFor, keywords=a,b) which are not valid JSON. - case value: String => - try entry.setValue(JsonUtils.deserialize(value, classOf[Object])) - catch { - case _: Exception if !StringUtils.startsWithAny(value.trim, "[", "{") && arrayPropList.contains(entry.getKey) => - entry.setValue(new util.ArrayList[String](value.split(",").map(_.trim).filter(StringUtils.isNotEmpty).toList.asJava)) - } - case _ => entry + val arrayPropList = definition.fetchArrayProps() + // Data migrated from Neo4j can hold array properties as plain comma-joined strings + // (e.g. ownershipType=createdFor, keywords=a,b) which are neither valid JSON nor arrays. + def isLegacyArrayValue(key: String, value: String): Boolean = + arrayPropList.contains(key) && !StringUtils.startsWithAny(value.trim, "[", "{") + def toList(value: String): util.List[String] = + new util.ArrayList[String](value.split(",").map(_.trim).filter(StringUtils.isNotEmpty).toList.asJava) + node.getMetadata.entrySet().asScala.foreach(entry => { + entry.getValue match { + case value: String if jsonPropList.contains(entry.getKey) => + try entry.setValue(JsonUtils.deserialize(value, classOf[Object])) + catch { + case _: Exception if isLegacyArrayValue(entry.getKey, value) => entry.setValue(toList(value)) } - } - }) - } + case value: String if isLegacyArrayValue(entry.getKey, value) => entry.setValue(toList(value)) + case _ => + } + }) node }