Mercurial > hg > orthanc
changeset 4560:929409e40008 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Mar 2021 18:42:25 +0100 |
parents | 19b1921aee06 |
children | 02510325d869 |
files | OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h |
diffstat | 2 files changed, 150 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- 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<FileContentType>& 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<std::string*, std::string, ResourceType, MetadataType> + { + 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<FileContentType>& target, + const std::string& publicId, + ResourceType expectedType) + { + class Operations : public ReadOnlyOperationsT3<std::set<FileContentType>*, 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<std::string*, std::string> + { + 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(); + } }
--- 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<FileContentType>& 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<FileContentType>& 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<std::string>& result, const std::string& publicId); + + bool LookupMetadata(std::string& target, + const std::string& publicId, + ResourceType expectedType, + MetadataType type); + + void ListAvailableAttachments(std::set<FileContentType>& target, + const std::string& publicId, + ResourceType expectedType); + + bool LookupParent(std::string& target, + const std::string& publicId); }; }