Skip to content
Open
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,26 @@ 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)
if (!jsonPropList.isEmpty) {
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]))
case _ => entry
val definition = DefinitionFactory.getDefinition(graphId, schemaName, version, ocd)
val jsonPropList = definition.fetchJsonProps()
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
}

Expand Down
Loading