Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.cpp @ 4555:456ed3fcff81 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Mar 2021 17:13:41 +0100 |
parents | efd90f778cd2 |
children | 2a0f8031fb93 |
comparison
equal
deleted
inserted
replaced
4554:efd90f778cd2 | 4555:456ed3fcff81 |
---|---|
1137 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); | 1137 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); |
1138 } | 1138 } |
1139 } | 1139 } |
1140 | 1140 |
1141 | 1141 |
1142 bool ServerIndex::LookupAttachment(FileInfo& attachment, | |
1143 const std::string& instanceUuid, | |
1144 FileContentType contentType) | |
1145 { | |
1146 boost::mutex::scoped_lock lock(mutex_); | |
1147 | |
1148 int64_t id; | |
1149 ResourceType type; | |
1150 if (!db_.LookupResource(id, type, instanceUuid)) | |
1151 { | |
1152 throw OrthancException(ErrorCode_UnknownResource); | |
1153 } | |
1154 | |
1155 if (db_.LookupAttachment(attachment, id, contentType)) | |
1156 { | |
1157 assert(attachment.GetContentType() == contentType); | |
1158 return true; | |
1159 } | |
1160 else | |
1161 { | |
1162 return false; | |
1163 } | |
1164 } | |
1165 | |
1166 | |
1167 | |
1168 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
1169 ResourceType resourceType) | |
1170 { | |
1171 boost::mutex::scoped_lock lock(mutex_); | |
1172 db_.GetAllPublicIds(target, resourceType); | |
1173 } | |
1174 | |
1175 | |
1176 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
1177 ResourceType resourceType, | |
1178 size_t since, | |
1179 size_t limit) | |
1180 { | |
1181 if (limit == 0) | |
1182 { | |
1183 target.clear(); | |
1184 return; | |
1185 } | |
1186 | |
1187 boost::mutex::scoped_lock lock(mutex_); | |
1188 db_.GetAllPublicIds(target, resourceType, since, limit); | |
1189 } | |
1190 | |
1191 | |
1192 template <typename T> | 1142 template <typename T> |
1193 static void FormatLog(Json::Value& target, | 1143 static void FormatLog(Json::Value& target, |
1194 const std::list<T>& log, | 1144 const std::list<T>& log, |
1195 const std::string& name, | 1145 const std::string& name, |
1196 bool done, | 1146 bool done, |
2444 { | 2394 { |
2445 private: | 2395 private: |
2446 ReadOnlyFunction func_; | 2396 ReadOnlyFunction func_; |
2447 | 2397 |
2448 public: | 2398 public: |
2449 ReadOnlyWrapper(ReadOnlyFunction func) : | 2399 explicit ReadOnlyWrapper(ReadOnlyFunction func) : |
2450 func_(func) | 2400 func_(func) |
2451 { | 2401 { |
2452 assert(func_ != NULL); | 2402 assert(func_ != NULL); |
2453 } | 2403 } |
2454 | 2404 |
2455 virtual void Apply(ReadOnlyTransaction& transaction) | 2405 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE |
2456 { | 2406 { |
2457 func_(transaction); | 2407 func_(transaction); |
2458 } | 2408 } |
2459 }; | 2409 }; |
2460 | 2410 |
2463 { | 2413 { |
2464 private: | 2414 private: |
2465 ReadWriteFunction func_; | 2415 ReadWriteFunction func_; |
2466 | 2416 |
2467 public: | 2417 public: |
2468 ReadWriteWrapper(ReadWriteFunction func) : | 2418 explicit ReadWriteWrapper(ReadWriteFunction func) : |
2469 func_(func) | 2419 func_(func) |
2470 { | 2420 { |
2471 assert(func_ != NULL); | 2421 assert(func_ != NULL); |
2472 } | 2422 } |
2473 | 2423 |
2474 virtual void Apply(ReadWriteTransaction& transaction) | 2424 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
2475 { | 2425 { |
2476 func_(transaction); | 2426 func_(transaction); |
2477 } | 2427 } |
2478 }; | 2428 }; |
2479 | 2429 |
2820 }; | 2770 }; |
2821 | 2771 |
2822 Operations operations(target, publicId, level); | 2772 Operations operations(target, publicId, level); |
2823 Apply(operations); | 2773 Apply(operations); |
2824 } | 2774 } |
2775 | |
2776 | |
2777 bool ServerIndex::LookupAttachment(FileInfo& attachment, | |
2778 const std::string& instancePublicId, | |
2779 FileContentType contentType) | |
2780 { | |
2781 class Operations : public ServerIndex::IReadOnlyOperations | |
2782 { | |
2783 private: | |
2784 FileInfo& attachment_; | |
2785 bool found_; | |
2786 std::string instancePublicId_; | |
2787 FileContentType contentType_; | |
2788 | |
2789 public: | |
2790 Operations(FileInfo& attachment, | |
2791 const std::string& instancePublicId, | |
2792 FileContentType contentType) : | |
2793 attachment_(attachment), | |
2794 found_(false), | |
2795 instancePublicId_(instancePublicId), | |
2796 contentType_(contentType) | |
2797 { | |
2798 } | |
2799 | |
2800 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
2801 { | |
2802 int64_t internalId; | |
2803 ResourceType type; | |
2804 if (!transaction.LookupResource(internalId, type, instancePublicId_)) | |
2805 { | |
2806 throw OrthancException(ErrorCode_UnknownResource); | |
2807 } | |
2808 else if (transaction.LookupAttachment(attachment_, internalId, contentType_)) | |
2809 { | |
2810 assert(attachment_.GetContentType() == contentType_); | |
2811 found_ = true; | |
2812 } | |
2813 else | |
2814 { | |
2815 found_ = false; | |
2816 } | |
2817 } | |
2818 | |
2819 bool HasFound() const | |
2820 { | |
2821 return found_; | |
2822 } | |
2823 }; | |
2824 | |
2825 Operations operations(attachment, instancePublicId, contentType); | |
2826 Apply(operations); | |
2827 return operations.HasFound(); | |
2828 } | |
2829 | |
2830 | |
2831 | |
2832 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
2833 ResourceType resourceType) | |
2834 { | |
2835 class Operations : public ServerIndex::IReadOnlyOperations | |
2836 { | |
2837 private: | |
2838 std::list<std::string>& target_; | |
2839 ResourceType resourceType_; | |
2840 | |
2841 public: | |
2842 Operations(std::list<std::string>& target, | |
2843 ResourceType resourceType) : | |
2844 target_(target), | |
2845 resourceType_(resourceType) | |
2846 { | |
2847 } | |
2848 | |
2849 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
2850 { | |
2851 transaction.GetAllPublicIds(target_, resourceType_); | |
2852 } | |
2853 }; | |
2854 | |
2855 Operations operations(target, resourceType); | |
2856 Apply(operations); | |
2857 } | |
2858 | |
2859 | |
2860 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
2861 ResourceType resourceType, | |
2862 size_t since, | |
2863 size_t limit) | |
2864 { | |
2865 if (limit == 0) | |
2866 { | |
2867 target.clear(); | |
2868 } | |
2869 else | |
2870 { | |
2871 class Operations : public ServerIndex::IReadOnlyOperations | |
2872 { | |
2873 private: | |
2874 std::list<std::string>& target_; | |
2875 ResourceType resourceType_; | |
2876 size_t since_; | |
2877 size_t limit_; | |
2878 | |
2879 public: | |
2880 Operations(std::list<std::string>& target, | |
2881 ResourceType resourceType, | |
2882 size_t since, | |
2883 size_t limit) : | |
2884 target_(target), | |
2885 resourceType_(resourceType), | |
2886 since_(since), | |
2887 limit_(limit) | |
2888 { | |
2889 } | |
2890 | |
2891 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
2892 { | |
2893 transaction.GetAllPublicIds(target_, resourceType_, since_, limit_); | |
2894 } | |
2895 }; | |
2896 | |
2897 Operations operations(target, resourceType, since, limit); | |
2898 Apply(operations); | |
2899 } | |
2900 } | |
2825 } | 2901 } |