changeset 1063:0332e6e8c679

Fix automated generation of the list of resource children in the REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Jul 2014 16:06:26 +0200
parents 804a75413ee7
children cd20e2568fc2
files Core/RestApi/RestApi.cpp Core/RestApi/RestApi.h Core/RestApi/RestApiHierarchy.cpp NEWS OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/OrthancRestApi/OrthancRestModalities.cpp
diffstat 6 files changed, 27 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Core/RestApi/RestApi.cpp	Fri Jul 25 14:51:18 2014 +0200
+++ b/Core/RestApi/RestApi.cpp	Fri Jul 25 16:06:26 2014 +0200
@@ -195,13 +195,6 @@
       return true;
     }
 
-    Json::Value directory;
-    if (root_.GetDirectory(directory, uri))
-    {
-      wrappedOutput.AnswerJson(directory);
-      return true;
-    }
-
     std::set<HttpMethod> methods;
     root_.GetAcceptedMethods(methods, uri);
 
@@ -243,4 +236,15 @@
   {
     root_.Register(path, handler);
   }
+  
+  void RestApi::AutoListChildren(RestApiGetCall& call)
+  {
+    RestApi& context = call.GetContext();
+
+    Json::Value directory;
+    if (context.root_.GetDirectory(directory, call.GetFullUri()))
+    {
+      call.GetOutput().AnswerJson(directory);
+    }    
+  }
 }
--- a/Core/RestApi/RestApi.h	Fri Jul 25 14:51:18 2014 +0200
+++ b/Core/RestApi/RestApi.h	Fri Jul 25 16:06:26 2014 +0200
@@ -44,6 +44,8 @@
     RestApiHierarchy root_;
 
   public:
+    static void AutoListChildren(RestApiGetCall& call);
+
     virtual bool Handle(HttpOutput& output,
                         HttpMethod method,
                         const UriComponents& uri,
--- a/Core/RestApi/RestApiHierarchy.cpp	Fri Jul 25 14:51:18 2014 +0200
+++ b/Core/RestApi/RestApiHierarchy.cpp	Fri Jul 25 16:06:26 2014 +0200
@@ -35,6 +35,7 @@
 #include "../OrthancException.h"
 
 #include <cassert>
+#include <stdio.h>
 
 namespace Orthanc
 {
@@ -274,8 +275,7 @@
 
   bool RestApiHierarchy::CanGenerateDirectory() const
   {
-    return (!handlers_.HasHandler(HttpMethod_Get) && 
-            universalHandlers_.IsEmpty() &&
+    return (universalHandlers_.IsEmpty() &&
             wildcardChildren_.size() == 0);
   }
 
--- a/NEWS	Fri Jul 25 14:51:18 2014 +0200
+++ b/NEWS	Fri Jul 25 16:06:26 2014 +0200
@@ -9,7 +9,6 @@
 * On-the-fly conversion of JSON to XML according to the HTTP Accept header
 * C-Echo SCU in the REST API
 * Lua scripts can do HTTP requests, and thus can call Web services
-* Fix build of Google Log with Visual Studio >= 11.0
 
 Plugins
 -------
@@ -17,6 +16,12 @@
 * Lookup for DICOM UIDs in the plugin SDK
 * Plugins have access to the HTTP headers and can answer with HTTP status codes
 
+Fixes
+-----
+
+* Fix build of Google Log with Visual Studio >= 11.0
+* Fix automated generation of the list of resource children in the REST API
+
 
 Version 0.8.0 (2014/07/10)
 ==========================
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Fri Jul 25 14:51:18 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Fri Jul 25 16:06:26 2014 +0200
@@ -96,5 +96,9 @@
     RegisterArchive();
 
     Register("/instances", UploadDicomFile);
+
+    // Auto-generated directories
+    Register("/tools", RestApi::AutoListChildren);
+    Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren);
   }
 }
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Fri Jul 25 14:51:18 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Fri Jul 25 16:06:26 2014 +0200
@@ -391,9 +391,7 @@
     std::string id = call.GetUriComponent("id", "");
     if (IsExistingPeer(peers, id))
     {
-      Json::Value result = Json::arrayValue;
-      result.append("store");
-      call.GetOutput().AnswerJson(result);
+      RestApi::AutoListChildren(call);
     }
   }
 
@@ -458,15 +456,7 @@
     std::string id = call.GetUriComponent("id", "");
     if (IsExistingModality(modalities, id))
     {
-      Json::Value result = Json::arrayValue;
-      result.append("echo");
-      result.append("find-patient");
-      result.append("find-study");
-      result.append("find-series");
-      result.append("find-instance");
-      result.append("find");
-      result.append("store");
-      call.GetOutput().AnswerJson(result);
+      RestApi::AutoListChildren(call);
     }
   }