Mercurial > hg > orthanc-databases
comparison Framework/Plugins/DatabaseBackendAdapterV4.cpp @ 379:33b2aaffdd6c db-protobuf
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Mar 2023 08:47:35 +0200 |
parents | 9db9e0275ec0 |
children | cb91096fef06 |
comparison
equal
deleted
inserted
replaced
378:9db9e0275ec0 | 379:33b2aaffdd6c |
---|---|
98 Orthanc::DatabasePluginMessages::GetChanges::Response* getChanges_; | 98 Orthanc::DatabasePluginMessages::GetChanges::Response* getChanges_; |
99 Orthanc::DatabasePluginMessages::GetExportedResources::Response* getExportedResources_; | 99 Orthanc::DatabasePluginMessages::GetExportedResources::Response* getExportedResources_; |
100 Orthanc::DatabasePluginMessages::GetLastChange::Response* getLastChange_; | 100 Orthanc::DatabasePluginMessages::GetLastChange::Response* getLastChange_; |
101 Orthanc::DatabasePluginMessages::GetLastExportedResource::Response* getLastExportedResource_; | 101 Orthanc::DatabasePluginMessages::GetLastExportedResource::Response* getLastExportedResource_; |
102 Orthanc::DatabasePluginMessages::GetMainDicomTags::Response* getMainDicomTags_; | 102 Orthanc::DatabasePluginMessages::GetMainDicomTags::Response* getMainDicomTags_; |
103 Orthanc::DatabasePluginMessages::LookupAttachment::Response* lookupAttachment_; | |
103 | 104 |
104 void Clear() | 105 void Clear() |
105 { | 106 { |
106 deleteAttachment_ = NULL; | 107 deleteAttachment_ = NULL; |
107 deleteResource_ = NULL; | 108 deleteResource_ = NULL; |
108 getChanges_ = NULL; | 109 getChanges_ = NULL; |
109 getExportedResources_ = NULL; | 110 getExportedResources_ = NULL; |
110 getLastChange_ = NULL; | 111 getLastChange_ = NULL; |
111 getLastExportedResource_ = NULL; | 112 getLastExportedResource_ = NULL; |
113 lookupAttachment_ = NULL; | |
112 } | 114 } |
113 | 115 |
114 public: | 116 public: |
115 Output(Orthanc::DatabasePluginMessages::DeleteAttachment::Response& deleteAttachment) | 117 Output(Orthanc::DatabasePluginMessages::DeleteAttachment::Response& deleteAttachment) |
116 { | 118 { |
150 | 152 |
151 Output(Orthanc::DatabasePluginMessages::GetMainDicomTags::Response& getMainDicomTags) | 153 Output(Orthanc::DatabasePluginMessages::GetMainDicomTags::Response& getMainDicomTags) |
152 { | 154 { |
153 Clear(); | 155 Clear(); |
154 getMainDicomTags_ = &getMainDicomTags; | 156 getMainDicomTags_ = &getMainDicomTags; |
157 } | |
158 | |
159 Output(Orthanc::DatabasePluginMessages::LookupAttachment::Response& lookupAttachment) | |
160 { | |
161 Clear(); | |
162 lookupAttachment_ = &lookupAttachment; | |
155 } | 163 } |
156 | 164 |
157 virtual void SignalDeletedAttachment(const std::string& uuid, | 165 virtual void SignalDeletedAttachment(const std::string& uuid, |
158 int32_t contentType, | 166 int32_t contentType, |
159 uint64_t uncompressedSize, | 167 uint64_t uncompressedSize, |
234 const std::string& uncompressedHash, | 242 const std::string& uncompressedHash, |
235 int32_t compressionType, | 243 int32_t compressionType, |
236 uint64_t compressedSize, | 244 uint64_t compressedSize, |
237 const std::string& compressedHash) ORTHANC_OVERRIDE | 245 const std::string& compressedHash) ORTHANC_OVERRIDE |
238 { | 246 { |
239 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 247 if (lookupAttachment_ != NULL) |
248 { | |
249 if (lookupAttachment_->found()) | |
250 { | |
251 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
252 } | |
253 | |
254 lookupAttachment_->set_found(true); | |
255 lookupAttachment_->mutable_attachment()->set_uuid(uuid); | |
256 lookupAttachment_->mutable_attachment()->set_content_type(contentType); | |
257 lookupAttachment_->mutable_attachment()->set_uncompressed_size(uncompressedSize); | |
258 lookupAttachment_->mutable_attachment()->set_uncompressed_hash(uncompressedHash); | |
259 lookupAttachment_->mutable_attachment()->set_compression_type(compressionType); | |
260 lookupAttachment_->mutable_attachment()->set_compressed_size(compressedSize); | |
261 lookupAttachment_->mutable_attachment()->set_compressed_hash(compressedHash); | |
262 } | |
263 else | |
264 { | |
265 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
266 } | |
240 } | 267 } |
241 | 268 |
242 virtual void AnswerChange(int64_t seq, | 269 virtual void AnswerChange(int64_t seq, |
243 int32_t changeType, | 270 int32_t changeType, |
244 OrthancPluginResourceType resourceType, | 271 OrthancPluginResourceType resourceType, |
251 { | 278 { |
252 change = getChanges_->add_changes(); | 279 change = getChanges_->add_changes(); |
253 } | 280 } |
254 else if (getLastChange_ != NULL) | 281 else if (getLastChange_ != NULL) |
255 { | 282 { |
256 if (getLastChange_->exists()) | 283 if (getLastChange_->found()) |
257 { | 284 { |
258 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 285 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
259 } | 286 } |
260 | 287 |
261 getLastChange_->set_exists(true); | 288 getLastChange_->set_found(true); |
262 change = getLastChange_->mutable_change(); | 289 change = getLastChange_->mutable_change(); |
263 } | 290 } |
264 else | 291 else |
265 { | 292 { |
266 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 293 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
305 { | 332 { |
306 resource = getExportedResources_->add_resources(); | 333 resource = getExportedResources_->add_resources(); |
307 } | 334 } |
308 else if (getLastExportedResource_ != NULL) | 335 else if (getLastExportedResource_ != NULL) |
309 { | 336 { |
310 if (getLastExportedResource_->exists()) | 337 if (getLastExportedResource_->found()) |
311 { | 338 { |
312 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 339 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
313 } | 340 } |
314 | 341 |
315 getLastExportedResource_->set_exists(true); | 342 getLastExportedResource_->set_found(true); |
316 resource = getLastExportedResource_->mutable_resource(); | 343 resource = getLastExportedResource_->mutable_resource(); |
317 } | 344 } |
318 else | 345 else |
319 { | 346 { |
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 347 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
577 break; | 604 break; |
578 } | 605 } |
579 | 606 |
580 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE: | 607 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE: |
581 { | 608 { |
582 response.mutable_get_last_change()->set_exists(false); | 609 response.mutable_get_last_change()->set_found(false); |
583 | 610 |
584 Output output(*response.mutable_get_last_change()); | 611 Output output(*response.mutable_get_last_change()); |
585 backend.GetLastChange(output, manager); | 612 backend.GetLastChange(output, manager); |
586 break; | 613 break; |
587 } | 614 } |
588 | 615 |
589 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_EXPORTED_RESOURCE: | 616 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_EXPORTED_RESOURCE: |
590 { | 617 { |
591 response.mutable_get_last_exported_resource()->set_exists(false); | 618 response.mutable_get_last_exported_resource()->set_found(false); |
592 | 619 |
593 Output output(*response.mutable_get_last_exported_resource()); | 620 Output output(*response.mutable_get_last_exported_resource()); |
594 backend.GetLastExportedResource(output, manager); | 621 backend.GetLastExportedResource(output, manager); |
595 break; | 622 break; |
596 } | 623 } |
677 request.log_exported_resource().series_instance_uid().c_str(), | 704 request.log_exported_resource().series_instance_uid().c_str(), |
678 request.log_exported_resource().sop_instance_uid().c_str()); | 705 request.log_exported_resource().sop_instance_uid().c_str()); |
679 break; | 706 break; |
680 } | 707 } |
681 | 708 |
709 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_ATTACHMENT: | |
710 { | |
711 Output output(*response.mutable_lookup_attachment()); | |
712 | |
713 int64_t revision = -1; | |
714 backend.LookupAttachment(output, revision, manager, request.lookup_attachment().id(), request.lookup_attachment().content_type()); | |
715 | |
716 if (response.lookup_attachment().found()) | |
717 { | |
718 response.mutable_lookup_attachment()->set_revision(revision); | |
719 } | |
720 | |
721 break; | |
722 } | |
723 | |
724 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_GLOBAL_PROPERTY: | |
725 { | |
726 std::string value; | |
727 if (backend.LookupGlobalProperty(value, manager, request.lookup_global_property().server_id().c_str(), | |
728 request.lookup_global_property().property())) | |
729 { | |
730 response.mutable_lookup_global_property()->set_found(true); | |
731 response.mutable_lookup_global_property()->set_value(value); | |
732 } | |
733 else | |
734 { | |
735 response.mutable_lookup_global_property()->set_found(false); | |
736 } | |
737 | |
738 break; | |
739 } | |
740 | |
741 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_METADATA: | |
742 { | |
743 std::string value; | |
744 int64_t revision = -1; | |
745 if (backend.LookupMetadata(value, revision, manager, request.lookup_metadata().id(), request.lookup_metadata().metadata_type())) | |
746 { | |
747 response.mutable_lookup_metadata()->set_found(true); | |
748 response.mutable_lookup_metadata()->set_value(value); | |
749 response.mutable_lookup_metadata()->set_revision(revision); | |
750 } | |
751 else | |
752 { | |
753 response.mutable_lookup_metadata()->set_found(false); | |
754 } | |
755 | |
756 break; | |
757 } | |
758 | |
759 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_PARENT: | |
760 { | |
761 int64_t parent = -1; | |
762 if (backend.LookupParent(parent, manager, request.lookup_parent().id())) | |
763 { | |
764 response.mutable_lookup_parent()->set_found(true); | |
765 response.mutable_lookup_parent()->set_parent(parent); | |
766 } | |
767 else | |
768 { | |
769 response.mutable_lookup_parent()->set_found(false); | |
770 } | |
771 | |
772 break; | |
773 } | |
774 | |
775 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE: | |
776 { | |
777 int64_t internalId = -1; | |
778 OrthancPluginResourceType type; | |
779 if (backend.LookupResource(internalId, type, manager, request.lookup_resource().public_id().c_str())) | |
780 { | |
781 response.mutable_lookup_resource()->set_found(true); | |
782 response.mutable_lookup_resource()->set_internal_id(internalId); | |
783 response.mutable_lookup_resource()->set_type(Convert(type)); | |
784 } | |
785 else | |
786 { | |
787 response.mutable_lookup_resource()->set_found(false); | |
788 } | |
789 | |
790 break; | |
791 } | |
792 | |
793 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE: | |
794 { | |
795 int64_t patientId = -1; | |
796 if (backend.SelectPatientToRecycle(patientId, manager)) | |
797 { | |
798 response.mutable_select_patient_to_recycle()->set_found(true); | |
799 response.mutable_select_patient_to_recycle()->set_patient_id(patientId); | |
800 } | |
801 else | |
802 { | |
803 response.mutable_select_patient_to_recycle()->set_found(false); | |
804 } | |
805 | |
806 break; | |
807 } | |
808 | |
809 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE_WITH_AVOID: | |
810 { | |
811 int64_t patientId = -1; | |
812 if (backend.SelectPatientToRecycle(patientId, manager, request.select_patient_to_recycle_with_avoid().patient_id_to_avoid())) | |
813 { | |
814 response.mutable_select_patient_to_recycle_with_avoid()->set_found(true); | |
815 response.mutable_select_patient_to_recycle_with_avoid()->set_patient_id(patientId); | |
816 } | |
817 else | |
818 { | |
819 response.mutable_select_patient_to_recycle_with_avoid()->set_found(false); | |
820 } | |
821 | |
822 break; | |
823 } | |
824 | |
825 case Orthanc::DatabasePluginMessages::OPERATION_SET_GLOBAL_PROPERTY: | |
826 { | |
827 backend.SetGlobalProperty(manager, request.set_global_property().server_id().c_str(), | |
828 request.set_global_property().property(), | |
829 request.set_global_property().value().c_str()); | |
830 break; | |
831 } | |
832 | |
833 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_MAIN_DICOM_TAGS: | |
834 { | |
835 backend.ClearMainDicomTags(manager, request.clear_main_dicom_tags().id()); | |
836 break; | |
837 } | |
838 | |
839 case Orthanc::DatabasePluginMessages::OPERATION_SET_METADATA: | |
840 { | |
841 backend.SetMetadata(manager, request.set_metadata().id(), | |
842 request.set_metadata().metadata_type(), | |
843 request.set_metadata().value().c_str(), | |
844 request.set_metadata().revision()); | |
845 break; | |
846 } | |
847 | |
848 case Orthanc::DatabasePluginMessages::OPERATION_SET_PROTECTED_PATIENT: | |
849 { | |
850 backend.SetProtectedPatient(manager, request.set_protected_patient().patient_id(), | |
851 request.set_protected_patient().protected_patient()); | |
852 break; | |
853 } | |
854 | |
855 case Orthanc::DatabasePluginMessages::OPERATION_IS_DISK_SIZE_ABOVE: | |
856 { | |
857 bool above = (backend.GetTotalCompressedSize(manager) >= request.is_disk_size_above().threshold()); | |
858 response.mutable_is_disk_size_above()->set_result(above); | |
859 break; | |
860 } | |
861 | |
682 default: | 862 default: |
683 LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation(); | 863 LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation(); |
684 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 864 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
685 } | 865 } |
686 } | 866 } |