# HG changeset patch # User Sebastien Jodogne # Date 1614879745 -3600 # Node ID 929409e40008372ead72c852bec3bab728d24232 # Parent 19b1921aee0625a095b70f7889100a6ce083277b cont diff -r 19b1921aee06 -r 929409e40008 OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Thu Mar 04 17:59:40 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Thu Mar 04 18:42:25 2021 +0100 @@ -1440,68 +1440,6 @@ } - bool ServerIndex::LookupMetadata(std::string& target, - const std::string& publicId, - ResourceType expectedType, - MetadataType type) - { - boost::mutex::scoped_lock lock(mutex_); - - ResourceType rtype; - int64_t id; - if (!db_.LookupResource(id, rtype, publicId) || - rtype != expectedType) - { - throw OrthancException(ErrorCode_UnknownResource); - } - - return db_.LookupMetadata(target, id, type); - } - - - void ServerIndex::ListAvailableAttachments(std::set& target, - const std::string& publicId, - ResourceType expectedType) - { - boost::mutex::scoped_lock lock(mutex_); - - ResourceType type; - int64_t id; - if (!db_.LookupResource(id, type, publicId) || - expectedType != type) - { - throw OrthancException(ErrorCode_UnknownResource); - } - - db_.ListAvailableAttachments(target, id); - } - - - bool ServerIndex::LookupParent(std::string& target, - const std::string& publicId) - { - boost::mutex::scoped_lock lock(mutex_); - - ResourceType type; - int64_t id; - if (!db_.LookupResource(id, type, publicId)) - { - throw OrthancException(ErrorCode_UnknownResource); - } - - int64_t parentId; - if (db_.LookupParent(parentId, id)) - { - target = db_.GetPublicId(parentId); - return true; - } - else - { - return false; - } - } - - uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) { boost::mutex::scoped_lock lock(mutex_); @@ -3130,4 +3068,123 @@ Operations operations; operations.Apply(*this, &result, publicId); } + + + bool ServerIndex::LookupMetadata(std::string& target, + const std::string& publicId, + ResourceType expectedType, + MetadataType type) + { + class Operations : public ReadOnlyOperationsT4 + { + private: + bool found_; + + public: + Operations() : + found_(false) + { + } + + bool HasFound() + { + return found_; + } + + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + ResourceType rtype; + int64_t id; + if (!transaction.LookupResource(id, rtype, tuple.get<1>()) || + rtype != tuple.get<2>()) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else + { + found_ = transaction.LookupMetadata(*tuple.get<0>(), id, tuple.get<3>()); + } + } + }; + + Operations operations; + operations.Apply(*this, &target, publicId, expectedType, type); + return operations.HasFound(); + } + + + void ServerIndex::ListAvailableAttachments(std::set& target, + const std::string& publicId, + ResourceType expectedType) + { + class Operations : public ReadOnlyOperationsT3*, std::string, ResourceType> + { + public: + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + ResourceType type; + int64_t id; + if (!transaction.LookupResource(id, type, tuple.get<1>()) || + tuple.get<2>() != type) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else + { + transaction.ListAvailableAttachments(*tuple.get<0>(), id); + } + } + }; + + Operations operations; + operations.Apply(*this, &target, publicId, expectedType); + } + + + bool ServerIndex::LookupParent(std::string& target, + const std::string& publicId) + { + class Operations : public ReadOnlyOperationsT2 + { + private: + bool found_; + + public: + Operations() : + found_(false) + { + } + + bool HasFound() + { + return found_; + } + + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + ResourceType type; + int64_t id; + if (!transaction.LookupResource(id, type, tuple.get<1>())) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else + { + int64_t parentId; + if (transaction.LookupParent(parentId, id)) + { + *tuple.get<0>() = transaction.GetPublicId(parentId); + found_ = true; + } + } + } + }; + + Operations operations; + operations.Apply(*this, &target, publicId); + return operations.HasFound(); + } } diff -r 19b1921aee06 -r 929409e40008 OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Thu Mar 04 17:59:40 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Thu Mar 04 18:42:25 2021 +0100 @@ -172,18 +172,6 @@ void DeleteMetadata(const std::string& publicId, MetadataType type); - bool LookupMetadata(std::string& target, - const std::string& publicId, - ResourceType expectedType, - MetadataType type); - - void ListAvailableAttachments(std::set& target, - const std::string& publicId, - ResourceType expectedType); - - bool LookupParent(std::string& target, - const std::string& publicId); - uint64_t IncrementGlobalSequence(GlobalProperty sequence); void LogChange(ChangeType changeType, @@ -387,6 +375,12 @@ return db_.IsProtectedPatient(internalId); } + void ListAvailableAttachments(std::set& target, + int64_t id) + { + db_.ListAvailableAttachments(target, id); + } + bool LookupAttachment(FileInfo& attachment, int64_t id, FileContentType contentType) @@ -394,6 +388,19 @@ return db_.LookupAttachment(attachment, id, contentType); } + bool LookupMetadata(std::string& target, + int64_t id, + MetadataType type) + { + return db_.LookupMetadata(target, id, type); + } + + bool LookupParent(int64_t& parentId, + int64_t resourceId) + { + return db_.LookupParent(parentId, resourceId); + } + bool LookupResource(int64_t& id, ResourceType& type, const std::string& publicId) @@ -512,5 +519,17 @@ void GetChildInstances(std::list& result, const std::string& publicId); + + bool LookupMetadata(std::string& target, + const std::string& publicId, + ResourceType expectedType, + MetadataType type); + + void ListAvailableAttachments(std::set& target, + const std::string& publicId, + ResourceType expectedType); + + bool LookupParent(std::string& target, + const std::string& publicId); }; }