mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
Collection management (#520)
* Tech spec * Refactored Cassanda knowledge graph for single table * Collection management, librarian services to manage metadata and collection deletion
This commit is contained in:
parent
48016d8fb2
commit
13ff7d765d
48 changed files with 2941 additions and 425 deletions
112
trustgraph-base/trustgraph/messaging/translators/collection.py
Normal file
112
trustgraph-base/trustgraph/messaging/translators/collection.py
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
from typing import Dict, Any, List
|
||||
from ...schema import CollectionManagementRequest, CollectionManagementResponse, CollectionMetadata, Error
|
||||
from .base import MessageTranslator
|
||||
|
||||
|
||||
class CollectionManagementRequestTranslator(MessageTranslator):
|
||||
"""Translator for CollectionManagementRequest schema objects"""
|
||||
|
||||
def to_pulsar(self, data: Dict[str, Any]) -> CollectionManagementRequest:
|
||||
return CollectionManagementRequest(
|
||||
operation=data.get("operation", ""),
|
||||
user=data.get("user", ""),
|
||||
collection=data.get("collection", ""),
|
||||
timestamp=data.get("timestamp", ""),
|
||||
name=data.get("name", ""),
|
||||
description=data.get("description", ""),
|
||||
tags=data.get("tags", []),
|
||||
created_at=data.get("created_at", ""),
|
||||
updated_at=data.get("updated_at", ""),
|
||||
tag_filter=data.get("tag_filter", []),
|
||||
limit=data.get("limit", 50)
|
||||
)
|
||||
|
||||
def from_pulsar(self, obj: CollectionManagementRequest) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
if obj.operation:
|
||||
result["operation"] = obj.operation
|
||||
if obj.user:
|
||||
result["user"] = obj.user
|
||||
if obj.collection:
|
||||
result["collection"] = obj.collection
|
||||
if obj.timestamp:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.name:
|
||||
result["name"] = obj.name
|
||||
if obj.description:
|
||||
result["description"] = obj.description
|
||||
if obj.tags:
|
||||
result["tags"] = list(obj.tags)
|
||||
if obj.created_at:
|
||||
result["created_at"] = obj.created_at
|
||||
if obj.updated_at:
|
||||
result["updated_at"] = obj.updated_at
|
||||
if obj.tag_filter:
|
||||
result["tag_filter"] = list(obj.tag_filter)
|
||||
if obj.limit:
|
||||
result["limit"] = obj.limit
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class CollectionManagementResponseTranslator(MessageTranslator):
|
||||
"""Translator for CollectionManagementResponse schema objects"""
|
||||
|
||||
def to_pulsar(self, data: Dict[str, Any]) -> CollectionManagementResponse:
|
||||
# Handle error
|
||||
error = None
|
||||
if "error" in data and data["error"]:
|
||||
error_data = data["error"]
|
||||
error = Error(
|
||||
type=error_data.get("type", ""),
|
||||
message=error_data.get("message", "")
|
||||
)
|
||||
|
||||
# Handle collections array
|
||||
collections = []
|
||||
if "collections" in data:
|
||||
for coll_data in data["collections"]:
|
||||
collections.append(CollectionMetadata(
|
||||
user=coll_data.get("user", ""),
|
||||
collection=coll_data.get("collection", ""),
|
||||
name=coll_data.get("name", ""),
|
||||
description=coll_data.get("description", ""),
|
||||
tags=coll_data.get("tags", []),
|
||||
created_at=coll_data.get("created_at", ""),
|
||||
updated_at=coll_data.get("updated_at", "")
|
||||
))
|
||||
|
||||
return CollectionManagementResponse(
|
||||
success=data.get("success", ""),
|
||||
error=error,
|
||||
timestamp=data.get("timestamp", ""),
|
||||
collections=collections
|
||||
)
|
||||
|
||||
def from_pulsar(self, obj: CollectionManagementResponse) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
if obj.success:
|
||||
result["success"] = obj.success
|
||||
if obj.error:
|
||||
result["error"] = {
|
||||
"type": obj.error.type,
|
||||
"message": obj.error.message
|
||||
}
|
||||
if obj.timestamp:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.collections:
|
||||
result["collections"] = []
|
||||
for coll in obj.collections:
|
||||
result["collections"].append({
|
||||
"user": coll.user,
|
||||
"collection": coll.collection,
|
||||
"name": coll.name,
|
||||
"description": coll.description,
|
||||
"tags": list(coll.tags) if coll.tags else [],
|
||||
"created_at": coll.created_at,
|
||||
"updated_at": coll.updated_at
|
||||
})
|
||||
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue