Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp @ 4417:a4518adede59
openapi for plugins and jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Dec 2020 17:40:35 +0100 |
parents | ad646ff506d0 |
children | 9d6fa3da8f00 |
comparison
equal
deleted
inserted
replaced
4416:0b27841950d5 | 4417:a4518adede59 |
---|---|
320 | 320 |
321 // Plugins information ------------------------------------------------------ | 321 // Plugins information ------------------------------------------------------ |
322 | 322 |
323 static void ListPlugins(RestApiGetCall& call) | 323 static void ListPlugins(RestApiGetCall& call) |
324 { | 324 { |
325 if (call.IsDocumentation()) | |
326 { | |
327 call.GetDocumentation() | |
328 .SetTag("System") | |
329 .SetSummary("List plugins") | |
330 .SetDescription("List all the installed plugins") | |
331 .AddAnswerType(MimeType_Json, "JSON array containing the identifiers of the installed plugins") | |
332 .SetHttpGetSample("https://demo.orthanc-server.com/plugins", true); | |
333 return; | |
334 } | |
335 | |
325 Json::Value v = Json::arrayValue; | 336 Json::Value v = Json::arrayValue; |
326 | 337 |
327 v.append("explorer.js"); | 338 v.append("explorer.js"); |
328 | 339 |
329 if (OrthancRestApi::GetContext(call).HasPlugins()) | 340 if (OrthancRestApi::GetContext(call).HasPlugins()) |
344 } | 355 } |
345 | 356 |
346 | 357 |
347 static void GetPlugin(RestApiGetCall& call) | 358 static void GetPlugin(RestApiGetCall& call) |
348 { | 359 { |
360 if (call.IsDocumentation()) | |
361 { | |
362 call.GetDocumentation() | |
363 .SetTag("System") | |
364 .SetSummary("Get plugin") | |
365 .SetDescription("Get system information about the plugin whose identifier is provided in the URL") | |
366 .SetUriArgument("id", "Identifier of the job of interest") | |
367 .AddAnswerType(MimeType_Json, "JSON object containing information about the plugin") | |
368 .SetHttpGetSample("https://demo.orthanc-server.com/plugins/dicom-web", true); | |
369 return; | |
370 } | |
371 | |
349 if (!OrthancRestApi::GetContext(call).HasPlugins()) | 372 if (!OrthancRestApi::GetContext(call).HasPlugins()) |
350 { | 373 { |
351 return; | 374 return; |
352 } | 375 } |
353 | 376 |
427 | 450 |
428 // Jobs information ------------------------------------------------------ | 451 // Jobs information ------------------------------------------------------ |
429 | 452 |
430 static void ListJobs(RestApiGetCall& call) | 453 static void ListJobs(RestApiGetCall& call) |
431 { | 454 { |
455 if (call.IsDocumentation()) | |
456 { | |
457 call.GetDocumentation() | |
458 .SetTag("Jobs") | |
459 .SetSummary("List jobs") | |
460 .SetDescription("List all the available jobs") | |
461 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, | |
462 "If present, retrieve detailed information about the individual jobs", false) | |
463 .AddAnswerType(MimeType_Json, "JSON array containing either the jobs identifiers, or detailed information " | |
464 "about the reported jobs (if `expand` argument is provided)") | |
465 .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/jobs", 3); | |
466 return; | |
467 } | |
468 | |
432 bool expand = call.HasArgument("expand"); | 469 bool expand = call.HasArgument("expand"); |
433 | 470 |
434 Json::Value v = Json::arrayValue; | 471 Json::Value v = Json::arrayValue; |
435 | 472 |
436 std::set<std::string> jobs; | 473 std::set<std::string> jobs; |
458 call.GetOutput().AnswerJson(v); | 495 call.GetOutput().AnswerJson(v); |
459 } | 496 } |
460 | 497 |
461 static void GetJobInfo(RestApiGetCall& call) | 498 static void GetJobInfo(RestApiGetCall& call) |
462 { | 499 { |
500 if (call.IsDocumentation()) | |
501 { | |
502 Json::Value sample; | |
503 sample["CompletionTime"] = "20201227T161842.520129"; | |
504 sample["Content"]["ArchiveSizeMB"] = 22; | |
505 sample["Content"]["Description"] = "REST API"; | |
506 sample["Content"]["InstancesCount"] = 232; | |
507 sample["Content"]["UncompressedSizeMB"] = 64; | |
508 sample["CreationTime"] = "20201227T161836.428311"; | |
509 sample["EffectiveRuntime"] = 6.0810000000000004; | |
510 sample["ErrorCode"] = 0; | |
511 sample["ErrorDescription"] = "Success"; | |
512 sample["ID"] = "645ecb02-7c0e-4465-b767-df873222dcfb"; | |
513 sample["Priority"] = 0; | |
514 sample["Progress"] = 100; | |
515 sample["State"] = "Success"; | |
516 sample["Timestamp"] = "20201228T160340.253201"; | |
517 sample["Type"] = "Media"; | |
518 | |
519 call.GetDocumentation() | |
520 .SetTag("Jobs") | |
521 .SetSummary("Get job") | |
522 .SetDescription("Retrieve detailed information about the job whose identifier is provided in the URL: " | |
523 "https://book.orthanc-server.com/users/advanced-rest.html#jobs") | |
524 .SetUriArgument("id", "Identifier of the job of interest") | |
525 .AddAnswerType(MimeType_Json, "JSON object detailing the job") | |
526 .SetSample(sample); | |
527 return; | |
528 } | |
529 | |
463 std::string id = call.GetUriComponent("id", ""); | 530 std::string id = call.GetUriComponent("id", ""); |
464 | 531 |
465 JobInfo info; | 532 JobInfo info; |
466 if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().GetJobInfo(info, id)) | 533 if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().GetJobInfo(info, id)) |
467 { | 534 { |
472 } | 539 } |
473 | 540 |
474 | 541 |
475 static void GetJobOutput(RestApiGetCall& call) | 542 static void GetJobOutput(RestApiGetCall& call) |
476 { | 543 { |
544 if (call.IsDocumentation()) | |
545 { | |
546 call.GetDocumentation() | |
547 .SetTag("Jobs") | |
548 .SetSummary("Get job output") | |
549 .SetDescription("Retrieve some output produced by a job. As of Orthanc 1.8.2, only the jobs that generate a " | |
550 "DICOMDIR media or a ZIP archive provide such an output (with `key` equals to `archive`).") | |
551 .SetUriArgument("id", "Identifier of the job of interest") | |
552 .SetUriArgument("key", "Name of the output of interest") | |
553 .AddAnswerType(MimeType_Binary, "Content of the output of the job"); | |
554 return; | |
555 } | |
556 | |
477 std::string job = call.GetUriComponent("id", ""); | 557 std::string job = call.GetUriComponent("id", ""); |
478 std::string key = call.GetUriComponent("key", ""); | 558 std::string key = call.GetUriComponent("key", ""); |
479 | 559 |
480 std::string value; | 560 std::string value; |
481 MimeType mime; | 561 MimeType mime; |
502 }; | 582 }; |
503 | 583 |
504 template <JobAction action> | 584 template <JobAction action> |
505 static void ApplyJobAction(RestApiPostCall& call) | 585 static void ApplyJobAction(RestApiPostCall& call) |
506 { | 586 { |
587 if (call.IsDocumentation()) | |
588 { | |
589 std::string verb; | |
590 switch (action) | |
591 { | |
592 case JobAction_Cancel: | |
593 verb = "Cancel"; | |
594 break; | |
595 | |
596 case JobAction_Pause: | |
597 verb = "Pause"; | |
598 break; | |
599 | |
600 case JobAction_Resubmit: | |
601 verb = "Resubmit"; | |
602 break; | |
603 | |
604 case JobAction_Resume: | |
605 verb = "Resume"; | |
606 break; | |
607 | |
608 default: | |
609 throw OrthancException(ErrorCode_InternalError); | |
610 } | |
611 | |
612 call.GetDocumentation() | |
613 .SetTag("Jobs") | |
614 .SetSummary(verb + " job") | |
615 .SetDescription(verb + " the job whose identifier is provided in the URL. Check out the " | |
616 "Orthanc Book for more information about the state machine applicable to jobs: " | |
617 "https://book.orthanc-server.com/users/advanced-rest.html#jobs") | |
618 .SetUriArgument("id", "Identifier of the job of interest") | |
619 .AddAnswerType(MimeType_Json, "Empty JSON object in the case of a success"); | |
620 return; | |
621 } | |
622 | |
507 std::string id = call.GetUriComponent("id", ""); | 623 std::string id = call.GetUriComponent("id", ""); |
508 | 624 |
509 bool ok = false; | 625 bool ok = false; |
510 | 626 |
511 switch (action) | 627 switch (action) |