Mercurial > hg > orthanc
comparison OrthancServer/OrthancConfiguration.cpp @ 2946:2e751f615e03
new configuration options: DicomModalitiesInDatabase and OrthancPeersInDatabase
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2018 17:15:29 +0100 |
parents | f395460af74d |
children | bbfd95a0c429 |
comparison
equal
deleted
inserted
replaced
2945:3c636087d060 | 2946:2e751f615e03 |
---|---|
42 | 42 |
43 #include "ServerIndex.h" | 43 #include "ServerIndex.h" |
44 | 44 |
45 | 45 |
46 static const char* const DICOM_MODALITIES = "DicomModalities"; | 46 static const char* const DICOM_MODALITIES = "DicomModalities"; |
47 static const char* const DICOM_MODALITIES_IN_DB = "DicomModalitiesInDatabase"; | |
47 static const char* const ORTHANC_PEERS = "OrthancPeers"; | 48 static const char* const ORTHANC_PEERS = "OrthancPeers"; |
48 | 49 static const char* const ORTHANC_PEERS_IN_DB = "OrthancPeersInDatabase"; |
49 | 50 |
50 namespace Orthanc | 51 namespace Orthanc |
51 { | 52 { |
52 static void AddFileToConfiguration(Json::Value& target, | 53 static void AddFileToConfiguration(Json::Value& target, |
53 const boost::filesystem::path& path) | 54 const boost::filesystem::path& path) |
208 modalities_[name] = modality; | 209 modalities_[name] = modality; |
209 } | 210 } |
210 } | 211 } |
211 | 212 |
212 | 213 |
213 void OrthancConfiguration::SaveModalitiesToJson(Json::Value& target) | |
214 { | |
215 target = Json::objectValue; | |
216 | |
217 for (Modalities::const_iterator it = modalities_.begin(); it != modalities_.end(); ++it) | |
218 { | |
219 Json::Value modality; | |
220 it->second.Serialize(modality, true /* force advanced format */); | |
221 | |
222 target[it->first] = modality; | |
223 } | |
224 } | |
225 | |
226 | |
227 void OrthancConfiguration::LoadPeersFromJson(const Json::Value& source) | 214 void OrthancConfiguration::LoadPeersFromJson(const Json::Value& source) |
228 { | 215 { |
229 peers_.clear(); | 216 peers_.clear(); |
230 | 217 |
231 if (source.type() != Json::objectValue) | 218 if (source.type() != Json::objectValue) |
246 peers_[name] = peer; | 233 peers_[name] = peer; |
247 } | 234 } |
248 } | 235 } |
249 | 236 |
250 | 237 |
238 void OrthancConfiguration::LoadModalities() | |
239 { | |
240 if (GetBooleanParameter(DICOM_MODALITIES_IN_DB, false)) | |
241 { | |
242 // Modalities are stored in the database | |
243 if (serverIndex_ == NULL) | |
244 { | |
245 throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); | |
246 } | |
247 else | |
248 { | |
249 std::string property = serverIndex_->GetGlobalProperty(GlobalProperty_Modalities, "{}"); | |
250 | |
251 Json::Reader reader; | |
252 Json::Value modalities; | |
253 if (reader.parse(property, modalities)) | |
254 { | |
255 LoadModalitiesFromJson(modalities); | |
256 } | |
257 else | |
258 { | |
259 LOG(ERROR) << "Cannot unserialize the list of modalities from the Orthanc database"; | |
260 throw OrthancException(ErrorCode_InternalError); | |
261 } | |
262 } | |
263 } | |
264 else | |
265 { | |
266 // Modalities are stored in the configuration files | |
267 if (json_.isMember(DICOM_MODALITIES)) | |
268 { | |
269 LoadModalitiesFromJson(json_[DICOM_MODALITIES]); | |
270 } | |
271 else | |
272 { | |
273 modalities_.clear(); | |
274 } | |
275 } | |
276 } | |
277 | |
278 void OrthancConfiguration::LoadPeers() | |
279 { | |
280 if (GetBooleanParameter(ORTHANC_PEERS_IN_DB, false)) | |
281 { | |
282 // Peers are stored in the database | |
283 if (serverIndex_ == NULL) | |
284 { | |
285 throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); | |
286 } | |
287 else | |
288 { | |
289 std::string property = serverIndex_->GetGlobalProperty(GlobalProperty_Peers, "{}"); | |
290 | |
291 Json::Reader reader; | |
292 Json::Value peers; | |
293 if (reader.parse(property, peers)) | |
294 { | |
295 LoadPeersFromJson(peers); | |
296 } | |
297 else | |
298 { | |
299 LOG(ERROR) << "Cannot unserialize the list of peers from the Orthanc database"; | |
300 throw OrthancException(ErrorCode_InternalError); | |
301 } | |
302 } | |
303 } | |
304 else | |
305 { | |
306 // Peers are stored in the configuration files | |
307 if (json_.isMember(ORTHANC_PEERS)) | |
308 { | |
309 LoadPeersFromJson(json_[ORTHANC_PEERS]); | |
310 } | |
311 else | |
312 { | |
313 peers_.clear(); | |
314 } | |
315 } | |
316 } | |
317 | |
318 | |
319 void OrthancConfiguration::SaveModalitiesToJson(Json::Value& target) | |
320 { | |
321 target = Json::objectValue; | |
322 | |
323 for (Modalities::const_iterator it = modalities_.begin(); it != modalities_.end(); ++it) | |
324 { | |
325 Json::Value modality; | |
326 it->second.Serialize(modality, true /* force advanced format */); | |
327 | |
328 target[it->first] = modality; | |
329 } | |
330 } | |
331 | |
332 | |
251 void OrthancConfiguration::SavePeersToJson(Json::Value& target) | 333 void OrthancConfiguration::SavePeersToJson(Json::Value& target) |
252 { | 334 { |
253 target = Json::objectValue; | 335 target = Json::objectValue; |
254 | 336 |
255 for (Peers::const_iterator it = peers_.begin(); it != peers_.end(); ++it) | 337 for (Peers::const_iterator it = peers_.begin(); it != peers_.end(); ++it) |
262 target[it->first] = peer; | 344 target[it->first] = peer; |
263 } | 345 } |
264 } | 346 } |
265 | 347 |
266 | 348 |
267 void OrthancConfiguration::LoadModalitiesAndPeers() | |
268 { | |
269 if (json_.isMember(DICOM_MODALITIES)) | |
270 { | |
271 LoadModalitiesFromJson(json_[DICOM_MODALITIES]); | |
272 } | |
273 else | |
274 { | |
275 // TODO - Read from DB | |
276 modalities_.clear(); | |
277 } | |
278 | |
279 if (json_.isMember(ORTHANC_PEERS)) | |
280 { | |
281 LoadPeersFromJson(json_[ORTHANC_PEERS]); | |
282 } | |
283 else | |
284 { | |
285 // TODO - Read from DB | |
286 peers_.clear(); | |
287 } | |
288 } | |
289 | |
290 | |
291 void OrthancConfiguration::SaveModalities() | 349 void OrthancConfiguration::SaveModalities() |
292 { | 350 { |
293 if (!modalities_.empty() || | 351 if (GetBooleanParameter(DICOM_MODALITIES_IN_DB, false)) |
294 json_.isMember(DICOM_MODALITIES)) | 352 { |
295 { | 353 // Modalities are stored in the database |
296 SaveModalitiesToJson(json_[DICOM_MODALITIES]); | 354 if (serverIndex_ == NULL) |
297 } | 355 { |
298 | 356 throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); |
299 // TODO - Write to DB | 357 } |
358 else | |
359 { | |
360 Json::Value modalities; | |
361 SaveModalitiesToJson(modalities); | |
362 | |
363 Json::FastWriter writer; | |
364 std::string s = writer.write(modalities); | |
365 | |
366 serverIndex_->SetGlobalProperty(GlobalProperty_Modalities, s); | |
367 } | |
368 } | |
369 else | |
370 { | |
371 // Modalities are stored in the configuration files | |
372 if (!modalities_.empty() || | |
373 json_.isMember(DICOM_MODALITIES)) | |
374 { | |
375 SaveModalitiesToJson(json_[DICOM_MODALITIES]); | |
376 } | |
377 } | |
300 } | 378 } |
301 | 379 |
302 | 380 |
303 void OrthancConfiguration::SavePeers() | 381 void OrthancConfiguration::SavePeers() |
304 { | 382 { |
305 if (!peers_.empty() || | 383 if (GetBooleanParameter(ORTHANC_PEERS_IN_DB, false)) |
306 json_.isMember(ORTHANC_PEERS)) | 384 { |
307 { | 385 // Peers are stored in the database |
308 SavePeersToJson(json_[ORTHANC_PEERS]); | 386 if (serverIndex_ == NULL) |
309 } | 387 { |
310 | 388 throw Orthanc::OrthancException(ErrorCode_BadSequenceOfCalls); |
311 // TODO - Write to DB | 389 } |
390 else | |
391 { | |
392 Json::Value peers; | |
393 SavePeersToJson(peers); | |
394 | |
395 Json::FastWriter writer; | |
396 std::string s = writer.write(peers); | |
397 | |
398 serverIndex_->SetGlobalProperty(GlobalProperty_Peers, s); | |
399 } | |
400 } | |
401 else | |
402 { | |
403 // Peers are stored in the configuration files | |
404 if (!peers_.empty() || | |
405 json_.isMember(ORTHANC_PEERS)) | |
406 { | |
407 SavePeersToJson(json_[ORTHANC_PEERS]); | |
408 } | |
409 } | |
312 } | 410 } |
313 | 411 |
314 | 412 |
315 OrthancConfiguration& OrthancConfiguration::GetInstance() | 413 OrthancConfiguration& OrthancConfiguration::GetInstance() |
316 { | 414 { |
437 p /= "Resources"; | 535 p /= "Resources"; |
438 p /= "Configuration.json"; | 536 p /= "Configuration.json"; |
439 configurationAbsolutePath_ = boost::filesystem::absolute(p).string(); | 537 configurationAbsolutePath_ = boost::filesystem::absolute(p).string(); |
440 #endif | 538 #endif |
441 } | 539 } |
442 | 540 } |
443 LoadModalitiesAndPeers(); | 541 |
542 | |
543 void OrthancConfiguration::LoadModalitiesAndPeers() | |
544 { | |
545 LoadModalities(); | |
546 LoadPeers(); | |
444 } | 547 } |
445 | 548 |
446 | 549 |
447 void OrthancConfiguration::GetDicomModalityUsingSymbolicName( | 550 void OrthancConfiguration::GetDicomModalityUsingSymbolicName( |
448 RemoteModalityParameters& modality, | 551 RemoteModalityParameters& modality, |