diff OrthancServer/Sources/ResourceFinder.cpp @ 5615:a10978a5e65c find-refactoring

expansion of single resources using ResourceFinder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 May 2024 12:24:29 +0200
parents 599ce5ed126c
children 1e92fb051fd7
line wrap: on
line diff
--- a/OrthancServer/Sources/ResourceFinder.cpp	Thu May 09 11:59:56 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Thu May 09 12:24:29 2024 +0200
@@ -581,4 +581,31 @@
       }
     }
   }
+
+
+  bool ResourceFinder::ExecuteOneResource(Json::Value& target,
+                                          ServerContext& context)
+  {
+    Json::Value answer;
+    Execute(answer, context);
+
+    if (answer.type() != Json::arrayValue)
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+    else if (answer.size() > 1)
+    {
+      throw OrthancException(ErrorCode_DatabasePlugin);
+    }
+    else if (answer.empty())
+    {
+      // Inexistent resource (or was deleted between the first and second phases)
+      return false;
+    }
+    else
+    {
+      target = answer[0];
+      return true;
+    }
+  }
 }