changeset 5709:476b1db52110 find-refactoring

removed the "format_" member from ResourceFinder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2024 18:41:44 +0200
parents 1891a8c2dbb4
children a786da7599d5 d851a54e49b7
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ResourceFinder.cpp OrthancServer/Sources/ResourceFinder.h
diffstat 4 files changed, 32 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Jul 12 18:31:14 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Jul 12 18:41:44 2024 +0200
@@ -138,7 +138,6 @@
   {
     ResourceFinder finder(level, true /* expand */);
     finder.SetOrthancId(level, identifier);
-    finder.SetFormat(format);
     finder.SetRetrieveMetadata(retrieveMetadata);
 
     FindResponse response;
@@ -151,7 +150,7 @@
     else
     {
       const FindResponse::Resource& resource = response.GetResourceByIndex(0);
-      finder.Expand(target, resource, index);
+      finder.Expand(target, resource, index, format);
 
       if (retrieveMetadata)
       {
@@ -288,7 +287,6 @@
 
       ResourceFinder finder(resourceType, expand);
       finder.AddRequestedTags(requestedTags);
-      finder.SetFormat(OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human));
 
       if (call.HasArgument("limit") ||
           call.HasArgument("since"))
@@ -314,7 +312,7 @@
       }
 
       Json::Value answer;
-      finder.Execute(answer, context);
+      finder.Execute(answer, context, OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human));
       call.GetOutput().AnswerJson(answer);
     }
     else
@@ -395,11 +393,10 @@
 
       ResourceFinder finder(resourceType, true /* expand */);
       finder.AddRequestedTags(requestedTags);
-      finder.SetFormat(OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human));
       finder.SetOrthancId(resourceType, call.GetUriComponent("id", ""));
 
       Json::Value json;
-      if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call)))
+      if (finder.ExecuteOneResource(json, OrthancRestApi::GetContext(call), format))
       {
         call.GetOutput().AnswerJson(json);
       }
@@ -3390,7 +3387,8 @@
 
       ResourceFinder finder(level, expand);
       finder.SetDatabaseLimits(context.GetDatabaseLimits(level));
-      finder.SetFormat(OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human));
+
+      const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(request, DicomToJsonFormat_Human);
 
       if (request.isMember(KEY_LIMIT))
       {
@@ -3499,7 +3497,7 @@
       }
 
       Json::Value answer;
-      finder.Execute(answer, context);
+      finder.Execute(answer, context, format);
       call.GetOutput().AnswerJson(answer);
     }
     else
@@ -3668,10 +3666,9 @@
       ResourceFinder finder(end, expand);
       finder.SetOrthancId(start, call.GetUriComponent("id", ""));
       finder.AddRequestedTags(requestedTags);
-      finder.SetFormat(format);
 
       Json::Value answer;
-      finder.Execute(answer, context);
+      finder.Execute(answer, context, format);
       call.GetOutput().AnswerJson(answer);
     }
     else
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Fri Jul 12 18:31:14 2024 +0200
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Fri Jul 12 18:41:44 2024 +0200
@@ -1670,7 +1670,7 @@
     finder.SetDatabaseLookup(query);
 
     Json::Value expanded;
