Skip to content

Commit

Permalink
Merge branch 'release-3.9.0' into release-4.0.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	content-api/hierarchy-manager/src/main/scala/org/sunbird/managers/UpdateHierarchyManager.scala
  • Loading branch information
AmiableAnil committed Jul 7, 2021
2 parents 7d5ed00 + 32dcde3 commit 2163b54
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
5 changes: 5 additions & 0 deletions assessment-api/assessment-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<artifactId>joda-convert</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.github.danielwegener</groupId>
<artifactId>logback-kafka-appender</artifactId>
<version>0.2.0-RC2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/app</sourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ object HierarchyManager {
})
}

def addChildrenToUnit(children: java.util.List[java.util.Map[String,AnyRef]], unitId:String, leafNodes: java.util.List[java.util.Map[String, AnyRef]], leafNodeIds: java.util.List[String])(implicit oec: OntologyEngineContext, ec: ExecutionContext): Unit = {
def addChildrenToUnit(children: java.util.List[java.util.Map[String,AnyRef]], unitId:String, leafNodes: java.util.List[java.util.Map[String, AnyRef]], leafNodeIds: java.util.List[String], request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Unit = {
val childNodes = children.filter(child => ("Parent".equalsIgnoreCase(child.get("visibility").asInstanceOf[String]) && unitId.equalsIgnoreCase(child.get("identifier").asInstanceOf[String]))).toList
if(null != childNodes && !childNodes.isEmpty){
val child = childNodes.get(0)
leafNodes.toList.map(leafNode => validateLeafNodes(child, leafNode))
leafNodes.toList.map(leafNode => validateLeafNodes(child, leafNode, request))
val childList = child.get("children").asInstanceOf[java.util.List[java.util.Map[String,AnyRef]]]
val restructuredChildren: java.util.List[java.util.Map[String,AnyRef]] = restructureUnit(childList, leafNodes, leafNodeIds, (child.get("depth").asInstanceOf[Integer] + 1), unitId)
child.put("children", restructuredChildren)
} else {
for(child <- children) {
if(null !=child.get("children") && !child.get("children").asInstanceOf[java.util.List[java.util.Map[String,AnyRef]]].isEmpty)
addChildrenToUnit(child.get("children").asInstanceOf[java.util.List[java.util.Map[String,AnyRef]]], unitId, leafNodes, leafNodeIds)
addChildrenToUnit(child.get("children").asInstanceOf[java.util.List[java.util.Map[String,AnyRef]]], unitId, leafNodes, leafNodeIds, request)
}
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ object HierarchyManager {
val leafNodeIds = request.get("children").asInstanceOf[java.util.List[String]]
if("add".equalsIgnoreCase(operation)){
val leafNodesMap:java.util.List[java.util.Map[String, AnyRef]] = convertNodeToMap(leafNodes)
addChildrenToUnit(children, unitId, leafNodesMap, leafNodeIds)
addChildrenToUnit(children, unitId, leafNodesMap, leafNodeIds, request)
}
if("remove".equalsIgnoreCase(operation)) {
removeChildrenFromUnit(children,unitId, leafNodeIds)
Expand Down Expand Up @@ -606,11 +606,15 @@ object HierarchyManager {
updatedHierarchy
}

def validateLeafNodes(parentNode: java.util.Map[String, AnyRef], childNode: java.util.Map[String, AnyRef])(implicit oec: OntologyEngineContext, ec: ExecutionContext) = {
def validateLeafNodes(parentNode: java.util.Map[String, AnyRef], childNode: java.util.Map[String, AnyRef], request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext) = {
val primaryCategory = parentNode.getOrDefault("primaryCategory", "").asInstanceOf[String]
val channel: String = parentNode.getOrDefault("channel", "all").asInstanceOf[String]
val objectCategoryDefinition: ObjectCategoryDefinition = DefinitionNode.getObjectCategoryDefinition(primaryCategory, parentNode.getOrDefault("objectType", "").asInstanceOf[String].toLowerCase(), channel)
val outRelations = DefinitionNode.getOutRelations(HierarchyConstants.GRAPH_ID, "1.0", parentNode.getOrDefault("objectType", "").asInstanceOf[String].toLowerCase().replace("image", ""), objectCategoryDefinition)
//val objectCategoryDefinition: ObjectCategoryDefinition = DefinitionNode.getObjectCategoryDefinition(primaryCategory, parentNode.getOrDefault("objectType", "").asInstanceOf[String].toLowerCase(), channel)
//val outRelations = DefinitionNode.getOutRelations(HierarchyConstants.GRAPH_ID, "1.0", parentNode.getOrDefault("objectType", "").asInstanceOf[String].toLowerCase().replace("image", ""), objectCategoryDefinition)

val objectCategoryDefinition: ObjectCategoryDefinition = DefinitionNode.getObjectCategoryDefinition(primaryCategory, request.getContext.get(HierarchyConstants.SCHEMA_NAME).asInstanceOf[String].toLowerCase(), channel)
val outRelations = DefinitionNode.getOutRelations(HierarchyConstants.GRAPH_ID, "1.0", request.getContext.get(HierarchyConstants.SCHEMA_NAME).asInstanceOf[String].toLowerCase(), objectCategoryDefinition)

val configObjTypes: List[String] = outRelations.find(_.keySet.contains("children")).orNull.getOrElse("children", Map()).asInstanceOf[java.util.Map[String, AnyRef]].getOrElse("objects", new util.ArrayList[String]()).asInstanceOf[java.util.List[String]].toList
if(configObjTypes.nonEmpty && !configObjTypes.contains(childNode.getOrDefault("objectType", "").asInstanceOf[String]))
throw new ClientException("ERR_INVALID_CHILDREN", "Invalid Children objectType "+childNode.get("objectType")+" found for : "+childNode.get("identifier") + "| Please provide children having one of the objectType from "+ configObjTypes.asJava)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object UpdateHierarchyManager {
idMap += (rootId -> rootId)
updateNodesModifiedInNodeList(nodes, nodesModified, request, idMap).map(modifiedNodeList => {

getChildrenHierarchy(modifiedNodeList, rootId, hierarchy, idMap, result._1).map(children => {
getChildrenHierarchy(modifiedNodeList, rootId, hierarchy, idMap, result._1, request).map(children => {
TelemetryManager.log("Children for root id :" + rootId +" :: " + JsonUtils.serialize(children))
updateHierarchyData(rootId, children, modifiedNodeList, request).map(node => {
val response = ResponseHandler.OK()
Expand Down Expand Up @@ -293,10 +293,10 @@ object UpdateHierarchyManager {
}

@throws[Exception]
private def getChildrenHierarchy(nodeList: List[Node], rootId: String, hierarchyData: java.util.HashMap[String, AnyRef], idMap: mutable.Map[String, String], existingHierarchy: java.util.Map[String, AnyRef])(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[java.util.List[java.util.Map[String, AnyRef]]] = {
private def getChildrenHierarchy(nodeList: List[Node], rootId: String, hierarchyData: java.util.HashMap[String, AnyRef], idMap: mutable.Map[String, String], existingHierarchy: java.util.Map[String, AnyRef], request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[java.util.List[java.util.Map[String, AnyRef]]] = {
val childrenIdentifiersMap: Map[String, Map[String, Int]] = getChildrenIdentifiersMap(hierarchyData, idMap, existingHierarchy)
// TelemetryManager.log("Children Id map for root id :" + rootId + " :: " + ScalaJsonUtils.serialize(childrenIdentifiersMap))
getPreparedHierarchyData(nodeList, rootId, childrenIdentifiersMap).map(nodeMaps => {
getPreparedHierarchyData(nodeList, rootId, childrenIdentifiersMap, request).map(nodeMaps => {
TelemetryManager.info("prepared hierarchy list without filtering: " + nodeMaps.size())
val filteredNodeMaps = nodeMaps.filter(nodeMap => null != nodeMap.get(HierarchyConstants.DEPTH)).toList
TelemetryManager.info("prepared hierarchy list with filtering: " + filteredNodeMaps.size())
Expand Down Expand Up @@ -337,11 +337,11 @@ object UpdateHierarchyManager {
}

@throws[Exception]
private def getPreparedHierarchyData(nodeList: List[Node], rootId: String, childrenIdentifiersMap: Map[String, Map[String, Int]])(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[java.util.List[java.util.Map[String, AnyRef]]] = {
private def getPreparedHierarchyData(nodeList: List[Node], rootId: String, childrenIdentifiersMap: Map[String, Map[String, Int]], request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[java.util.List[java.util.Map[String, AnyRef]]] = {
if (MapUtils.isNotEmpty(childrenIdentifiersMap)) {
val updatedNodeList = getTempNode(nodeList, rootId) :: List()
updateHierarchyRelatedData(childrenIdentifiersMap.getOrElse(rootId, Map[String, Int]()), 1,
rootId, nodeList, childrenIdentifiersMap, updatedNodeList).map(finalEnrichedNodeList => {
rootId, nodeList, childrenIdentifiersMap, updatedNodeList, request).map(finalEnrichedNodeList => {
TelemetryManager.info("Final enriched list size: " + finalEnrichedNodeList.size)
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)
Expand All @@ -364,7 +364,7 @@ object UpdateHierarchyManager {
}

@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])(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)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[List[Node]] = {
val futures = childrenIds.map(child => {
val id = child._1
val index = child._2 + 1
Expand All @@ -374,7 +374,7 @@ object UpdateHierarchyManager {
val nxtEnrichedNodeList = tempNode :: enrichedNodeList
if (MapUtils.isNotEmpty(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)
tempNode.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request)
else
Future(nxtEnrichedNodeList)
} else {
Expand All @@ -385,7 +385,7 @@ object UpdateHierarchyManager {
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 childMetadata: java.util.Map[String, AnyRef] = NodeUtil.serialize(node, new java.util.ArrayList[String](), node.getObjectType.toLowerCase, "1.0")
HierarchyManager.validateLeafNodes(parentMetadata, childMetadata)
HierarchyManager.validateLeafNodes(parentMetadata, childMetadata, request)
populateHierarchyRelatedData(node, depth, index, parent)
node.getMetadata.put(HierarchyConstants.VISIBILITY, HierarchyConstants.DEFAULT)
//TODO: Populate category mapping before updating for backward
Expand All @@ -397,7 +397,7 @@ object UpdateHierarchyManager {
enrichedNodeList
}
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)
updateHierarchyRelatedData(hierarchyStructure.getOrDefault(id, Map[String, Int]()), node.getMetadata.get(HierarchyConstants.DEPTH).asInstanceOf[Int] + 1, id, nodeList, hierarchyStructure, nxtEnrichedNodeList, request)
} else
Future(nxtEnrichedNodeList)
}).flatMap(f => f) recoverWith { case e: CompletionException => throw e.getCause }
Expand Down
5 changes: 5 additions & 0 deletions taxonomy-api/taxonomy-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<artifactId>joda-convert</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.github.danielwegener</groupId>
<artifactId>logback-kafka-appender</artifactId>
<version>0.2.0-RC2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/app</sourceDirectory>
Expand Down

0 comments on commit 2163b54

Please sign in to comment.