diff OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 2970:eea66afed0db

remove redundancies
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Dec 2018 10:10:58 +0100
parents 10c610e80b15
children cb5d75143da0
line wrap: on
line diff
--- 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;