comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5249:f22c8fac764b db-protobuf

added "/tools/labels" to list all the labels that are associated with any resource
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Apr 2023 22:54:57 +0200
parents a7d95f951f8a
children fafdb6179829
comparison
equal deleted inserted replaced
5248:a7d95f951f8a 5249:f22c8fac764b
220 DatabasePluginMessages::TransactionResponse response; // Ignored 220 DatabasePluginMessages::TransactionResponse response; // Ignored
221 DatabasePluginMessages::TransactionRequest request; // Ignored 221 DatabasePluginMessages::TransactionRequest request; // Ignored
222 ExecuteTransaction(response, operation, request); 222 ExecuteTransaction(response, operation, request);
223 } 223 }
224 224
225
226 void ListLabelsInternal(std::set<std::string>& target,
227 bool isSingleResource,
228 int64_t resource)
229 {
230 if (database_.HasLabelsSupport())
231 {
232 DatabasePluginMessages::TransactionRequest request;
233 request.mutable_list_labels()->set_single_resource(isSingleResource);
234 request.mutable_list_labels()->set_id(resource);
235
236 DatabasePluginMessages::TransactionResponse response;
237 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_LABELS, request);
238
239 target.clear();
240 for (int i = 0; i < response.list_labels().labels().size(); i++)
241 {
242 target.insert(response.list_labels().labels(i));
243 }
244 }
245 else
246 {
247 // This method shouldn't have been called
248 throw OrthancException(ErrorCode_InternalError);
249 }
250 }
251
225 252
226 public: 253 public:
227 Transaction(OrthancPluginDatabaseV4& database, 254 Transaction(OrthancPluginDatabaseV4& database,
228 IDatabaseListener& listener, 255 IDatabaseListener& listener,
229 TransactionType type) : 256 TransactionType type) :
1204 1231
1205 1232
1206 virtual void ListLabels(std::set<std::string>& target, 1233 virtual void ListLabels(std::set<std::string>& target,
1207 int64_t resource) ORTHANC_OVERRIDE 1234 int64_t resource) ORTHANC_OVERRIDE
1208 { 1235 {
1209 if (database_.HasLabelsSupport()) 1236 ListLabelsInternal(target, true, resource);
1210 { 1237 }
1211 DatabasePluginMessages::TransactionRequest request; 1238
1212 request.mutable_list_labels()->set_id(resource); 1239
1213 1240 virtual void ListAllLabels(std::set<std::string>& target) ORTHANC_OVERRIDE
1214 DatabasePluginMessages::TransactionResponse response; 1241 {
1215 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_LABELS, request); 1242 ListLabelsInternal(target, false, -1);
1216
1217 target.clear();
1218 for (int i = 0; i < response.list_labels().labels().size(); i++)
1219 {
1220 target.insert(response.list_labels().labels(i));
1221 }
1222 }
1223 else
1224 {
1225 // This method shouldn't have been called
1226 throw OrthancException(ErrorCode_InternalError);
1227 }
1228 } 1243 }
1229 }; 1244 };
1230 1245
1231 1246
1232 OrthancPluginDatabaseV4::OrthancPluginDatabaseV4(SharedLibrary& library, 1247 OrthancPluginDatabaseV4::OrthancPluginDatabaseV4(SharedLibrary& library,