diff OrthancServer/OrthancRestApi/OrthancRestSystem.cpp @ 2582:b3da733d984c jobs

job actions in Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 May 2018 17:58:06 +0200
parents 3372c5255333
children a3fdfb6979ed
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri May 11 17:33:19 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri May 11 17:58:06 2018 +0200
@@ -317,11 +317,45 @@
     }
   }
 
-  static void PauseJob(RestApiPostCall& call)
+
+  enum JobAction
+  {
+    JobAction_Cancel,
+    JobAction_Pause,
+    JobAction_Resubmit,
+    JobAction_Resume
+  };
+
+  template <JobAction action>
+  static void ApplyJobAction(RestApiPostCall& call)
   {
     std::string id = call.GetUriComponent("id", "");
 
-    if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id))
+    bool ok = false;
+
+    switch (action)
+    {
+      case JobAction_Cancel:
+        ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Cancel(id);
+        break;
+
+      case JobAction_Pause:
+        ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id);
+        break;
+ 
+      case JobAction_Resubmit:
+        ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resubmit(id);
+        break;
+
+      case JobAction_Resume:
+        ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resume(id);
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_InternalError);
+    }
+    
+    if (ok)
     {
       call.GetOutput().AnswerBuffer("{}", "application/json");
     }
@@ -347,6 +381,9 @@
 
     Register("/jobs", ListJobs);
     Register("/jobs/{id}", GetJobInfo);
-    Register("/jobs/{id}/pause", PauseJob);
+    Register("/jobs/{id}/cancel", ApplyJobAction<JobAction_Cancel>);
+    Register("/jobs/{id}/pause", ApplyJobAction<JobAction_Pause>);
+    Register("/jobs/{id}/resubmit", ApplyJobAction<JobAction_Resubmit>);
+    Register("/jobs/{id}/resume", ApplyJobAction<JobAction_Resume>);
   }
 }