# HG changeset patch # User Sebastien Jodogne # Date 1544087458 -3600 # Node ID eea66afed0dbc74ad4676ad7a1edf2deb5c898f1 # Parent 2c16c29b287d43ba00f35668e8b42cf5e005b82f remove redundancies diff -r 2c16c29b287d -r eea66afed0db OrthancServer/OrthancRestApi/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Wed Dec 05 18:02:11 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp Thu Dec 06 10:10:58 2018 +0100 @@ -196,6 +196,20 @@ } } + + unsigned int OrthancRestApi::GetJobRequestPriority(const Json::Value& body) + { + if (body.type() != Json::objectValue || + !body.isMember(KEY_PRIORITY)) + { + return 0; // Default priority + } + else + { + return SerializationToolbox::ReadInteger(body, KEY_PRIORITY); + } + } + void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call, IJob* job, @@ -214,18 +228,11 @@ throw OrthancException(ErrorCode_BadFileFormat); } - int priority = 0; - - if (body.isMember(KEY_PRIORITY)) - { - priority = SerializationToolbox::ReadInteger(body, KEY_PRIORITY); - } - if (IsSynchronousJobRequest(isDefaultSynchronous, body)) { Json::Value successContent; if (context_.GetJobsEngine().GetRegistry().SubmitAndWait - (successContent, raii.release(), priority)) + (successContent, raii.release(), GetJobRequestPriority(body))) { // Success in synchronous execution call.GetOutput().AnswerJson(successContent); @@ -240,7 +247,8 @@ { // Asynchronous mode: Submit the job, but don't wait for its completion std::string id; - context_.GetJobsEngine().GetRegistry().Submit(id, raii.release(), priority); + context_.GetJobsEngine().GetRegistry().Submit + (id, raii.release(), GetJobRequestPriority(body)); Json::Value v; v["ID"] = id; diff -r 2c16c29b287d -r eea66afed0db OrthancServer/OrthancRestApi/OrthancRestApi.h --- a/OrthancServer/OrthancRestApi/OrthancRestApi.h Wed Dec 05 18:02:11 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestApi.h Thu Dec 06 10:10:58 2018 +0100 @@ -106,6 +106,8 @@ static bool IsSynchronousJobRequest(bool isDefaultSynchronous, const Json::Value& body); + static unsigned int GetJobRequestPriority(const Json::Value& body); + void SubmitGenericJob(RestApiPostCall& call, IJob* job, bool isDefaultSynchronous, diff -r 2c16c29b287d -r eea66afed0db OrthancServer/OrthancRestApi/OrthancRestArchive.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Wed Dec 05 18:02:11 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Thu Dec 06 10:10:58 2018 +0100 @@ -96,12 +96,15 @@ static void GetJobParameters(bool& synchronous, /* out */ bool& extended, /* out */ + int& priority, /* out */ const Json::Value& body, /* in */ const bool defaultExtended /* in */) { synchronous = OrthancRestApi::IsSynchronousJobRequest (true /* synchronous by default */, body); + priority = OrthancRestApi::GetJobRequestPriority(body); + if (body.type() == Json::objectValue && body.isMember(KEY_EXTENDED)) { @@ -117,6 +120,7 @@ static void SubmitJob(RestApiOutput& output, ServerContext& context, std::auto_ptr& job, + int priority, bool synchronous, const std::string& filename) { @@ -134,7 +138,7 @@ Json::Value publicContent; if (context.GetJobsEngine().GetRegistry().SubmitAndWait - (publicContent, job.release(), 0 /* TODO priority */)) + (publicContent, job.release(), priority)) { // The archive is now created: Prepare the sending of the ZIP file FilesystemHttpSender sender(tmp->GetPath()); @@ -156,7 +160,9 @@ } - static void CreateBatchArchive(RestApiPostCall& call) + template + static void CreateBatch(RestApiPostCall& call) { ServerContext& context = OrthancRestApi::GetContext(call); @@ -164,34 +170,12 @@ if (call.ParseJsonRequest(body)) { bool synchronous, extended; - GetJobParameters(synchronous, extended, body, false /* by default, not extended */); + int priority; + GetJobParameters(synchronous, extended, priority, body, DEFAULT_IS_EXTENDED); - std::auto_ptr job(new ArchiveJob(context, false, extended)); + std::auto_ptr job(new ArchiveJob(context, IS_MEDIA, extended)); AddResourcesOfInterest(*job, body); - SubmitJob(call.GetOutput(), context, job, synchronous, "Archive.zip"); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat, - "Expected a list of resources to archive in the body"); - } - } - - - template - static void CreateBatchMedia(RestApiPostCall& call) - { - ServerContext& context = OrthancRestApi::GetContext(call); - - Json::Value body; - if (call.ParseJsonRequest(body)) - { - bool synchronous, extended; - GetJobParameters(synchronous, extended, body, DEFAULT_EXTENDED); - - std::auto_ptr job(new ArchiveJob(context, true, extended)); - AddResourcesOfInterest(*job, body); - SubmitJob(call.GetOutput(), context, job, synchronous, "Archive.zip"); + SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip"); } else { @@ -201,44 +185,53 @@ } - static void CreateArchive(RestApiGetCall& call) - { - ServerContext& context = OrthancRestApi::GetContext(call); - - std::string id = call.GetUriComponent("id", ""); - - std::auto_ptr job(new ArchiveJob(context, false, false)); - job->AddResource(id); - - SubmitJob(call.GetOutput(), context, job, true /* synchronous */, id + ".zip"); - } - - - static void CreateMedia(RestApiGetCall& call) + template + static void CreateSingleGet(RestApiGetCall& call) { ServerContext& context = OrthancRestApi::GetContext(call); std::string id = call.GetUriComponent("id", ""); - std::auto_ptr job(new ArchiveJob(context, true, call.HasArgument("extended"))); + bool extended; + if (IS_MEDIA) + { + extended = call.HasArgument("extended"); + } + else + { + extended = false; + } + + std::auto_ptr job(new ArchiveJob(context, IS_MEDIA, extended)); job->AddResource(id); - SubmitJob(call.GetOutput(), context, job, true /* synchronous */, id + ".zip"); + SubmitJob(call.GetOutput(), context, job, 0 /* priority */, + true /* synchronous */, id + ".zip"); } void OrthancRestApi::RegisterArchive() { - Register("/patients/{id}/archive", CreateArchive); - Register("/studies/{id}/archive", CreateArchive); - Register("/series/{id}/archive", CreateArchive); + Register("/patients/{id}/archive", + CreateSingleGet); + Register("/studies/{id}/archive", + CreateSingleGet); + Register("/series/{id}/archive", + CreateSingleGet); - Register("/patients/{id}/media", CreateMedia); - Register("/studies/{id}/media", CreateMedia); - Register("/series/{id}/media", CreateMedia); + Register("/patients/{id}/media", + CreateSingleGet); + Register("/studies/{id}/media", + CreateSingleGet); + Register("/series/{id}/media", + CreateSingleGet); - Register("/tools/create-archive", CreateBatchArchive); - Register("/tools/create-media", CreateBatchMedia); - Register("/tools/create-media-extended", CreateBatchMedia); + Register("/tools/create-archive", + CreateBatch); + Register("/tools/create-media", + CreateBatch); + Register("/tools/create-media-extended", + CreateBatch); } }