# HG changeset patch # User Sebastien Jodogne # Date 1354179406 -3600 # Node ID b7aea293b9658438cdedec0b20b382a2695ef9c8 # Parent 96b7918a6a185f425200f8070592a25fbd141718 list of resources diff -r 96b7918a6a18 -r b7aea293b965 Core/Enumerations.h --- 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, diff -r 96b7918a6a18 -r b7aea293b965 Core/OrthancException.cpp --- 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 "???"; diff -r 96b7918a6a18 -r b7aea293b965 Core/RestApi/RestApiOutput.cpp --- 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; } diff -r 96b7918a6a18 -r b7aea293b965 Core/RestApi/RestApiOutput.h --- 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); diff -r 96b7918a6a18 -r b7aea293b965 NEWS --- 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) diff -r 96b7918a6a18 -r b7aea293b965 OrthancServer/OrthancRestApi.cpp --- 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 && diff -r 96b7918a6a18 -r b7aea293b965 OrthancServer/OrthancRestApi2.cpp --- 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 + 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); + Register("/patients", ListResources); + Register("/series", ListResources); + Register("/studies", ListResources); } }