diff OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5609:4690a0d2b01e find-refactoring

preliminary support of requestedTags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 May 2024 18:28:36 +0200
parents 6e2dad336446
children 4640b7ae9a11
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed May 08 13:37:23 2024 +0200
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed May 08 18:28:36 2024 +0200
@@ -279,48 +279,27 @@
         resource->AddChildrenMetadata(*it, values);
       }
 
-      if (!request.GetRetrieveAttachmentOfOneInstance().empty())
+      if (request.IsRetrieveOneInstanceIdentifier())
       {
-        std::set<FileContentType> todo = request.GetRetrieveAttachmentOfOneInstance();
-        std::stack< std::pair<ResourceType, int64_t> > candidates;
-        candidates.push(std::make_pair(level, internalId));
-
-        while (!todo.empty() &&
-               !candidates.empty())
-        {
-          std::pair<ResourceType, int64_t> top = candidates.top();
-          candidates.pop();
-
-          if (top.first == ResourceType_Instance)
-          {
-            std::set<FileContentType> nextTodo;
+        int64_t currentId = internalId;
+        ResourceType currentLevel = level;
 
-            for (std::set<FileContentType>::const_iterator it = todo.begin(); it != todo.end(); ++it)
-            {
-              FileInfo attachment;
-              int64_t revision;
-              if (transaction_.LookupAttachment(attachment, revision, top.second, *it))
-              {
-                resource->AddAttachmentOfOneInstance(attachment);
-              }
-              else
-              {
-                nextTodo.insert(*it);
-              }
-            }
-
-            todo = nextTodo;
+        while (currentLevel != ResourceType_Instance)
+        {
+          std::list<int64_t> children;
+          transaction_.GetChildrenInternalId(children, currentId);
+          if (children.empty())
+          {
+            throw OrthancException(ErrorCode_DatabasePlugin);
           }
           else
           {
-            std::list<int64_t> children;
-            transaction_.GetChildrenInternalId(children, top.second);
-            for (std::list<int64_t>::const_iterator it = children.begin(); it != children.end(); ++it)
-            {
-              candidates.push(std::make_pair(GetChildResourceType(top.first), *it));
-            }
+            currentId = children.front();
+            currentLevel = GetChildResourceType(currentLevel);
           }
         }
+
+        resource->SetOneInstanceIdentifier(transaction_.GetPublicId(currentId));
       }
 
       response.Add(resource.release());