changeset 2441:67c01a6f151e

added ?expand argument to /peers and /modalities routes
author amazy
date Tue, 05 Dec 2017 12:43:28 +0100
parents e11483be3f3b
children 330349d712f9
files NEWS OrthancServer/OrthancRestApi/OrthancRestModalities.cpp
diffstat 2 files changed, 54 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Nov 30 10:26:56 2017 +0100
+++ b/NEWS	Tue Dec 05 12:43:28 2017 +0100
@@ -1,6 +1,11 @@
 Pending changes in the mainline
 ===============================
 
+REST API
+--------
+
+* added ?expand argument to /peers and /modalities routes
+
 
 Version 1.3.1 (2017-11-29)
 ==========================
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Nov 30 10:26:56 2017 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Tue Dec 05 12:43:28 2017 +0100
@@ -792,14 +792,37 @@
     OrthancRestApi::SetOfStrings peers;
     Configuration::GetListOfOrthancPeers(peers);
 
-    Json::Value result = Json::arrayValue;
-    for (OrthancRestApi::SetOfStrings::const_iterator 
-           it = peers.begin(); it != peers.end(); ++it)
+    if (call.HasArgument("expand"))
     {
-      result.append(*it);
+      Json::Value result = Json::objectValue;
+      for (OrthancRestApi::SetOfStrings::const_iterator
+             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())
+        {
+          jsonPeer["Username"] = peer.GetUsername();
+        }
+        result[*it] = jsonPeer;
+      }
+      call.GetOutput().AnswerJson(result);
     }
+    else // if expand is not present, keep backward compatibility and return an array of peers
+    {
+      Json::Value result = Json::arrayValue;
+      for (OrthancRestApi::SetOfStrings::const_iterator
+             it = peers.begin(); it != peers.end(); ++it)
+      {
+        result.append(*it);
+      }
 
-    call.GetOutput().AnswerJson(result);
+      call.GetOutput().AnswerJson(result);
+    }
   }
 
   static void ListPeerOperations(RestApiGetCall& call)
@@ -872,14 +895,29 @@
     OrthancRestApi::SetOfStrings modalities;
     Configuration::GetListOfDicomModalities(modalities);
 
-    Json::Value result = Json::arrayValue;
-    for (OrthancRestApi::SetOfStrings::const_iterator 
-           it = modalities.begin(); it != modalities.end(); ++it)
+    if (call.HasArgument("expand"))
     {
-      result.append(*it);
+      Json::Value result = Json::objectValue;
+      for (OrthancRestApi::SetOfStrings::const_iterator
+             it = modalities.begin(); it != modalities.end(); ++it)
+      {
+        Json::Value modality;
+        Configuration::GetModalityUsingSymbolicName(*it).ToJson(modality);
+
+        result[*it] = modality;
+      }
+      call.GetOutput().AnswerJson(result);
     }
-
-    call.GetOutput().AnswerJson(result);
+    else // if expand is not present, keep backward compatibility and return an array of modalities ids
+    {
+      Json::Value result = Json::arrayValue;
+      for (OrthancRestApi::SetOfStrings::const_iterator
+             it = modalities.begin(); it != modalities.end(); ++it)
+      {
+        result.append(*it);
+      }
+      call.GetOutput().AnswerJson(result);
+    }
   }