Mercurial > hg > orthanc
comparison OrthancServer/OrthancConfiguration.cpp @ 2956:bfee0b9f3209
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 15:11:42 +0100 |
parents | bbfd95a0c429 |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
2955:bbfd95a0c429 | 2956:bfee0b9f3209 |
---|---|
132 static void ReadConfiguration(Json::Value& target, | 132 static void ReadConfiguration(Json::Value& target, |
133 const char* configurationFile) | 133 const char* configurationFile) |
134 { | 134 { |
135 target = Json::objectValue; | 135 target = Json::objectValue; |
136 | 136 |
137 if (configurationFile) | 137 if (configurationFile != NULL) |
138 { | 138 { |
139 if (!boost::filesystem::exists(configurationFile)) | 139 if (!boost::filesystem::exists(configurationFile)) |
140 { | 140 { |
141 LOG(ERROR) << "Inexistent path to configuration: " << configurationFile; | 141 throw OrthancException(ErrorCode_InexistentFile, |
142 throw OrthancException(ErrorCode_InexistentFile); | 142 "Inexistent path to configuration: " + |
143 std::string(configurationFile)); | |
143 } | 144 } |
144 | 145 |
145 if (boost::filesystem::is_directory(configurationFile)) | 146 if (boost::filesystem::is_directory(configurationFile)) |
146 { | 147 { |
147 ScanFolderForConfiguration(target, configurationFile); | 148 ScanFolderForConfiguration(target, configurationFile); |
177 for (size_t j = 0; j < s.size(); j++) | 178 for (size_t j = 0; j < s.size(); j++) |
178 { | 179 { |
179 if (!isalnum(s[j]) && | 180 if (!isalnum(s[j]) && |
180 s[j] != '-') | 181 s[j] != '-') |
181 { | 182 { |
182 LOG(ERROR) << "Only alphanumeric and dash characters are allowed " | 183 throw OrthancException(ErrorCode_BadFileFormat, |
183 << "in the names of modalities/peers, but found: " << s; | 184 "Only alphanumeric and dash characters are allowed " |
184 throw OrthancException(ErrorCode_BadFileFormat); | 185 "in the names of modalities/peers, but found: " + s); |
185 } | 186 } |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 | 190 |
191 { | 192 { |
192 modalities_.clear(); | 193 modalities_.clear(); |
193 | 194 |
194 if (source.type() != Json::objectValue) | 195 if (source.type() != Json::objectValue) |
195 { | 196 { |
196 LOG(ERROR) << "Bad format of the \"" << DICOM_MODALITIES << "\" configuration section"; | 197 throw OrthancException(ErrorCode_BadFileFormat, |
197 throw OrthancException(ErrorCode_BadFileFormat); | 198 "Bad format of the \"" + std::string(DICOM_MODALITIES) + |
199 "\" configuration section"); | |
198 } | 200 } |
199 | 201 |
200 Json::Value::Members members = source.getMemberNames(); | 202 Json::Value::Members members = source.getMemberNames(); |
201 | 203 |
202 for (size_t i = 0; i < members.size(); i++) | 204 for (size_t i = 0; i < members.size(); i++) |
215 { | 217 { |
216 peers_.clear(); | 218 peers_.clear(); |
217 | 219 |
218 if (source.type() != Json::objectValue) | 220 if (source.type() != Json::objectValue) |
219 { | 221 { |
220 LOG(ERROR) << "Bad format of the \"" << ORTHANC_PEERS << "\" configuration section"; | 222 throw OrthancException(ErrorCode_BadFileFormat, |
221 throw OrthancException(ErrorCode_BadFileFormat); | 223 "Bad format of the \"" + std::string(ORTHANC_PEERS) + |
224 "\" configuration section"); | |
222 } | 225 } |
223 | 226 |
224 Json::Value::Members members = source.getMemberNames(); | 227 Json::Value::Members members = source.getMemberNames(); |
225 | 228 |
226 for (size_t i = 0; i < members.size(); i++) | 229 for (size_t i = 0; i < members.size(); i++) |
254 { | 257 { |
255 LoadModalitiesFromJson(modalities); | 258 LoadModalitiesFromJson(modalities); |
256 } | 259 } |
257 else | 260 else |
258 { | 261 { |
259 LOG(ERROR) << "Cannot unserialize the list of modalities from the Orthanc database"; | 262 throw OrthancException(ErrorCode_InternalError, |
260 throw OrthancException(ErrorCode_InternalError); | 263 "Cannot unserialize the list of modalities from the Orthanc database"); |
261 } | 264 } |
262 } | 265 } |
263 } | 266 } |
264 else | 267 else |
265 { | 268 { |
294 { | 297 { |
295 LoadPeersFromJson(peers); | 298 LoadPeersFromJson(peers); |
296 } | 299 } |
297 else | 300 else |
298 { | 301 { |
299 LOG(ERROR) << "Cannot unserialize the list of peers from the Orthanc database"; | 302 throw OrthancException(ErrorCode_InternalError, |
300 throw OrthancException(ErrorCode_InternalError); | 303 "Cannot unserialize the list of peers from the Orthanc database"); |
301 } | 304 } |
302 } | 305 } |
303 } | 306 } |
304 else | 307 else |
305 { | 308 { |
422 { | 425 { |
423 if (json_.isMember(parameter)) | 426 if (json_.isMember(parameter)) |
424 { | 427 { |
425 if (json_[parameter].type() != Json::stringValue) | 428 if (json_[parameter].type() != Json::stringValue) |
426 { | 429 { |
427 LOG(ERROR) << "The configuration option \"" << parameter << "\" must be a string"; | 430 throw OrthancException(ErrorCode_BadParameterType, |
428 throw OrthancException(ErrorCode_BadParameterType); | 431 "The configuration option \"" + parameter + "\" must be a string"); |
429 } | 432 } |
430 else | 433 else |
431 { | 434 { |
432 return json_[parameter].asString(); | 435 return json_[parameter].asString(); |
433 } | 436 } |
444 { | 447 { |
445 if (json_.isMember(parameter)) | 448 if (json_.isMember(parameter)) |
446 { | 449 { |
447 if (json_[parameter].type() != Json::intValue) | 450 if (json_[parameter].type() != Json::intValue) |
448 { | 451 { |
449 LOG(ERROR) << "The configuration option \"" << parameter << "\" must be an integer"; | 452 throw OrthancException(ErrorCode_BadParameterType, |
450 throw OrthancException(ErrorCode_BadParameterType); | 453 "The configuration option \"" + parameter + "\" must be an integer"); |
451 } | 454 } |
452 else | 455 else |
453 { | 456 { |
454 return json_[parameter].asInt(); | 457 return json_[parameter].asInt(); |
455 } | 458 } |
467 { | 470 { |
468 int v = GetIntegerParameter(parameter, defaultValue); | 471 int v = GetIntegerParameter(parameter, defaultValue); |
469 | 472 |
470 if (v < 0) | 473 if (v < 0) |
471 { | 474 { |
472 LOG(ERROR) << "The configuration option \"" << parameter << "\" must be a positive integer"; | 475 throw OrthancException(ErrorCode_ParameterOutOfRange, |
473 throw OrthancException(ErrorCode_ParameterOutOfRange); | 476 "The configuration option \"" + parameter + "\" must be a positive integer"); |
474 } | 477 } |
475 else | 478 else |
476 { | 479 { |
477 return static_cast<unsigned int>(v); | 480 return static_cast<unsigned int>(v); |
478 } | 481 } |
484 { | 487 { |
485 if (json_.isMember(parameter)) | 488 if (json_.isMember(parameter)) |
486 { | 489 { |
487 if (json_[parameter].type() != Json::booleanValue) | 490 if (json_[parameter].type() != Json::booleanValue) |
488 { | 491 { |
489 LOG(ERROR) << "The configuration option \"" << parameter | 492 throw OrthancException(ErrorCode_BadParameterType, |
490 << "\" must be a Boolean (true or false)"; | 493 "The configuration option \"" + parameter + |
491 throw OrthancException(ErrorCode_BadParameterType); | 494 "\" must be a Boolean (true or false)"); |
492 } | 495 } |
493 else | 496 else |
494 { | 497 { |
495 return json_[parameter].asBool(); | 498 return json_[parameter].asBool(); |
496 } | 499 } |
553 { | 556 { |
554 Modalities::const_iterator found = modalities_.find(name); | 557 Modalities::const_iterator found = modalities_.find(name); |
555 | 558 |
556 if (found == modalities_.end()) | 559 if (found == modalities_.end()) |
557 { | 560 { |
558 LOG(ERROR) << "No modality with symbolic name: " << name; | 561 throw OrthancException(ErrorCode_InexistentItem, |
559 throw OrthancException(ErrorCode_InexistentItem); | 562 "No modality with symbolic name: " + name); |
560 } | 563 } |
561 else | 564 else |
562 { | 565 { |
563 modality = found->second; | 566 modality = found->second; |
564 } | 567 } |
616 } | 619 } |
617 | 620 |
618 const Json::Value& users = json_["RegisteredUsers"]; | 621 const Json::Value& users = json_["RegisteredUsers"]; |
619 if (users.type() != Json::objectValue) | 622 if (users.type() != Json::objectValue) |
620 { | 623 { |
621 LOG(ERROR) << "Badly formatted list of users"; | 624 throw OrthancException(ErrorCode_BadFileFormat, "Badly formatted list of users"); |
622 throw OrthancException(ErrorCode_BadFileFormat); | |
623 } | 625 } |
624 | 626 |
625 Json::Value::Members usernames = users.getMemberNames(); | 627 Json::Value::Members usernames = users.getMemberNames(); |
626 for (size_t i = 0; i < usernames.size(); i++) | 628 for (size_t i = 0; i < usernames.size(); i++) |
627 { | 629 { |
651 | 653 |
652 const Json::Value& lst = json_[key]; | 654 const Json::Value& lst = json_[key]; |
653 | 655 |
654 if (lst.type() != Json::arrayValue) | 656 if (lst.type() != Json::arrayValue) |
655 { | 657 { |
656 LOG(ERROR) << "Badly formatted list of strings"; | 658 throw OrthancException(ErrorCode_BadFileFormat, "Badly formatted list of strings"); |
657 throw OrthancException(ErrorCode_BadFileFormat); | |
658 } | 659 } |
659 | 660 |
660 for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++) | 661 for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++) |
661 { | 662 { |
662 target.push_back(lst[i].asString()); | 663 target.push_back(lst[i].asString()); |
745 { | 746 { |
746 return modality; | 747 return modality; |
747 } | 748 } |
748 else | 749 else |
749 { | 750 { |
750 LOG(ERROR) << "Unknown modality for AET: " << aet; | 751 throw OrthancException(ErrorCode_InexistentItem, |
751 throw OrthancException(ErrorCode_InexistentItem); | 752 "Unknown modality for AET: " + aet); |
752 } | 753 } |
753 } | 754 } |
754 | 755 |
755 | 756 |
756 void OrthancConfiguration::UpdateModality(const std::string& symbolicName, | 757 void OrthancConfiguration::UpdateModality(const std::string& symbolicName, |