changeset 5610:d4b570834d3a find-refactoring

adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 May 2024 10:36:03 +0200
parents 4690a0d2b01e
children 599ce5ed126c
files OrthancServer/Sources/Database/FindRequest.cpp OrthancServer/Sources/Database/FindRequest.h OrthancServer/Sources/Database/FindResponse.cpp OrthancServer/Sources/ResourceFinder.cpp
diffstat 4 files changed, 41 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/FindRequest.cpp	Wed May 08 18:28:36 2024 +0200
+++ b/OrthancServer/Sources/Database/FindRequest.cpp	Thu May 09 10:36:03 2024 +0200
@@ -366,4 +366,17 @@
       retrieveChildrenMetadata_.insert(metadata);
     }
   }
+
+
+  void FindRequest::SetRetrieveOneInstanceIdentifier(bool retrieve)
+  {
+    if (level_ == ResourceType_Instance)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      retrieveOneInstanceIdentifier_ = retrieve;
+    }
+  }
 }
--- a/OrthancServer/Sources/Database/FindRequest.h	Wed May 08 18:28:36 2024 +0200
+++ b/OrthancServer/Sources/Database/FindRequest.h	Thu May 09 10:36:03 2024 +0200
@@ -313,10 +313,7 @@
       return retrieveChildrenMetadata_;
     }
 
-    void SetRetrieveOneInstanceIdentifier(bool retrieve)
-    {
-      retrieveOneInstanceIdentifier_ = retrieve;
-    }
+    void SetRetrieveOneInstanceIdentifier(bool retrieve);
 
     bool IsRetrieveOneInstanceIdentifier() const
     {
--- a/OrthancServer/Sources/Database/FindResponse.cpp	Wed May 08 18:28:36 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.cpp	Thu May 09 10:36:03 2024 +0200
@@ -376,7 +376,11 @@
 
   void FindResponse::Resource::SetOneInstanceIdentifier(const std::string& id)
   {
-    if (HasOneInstanceIdentifier())
+    if (level_ == ResourceType_Instance)
+    {
+      throw OrthancException(ErrorCode_BadParameterType);
+    }
+    else if (HasOneInstanceIdentifier())
     {
       throw OrthancException(ErrorCode_BadSequenceOfCalls);
     }
@@ -389,7 +393,11 @@
 
   const std::string& FindResponse::Resource::GetOneInstanceIdentifier() const
   {
-    if (HasOneInstanceIdentifier())
+    if (level_ == ResourceType_Instance)
+    {
+      throw OrthancException(ErrorCode_BadParameterType);
+    }
+    else if (HasOneInstanceIdentifier())
     {
       return *oneInstanceIdentifier_;
     }
@@ -402,7 +410,14 @@
 
   bool FindResponse::Resource::HasOneInstanceIdentifier() const
   {
-    return oneInstanceIdentifier_.get() != NULL;
+    if (level_ == ResourceType_Instance)
+    {
+      throw OrthancException(ErrorCode_BadParameterType);
+    }
+    else
+    {
+      return oneInstanceIdentifier_.get() != NULL;
+    }
   }
 
 
--- a/OrthancServer/Sources/ResourceFinder.cpp	Wed May 08 18:28:36 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Thu May 09 10:36:03 2024 +0200
@@ -449,8 +449,12 @@
     else
     {
       // This is not a main DICOM tag: We will be forced to access the DICOM file anyway
-      request_.SetRetrieveOneInstanceIdentifier(true);
       requestedTagsFromFileStorage_.insert(tag);
+
+      if (request_.GetLevel() != ResourceType_Instance)
+      {
+        request_.SetRetrieveOneInstanceIdentifier(true);
+      }
     }
 
     hasRequestedTags_ = true;
@@ -510,6 +514,10 @@
           {
             instancePublicId = resource.GetOneInstanceIdentifier();
           }
+          else if (request_.GetLevel() == ResourceType_Instance)
+          {
+            instancePublicId = resource.GetIdentifier();
+          }
           else
           {
             FindRequest requestDicomAttachment(request_.GetLevel());