diff OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 2799:6e3a60b85da6

New primitives to access Orthanc peers from plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 22 Aug 2018 16:55:07 +0200
parents 6801f99bbc2f
children dc7330089736
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Tue Aug 21 10:42:16 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Wed Aug 22 16:55:07 2018 +0200
@@ -836,16 +836,18 @@
              it = peers.begin(); it != peers.end(); ++it)
       {
         WebServiceParameters peer;
-        Configuration::GetOrthancPeer(peer, *it);
-
-        Json::Value jsonPeer = Json::objectValue;
-        // only return the minimum information to identify the destination, do not include "security" information like passwords
-        jsonPeer["Url"] = peer.GetUrl();
-        if (!peer.GetUsername().empty())
+        
+        if (Configuration::GetOrthancPeer(peer, *it))
         {
-          jsonPeer["Username"] = peer.GetUsername();
+          Json::Value jsonPeer = Json::objectValue;
+          // only return the minimum information to identify the destination, do not include "security" information like passwords
+          jsonPeer["Url"] = peer.GetUrl();
+          if (!peer.GetUsername().empty())
+          {
+            jsonPeer["Username"] = peer.GetUsername();
+          }
+          result[*it] = jsonPeer;
         }
-        result[*it] = jsonPeer;
       }
       call.GetOutput().AnswerJson(result);
     }
@@ -886,12 +888,17 @@
     if (GetInstancesToExport(request, *job, remote, call))
     {
       WebServiceParameters peer;
-      Configuration::GetOrthancPeer(peer, remote);
-      
-      job->SetDescription("REST API");
-      job->SetPeer(peer);    
-      
-      SubmitJob(call, request, job.release());
+      if (Configuration::GetOrthancPeer(peer, remote))
+      {
+        job->SetDescription("REST API");
+        job->SetPeer(peer);    
+        SubmitJob(call, request, job.release());
+      }
+      else
+      {
+        LOG(ERROR) << "No peer with symbolic name: " << remote;
+        throw OrthancException(ErrorCode_UnknownResource);
+      }
     }
   }