comparison OrthancServer/OrthancInitialization.cpp @ 1422:52b2070fc8f1

improvements to the logs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Jun 2015 16:17:43 +0200
parents a3559b66fba7
children 7b7d597a190c
comparison
equal deleted inserted replaced
1421:d401287210d3 1422:52b2070fc8f1
111 111
112 112
113 Json::Reader reader; 113 Json::Reader reader;
114 if (!reader.parse(content, *configuration_)) 114 if (!reader.parse(content, *configuration_))
115 { 115 {
116 throw OrthancException("Unable to read the configuration file"); 116 LOG(ERROR) << "Unable to read the configuration file";
117 throw OrthancException(ErrorCode_BadFileFormat);
117 } 118 }
118 } 119 }
119 120
120 121
121 static void RegisterUserMetadata() 122 static void RegisterUserMetadata()
289 { 290 {
290 boost::mutex::scoped_lock lock(globalMutex_); 291 boost::mutex::scoped_lock lock(globalMutex_);
291 292
292 if (configuration_.get() == NULL) 293 if (configuration_.get() == NULL)
293 { 294 {
295 LOG(ERROR) << "The configuration file was not properly loaded";
294 throw OrthancException(ErrorCode_InexistentItem); 296 throw OrthancException(ErrorCode_InexistentItem);
295 } 297 }
296 298
297 if (!configuration_->isMember("DicomModalities")) 299 if (!configuration_->isMember("DicomModalities"))
298 { 300 {
299 throw OrthancException(ErrorCode_BadFileFormat); 301 LOG(ERROR) << "No modality with symbolic name: " << name;
302 throw OrthancException(ErrorCode_InexistentItem);
300 } 303 }
301 304
302 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; 305 const Json::Value& modalities = (*configuration_) ["DicomModalities"];
303 if (modalities.type() != Json::objectValue || 306 if (modalities.type() != Json::objectValue ||
304 !modalities.isMember(name)) 307 !modalities.isMember(name))
326 { 329 {
327 boost::mutex::scoped_lock lock(globalMutex_); 330 boost::mutex::scoped_lock lock(globalMutex_);
328 331
329 if (configuration_.get() == NULL) 332 if (configuration_.get() == NULL)
330 { 333 {
334 LOG(ERROR) << "The configuration file was not properly loaded";
331 throw OrthancException(ErrorCode_InexistentItem); 335 throw OrthancException(ErrorCode_InexistentItem);
332 } 336 }
333 337
334 if (!configuration_->isMember("OrthancPeers")) 338 if (!configuration_->isMember("OrthancPeers"))
335 { 339 {
336 throw OrthancException(ErrorCode_BadFileFormat); 340 LOG(ERROR) << "No peer with symbolic name: " << name;
341 throw OrthancException(ErrorCode_InexistentItem);
337 } 342 }
338 343
339 try 344 try
340 { 345 {
341 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; 346 const Json::Value& modalities = (*configuration_) ["OrthancPeers"];
372 } 377 }
373 378
374 const Json::Value& modalities = (*configuration_) [parameter]; 379 const Json::Value& modalities = (*configuration_) [parameter];
375 if (modalities.type() != Json::objectValue) 380 if (modalities.type() != Json::objectValue)
376 { 381 {
382 LOG(ERROR) << "Bad format of the \"DicomModalities\" configuration section";
377 throw OrthancException(ErrorCode_BadFileFormat); 383 throw OrthancException(ErrorCode_BadFileFormat);
378 } 384 }
379 385
380 Json::Value::Members members = modalities.getMemberNames(); 386 Json::Value::Members members = modalities.getMemberNames();
381 for (size_t i = 0; i < members.size(); i++) 387 for (size_t i = 0; i < members.size(); i++)
400 406
401 void Configuration::GetListOfDicomModalities(std::set<std::string>& target) 407 void Configuration::GetListOfDicomModalities(std::set<std::string>& target)
402 { 408 {
403 if (!ReadKeys(target, "DicomModalities", true)) 409 if (!ReadKeys(target, "DicomModalities", true))
404 { 410 {
405 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities"); 411 LOG(ERROR) << "Only alphanumeric and dash characters are allowed in the names of the modalities";
412 throw OrthancException(ErrorCode_BadFileFormat);
406 } 413 }
407 } 414 }
408 415
409 416
410 void Configuration::GetListOfOrthancPeers(std::set<std::string>& target) 417 void Configuration::GetListOfOrthancPeers(std::set<std::string>& target)
411 { 418 {
412 if (!ReadKeys(target, "OrthancPeers", true)) 419 if (!ReadKeys(target, "OrthancPeers", true))
413 { 420 {
414 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of Orthanc peers"); 421 LOG(ERROR) << "Only alphanumeric and dash characters are allowed in the names of Orthanc peers";
422 throw OrthancException(ErrorCode_BadFileFormat);
415 } 423 }
416 } 424 }
417 425
418 426
419 427
430 } 438 }
431 439
432 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; 440 const Json::Value& users = (*configuration_) ["RegisteredUsers"];
433 if (users.type() != Json::objectValue) 441 if (users.type() != Json::objectValue)
434 { 442 {
435 throw OrthancException("Badly formatted list of users"); 443 LOG(ERROR) << "Badly formatted list of users";
444 throw OrthancException(ErrorCode_BadFileFormat);
436 } 445 }
437 446
438 Json::Value::Members usernames = users.getMemberNames(); 447 Json::Value::Members usernames = users.getMemberNames();
439 for (size_t i = 0; i < usernames.size(); i++) 448 for (size_t i = 0; i < usernames.size(); i++)
440 { 449 {
493 502
494 const Json::Value& lst = (*configuration_) [key]; 503 const Json::Value& lst = (*configuration_) [key];
495 504
496 if (lst.type() != Json::arrayValue) 505 if (lst.type() != Json::arrayValue)
497 { 506 {
498 throw OrthancException("Badly formatted list of strings"); 507 LOG(ERROR) << "Badly formatted list of strings";
508 throw OrthancException(ErrorCode_BadFileFormat);
499 } 509 }
500 510
501 for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++) 511 for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++)
502 { 512 {
503 target.push_back(lst[i].asString()); 513 target.push_back(lst[i].asString());
575 { 585 {
576 return modality; 586 return modality;
577 } 587 }
578 else 588 else
579 { 589 {
580 throw OrthancException("Unknown modality for AET: " + aet); 590 LOG(ERROR) << "Unknown modality for AET: " << aet;
591 throw OrthancException(ErrorCode_InexistentItem);
581 } 592 }
582 } 593 }
583 594
584 595
585 void Configuration::UpdateModality(const std::string& symbolicName, 596 void Configuration::UpdateModality(const std::string& symbolicName,
587 { 598 {
588 boost::mutex::scoped_lock lock(globalMutex_); 599 boost::mutex::scoped_lock lock(globalMutex_);
589 600
590 if (configuration_.get() == NULL) 601 if (configuration_.get() == NULL)
591 { 602 {
603 LOG(ERROR) << "The configuration file was not properly loaded";
592 throw OrthancException(ErrorCode_InternalError); 604 throw OrthancException(ErrorCode_InternalError);
593 } 605 }
594 606
595 if (!configuration_->isMember("DicomModalities")) 607 if (!configuration_->isMember("DicomModalities"))
596 { 608 {
598 } 610 }
599 611
600 Json::Value& modalities = (*configuration_) ["DicomModalities"]; 612 Json::Value& modalities = (*configuration_) ["DicomModalities"];
601 if (modalities.type() != Json::objectValue) 613 if (modalities.type() != Json::objectValue)
602 { 614 {
615 LOG(ERROR) << "Bad file format for modality: " << symbolicName;
603 throw OrthancException(ErrorCode_BadFileFormat); 616 throw OrthancException(ErrorCode_BadFileFormat);
604 } 617 }
605 618
606 modalities.removeMember(symbolicName); 619 modalities.removeMember(symbolicName);
607 620
615 { 628 {
616 boost::mutex::scoped_lock lock(globalMutex_); 629 boost::mutex::scoped_lock lock(globalMutex_);
617 630
618 if (configuration_.get() == NULL) 631 if (configuration_.get() == NULL)
619 { 632 {
633 LOG(ERROR) << "The configuration file was not properly loaded";
620 throw OrthancException(ErrorCode_InternalError); 634 throw OrthancException(ErrorCode_InternalError);
621 } 635 }
622 636
623 if (!configuration_->isMember("DicomModalities")) 637 if (!configuration_->isMember("DicomModalities"))
624 { 638 {
639 LOG(ERROR) << "No modality with symbolic name: " << symbolicName;
625 throw OrthancException(ErrorCode_BadFileFormat); 640 throw OrthancException(ErrorCode_BadFileFormat);
626 } 641 }
627 642
628 Json::Value& modalities = (*configuration_) ["DicomModalities"]; 643 Json::Value& modalities = (*configuration_) ["DicomModalities"];
629 if (modalities.type() != Json::objectValue) 644 if (modalities.type() != Json::objectValue)
630 { 645 {
646 LOG(ERROR) << "Bad file format for the \"DicomModalities\" configuration section";
631 throw OrthancException(ErrorCode_BadFileFormat); 647 throw OrthancException(ErrorCode_BadFileFormat);
632 } 648 }
633 649
634 modalities.removeMember(symbolicName.c_str()); 650 modalities.removeMember(symbolicName.c_str());
635 } 651 }
640 { 656 {
641 boost::mutex::scoped_lock lock(globalMutex_); 657 boost::mutex::scoped_lock lock(globalMutex_);
642 658
643 if (configuration_.get() == NULL) 659 if (configuration_.get() == NULL)
644 { 660 {
661 LOG(ERROR) << "The configuration file was not properly loaded";
645 throw OrthancException(ErrorCode_InternalError); 662 throw OrthancException(ErrorCode_InternalError);
646 } 663 }
647 664
648 if (!configuration_->isMember("OrthancPeers")) 665 if (!configuration_->isMember("OrthancPeers"))
649 { 666 {
667 LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
650 (*configuration_) ["OrthancPeers"] = Json::objectValue; 668 (*configuration_) ["OrthancPeers"] = Json::objectValue;
651 } 669 }
652 670
653 Json::Value& peers = (*configuration_) ["OrthancPeers"]; 671 Json::Value& peers = (*configuration_) ["OrthancPeers"];
654 if (peers.type() != Json::objectValue) 672 if (peers.type() != Json::objectValue)
655 { 673 {
674 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
656 throw OrthancException(ErrorCode_BadFileFormat); 675 throw OrthancException(ErrorCode_BadFileFormat);
657 } 676 }
658 677
659 peers.removeMember(symbolicName); 678 peers.removeMember(symbolicName);
660 679
668 { 687 {
669 boost::mutex::scoped_lock lock(globalMutex_); 688 boost::mutex::scoped_lock lock(globalMutex_);
670 689
671 if (configuration_.get() == NULL) 690 if (configuration_.get() == NULL)
672 { 691 {
692 LOG(ERROR) << "The configuration file was not properly loaded";
673 throw OrthancException(ErrorCode_InternalError); 693 throw OrthancException(ErrorCode_InternalError);
674 } 694 }
675 695
676 if (!configuration_->isMember("OrthancPeers")) 696 if (!configuration_->isMember("OrthancPeers"))
677 { 697 {
698 LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
678 throw OrthancException(ErrorCode_BadFileFormat); 699 throw OrthancException(ErrorCode_BadFileFormat);
679 } 700 }
680 701
681 Json::Value& peers = (*configuration_) ["OrthancPeers"]; 702 Json::Value& peers = (*configuration_) ["OrthancPeers"];
682 if (peers.type() != Json::objectValue) 703 if (peers.type() != Json::objectValue)
683 { 704 {
705 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
684 throw OrthancException(ErrorCode_BadFileFormat); 706 throw OrthancException(ErrorCode_BadFileFormat);
685 } 707 }
686 708
687 peers.removeMember(symbolicName.c_str()); 709 peers.removeMember(symbolicName.c_str());
688 } 710 }