changeset 211:b7aea293b965

list of resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Nov 2012 09:56:46 +0100
parents 96b7918a6a18
children f276b175dcaf
files Core/Enumerations.h Core/OrthancException.cpp Core/RestApi/RestApiOutput.cpp Core/RestApi/RestApiOutput.h NEWS OrthancServer/OrthancRestApi.cpp OrthancServer/OrthancRestApi2.cpp
diffstat 7 files changed, 50 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.h	Wed Nov 28 18:03:44 2012 +0100
+++ b/Core/Enumerations.h	Thu Nov 29 09:56:46 2012 +0100
@@ -46,6 +46,7 @@
     ErrorCode_ParameterOutOfRange,
     ErrorCode_NotEnoughMemory,
     ErrorCode_BadParameterType,
+    ErrorCode_BadSequenceOfCalls,
 
     // Specific error codes
     ErrorCode_UriSyntax,
--- a/Core/OrthancException.cpp	Wed Nov 28 18:03:44 2012 +0100
+++ b/Core/OrthancException.cpp	Thu Nov 29 09:56:46 2012 +0100
@@ -87,6 +87,9 @@
     case ErrorCode_UnknownResource:
       return "Unknown resource";
 
+    case ErrorCode_BadSequenceOfCalls:
+      return "Bad sequence of calls";
+
     case ErrorCode_Custom:
     default:
       return "???";
--- a/Core/RestApi/RestApiOutput.cpp	Wed Nov 28 18:03:44 2012 +0100
+++ b/Core/RestApi/RestApiOutput.cpp	Thu Nov 29 09:56:46 2012 +0100
@@ -32,6 +32,8 @@
 
 #include "RestApiOutput.h"
 
+#include "../OrthancException.h"
+
 namespace Orthanc
 {
   RestApiOutput::RestApiOutput(HttpOutput& output) : 
@@ -40,7 +42,6 @@
     existingResource_ = false;
   }
 
-
   RestApiOutput::~RestApiOutput()
   {
     if (!existingResource_)
@@ -48,15 +49,25 @@
       output_.SendHeader(Orthanc_HttpStatus_400_BadRequest);
     }
   }
+  
+  void RestApiOutput::CheckStatus()
+  {
+    if (existingResource_)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
 
   void RestApiOutput::AnswerFile(HttpFileSender& sender)
   {
+    CheckStatus();
     sender.Send(output_);
     existingResource_ = true;
   }
 
   void RestApiOutput::AnswerJson(const Json::Value& value)
   {
+    CheckStatus();
     Json::StyledWriter writer;
     std::string s = writer.write(value);
     output_.AnswerBufferWithContentType(s, "application/json");
@@ -66,12 +77,14 @@
   void RestApiOutput::AnswerBuffer(const std::string& buffer,
                                    const std::string& contentType)
   {
+    CheckStatus();
     output_.AnswerBufferWithContentType(buffer, contentType);
     existingResource_ = true;
   }
 
   void RestApiOutput::Redirect(const char* path)
   {
+    CheckStatus();
     output_.Redirect(path);
     existingResource_ = true;
   }
--- a/Core/RestApi/RestApiOutput.h	Wed Nov 28 18:03:44 2012 +0100
+++ b/Core/RestApi/RestApiOutput.h	Thu Nov 29 09:56:46 2012 +0100
@@ -45,6 +45,8 @@
     HttpOutput& output_;
     bool existingResource_;
 
+    void CheckStatus();
+
   public:
     RestApiOutput(HttpOutput& output);
 
--- a/NEWS	Wed Nov 28 18:03:44 2012 +0100
+++ b/NEWS	Thu Nov 29 09:56:46 2012 +0100
@@ -4,12 +4,16 @@
 Major changes
 -------------
 
-* Full refactoring of the DB schema
-* Generate a sample configuration file from command line
+* Full refactoring of the DB schema and of the REST API
+* Introduction of generic classes for REST APIs (in Core/RestApi)
+* The patient/study/series/instances are now indexed by SHA-1 digests
+  of their DICOM Instance IDs (and not by UUIDs anymore): The same
+  DICOM objects are thus always identified by the same Orthanc IDs
 
 Minor changes
 -------------
 
+* Generate a sample configuration file from command line
 * "CompletedSeries" event in the changes API
 * Thread to continuously flush DB to disk (robustness against reboots)
 
--- a/OrthancServer/OrthancRestApi.cpp	Wed Nov 28 18:03:44 2012 +0100
+++ b/OrthancServer/OrthancRestApi.cpp	Thu Nov 29 09:56:46 2012 +0100
@@ -401,20 +401,6 @@
     const Arguments& getArguments,
     const std::string& postData)
   {
-    if (uri.size() == 0)
-    {
-      if (method == "GET")
-      {
-        output.Redirect("app/explorer.html");
-      }
-      else
-      {
-        output.SendMethodNotAllowedError("GET");
-      }
-
-      return;
-    }
-
     bool existingResource = false;
     Json::Value result(Json::objectValue);
 
@@ -451,36 +437,6 @@
     }
 
 
-    // List all the patients, studies or series ---------------------------------
- 
-    if (uri.size() == 1 && 
-        (uri[0] == "series" ||
-         uri[0] == "studies" ||
-         uri[0] == "patients"))
-    {
-      if (method == "GET")
-      {
-        result = Json::Value(Json::arrayValue);
-
-        if (uri[0] == "instances")
-          index_.GetAllUuids(result, ResourceType_Instance);
-        else if (uri[0] == "series")
-          index_.GetAllUuids(result, ResourceType_Series);
-        else if (uri[0] == "studies")
-          index_.GetAllUuids(result, ResourceType_Study);
-        else if (uri[0] == "patients")
-          index_.GetAllUuids(result, ResourceType_Patient);
-
-        existingResource = true;
-      }
-      else
-      {
-        output.SendMethodNotAllowedError("GET");
-        return;
-      }
-    }
-
-
     // Information about a single object ----------------------------------------
  
     else if (uri.size() == 2 && 
--- a/OrthancServer/OrthancRestApi2.cpp	Wed Nov 28 18:03:44 2012 +0100
+++ b/OrthancServer/OrthancRestApi2.cpp	Thu Nov 29 09:56:46 2012 +0100
@@ -49,6 +49,11 @@
 namespace Orthanc
 {
   // System information -------------------------------------------------------
+
+  static void ServeRoot(RestApi::GetCall& call)
+  {
+    call.GetOutput().Redirect("app/explorer.html");
+  }
  
   static void GetSystemInformation(RestApi::GetCall& call)
   {
@@ -63,6 +68,19 @@
   }
 
 
+  // List all the patients, studies, series or instances ----------------------
+ 
+  template <enum ResourceType resourceType>
+  static void ListResources(RestApi::GetCall& call)
+  {
+    RETRIEVE_CONTEXT(call);
+
+    Json::Value result;
+    context.GetIndex().GetAllUuids(result, resourceType);
+    call.GetOutput().AnswerJson(result);
+  }
+
+
   // Changes API --------------------------------------------------------------
  
   static void GetChanges(RestApi::GetCall& call)
@@ -126,8 +144,14 @@
   {
     GetListOfDicomModalities(modalities_);
 
+    Register("/", ServeRoot);
     Register("/system", GetSystemInformation);
     Register("/changes", GetChanges);
     Register("/modalities", ListModalities);
+
+    Register("/instances", ListResources<ResourceType_Instance>);
+    Register("/patients", ListResources<ResourceType_Patient>);
+    Register("/series", ListResources<ResourceType_Series>);
+    Register("/studies", ListResources<ResourceType_Study>);
   }
 }