mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 04:31:02 +02:00
Fix schema mapping
This commit is contained in:
parent
ff5e6d7df1
commit
80708c6a9c
2 changed files with 72 additions and 13 deletions
|
|
@ -44,14 +44,21 @@ class LibraryRequestTranslator(MessageTranslator):
|
||||||
|
|
||||||
return LibrarianRequest(
|
return LibrarianRequest(
|
||||||
operation=data.get("operation"),
|
operation=data.get("operation"),
|
||||||
document_id=data.get("document-id"),
|
document_id=data.get("document-id", ""),
|
||||||
processing_id=data.get("processing-id"),
|
processing_id=data.get("processing-id", ""),
|
||||||
document_metadata=doc_metadata,
|
document_metadata=doc_metadata,
|
||||||
processing_metadata=proc_metadata,
|
processing_metadata=proc_metadata,
|
||||||
content=content,
|
content=content,
|
||||||
user=data.get("user"),
|
user=data.get("user", ""),
|
||||||
collection=data.get("collection"),
|
collection=data.get("collection", ""),
|
||||||
criteria=criteria
|
criteria=criteria,
|
||||||
|
# Chunked upload fields
|
||||||
|
total_size=data.get("total-size", 0),
|
||||||
|
chunk_size=data.get("chunk-size", 0),
|
||||||
|
upload_id=data.get("upload-id", ""),
|
||||||
|
chunk_index=data.get("chunk-index", 0),
|
||||||
|
# List documents filtering
|
||||||
|
include_children=data.get("include-children", False),
|
||||||
)
|
)
|
||||||
|
|
||||||
def from_pulsar(self, obj: LibrarianRequest) -> Dict[str, Any]:
|
def from_pulsar(self, obj: LibrarianRequest) -> Dict[str, Any]:
|
||||||
|
|
@ -99,6 +106,12 @@ class LibraryResponseTranslator(MessageTranslator):
|
||||||
def from_pulsar(self, obj: LibrarianResponse) -> Dict[str, Any]:
|
def from_pulsar(self, obj: LibrarianResponse) -> Dict[str, Any]:
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
|
if obj.error:
|
||||||
|
result["error"] = {
|
||||||
|
"type": obj.error.type,
|
||||||
|
"message": obj.error.message,
|
||||||
|
}
|
||||||
|
|
||||||
if obj.document_metadata:
|
if obj.document_metadata:
|
||||||
result["document-metadata"] = self.doc_metadata_translator.from_pulsar(obj.document_metadata)
|
result["document-metadata"] = self.doc_metadata_translator.from_pulsar(obj.document_metadata)
|
||||||
|
|
||||||
|
|
@ -117,6 +130,46 @@ class LibraryResponseTranslator(MessageTranslator):
|
||||||
for pm in obj.processing_metadatas
|
for pm in obj.processing_metadatas
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Chunked upload response fields
|
||||||
|
if obj.upload_id:
|
||||||
|
result["upload-id"] = obj.upload_id
|
||||||
|
if obj.chunk_size:
|
||||||
|
result["chunk-size"] = obj.chunk_size
|
||||||
|
if obj.total_chunks:
|
||||||
|
result["total-chunks"] = obj.total_chunks
|
||||||
|
if obj.chunk_index:
|
||||||
|
result["chunk-index"] = obj.chunk_index
|
||||||
|
if obj.chunks_received:
|
||||||
|
result["chunks-received"] = obj.chunks_received
|
||||||
|
if obj.bytes_received:
|
||||||
|
result["bytes-received"] = obj.bytes_received
|
||||||
|
if obj.total_bytes:
|
||||||
|
result["total-bytes"] = obj.total_bytes
|
||||||
|
if obj.document_id:
|
||||||
|
result["document-id"] = obj.document_id
|
||||||
|
if obj.object_id:
|
||||||
|
result["object-id"] = obj.object_id
|
||||||
|
if obj.upload_state:
|
||||||
|
result["upload-state"] = obj.upload_state
|
||||||
|
if obj.received_chunks:
|
||||||
|
result["received-chunks"] = obj.received_chunks
|
||||||
|
if obj.missing_chunks:
|
||||||
|
result["missing-chunks"] = obj.missing_chunks
|
||||||
|
if obj.upload_sessions:
|
||||||
|
result["upload-sessions"] = [
|
||||||
|
{
|
||||||
|
"upload-id": s.upload_id,
|
||||||
|
"document-id": s.document_id,
|
||||||
|
"document-metadata-json": s.document_metadata_json,
|
||||||
|
"total-size": s.total_size,
|
||||||
|
"chunk-size": s.chunk_size,
|
||||||
|
"total-chunks": s.total_chunks,
|
||||||
|
"chunks-received": s.chunks_received,
|
||||||
|
"created-at": s.created_at,
|
||||||
|
}
|
||||||
|
for s in obj.upload_sessions
|
||||||
|
]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def from_response_with_completion(self, obj: LibrarianResponse) -> Tuple[Dict[str, Any], bool]:
|
def from_response_with_completion(self, obj: LibrarianResponse) -> Tuple[Dict[str, Any], bool]:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ class DocumentMetadataTranslator(Translator):
|
||||||
comments=data.get("comments"),
|
comments=data.get("comments"),
|
||||||
metadata=self.subgraph_translator.to_pulsar(metadata) if metadata is not None else [],
|
metadata=self.subgraph_translator.to_pulsar(metadata) if metadata is not None else [],
|
||||||
user=data.get("user"),
|
user=data.get("user"),
|
||||||
tags=data.get("tags")
|
tags=data.get("tags"),
|
||||||
|
parent_id=data.get("parent-id", ""),
|
||||||
|
document_type=data.get("document-type", "source"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def from_pulsar(self, obj: DocumentMetadata) -> Dict[str, Any]:
|
def from_pulsar(self, obj: DocumentMetadata) -> Dict[str, Any]:
|
||||||
|
|
@ -42,6 +44,10 @@ class DocumentMetadataTranslator(Translator):
|
||||||
result["user"] = obj.user
|
result["user"] = obj.user
|
||||||
if obj.tags is not None:
|
if obj.tags is not None:
|
||||||
result["tags"] = obj.tags
|
result["tags"] = obj.tags
|
||||||
|
if obj.parent_id:
|
||||||
|
result["parent-id"] = obj.parent_id
|
||||||
|
if obj.document_type:
|
||||||
|
result["document-type"] = obj.document_type
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue