Commit b4927861 authored by harshavardhan.c's avatar harshavardhan.c

Add: logic addition for deleting nodes.

parent 55925c98
from scripts.db.graphdb.neo4j import Neo4jHandler from scripts.db.graphdb.neo4j import Neo4jHandler
from scripts.db.models import NodePropertiesSchema, RelationShipMapper from scripts.db.models import NodePropertiesSchema, RelationShipMapper, NodeFetchSchema
from scripts.logging import logger from scripts.logging import logger
from scripts.schemas import GraphData, NodeSchemaValidation, NodeActionOptions from scripts.schemas import GraphData, NodeSchemaValidation, NodeActionOptions
from scripts.utils.graph_utility import GraphUtility from scripts.utils.graph_utility import GraphUtility
...@@ -22,7 +22,7 @@ class GraphTraversal: ...@@ -22,7 +22,7 @@ class GraphTraversal:
for node_type, node_obj in graph_data.__root__.items(): for node_type, node_obj in graph_data.__root__.items():
process_obj = NodeSchemaValidation(**node_obj.dict(), label=node_type) process_obj = NodeSchemaValidation(**node_obj.dict(), label=node_type)
if node_obj.action == NodeActionOptions.delete: if node_obj.action == NodeActionOptions.delete:
... self.perform_delete_node_action(graph_data=process_obj)
else: else:
nodes_map, edges_info = self.perform_save_node_action(node_obj=process_obj, nodes_map=nodes_map, nodes_map, edges_info = self.perform_save_node_action(node_obj=process_obj, nodes_map=nodes_map,
edges_info=edges_info, node_type=node_type) edges_info=edges_info, node_type=node_type)
...@@ -34,10 +34,8 @@ class GraphTraversal: ...@@ -34,10 +34,8 @@ class GraphTraversal:
rel_data=RelationShipMapper(_start_node_id=nodes_map[edge.bind_to]._id, rel_data=RelationShipMapper(_start_node_id=nodes_map[edge.bind_to]._id,
_end_node_id=nodes_map[des_edge]._id, _end_node_id=nodes_map[des_edge]._id,
_type=edge.rel_name, _type=edge.rel_name,
**nodes_map[des_edge].dict(), project_id=nodes_map[des_edge].project_id,
), new_rel_name=edge.new_rel_name) ), new_rel_name=edge.new_rel_name)
except Exception as e: except Exception as e:
logger.exception(f'{e.args}') logger.exception(f'{e.args}')
...@@ -63,3 +61,9 @@ class GraphTraversal: ...@@ -63,3 +61,9 @@ class GraphTraversal:
except Exception as e: except Exception as e:
logger.exception(f'Exception Occurred while deleting node info {e.args}') logger.exception(f'Exception Occurred while deleting node info {e.args}')
raise raise
def fetch_node_data(self, graph_request: NodeFetchSchema):
try:
existing_data = self.graph_util.load_node_data_from_graph(node_data=graph_request)
except Exception as e:
logger.exception(f"Exception Occurred while fetching data from node")
from scripts.core.engine import GraphTraversal from scripts.core.engine import GraphTraversal
from scripts.schemas import GraphData from scripts.schemas import GraphData, GetNodeInfo
class GraphTrackingHandler: class GraphTrackingHandler:
...@@ -11,7 +11,7 @@ class GraphTrackingHandler: ...@@ -11,7 +11,7 @@ class GraphTrackingHandler:
""" """
return self.graph_traversal.ingest_data_handler(graph_data=graph_data) return self.graph_traversal.ingest_data_handler(graph_data=graph_data)
def graph_traverse_handler(self, graph_data_request: GenealogyDataRequest) -> str: def graph_traverse_handler(self, graph_data_request: GetNodeInfo) -> str:
""" """
""" """
return self.graph_traversal.get_genealogy(genealogy_data=graph_data_request) return self.graph_traversal.get_genealogy(genealogy_data=graph_data_request)
from typing import Optional
from gqlalchemy import Node, Relationship from gqlalchemy import Node, Relationship
from pydantic import Field from pydantic import Field
...@@ -15,6 +17,12 @@ class NodePropertiesSchema(NodeCreationSchema): ...@@ -15,6 +17,12 @@ class NodePropertiesSchema(NodeCreationSchema):
class RelationShipMapper(Relationship, type="Relation_Mapper"): class RelationShipMapper(Relationship, type="Relation_Mapper"):
project_id: str = Field() project_id: str = Field()
class Config: class Config:
allow_population_by_field_name = True allow_population_by_field_name = True
class NodeFetchSchema(Node):
id: Optional[str]
name: Optional[str]
project_id: str
...@@ -90,3 +90,8 @@ class GraphData(BaseModel): ...@@ -90,3 +90,8 @@ class GraphData(BaseModel):
} }
} }
} }
class GetNodeInfo(BaseModel):
project_id: str
event_id: str
...@@ -3,7 +3,7 @@ from typing import List ...@@ -3,7 +3,7 @@ from typing import List
from gqlalchemy import GQLAlchemyError from gqlalchemy import GQLAlchemyError
from scripts.db.graphdb.neo4j import Neo4jHandler from scripts.db.graphdb.neo4j import Neo4jHandler
from scripts.db.models import NodeCreationSchema, RelationShipMapper, NodePropertiesSchema from scripts.db.models import RelationShipMapper, NodePropertiesSchema, NodeFetchSchema
from scripts.logging import logger from scripts.logging import logger
......
Markdown is supported
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