comparison 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
comparison
equal deleted inserted replaced
2581:8da2cffc2378 2582:b3da733d984c
315 info.Serialize(json); 315 info.Serialize(json);
316 call.GetOutput().AnswerJson(json); 316 call.GetOutput().AnswerJson(json);
317 } 317 }
318 } 318 }
319 319
320 static void PauseJob(RestApiPostCall& call) 320
321 enum JobAction
322 {
323 JobAction_Cancel,
324 JobAction_Pause,
325 JobAction_Resubmit,
326 JobAction_Resume
327 };
328
329 template <JobAction action>
330 static void ApplyJobAction(RestApiPostCall& call)
321 { 331 {
322 std::string id = call.GetUriComponent("id", ""); 332 std::string id = call.GetUriComponent("id", "");
323 333
324 if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id)) 334 bool ok = false;
335
336 switch (action)
337 {
338 case JobAction_Cancel:
339 ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Cancel(id);
340 break;
341
342 case JobAction_Pause:
343 ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id);
344 break;
345
346 case JobAction_Resubmit:
347 ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resubmit(id);
348 break;
349
350 case JobAction_Resume:
351 ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resume(id);
352 break;
353
354 default:
355 throw OrthancException(ErrorCode_InternalError);
356 }
357
358 if (ok)
325 { 359 {
326 call.GetOutput().AnswerBuffer("{}", "application/json"); 360 call.GetOutput().AnswerBuffer("{}", "application/json");
327 } 361 }
328 } 362 }
329 363
345 Register("/plugins/{id}", GetPlugin); 379 Register("/plugins/{id}", GetPlugin);
346 Register("/plugins/explorer.js", GetOrthancExplorerPlugins); 380 Register("/plugins/explorer.js", GetOrthancExplorerPlugins);
347 381
348 Register("/jobs", ListJobs); 382 Register("/jobs", ListJobs);
349 Register("/jobs/{id}", GetJobInfo); 383 Register("/jobs/{id}", GetJobInfo);
350 Register("/jobs/{id}/pause", PauseJob); 384 Register("/jobs/{id}/cancel", ApplyJobAction<JobAction_Cancel>);
385 Register("/jobs/{id}/pause", ApplyJobAction<JobAction_Pause>);
386 Register("/jobs/{id}/resubmit", ApplyJobAction<JobAction_Resubmit>);
387 Register("/jobs/{id}/resume", ApplyJobAction<JobAction_Resume>);
351 } 388 }
352 } 389 }