Commit 696d0d3a authored by Karthikeyan R's avatar Karthikeyan R
Browse files

SB-29856 | Fix for hierarchy update

Showing with 12 additions and 5 deletions
+12 -5
...@@ -345,7 +345,7 @@ object UpdateHierarchyManager { ...@@ -345,7 +345,7 @@ object UpdateHierarchyManager {
if (MapUtils.isNotEmpty(childrenIdentifiersMap)) { if (MapUtils.isNotEmpty(childrenIdentifiersMap)) {
val updatedNodeList = getTempNode(nodeList, rootId) :: List() val updatedNodeList = getTempNode(nodeList, rootId) :: List()
updateHierarchyRelatedData(childrenIdentifiersMap.getOrElse(rootId, Map[String, Int]()), 1, updateHierarchyRelatedData(childrenIdentifiersMap.getOrElse(rootId, Map[String, Int]()), 1,
rootId, nodeList, childrenIdentifiersMap, updatedNodeList, request).map(finalEnrichedNodeList => { rootId, nodeList, childrenIdentifiersMap, updatedNodeList, request, rootId).map(finalEnrichedNodeList => {
TelemetryManager.info("Final enriched list size: " + finalEnrichedNodeList.size) TelemetryManager.info("Final enriched list size: " + finalEnrichedNodeList.size)
val childNodeIds = finalEnrichedNodeList.map(node => node.getIdentifier.replaceAll(".img", "")).filterNot(id => StringUtils.containsIgnoreCase(rootId, id)).distinct val childNodeIds = finalEnrichedNodeList.map(node => node.getIdentifier.replaceAll(".img", "")).filterNot(id => StringUtils.containsIgnoreCase(rootId, id)).distinct
TelemetryManager.info("Final enriched ids (childNodes): " + childNodeIds + " :: size: " + childNodeIds.size) TelemetryManager.info("Final enriched ids (childNodes): " + childNodeIds + " :: size: " + childNodeIds.size)
...@@ -368,7 +368,8 @@ object UpdateHierarchyManager { ...@@ -368,7 +368,8 @@ object UpdateHierarchyManager {
} }
@throws[Exception] @throws[Exception]
private def updateHierarchyRelatedData(childrenIds: Map[String, Int], depth: Int, parent: String, nodeList: List[Node], hierarchyStructure: Map[String, Map[String, Int]], enrichedNodeList: scala.collection.immutable.List[Node], request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[List[Node]] = { private def updateHierarchyRelatedData(childrenIds: Map[String, Int], depth: Int, parent: String, nodeList: List[Node], hierarchyStructure: Map[String, Map[String, Int]], enrichedNodeList: scala.collection.immutable.List[Node], request: Request, rootId: String)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[List[Node]] = {
val rootResourceChange: Boolean = if (Platform.config.hasPath("hierarchyUpdate.allow.resource.at.root.level")) Platform.config.getBoolean("hierarchyUpdate.allow.resource.at.root.level") else false
val futures = childrenIds.map(child => { val futures = childrenIds.map(child => {
val id = child._1 val id = child._1
val index = child._2 + 1 val index = child._2 + 1
...@@ -378,13 +379,19 @@ object UpdateHierarchyManager { ...@@ -378,13 +379,19 @@ object UpdateHierarchyManager {
val nxtEnrichedNodeList = tempNode :: enrichedNodeList val nxtEnrichedNodeList = tempNode :: enrichedNodeList
if (MapUtils.isNotEmpty(hierarchyStructure.getOrDefault(child._1, Map[String, Int]()))) if (MapUtils.isNotEmpty(hierarchyStructure.getOrDefault(child._1, Map[String, Int]())))
updateHierarchyRelatedData(hierarchyStructure.getOrDefault(child._1, Map[String, Int]()), updateHierarchyRelatedData(hierarchyStructure.getOrDefault(child._1, Map[String, Int]()),
tempNode.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request) tempNode.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request, rootId)
else else
Future(nxtEnrichedNodeList) Future(nxtEnrichedNodeList)
} else { } else {
// TelemetryManager.info("Get ContentNode as TempNode is null for ID: " + id) // TelemetryManager.info("Get ContentNode as TempNode is null for ID: " + id)
getContentNode(id, HierarchyConstants.TAXONOMY_ID).map(node => { getContentNode(id, HierarchyConstants.TAXONOMY_ID).map(node => {
val parentNode: Node = nodeList.find(p => p.getIdentifier.equals(parent)).orNull val parentNode: Node = if (rootResourceChange && nodeList.find(p => p.getIdentifier.equals(parent)).orNull == null) {
if (nodeList.find(p => p.getIdentifier.equals(rootId)).orNull == null)
nodeList.find(p => p.getIdentifier.equals(rootId + ".img")).orNull
else
nodeList.find(p => p.getIdentifier.equals(rootId)).orNull
} else
nodeList.find(p => p.getIdentifier.equals(parent)).orNull
val nxtEnrichedNodeList = if (null != parentNode) { val nxtEnrichedNodeList = if (null != parentNode) {
TelemetryManager.info(s"ObjectType for $parent is ${parentNode.getObjectType}...") TelemetryManager.info(s"ObjectType for $parent is ${parentNode.getObjectType}...")
val parentMetadata: java.util.Map[String, AnyRef] = NodeUtil.serialize(parentNode, new java.util.ArrayList[String](), parentNode.getObjectType.toLowerCase, "1.0") val parentMetadata: java.util.Map[String, AnyRef] = NodeUtil.serialize(parentNode, new java.util.ArrayList[String](), parentNode.getObjectType.toLowerCase, "1.0")
...@@ -401,7 +408,7 @@ object UpdateHierarchyManager { ...@@ -401,7 +408,7 @@ object UpdateHierarchyManager {
enrichedNodeList enrichedNodeList
} }
if (MapUtils.isNotEmpty(hierarchyStructure.getOrDefault(id, Map[String, Int]()))) { if (MapUtils.isNotEmpty(hierarchyStructure.getOrDefault(id, Map[String, Int]()))) {
updateHierarchyRelatedData(hierarchyStructure.getOrDefault(id, Map[String, Int]()), node.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request) updateHierarchyRelatedData(hierarchyStructure.getOrDefault(id, Map[String, Int]()), node.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request, rootId)
} else } else
Future(nxtEnrichedNodeList) Future(nxtEnrichedNodeList)
}).flatMap(f => f) recoverWith { case e: CompletionException => throw e.getCause } }).flatMap(f => f) recoverWith { case e: CompletionException => throw e.getCause }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment