# HG changeset patch # User Sebastien Jodogne # Date 1732869050 -3600 # Node ID 96f49b200c15849ca3b5c63e866380fc7b3f5c4f # Parent 1c562a107a8017baea83b6a5c383e1092003fe76 refactoring diff -r 1c562a107a80 -r 96f49b200c15 OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Thu Nov 28 11:59:51 2024 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Fri Nov 29 09:30:50 2024 +0100 @@ -580,7 +580,34 @@ { ApplyInternal(NULL, &operations); } - + + + const FindResponse::Resource& StatelessDatabaseOperations::ExecuteSingleResource(FindResponse& response, + const FindRequest& request) + { + ExecuteFind(response, request); + + if (response.GetSize() == 0) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else if (response.GetSize() == 1) + { + if (response.GetResourceByIndex(0).GetLevel() != request.GetLevel()) + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + else + { + return response.GetResourceByIndex(0); + } + } + else + { + throw OrthancException(ErrorCode_DatabasePlugin); + } + } + void StatelessDatabaseOperations::GetAllMetadata(std::map& target, const std::string& publicId, @@ -591,32 +618,13 @@ request.SetRetrieveMetadata(true); FindResponse response; - ExecuteFind(response, request); - - if (response.GetSize() == 0) - { - throw OrthancException(ErrorCode_UnknownResource); - } - else if (response.GetSize() == 1) + std::map metadata = ExecuteSingleResource(response, request).GetMetadata(level); + + target.clear(); + for (std::map::const_iterator + it = metadata.begin(); it != metadata.end(); ++it) { - if (response.GetResourceByIndex(0).GetLevel() != level) - { - throw OrthancException(ErrorCode_DatabasePlugin); - } - else - { - std::map metadata = response.GetResourceByIndex(0).GetMetadata(level); - - target.clear(); - for (std::map::const_iterator it = metadata.begin(); it != metadata.end(); ++it) - { - target[it->first] = it->second.GetValue(); - } - } - } - else - { - throw OrthancException(ErrorCode_DatabasePlugin); + target[it->first] = it->second.GetValue(); } } @@ -632,27 +640,7 @@ request.SetRetrieveAttachments(true); FindResponse response; - ExecuteFind(response, request); - - if (response.GetSize() == 0) - { - throw OrthancException(ErrorCode_UnknownResource); - } - else if (response.GetSize() == 1) - { - if (response.GetResourceByIndex(0).GetLevel() != level) - { - throw OrthancException(ErrorCode_DatabasePlugin); - } - else - { - return response.GetResourceByIndex(0).LookupAttachment(attachment, revision, contentType); - } - } - else - { - throw OrthancException(ErrorCode_DatabasePlugin); - } + return ExecuteSingleResource(response, request).LookupAttachment(attachment, revision, contentType); } @@ -1030,27 +1018,7 @@ request.SetRetrieveMetadataRevisions(false); // No need to retrieve revisions FindResponse response; - ExecuteFind(response, request); - - if (response.GetSize() == 0) - { - throw OrthancException(ErrorCode_UnknownResource); - } - else if (response.GetSize() == 1) - { - if (response.GetResourceByIndex(0).GetLevel() != expectedType) - { - throw OrthancException(ErrorCode_DatabasePlugin); - } - else - { - return response.GetResourceByIndex(0).LookupMetadata(target, expectedType, type); - } - } - else - { - throw OrthancException(ErrorCode_DatabasePlugin); - } + return ExecuteSingleResource(response, request).LookupMetadata(target, expectedType, type); } @@ -1066,27 +1034,7 @@ request.SetRetrieveMetadataRevisions(true); // We are asked to retrieve revisions FindResponse response; - ExecuteFind(response, request); - - if (response.GetSize() == 0) - { - throw OrthancException(ErrorCode_UnknownResource); - } - else if (response.GetSize() == 1) - { - if (response.GetResourceByIndex(0).GetLevel() != expectedType) - { - throw OrthancException(ErrorCode_DatabasePlugin); - } - else - { - return response.GetResourceByIndex(0).LookupMetadata(target, revision, expectedType, type); - } - } - else - { - throw OrthancException(ErrorCode_DatabasePlugin); - } + return ExecuteSingleResource(response, request).LookupMetadata(target, revision, expectedType, type); } diff -r 1c562a107a80 -r 96f49b200c15 OrthancServer/Sources/Database/StatelessDatabaseOperations.h --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Thu Nov 28 11:59:51 2024 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Fri Nov 29 09:30:50 2024 +0100 @@ -491,6 +491,9 @@ void ApplyInternal(IReadOnlyOperations* readOperations, IReadWriteOperations* writeOperations); + const FindResponse::Resource &ExecuteSingleResource(FindResponse &response, + const FindRequest &request); + protected: void StandaloneRecycling(MaxStorageMode maximumStorageMode, uint64_t maximumStorageSize,