mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-26 08:56:21 +02:00
Collection management part 2 (#522)
* Plumb collection manager into librarian * Test end-to-end
This commit is contained in:
parent
d378db9370
commit
fcd15d1833
16 changed files with 617 additions and 434 deletions
|
|
@ -27,6 +27,14 @@ class Collection:
|
|||
object = self.request(input)
|
||||
|
||||
try:
|
||||
# Handle case where collections might be None or missing
|
||||
if object is None or "collections" not in object:
|
||||
return []
|
||||
|
||||
collections = object.get("collections", [])
|
||||
if collections is None:
|
||||
return []
|
||||
|
||||
return [
|
||||
CollectionMetadata(
|
||||
user = v["user"],
|
||||
|
|
@ -37,7 +45,7 @@ class Collection:
|
|||
created_at = v["created_at"],
|
||||
updated_at = v["updated_at"]
|
||||
)
|
||||
for v in object["collections"]
|
||||
for v in collections
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error("Failed to parse collection list response", exc_info=True)
|
||||
|
|
|
|||
|
|
@ -8,43 +8,43 @@ class CollectionManagementRequestTranslator(MessageTranslator):
|
|||
|
||||
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)
|
||||
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")
|
||||
)
|
||||
|
||||
def from_pulsar(self, obj: CollectionManagementRequest) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
if obj.operation:
|
||||
if obj.operation is not None:
|
||||
result["operation"] = obj.operation
|
||||
if obj.user:
|
||||
if obj.user is not None:
|
||||
result["user"] = obj.user
|
||||
if obj.collection:
|
||||
if obj.collection is not None:
|
||||
result["collection"] = obj.collection
|
||||
if obj.timestamp:
|
||||
if obj.timestamp is not None:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.name:
|
||||
if obj.name is not None:
|
||||
result["name"] = obj.name
|
||||
if obj.description:
|
||||
if obj.description is not None:
|
||||
result["description"] = obj.description
|
||||
if obj.tags:
|
||||
if obj.tags is not None:
|
||||
result["tags"] = list(obj.tags)
|
||||
if obj.created_at:
|
||||
if obj.created_at is not None:
|
||||
result["created_at"] = obj.created_at
|
||||
if obj.updated_at:
|
||||
if obj.updated_at is not None:
|
||||
result["updated_at"] = obj.updated_at
|
||||
if obj.tag_filter:
|
||||
if obj.tag_filter is not None:
|
||||
result["tag_filter"] = list(obj.tag_filter)
|
||||
if obj.limit:
|
||||
if obj.limit is not None:
|
||||
result["limit"] = obj.limit
|
||||
|
||||
return result
|
||||
|
|
@ -54,13 +54,14 @@ 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", "")
|
||||
type=error_data.get("type"),
|
||||
message=error_data.get("message")
|
||||
)
|
||||
|
||||
# Handle collections array
|
||||
|
|
@ -68,35 +69,34 @@ class CollectionManagementResponseTranslator(MessageTranslator):
|
|||
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", "")
|
||||
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", ""),
|
||||
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:
|
||||
print("COLLECTIONMGMT", obj, flush=True)
|
||||
|
||||
if obj.error is not None:
|
||||
result["error"] = {
|
||||
"type": obj.error.type,
|
||||
"message": obj.error.message
|
||||
}
|
||||
if obj.timestamp:
|
||||
if obj.timestamp is not None:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.collections:
|
||||
if obj.collections is not None:
|
||||
result["collections"] = []
|
||||
for coll in obj.collections:
|
||||
result["collections"].append({
|
||||
|
|
@ -109,4 +109,6 @@ class CollectionManagementResponseTranslator(MessageTranslator):
|
|||
"updated_at": coll.updated_at
|
||||
})
|
||||
|
||||
return result
|
||||
print("RESULT IS", result, flush=True)
|
||||
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ class CollectionManagementRequest(Record):
|
|||
|
||||
class CollectionManagementResponse(Record):
|
||||
"""Response for collection management operations"""
|
||||
success = String() # "true" or "false"
|
||||
error = Error() # Only populated if success is "false"
|
||||
error = Error() # Only populated if there's an error
|
||||
timestamp = String() # ISO timestamp
|
||||
collections = Array(CollectionMetadata())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue