Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0fe1a8e
Issue KN-000 merge: Merge Release 5.6.0 into Master (#984)
pallakartheekreddy Sep 8, 2023
96390d4
Issue #KN fix: Updated the mvn command to build for content service
aimansharief Sep 13, 2023
4827b54
Merge pull request #990 from aimansharief/KN-UpdateReadme
pallakartheekreddy Nov 9, 2023
56ce3e5
Issue #KN-1041 fix: updated code to create vertices and edges
aimansharief May 19, 2024
9711990
Issue #KN-1041 fix: updated code for Gremlin Operations
aimansharief May 21, 2024
e82cb63
Issue #KN-1041 fix: Added fix for the vertex creation
aimansharief May 22, 2024
82a8551
Issue #KN-1041 fix: Restructure code specific for JanusGraph
aimansharief May 22, 2024
c908ece
Issue #KN-1041 fix: Unique key constraint violation error handling added
pallakartheekreddy May 22, 2024
4c55f1e
Issue #KN-1041 fix: Updated code to support the read vertex functiona…
aimansharief May 23, 2024
a45c601
Read Vertex changes initial commit
pallakartheekreddy May 23, 2024
815a463
Issue #KN-1041 fix: Updated the code to create and read vertex
aimansharief May 24, 2024
b030a54
Update relation changes
pallakartheekreddy May 24, 2024
37a742b
Issue #KN-1041 fix: added upsert vertex changes
shourya-solanki May 24, 2024
0e5b465
Issue #KN-1041 fix: Fixed the code to get values in a proper format
aimansharief May 24, 2024
a4ac065
Update Vertex fixes
pallakartheekreddy May 24, 2024
dd12903
Issue #KN-1041 fix: Added code to delete vertex
aimansharief May 24, 2024
6fa3853
Issue #KN-1041 fix: Added getNodeProperty and checkCyclicLoop
aimansharief May 27, 2024
b44ef9d
Issue #KN-1041 fix: 1. added updateVertexes changes, 2. added updateR…
ShouraySolanki May 27, 2024
dc127d5
Issue #KN-1041 fix: resolved merge conflicts
ShouraySolanki May 27, 2024
aed8969
Issue #KN-1041 fix: updated updateVertexes code
ShouraySolanki May 27, 2024
9689f73
Subgraph changes
pallakartheekreddy May 27, 2024
d84de81
Issue #KN-1041 fix: Vertex read and subgraph queries issue fixes
pallakartheekreddy May 30, 2024
fd39121
Merge remote-tracking branch 'upstream/master' into janusGraph
aimansharief Jun 25, 2024
f718a67
Merge branch 'release-6.1.0' into janusGraph
aimansharief Jun 25, 2024
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
13 changes: 13 additions & 0 deletions content-api/content-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@
<version>2.5.22</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.sunbird</groupId>
<artifactId>graph-dac</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import org.sunbird.content.review.mgr.ReviewManager
import org.sunbird.content.upload.mgr.UploadManager
import org.sunbird.content.util._
import org.sunbird.graph.OntologyEngineContext
import org.sunbird.graph.dac.model.Node
import org.sunbird.graph.dac.model.{Node, Vertex}
import org.sunbird.graph.nodes.DataNode
import org.sunbird.graph.vertex.DataVertex
import org.sunbird.graph.utils.NodeUtil
import org.sunbird.managers.HierarchyManager
import org.sunbird.managers.HierarchyManager.hierarchyPrefix
Expand Down Expand Up @@ -66,7 +67,7 @@ class ContentActor @Inject() (implicit oec: OntologyEngineContext, ss: StorageSe
def create(request: Request): Future[Response] = {
populateDefaultersForCreation(request)
RequestUtil.restrictProperties(request)
DataNode.create(request, dataModifier).map(node => {
DataVertex.create(request, vertexDataModifier).map(node => {
ResponseHandler.OK.put(ContentConstants.IDENTIFIER, node.getIdentifier).put("node_id", node.getIdentifier)
.put("versionKey", node.getMetadata.get("versionKey"))
})
Expand Down Expand Up @@ -296,6 +297,20 @@ class ContentActor @Inject() (implicit oec: OntologyEngineContext, ss: StorageSe
node
}

def vertexDataModifier(vertex: Vertex): Vertex = {
if (vertex.getMetadata.containsKey("trackable") &&
vertex.getMetadata.getOrDefault("trackable", new java.util.HashMap[String, AnyRef]).asInstanceOf[java.util.Map[String, AnyRef]].containsKey("enabled") &&
"Yes".equalsIgnoreCase(vertex.getMetadata.getOrDefault("trackable", new java.util.HashMap[String, AnyRef]).asInstanceOf[java.util.Map[String, AnyRef]].getOrDefault("enabled", "").asInstanceOf[String])) {
vertex.getMetadata.put("contentType", "Course")
}

//TODO: Below fix to be reviewed when the fix for null to Stringify in ExternalStore.scala is implemented
if (vertex.getExternalData != null && vertex.getExternalData.containsKey("relational_metadata") && vertex.getExternalData.get("relational_metadata") == null) {
vertex.getExternalData.put("relational_metadata", "{}")
}
vertex
}

def getImportConfig(): ImportConfig = {
val requiredProps = Platform.getStringList("import.required_props", java.util.Arrays.asList("name", "code", "mimeType", "contentType", "artifactUrl", "framework")).asScala.toList
val validStages = Platform.getStringList("import.valid_stages", java.util.Arrays.asList("create", "upload", "review", "publish")).asScala.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.sunbird.common.dto.{Request, Response, ResponseHandler}
import org.sunbird.common.exception.{ClientException, ResponseCode}
import org.sunbird.content.util.ContentConstants
import org.sunbird.graph.OntologyEngineContext
import org.sunbird.graph.dac.model.{Node, Relation}
import org.sunbird.graph.dac.model.{Node, Relation, Vertex}
import org.sunbird.graph.nodes.DataNode

import java.util
Expand Down Expand Up @@ -79,4 +79,13 @@ class EventActor @Inject()(implicit oec: OntologyEngineContext, ss: StorageServi
node
}

override def vertexDataModifier(vertex: Vertex): Vertex = {
if (vertex.getMetadata.containsKey("trackable") &&
vertex.getMetadata.getOrDefault("trackable", new java.util.HashMap[String, AnyRef]).asInstanceOf[java.util.Map[String, AnyRef]].containsKey("enabled") &&
"Yes".equalsIgnoreCase(vertex.getMetadata.getOrDefault("trackable", new java.util.HashMap[String, AnyRef]).asInstanceOf[java.util.Map[String, AnyRef]].getOrDefault("enabled", "").asInstanceOf[String])) {
vertex.getMetadata.put("contentType", "Event")
}
vertex
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public enum GraphDACParams {
MERGE, nodes, RETURN, keys, rootNode, nodeId, WHERE, startNodeId, endNodeId, relationType,
startNodeIds, endNodeIds, collectionId, collection, indexProperty, taskId, input, getTags,
searchCriteria, paramMap, cypherQuery, paramValueMap, queryStatementMap, SYS_INTERNAL_LAST_UPDATED_ON,
CONSUMER_ID, consumerId, CHANNEL_ID, channel, APP_ID, appId, Nodes_Count, Relations_Count;
CONSUMER_ID, consumerId, CHANNEL_ID, channel, APP_ID, appId, Nodes_Count, Relations_Count, vertex;
}
12 changes: 12 additions & 0 deletions ontology-engine/graph-core_2.12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>graph-dac</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>schema-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.lang
import scala.concurrent.{ExecutionContext, Future}

class GraphService {

implicit val ec: ExecutionContext = ExecutionContext.global
val isrRelativePathEnabled: lang.Boolean = Platform.getBoolean("cloudstorage.metadata.replace_absolute_path", false)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.sunbird.graph

import org.sunbird.common.Platform
import org.sunbird.common.dto.{Property, Request, Response}
import org.sunbird.graph.dac.model.{Vertex, VertexSubGraph}
import org.sunbird.graph.util.CSPMetaUtil
import org.sunbird.janus.service.operation.{EdgeOperations, SearchOperations, VertexOperations}

import java.lang
import scala.concurrent.{ExecutionContext, Future}
class JanusGraphService {

private val VertexOperations = new VertexOperations()
private val EdgeOperations = new EdgeOperations()
private val SearchOperations = new SearchOperations()

implicit val ec: ExecutionContext = ExecutionContext.global
val isrRelativePathEnabled: lang.Boolean = Platform.getBoolean("cloudstorage.metadata.replace_absolute_path", false)


def addVertex(graphId: String, vertex: Vertex): Future[Vertex] = {
if (isrRelativePathEnabled) {
val metadata = CSPMetaUtil.updateRelativePath(vertex.getMetadata)
vertex.setMetadata(metadata)
}
VertexOperations.addVertex(graphId, vertex).map(resVertex => if (isrRelativePathEnabled) CSPMetaUtil.updateAbsolutePath(resVertex) else resVertex)

}

def createEdges(graphId: String, edgeMap: java.util.List[java.util.Map[String, AnyRef]]): Future[Response] = {
EdgeOperations.createEdges(graphId, edgeMap)
}

def removeEdges(graphId: String, edgeMap: java.util.List[java.util.Map[String, AnyRef]]): Future[Response] = {
EdgeOperations.removeEdges(graphId, edgeMap)
}

def getNodeByUniqueId(graphId: String, vertexId: String, getTags: Boolean, request: Request): Future[Vertex] = {
SearchOperations.getNodeByUniqueId(graphId, vertexId, getTags, request).map(vertex => if (isrRelativePathEnabled) CSPMetaUtil.updateAbsolutePath(vertex) else vertex)
}

def deleteNode(graphId: String, vertexId: String, request: Request): Future[java.lang.Boolean] = {
VertexOperations.deleteVertex(graphId, vertexId, request)
}

def upsertVertex(graphId: String, vertex: Vertex, request: Request): Future[Vertex] = {
if (isrRelativePathEnabled) {
val metadata = CSPMetaUtil.updateRelativePath(vertex.getMetadata)
vertex.setMetadata(metadata)
}
VertexOperations.upsertVertex(graphId, vertex, request)
.map(resVertex => if (isrRelativePathEnabled) CSPMetaUtil.updateAbsolutePath(resVertex) else resVertex)
}

def upsertRootNode(graphId: String, request: Request): Future[Vertex] = {
VertexOperations.upsertRootVertex(graphId, request)
}

def updateVertexes(graphId: String, identifiers: java.util.List[String], metadata: java.util.Map[String, AnyRef]): Future[java.util.Map[String, Vertex]] = {
val updatedMetadata = if (isrRelativePathEnabled) CSPMetaUtil.updateRelativePath(metadata) else metadata
VertexOperations.updateVertexes(graphId, identifiers, updatedMetadata)
}

def getNodeProperty(graphId: String, identifier: String, property: String): Future[Property] = {
SearchOperations.getNodeProperty(graphId, identifier, property).map(property => if (isrRelativePathEnabled) CSPMetaUtil.updateAbsolutePath(property) else property)
}

def checkCyclicLoop(graphId: String, endNodeId: String, startNodeId: String, relationType: String) = {
SearchOperations.checkCyclicLoop(graphId, endNodeId, relationType, startNodeId)
}

def getSubGraph(graphId: String, nodeId: String, depth: Int): Future[VertexSubGraph] = {
EdgeOperations.getSubGraph(graphId, nodeId, depth)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ class OntologyEngineContext {
private val dialGraphDB = new DialGraphService
private val hUtil = new HttpUtil
private lazy val kfClient = new KafkaClient

private lazy val janusGraphDB = new JanusGraphService
def graphService = {
graphDB
}

def janusGraphService = {
janusGraphDB
}

def dialgraphService = {
dialGraphDB
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.sunbird.graph.util

import java.util

import org.apache.commons.collections4.MapUtils
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import org.sunbird.common.dto.Property
import org.sunbird.common.{JsonUtils, Platform}
import org.sunbird.graph.dac.model.Node
import org.sunbird.graph.dac.model.{Node, Vertex}

import scala.collection.JavaConverters._
import scala.collection.immutable.Map
Expand Down Expand Up @@ -43,6 +42,12 @@ object CSPMetaUtil {
node
}

def updateAbsolutePath(vertex: Vertex): Vertex = {
val metadata = updateAbsolutePath(vertex.getMetadata)
vertex.setMetadata(metadata)
vertex
}

def updateAbsolutePath(nodes: java.util.List[Node]): java.util.List[Node] = {
nodes.asScala.toList.map(node => {
updateAbsolutePath(node)
Expand Down
15 changes: 15 additions & 0 deletions ontology-engine/graph-dac-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@
<version>1.17.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-driver</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-inmemory</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Loading