Mercurial > hg > orthanc
changeset 6118:fd79cf7d1743 attach-custom-data
implement protobuf interface for Queues - KVS
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 20 May 2025 16:07:49 +0200 |
parents | fec888c37d4e |
children | 756983d498bb |
files | OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto |
diffstat | 2 files changed, 243 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Tue May 20 14:33:17 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Tue May 20 16:07:49 2025 +0200 @@ -1023,13 +1023,47 @@ int64_t& revision, const std::string& attachmentUuid) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_NotImplemented); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasAttachmentCustomDataSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_get_attachment()->set_uuid(attachmentUuid); + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_ATTACHMENT, request); + + if (response.get_attachment().found()) + { + revision = response.get_attachment().revision(); + attachment = Convert(response.get_attachment().attachment()); + return true; + } + + return false; + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual void UpdateAttachmentCustomData(const std::string& attachmentUuid, const std::string& customData) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_NotImplemented); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasAttachmentCustomDataSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_update_attachment_custom_data()->set_uuid(attachmentUuid); + request.mutable_update_attachment_custom_data()->set_custom_data(customData); + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_UPDATE_ATTACHMENT_CUSTOM_DATA, request); + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } @@ -1826,20 +1860,66 @@ const std::string& key, const std::string& value) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_NotImplemented); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasKeyValueStoresSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_store_key_value()->set_store_id(storeId); + request.mutable_store_key_value()->set_key(key); + request.mutable_store_key_value()->set_value(value); + + ExecuteTransaction(DatabasePluginMessages::OPERATION_STORE_KEY_VALUE, request); + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual void DeleteKeyValue(const std::string& storeId, const std::string& key) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_NotImplemented); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasKeyValueStoresSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_delete_key_value()->set_store_id(storeId); + request.mutable_delete_key_value()->set_key(key); + + ExecuteTransaction(DatabasePluginMessages::OPERATION_DELETE_KEY_VALUE, request); + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual bool GetKeyValue(std::string& value, const std::string& storeId, const std::string& key) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_NotImplemented); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasKeyValueStoresSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_get_key_value()->set_store_id(storeId); + request.mutable_get_key_value()->set_key(key); + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_KEY_VALUE, request); + + if (response.get_key_value().found()) + { + value = response.get_key_value().value(); + return true; + } + + return false; + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual void ListKeys(std::list<std::string>& keys, @@ -1847,25 +1927,102 @@ uint64_t since, uint64_t limit) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_InternalError); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasKeyValueStoresSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_list_key_values()->set_store_id(storeId); + request.mutable_list_key_values()->set_since(since); + request.mutable_list_key_values()->set_limit(limit); + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_KEY_VALUES, request); + + for (int i = 0; i < response.list_key_values().key_values_size(); ++i) + { + keys.push_back(response.list_key_values().key_values(i).key()); + // values .push_back(response.list_key_value().key_values(i)); // TODO_ATTACH_CUSTOM_DATA + } + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual void EnqueueValue(const std::string& queueId, const std::string& value) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_InternalError); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasQueuesSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_enqueue_value()->set_queue_id(queueId); + request.mutable_enqueue_value()->set_value(value); + + ExecuteTransaction(DatabasePluginMessages::OPERATION_ENQUEUE_VALUE, request); + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual bool DequeueValue(std::string& value, const std::string& queueId, QueueOrigin origin) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_InternalError); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasQueuesSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_dequeue_value()->set_queue_id(queueId); + switch (origin) + { + case QueueOrigin_Back: + request.mutable_dequeue_value()->set_origin(DatabasePluginMessages::QUEUE_ORIGIN_BACK); + break; + case QueueOrigin_Front: + request.mutable_dequeue_value()->set_origin(DatabasePluginMessages::QUEUE_ORIGIN_FRONT); + break; + default: + throw OrthancException(ErrorCode_InternalError); + } + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_DEQUEUE_VALUE, request); + + if (response.dequeue_value().found()) + { + value = response.dequeue_value().value(); + return true; + } + + return false; + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } virtual uint64_t GetQueueSize(const std::string& queueId) ORTHANC_OVERRIDE { - throw OrthancException(ErrorCode_InternalError); // TODO_ATTACH_CUSTOM_DATA + if (database_.GetDatabaseCapabilities().HasQueuesSupport()) + { + DatabasePluginMessages::TransactionRequest request; + request.mutable_get_queue_size()->set_queue_id(queueId); + + DatabasePluginMessages::TransactionResponse response; + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_QUEUE_SIZE, request); + + return response.get_queue_size().size(); + } + else + { + // This method shouldn't have been called + throw OrthancException(ErrorCode_InternalError); + } } };
--- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Tue May 20 14:33:17 2025 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Tue May 20 16:07:49 2025 +0200 @@ -332,8 +332,13 @@ OPERATION_STORE_KEY_VALUE = 53; // New in Orthanc 1.12.99 OPERATION_DELETE_KEY_VALUE = 54; // New in Orthanc 1.12.99 OPERATION_GET_KEY_VALUE = 55; // New in Orthanc 1.12.99 - OPERATION_ENQUEUE_VALUE = 56; // New in Orthanc 1.12.99 - OPERATION_DEQUEUE_VALUE = 57; // New in Orthanc 1.12.99 + OPERATION_LIST_KEY_VALUES = 56; // New in Orthanc 1.12.99 + OPERATION_ENQUEUE_VALUE = 57; // New in Orthanc 1.12.99 + OPERATION_DEQUEUE_VALUE = 58; // New in Orthanc 1.12.99 + OPERATION_GET_QUEUE_SIZE = 59; // New in Orthanc 1.12.99 + OPERATION_GET_ATTACHMENT = 60; // New in Orthanc 1.12.99 + OPERATION_UPDATE_ATTACHMENT_CUSTOM_DATA = 61; // New in Orthanc 1.12.99 + } message Rollback { @@ -989,7 +994,7 @@ message StoreKeyValue { message Request { - string plugin_id = 1; + string store_id = 1; string key = 2; string value = 3; } @@ -1000,7 +1005,7 @@ message DeleteKeyValue { message Request { - string plugin_id = 1; + string store_id = 1; string key = 2; } @@ -1010,18 +1015,36 @@ message GetKeyValue { message Request { - string plugin_id = 1; + string store_id = 1; string key = 2; } message Response { - string value = 1; + bool found = 1; + string value = 2; + } +} + +message KeyValue { + string key = 1; + string value = 2; +} + +message ListKeyValues { + message Request { + string store_id = 1; + uint64 since = 2; + uint64 limit = 3; + } + + message Response { + repeated KeyValue key_values = 1; } } message EnqueueValue { message Request { - string plugin_id = 1; + string queue_id = 1; string value = 2; } @@ -1031,12 +1054,45 @@ message DequeueValue { message Request { - string plugin_id = 1; + string queue_id = 1; QueueOrigin origin = 2; } message Response { - string value = 1; + bool found = 1; + string value = 2; + } +} + +message GetQueueSize { + message Request { + string queue_id = 1; + } + + message Response { + uint64 size = 1; + } +} + +message GetAttachment { + message Request { + string uuid = 1; + } + + message Response { + bool found = 1; + FileInfo attachment = 2; + int64 revision = 3; + } +} + +message UpdateAttachmentCustomData { + message Request { + string uuid = 1; + string custom_data = 2; + } + + message Response { } } @@ -1100,8 +1156,12 @@ StoreKeyValue.Request store_key_value = 153; DeleteKeyValue.Request delete_key_value = 154; GetKeyValue.Request get_key_value = 155; - EnqueueValue.Request enqueue_value = 156; - DequeueValue.Request dequeue_value = 157; + ListKeyValues.Request list_key_values = 156; + EnqueueValue.Request enqueue_value = 157; + DequeueValue.Request dequeue_value = 158; + GetQueueSize.Request get_queue_size = 159; + GetAttachment.Request get_attachment = 160; + UpdateAttachmentCustomData.Request update_attachment_custom_data = 161; } message TransactionResponse { @@ -1161,8 +1221,12 @@ StoreKeyValue.Response store_key_value = 153; DeleteKeyValue.Response delete_key_value = 154; GetKeyValue.Response get_key_value = 155; - EnqueueValue.Request enqueue_value = 156; - DequeueValue.Request dequeue_value = 157; + ListKeyValues.Response list_key_values = 156; + EnqueueValue.Response enqueue_value = 157; + DequeueValue.Response dequeue_value = 158; + GetQueueSize.Response get_queue_size = 159; + GetAttachment.Response get_attachment = 160; + UpdateAttachmentCustomData.Response update_attachment_custom_data = 161; } enum RequestType {