diff OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4551:350a22c094f2 db-changes

testing replay of transactions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Mar 2021 19:36:59 +0100
parents 5b929e6b3c36
children efd90f778cd2
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Mar 02 16:51:19 2021 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Mar 02 19:36:59 2021 +0100
@@ -168,10 +168,11 @@
     {
       if (expand)
       {
-        Json::Value item;
-        if (index.LookupResource(item, *resource, level))
+        ServerIndex::ExpandResourceOperation operation(*resource, level);
+        index.Apply(operation);
+        if (operation.IsFound())
         {
-          answer.append(item);
+          answer.append(operation.GetResource());
         }
       }
       else
@@ -255,11 +256,13 @@
         .SetHttpGetSample(GetDocumentationSampleResource(resourceType), true);
       return;
     }
-    
-    Json::Value result;
-    if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType))
+
+    ServerIndex::ExpandResourceOperation operation(call.GetUriComponent("id", ""), resourceType);
+    OrthancRestApi::GetIndex(call).Apply(operation);
+
+    if (operation.IsFound())
     {
-      call.GetOutput().AnswerJson(result);
+      call.GetOutput().AnswerJson(operation.GetResource());
     }
   }
 
@@ -1414,13 +1417,36 @@
       return;
     }
 
-    std::map<MetadataType, std::string> metadata;
-
     assert(!call.GetFullUri().empty());
-    const std::string publicId = call.GetUriComponent("id", "");
-    const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str());
-
-    OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level);
+
+    typedef std::map<MetadataType, std::string>  Metadata;
+
+    Metadata metadata;
+    
+    class Operation : public ServerIndex::IReadOnlyOperations
+    {
+    private:
+      Metadata&     metadata_;
+      std::string   publicId_;
+      ResourceType  level_;
+
+    public:
+      Operation(Metadata& metadata,
+                const RestApiGetCall& call) :
+        metadata_(metadata),
+        publicId_(call.GetUriComponent("id", "")),
+        level_(StringToResourceType(call.GetFullUri() [0].c_str()))        
+      {
+      }
+      
+      virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
+      {
+        transaction.GetAllMetadata(metadata_, publicId_, level_);
+      }
+    };
+
+    Operation operation(metadata, call);
+    OrthancRestApi::GetIndex(call).Apply(operation);
 
     Json::Value result;
 
@@ -1428,8 +1454,7 @@
     {
       result = Json::objectValue;
       
-      for (std::map<MetadataType, std::string>::const_iterator 
-             it = metadata.begin(); it != metadata.end(); ++it)
+      for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
       {
         std::string key = EnumerationToString(it->first);
         result[key] = it->second;
@@ -1439,8 +1464,7 @@
     {
       result = Json::arrayValue;
       
-      for (std::map<MetadataType, std::string>::const_iterator 
-             it = metadata.begin(); it != metadata.end(); ++it)
+      for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
       {       
         result.append(EnumerationToString(it->first));
       }
@@ -2544,11 +2568,12 @@
     for (std::list<std::string>::const_iterator
            it = a.begin(); it != a.end(); ++it)
     {
-      Json::Value item;
-
-      if (OrthancRestApi::GetIndex(call).LookupResource(item, *it, end))
+      ServerIndex::ExpandResourceOperation operation(*it, end);
+      OrthancRestApi::GetIndex(call).Apply(operation);
+
+      if (operation.IsFound())
       {
-        result.append(item);
+        result.append(operation.GetResource());
       }
     }
 
@@ -2654,10 +2679,12 @@
 
     assert(currentType == end);
 
-    Json::Value result;
-    if (index.LookupResource(result, current, end))
+    ServerIndex::ExpandResourceOperation operation(current, end);
+    OrthancRestApi::GetIndex(call).Apply(operation);
+
+    if (operation.IsFound())
     {
-      call.GetOutput().AnswerJson(result);
+      call.GetOutput().AnswerJson(operation.GetResource());
     }
   }