-    finder.Execute(expanded, context);
+    finder.Execute(expanded, context, DicomToJsonFormat_Human);
 
     if (expanded.size() != 1)
     {
--- a/OrthancServer/Sources/ResourceFinder.cpp	Fri Jul 12 18:31:14 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Fri Jul 12 18:41:44 2024 +0200
@@ -190,7 +190,8 @@
 
   void ResourceFinder::Expand(Json::Value& target,
                               const FindResponse::Resource& resource,
-                              ServerIndex& index) const
+                              ServerIndex& index,
+                              DicomToJsonFormat format) const
   {
     /**
      * This method closely follows "SerializeExpandedResource()" in
@@ -382,7 +383,7 @@
       allMainDicomTags.ExtractResourceInformation(levelMainDicomTags, resource.GetLevel());
 
       target[MAIN_DICOM_TAGS] = Json::objectValue;
-      FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format_);
+      FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format);
 
       if (resource.GetLevel() == ResourceType_Study)
       {
@@ -390,7 +391,7 @@
         allMainDicomTags.ExtractPatientInformation(patientMainDicomTags);
 
         target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue;
-        FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format_);
+        FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format);
       }
     }
 
@@ -481,7 +482,6 @@
     limitsSince_(0),
     limitsCount_(0),
     expand_(expand),
-    format_(DicomToJsonFormat_Human),
     allowStorageAccess_(true),
     hasRequestedTags_(false),
     includeAllMetadata_(false)
@@ -1002,24 +1002,28 @@
 
 
   void ResourceFinder::Execute(Json::Value& target,
-                               ServerContext& context) const
+                               ServerContext& context,
+                               DicomToJsonFormat format) const
   {
     class Visitor : public IVisitor
     {
     private:
       const ResourceFinder&  that_;
-      ServerIndex& index_;
-      Json::Value& target_;
-      bool         hasRequestedTags_;
+      ServerIndex&           index_;
+      Json::Value&           target_;
+      DicomToJsonFormat      format_;
+      bool                   hasRequestedTags_;
 
     public:
       Visitor(const ResourceFinder& that,
               ServerIndex& index,
               Json::Value& target,
+              DicomToJsonFormat format,
               bool hasRequestedTags) :
         that_(that),
         index_(index),
         target_(target),
+        format_(format),
         hasRequestedTags_(hasRequestedTags)
       {
       }
@@ -1030,13 +1034,13 @@
         if (that_.expand_)
         {
           Json::Value item;
-          that_.Expand(item, resource, index_);
+          that_.Expand(item, resource, index_, format_);
 
           if (hasRequestedTags_)
           {
             static const char* const REQUESTED_TAGS = "RequestedTags";
             item[REQUESTED_TAGS] = Json::objectValue;
-            FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, that_.format_);
+            FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, format_);
           }
 
           target_.append(item);
@@ -1054,16 +1058,17 @@
 
     target = Json::arrayValue;
 
-    Visitor visitor(*this, context.GetIndex(), target, hasRequestedTags_);
+    Visitor visitor(*this, context.GetIndex(), target, format, hasRequestedTags_);
     Execute(visitor, context);
   }
 
 
   bool ResourceFinder::ExecuteOneResource(Json::Value& target,
-                                          ServerContext& context) const
+                                          ServerContext& context,
+                                          DicomToJsonFormat format) const
   {
     Json::Value answer;
-    Execute(answer, context);
+    Execute(answer, context, format);
 
     if (answer.type() != Json::arrayValue)
     {
--- a/OrthancServer/Sources/ResourceFinder.h	Fri Jul 12 18:31:14 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.h	Fri Jul 12 18:41:44 2024 +0200
@@ -66,7 +66,6 @@
     uint64_t                         limitsSince_;
     uint64_t                         limitsCount_;
     bool                             expand_;
-    DicomToJsonFormat                format_;
     bool                             allowStorageAccess_;
     bool                             hasRequestedTags_;
     std::set<DicomTag>               requestedPatientTags_;
@@ -121,11 +120,6 @@
       request_.SetOrthancId(level, id);
     }
 
-    void SetFormat(DicomToJsonFormat format)
-    {
-      format_ = format;
-    }
-
     void SetLimitsSince(uint64_t since);
 
     void SetLimitsCount(uint64_t count);
@@ -173,7 +167,8 @@
 
     void Expand(Json::Value& target,
                 const FindResponse::Resource& resource,
-                ServerIndex& index) const;
+                ServerIndex& index,
+                DicomToJsonFormat format) const;
 
     void Execute(FindResponse& target,
                  ServerIndex& index) const;
@@ -182,9 +177,11 @@
                  ServerContext& context) const;
 
     void Execute(Json::Value& target,
-                 ServerContext& context) const;
+                 ServerContext& context,
+                 DicomToJsonFormat format) const;
 
     bool ExecuteOneResource(Json::Value& target,
-                            ServerContext& context) const;
+                            ServerContext& context,
+                            DicomToJsonFormat format) const;
   };
 }