comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 2128:9329ba17a069

Possibility to DELETE "dicom-as-json" attachments to reconstruct them
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Nov 2016 15:13:16 +0100
parents bfa92c9328d7
children 0c09d1af22f3
comparison
equal deleted inserted replaced
2127:bfa92c9328d7 2128:9329ba17a069
563 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata 563 if (IsUserMetadata(metadata)) // It is forbidden to modify internal metadata
564 { 564 {
565 OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata); 565 OrthancRestApi::GetIndex(call).DeleteMetadata(publicId, metadata);
566 call.GetOutput().AnswerBuffer("", "text/plain"); 566 call.GetOutput().AnswerBuffer("", "text/plain");
567 } 567 }
568 else
569 {
570 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
571 }
568 } 572 }
569 573
570 574
571 static void SetMetadata(RestApiPutCall& call) 575 static void SetMetadata(RestApiPutCall& call)
572 { 576 {
583 { 587 {
584 // It is forbidden to modify internal metadata 588 // It is forbidden to modify internal metadata
585 OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value); 589 OrthancRestApi::GetIndex(call).SetMetadata(publicId, metadata, value);
586 call.GetOutput().AnswerBuffer("", "text/plain"); 590 call.GetOutput().AnswerBuffer("", "text/plain");
587 } 591 }
592 else
593 {
594 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
595 }
588 } 596 }
589 597
590 598
591 599
592 600
677 } 685 }
678 else 686 else
679 { 687 {
680 // Return the raw data (possibly compressed), as stored on the filesystem 688 // Return the raw data (possibly compressed), as stored on the filesystem
681 std::string content; 689 std::string content;
682 context.ReadFile(content, publicId, type, false); 690 context.ReadAttachment(content, publicId, type, false);
683 call.GetOutput().AnswerBuffer(content, "application/octet-stream"); 691 call.GetOutput().AnswerBuffer(content, "application/octet-stream");
684 } 692 }
685 } 693 }
686 694
687 695
746 754
747 bool ok = false; 755 bool ok = false;
748 756
749 // First check whether the compressed data is correctly stored in the disk 757 // First check whether the compressed data is correctly stored in the disk
750 std::string data; 758 std::string data;
751 context.ReadFile(data, publicId, StringToContentType(name), false); 759 context.ReadAttachment(data, publicId, StringToContentType(name), false);
752 760
753 std::string actualMD5; 761 std::string actualMD5;
754 Toolbox::ComputeMD5(actualMD5, data); 762 Toolbox::ComputeMD5(actualMD5, data);
755 763
756 if (actualMD5 == info.GetCompressedMD5()) 764 if (actualMD5 == info.GetCompressedMD5())
761 { 769 {
762 ok = true; 770 ok = true;
763 } 771 }
764 else 772 else
765 { 773 {
766 context.ReadFile(data, publicId, StringToContentType(name), true); 774 context.ReadAttachment(data, publicId, StringToContentType(name), true);
767 Toolbox::ComputeMD5(actualMD5, data); 775 Toolbox::ComputeMD5(actualMD5, data);
768 ok = (actualMD5 == info.GetUncompressedMD5()); 776 ok = (actualMD5 == info.GetUncompressedMD5());
769 } 777 }
770 } 778 }
771 779
793 if (IsUserContentType(contentType) && // It is forbidden to modify internal attachments 801 if (IsUserContentType(contentType) && // It is forbidden to modify internal attachments
794 context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize())) 802 context.AddAttachment(publicId, StringToContentType(name), call.GetBodyData(), call.GetBodySize()))
795 { 803 {
796 call.GetOutput().AnswerBuffer("{}", "application/json"); 804 call.GetOutput().AnswerBuffer("{}", "application/json");
797 } 805 }
806 else
807 {
808 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
809 }
798 } 810 }
799 811
800 812
801 static void DeleteAttachment(RestApiDeleteCall& call) 813 static void DeleteAttachment(RestApiDeleteCall& call)
802 { 814 {
804 816
805 std::string publicId = call.GetUriComponent("id", ""); 817 std::string publicId = call.GetUriComponent("id", "");
806 std::string name = call.GetUriComponent("name", ""); 818 std::string name = call.GetUriComponent("name", "");
807 FileContentType contentType = StringToContentType(name); 819 FileContentType contentType = StringToContentType(name);
808 820
809 if (IsUserContentType(contentType)) // It is forbidden to delete internal attachments 821 bool allowed;
822 if (IsUserContentType(contentType))
823 {
824 allowed = true;
825 }
826 else if (Configuration::GetGlobalBoolParameter("StoreDicom", true) &&
827 contentType == FileContentType_DicomAsJson)
828 {
829 allowed = true;
830 }
831 else
832 {
833 // It is forbidden to delete internal attachments, except for
834 // the "DICOM as JSON" summary as of Orthanc 1.2.0 (this summary
835 // would be automatically reconstructed on the next GET call)
836 allowed = false;
837 }
838
839 if (allowed)
810 { 840 {
811 OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType); 841 OrthancRestApi::GetIndex(call).DeleteAttachment(publicId, contentType);
812 call.GetOutput().AnswerBuffer("{}", "application/json"); 842 call.GetOutput().AnswerBuffer("{}", "application/json");
843 }
844 else
845 {
846 call.GetOutput().SignalError(HttpStatus_403_Forbidden);
813 } 847 }
814 } 848 }
815 849
816 850
817 template <enum CompressionType compression> 851 template <enum CompressionType compression>