Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp @ 5169:8b74aa4f3515
enforce the existence of the patient/study/instance while creating its archive
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 24 Feb 2023 18:07:35 +0100 |
parents | c9c052ba309c |
children | 0ea402b4d901 |
comparison
equal
deleted
inserted
replaced
5168:688b83f915bc | 5169:8b74aa4f3515 |
---|---|
59 throw OrthancException(ErrorCode_BadFileFormat, | 59 throw OrthancException(ErrorCode_BadFileFormat, |
60 "Expected a list of strings (Orthanc identifiers)"); | 60 "Expected a list of strings (Orthanc identifiers)"); |
61 } | 61 } |
62 else | 62 else |
63 { | 63 { |
64 job.AddResource(resources[i].asString()); | 64 job.AddResource(resources[i].asString(), false, ResourceType_Patient /* dummy value */); |
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 | 69 |
574 "Expected a list of resources to archive in the body"); | 574 "Expected a list of resources to archive in the body"); |
575 } | 575 } |
576 } | 576 } |
577 | 577 |
578 | 578 |
579 template <bool IS_MEDIA> | 579 template <ResourceType LEVEL, |
580 bool IS_MEDIA> | |
580 static void CreateSingleGet(RestApiGetCall& call) | 581 static void CreateSingleGet(RestApiGetCall& call) |
581 { | 582 { |
582 static const char* const TRANSCODE = "transcode"; | 583 static const char* const TRANSCODE = "transcode"; |
583 static const char* const FILENAME = "filename"; | 584 static const char* const FILENAME = "filename"; |
584 | 585 |
625 { | 626 { |
626 extended = false; | 627 extended = false; |
627 } | 628 } |
628 | 629 |
629 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); | 630 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
630 job->AddResource(id); | 631 job->AddResource(id, true, LEVEL); |
631 | 632 |
632 if (call.HasArgument(TRANSCODE)) | 633 if (call.HasArgument(TRANSCODE)) |
633 { | 634 { |
634 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, ""))); | 635 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, ""))); |
635 } | 636 } |
643 SubmitJob(call.GetOutput(), context, job, 0 /* priority */, | 644 SubmitJob(call.GetOutput(), context, job, 0 /* priority */, |
644 true /* synchronous */, filename); | 645 true /* synchronous */, filename); |
645 } | 646 } |
646 | 647 |
647 | 648 |
648 template <bool IS_MEDIA> | 649 template <ResourceType LEVEL, |
650 bool IS_MEDIA> | |
649 static void CreateSinglePost(RestApiPostCall& call) | 651 static void CreateSinglePost(RestApiPostCall& call) |
650 { | 652 { |
651 if (call.IsDocumentation()) | 653 if (call.IsDocumentation()) |
652 { | 654 { |
653 DocumentPostArguments(call, IS_MEDIA, false /* not extended by default */); | 655 DocumentPostArguments(call, IS_MEDIA, false /* not extended by default */); |
676 unsigned int loaderThreads; | 678 unsigned int loaderThreads; |
677 GetJobParameters(synchronous, extended, transcode, transferSyntax, | 679 GetJobParameters(synchronous, extended, transcode, transferSyntax, |
678 priority, loaderThreads, body, false /* by default, not extented */); | 680 priority, loaderThreads, body, false /* by default, not extented */); |
679 | 681 |
680 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); | 682 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
681 job->AddResource(id); | 683 job->AddResource(id, true, LEVEL); |
682 | 684 |
683 if (transcode) | 685 if (transcode) |
684 { | 686 { |
685 job->SetTranscode(transferSyntax); | 687 job->SetTranscode(transferSyntax); |
686 } | 688 } |
696 } | 698 } |
697 | 699 |
698 | 700 |
699 void OrthancRestApi::RegisterArchive() | 701 void OrthancRestApi::RegisterArchive() |
700 { | 702 { |
701 Register("/patients/{id}/archive", CreateSingleGet<false /* ZIP */>); | 703 Register("/patients/{id}/archive", CreateSingleGet<ResourceType_Patient, false /* ZIP */>); |
702 Register("/patients/{id}/archive", CreateSinglePost<false /* ZIP */>); | 704 Register("/patients/{id}/archive", CreateSinglePost<ResourceType_Patient, false /* ZIP */>); |
703 Register("/patients/{id}/media", CreateSingleGet<true /* media */>); | 705 Register("/patients/{id}/media", CreateSingleGet<ResourceType_Patient, true /* media */>); |
704 Register("/patients/{id}/media", CreateSinglePost<true /* media */>); | 706 Register("/patients/{id}/media", CreateSinglePost<ResourceType_Patient, true /* media */>); |
705 Register("/series/{id}/archive", CreateSingleGet<false /* ZIP */>); | 707 Register("/series/{id}/archive", CreateSingleGet<ResourceType_Series, false /* ZIP */>); |
706 Register("/series/{id}/archive", CreateSinglePost<false /* ZIP */>); | 708 Register("/series/{id}/archive", CreateSinglePost<ResourceType_Series, false /* ZIP */>); |
707 Register("/series/{id}/media", CreateSingleGet<true /* media */>); | 709 Register("/series/{id}/media", CreateSingleGet<ResourceType_Series, true /* media */>); |
708 Register("/series/{id}/media", CreateSinglePost<true /* media */>); | 710 Register("/series/{id}/media", CreateSinglePost<ResourceType_Series, true /* media */>); |
709 Register("/studies/{id}/archive", CreateSingleGet<false /* ZIP */>); | 711 Register("/studies/{id}/archive", CreateSingleGet<ResourceType_Study, false /* ZIP */>); |
710 Register("/studies/{id}/archive", CreateSinglePost<false /* ZIP */>); | 712 Register("/studies/{id}/archive", CreateSinglePost<ResourceType_Study, false /* ZIP */>); |
711 Register("/studies/{id}/media", CreateSingleGet<true /* media */>); | 713 Register("/studies/{id}/media", CreateSingleGet<ResourceType_Study, true /* media */>); |
712 Register("/studies/{id}/media", CreateSinglePost<true /* media */>); | 714 Register("/studies/{id}/media", CreateSinglePost<ResourceType_Study, true /* media */>); |
713 | 715 |
714 Register("/tools/create-archive", | 716 Register("/tools/create-archive", |
715 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>); | 717 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>); |
716 Register("/tools/create-media", | 718 Register("/tools/create-media", |
717 CreateBatch<true /* media */, false /* not extended by default */>); | 719 CreateBatch<true /* media */, false /* not extended by default */>); |