comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5239:178b0434256a db-protobuf

added primitives to exchange labels with plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 11:31:05 +0200
parents d0f7c742d397
children a7d95f951f8a
comparison
equal deleted inserted replaced
5238:367e8af46cfd 5239:178b0434256a
974 default: 974 default:
975 throw OrthancException(ErrorCode_ParameterOutOfRange); 975 throw OrthancException(ErrorCode_ParameterOutOfRange);
976 } 976 }
977 } 977 }
978 978
979 if (!withLabels.empty() || 979 for (std::set<std::string>::const_iterator it = withLabels.begin(); it != withLabels.end(); ++it)
980 !withoutLabels.empty()) 980 {
981 { 981 request.mutable_lookup_resources()->add_with_labels(*it);
982 throw OrthancException(ErrorCode_NotImplemented); // TODO 982 }
983
984 for (std::set<std::string>::const_iterator it = withoutLabels.begin(); it != withoutLabels.end(); ++it)
985 {
986 request.mutable_lookup_resources()->add_without_labels(*it);
983 } 987 }
984 988
985 DatabasePluginMessages::TransactionResponse response; 989 DatabasePluginMessages::TransactionResponse response;
986 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_RESOURCES, request); 990 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_RESOURCES, request);
987 991
1150 1154
1151 1155
1152 virtual void AddLabel(int64_t resource, 1156 virtual void AddLabel(int64_t resource,
1153 const std::string& label) ORTHANC_OVERRIDE 1157 const std::string& label) ORTHANC_OVERRIDE
1154 { 1158 {
1155 throw OrthancException(ErrorCode_NotImplemented); 1159 if (database_.HasLabelsSupport())
1160 {
1161 DatabasePluginMessages::TransactionRequest request;
1162 request.mutable_add_label()->set_id(resource);
1163 request.mutable_add_label()->set_label(label);
1164
1165 ExecuteTransaction(DatabasePluginMessages::OPERATION_ADD_LABEL, request);
1166 }
1167 else
1168 {
1169 // This method shouldn't have been called
1170 throw OrthancException(ErrorCode_InternalError);
1171 }
1156 } 1172 }
1157 1173
1158 1174
1159 virtual void RemoveLabel(int64_t resource, 1175 virtual void RemoveLabel(int64_t resource,
1160 const std::string& label) ORTHANC_OVERRIDE 1176 const std::string& label) ORTHANC_OVERRIDE
1161 { 1177 {
1162 throw OrthancException(ErrorCode_NotImplemented); 1178 if (database_.HasLabelsSupport())
1179 {
1180 DatabasePluginMessages::TransactionRequest request;
1181 request.mutable_remove_label()->set_id(resource);
1182 request.mutable_remove_label()->set_label(label);
1183
1184 ExecuteTransaction(DatabasePluginMessages::OPERATION_REMOVE_LABEL, request);
1185 }
1186 else
1187 {
1188 // This method shouldn't have been called
1189 throw OrthancException(ErrorCode_InternalError);
1190 }
1163 } 1191 }
1164 1192
1165 1193
1166 virtual void ListLabels(std::set<std::string>& target, 1194 virtual void ListLabels(std::set<std::string>& target,
1167 int64_t resource) ORTHANC_OVERRIDE 1195 int64_t resource) ORTHANC_OVERRIDE
1168 { 1196 {
1169 throw OrthancException(ErrorCode_NotImplemented); 1197 if (database_.HasLabelsSupport())
1198 {
1199 DatabasePluginMessages::TransactionRequest request;
1200 request.mutable_list_labels()->set_id(resource);
1201
1202 DatabasePluginMessages::TransactionResponse response;
1203 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_LABELS, request);
1204
1205 target.clear();
1206 for (int i = 0; i < response.list_labels().labels().size(); i++)
1207 {
1208 target.insert(response.list_labels().labels(i));
1209 }
1210 }
1211 else
1212 {
1213 // This method shouldn't have been called
1214 throw OrthancException(ErrorCode_InternalError);
1215 }
1170 } 1216 }
1171 }; 1217 };
1172 1218
1173 1219
1174 OrthancPluginDatabaseV4::OrthancPluginDatabaseV4(SharedLibrary& library, 1220 OrthancPluginDatabaseV4::OrthancPluginDatabaseV4(SharedLibrary& library,