Mercurial > hg > orthanc
changeset 5713:d851a54e49b7 find-refactoring
removed "includeAllMetadata_" member from ResourceFinder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 13 Jul 2024 00:03:42 +0200 |
parents | 476b1db52110 |
children | 2b05428843d2 |
files | OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ResourceFinder.cpp OrthancServer/Sources/ResourceFinder.h |
diffstat | 4 files changed, 34 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Jul 12 18:41:44 2024 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Sat Jul 13 00:03:42 2024 +0200 @@ -150,23 +150,7 @@ else { const FindResponse::Resource& resource = response.GetResourceByIndex(0); - finder.Expand(target, resource, index, format); - - if (retrieveMetadata) - { - const std::map<MetadataType, std::string>& metadata = resource.GetMetadata(level); - - Json::Value tmp; - - for (std::map<MetadataType, std::string>::const_iterator - it = metadata.begin(); it != metadata.end(); ++it) - { - tmp[EnumerationToString(it->first)] = it->second; - } - - target["Metadata"] = tmp; - } - + finder.Expand(target, resource, index, format, retrieveMetadata); return true; } } @@ -312,7 +296,7 @@ } Json::Value answer; - finder.Execute(answer, context, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human)); + finder.Execute(answer, context, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human), false /* no "Metadata" field */); call.GetOutput().AnswerJson(answer); } else @@ -396,7 +380,7 @@ finder.SetOrthancId(resourceType, call.GetUriComponent("id", "")); Json::Value json; - if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format)) + if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format, false /* no "Metadata" field */)) { call.GetOutput().AnswerJson(json); } @@ -3497,7 +3481,7 @@ } Json::Value answer; - finder.Execute(answer, context, format); + finder.Execute(answer, context, format, false /* no "Metadata" field */); call.GetOutput().AnswerJson(answer); } else @@ -3668,7 +3652,7 @@ finder.AddRequestedTags(requestedTags); Json::Value answer; - finder.Execute(answer, context, format); + finder.Execute(answer, context, format, false /* no "Metadata" field */); call.GetOutput().AnswerJson(answer); } else
--- a/OrthancServer/Sources/OrthancWebDav.cpp Fri Jul 12 18:41:44 2024 +0200 +++ b/OrthancServer/Sources/OrthancWebDav.cpp Sat Jul 13 00:03:42 2024 +0200 @@ -1670,7 +1670,7 @@ finder.SetDatabaseLookup(query); Json::Value expanded; - finder.Execute(expanded, context, DicomToJsonFormat_Human); + finder.Execute(expanded, context, DicomToJsonFormat_Human, false /* don't add "Metadata" */); if (expanded.size() != 1) {
--- a/OrthancServer/Sources/ResourceFinder.cpp Fri Jul 12 18:41:44 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.cpp Sat Jul 13 00:03:42 2024 +0200 @@ -191,13 +191,19 @@ void ResourceFinder::Expand(Json::Value& target, const FindResponse::Resource& resource, ServerIndex& index, - DicomToJsonFormat format) const + DicomToJsonFormat format, + bool includeAllMetadata) const { /** * This method closely follows "SerializeExpandedResource()" in * "ServerContext.cpp" from Orthanc 1.12.4. **/ + if (!expand_) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + if (resource.GetLevel() != request_.GetLevel()) { throw OrthancException(ErrorCode_InternalError); @@ -407,7 +413,7 @@ target["Labels"] = labels; } - if (includeAllMetadata_) // new in Orthanc 1.12.4 + if (includeAllMetadata) // new in Orthanc 1.12.4 { const std::map<MetadataType, std::string>& m = resource.GetMetadata(resource.GetLevel()); @@ -483,8 +489,7 @@ limitsCount_(0), expand_(expand), allowStorageAccess_(true), - hasRequestedTags_(false), - includeAllMetadata_(false) + hasRequestedTags_(false) { UpdateRequestLimits(); @@ -1003,7 +1008,8 @@ void ResourceFinder::Execute(Json::Value& target, ServerContext& context, - DicomToJsonFormat format) const + DicomToJsonFormat format, + bool includeAllMetadata) const { class Visitor : public IVisitor { @@ -1013,18 +1019,21 @@ Json::Value& target_; DicomToJsonFormat format_; bool hasRequestedTags_; + bool includeAllMetadata_; public: Visitor(const ResourceFinder& that, ServerIndex& index, Json::Value& target, DicomToJsonFormat format, - bool hasRequestedTags) : + bool hasRequestedTags, + bool includeAllMetadata) : that_(that), index_(index), target_(target), format_(format), - hasRequestedTags_(hasRequestedTags) + hasRequestedTags_(hasRequestedTags), + includeAllMetadata_(includeAllMetadata) { } @@ -1034,7 +1043,7 @@ if (that_.expand_) { Json::Value item; - that_.Expand(item, resource, index_, format_); + that_.Expand(item, resource, index_, format_, includeAllMetadata_); if (hasRequestedTags_) { @@ -1058,17 +1067,18 @@ target = Json::arrayValue; - Visitor visitor(*this, context.GetIndex(), target, format, hasRequestedTags_); + Visitor visitor(*this, context.GetIndex(), target, format, hasRequestedTags_, includeAllMetadata); Execute(visitor, context); } bool ResourceFinder::ExecuteOneResource(Json::Value& target, ServerContext& context, - DicomToJsonFormat format) const + DicomToJsonFormat format, + bool includeAllMetadata) const { Json::Value answer; - Execute(answer, context, format); + Execute(answer, context, format, includeAllMetadata); if (answer.type() != Json::arrayValue) {
--- a/OrthancServer/Sources/ResourceFinder.h Fri Jul 12 18:41:44 2024 +0200 +++ b/OrthancServer/Sources/ResourceFinder.h Sat Jul 13 00:03:42 2024 +0200 @@ -74,7 +74,6 @@ std::set<DicomTag> requestedInstanceTags_; std::set<DicomTag> requestedTagsFromFileStorage_; std::set<DicomTag> requestedComputedTags_; - bool includeAllMetadata_; // Same as: ExpandResourceFlags_IncludeAllMetadata bool IsRequestedComputedTag(const DicomTag& tag) const { @@ -126,11 +125,6 @@ void SetDatabaseLookup(const DatabaseLookup& lookup); - void SetIncludeAllMetadata(bool include) - { - includeAllMetadata_ = include; - } - void AddRequestedTag(const DicomTag& tag); void AddRequestedTags(const std::set<DicomTag>& tags); @@ -165,10 +159,12 @@ request_.SetRetrieveAttachments(retrieve); } + // NB: "index" is only used in this method to fill the "IsStable" information void Expand(Json::Value& target, const FindResponse::Resource& resource, ServerIndex& index, - DicomToJsonFormat format) const; + DicomToJsonFormat format, + bool includeAllMetadata /* Same as: ExpandResourceFlags_IncludeAllMetadata */) const; void Execute(FindResponse& target, ServerIndex& index) const; @@ -178,10 +174,12 @@ void Execute(Json::Value& target, ServerContext& context, - DicomToJsonFormat format) const; + DicomToJsonFormat format, + bool includeAllMetadata) const; bool ExecuteOneResource(Json::Value& target, ServerContext& context, - DicomToJsonFormat format) const; + DicomToJsonFormat format, + bool includeAllMetadata) const; }; }