# HG changeset patch # User Sebastien Jodogne # Date 1561389303 -7200 # Node ID 6fe42a335a8068d14f125d682b81f7db294ac1f9 # Parent 0371b65d5f76014d19ad8940de9fe3c0dda23860 WebServiceParameters::GetBooleanUserProperty() diff -r 0371b65d5f76 -r 6fe42a335a80 Core/WebServiceParameters.cpp --- a/Core/WebServiceParameters.cpp Mon Jun 24 16:55:28 2019 +0200 +++ b/Core/WebServiceParameters.cpp Mon Jun 24 17:15:03 2019 +0200 @@ -289,13 +289,22 @@ { if (!IsReservedKey(*it)) { - if (peer[*it].type() != Json::stringValue) + switch (peer[*it].type()) { - throw OrthancException(ErrorCode_BadFileFormat); - } - else - { - userProperties_[*it] = peer[*it].asString(); + case Json::stringValue: + userProperties_[*it] = peer[*it].asString(); + break; + + case Json::booleanValue: + userProperties_[*it] = peer[*it].asBool() ? "1" : "0"; + break; + + case Json::intValue: + userProperties_[*it] = boost::lexical_cast(peer[*it].asInt()); + break; + + default: + throw OrthancException(ErrorCode_BadFileFormat); } } } @@ -402,6 +411,33 @@ return true; } } + + + bool WebServiceParameters::GetBooleanUserProperty(const std::string& key, + bool defaultValue) const + { + Dictionary::const_iterator found = userProperties_.find(key); + + if (found == userProperties_.end()) + { + return defaultValue; + } + else if (found->second == "0" || + found->second == "false") + { + return false; + } + else if (found->second == "1" || + found->second == "true") + { + return true; + } + else + { + throw OrthancException(ErrorCode_BadFileFormat, "Bad value for a Boolean user property in the parameters " + "of a Web service: Property \"" + key + "\" equals: " + found->second); + } + } bool WebServiceParameters::IsAdvancedFormatNeeded() const diff -r 0371b65d5f76 -r 6fe42a335a80 Core/WebServiceParameters.h --- a/Core/WebServiceParameters.h Mon Jun 24 16:55:28 2019 +0200 +++ b/Core/WebServiceParameters.h Mon Jun 24 17:15:03 2019 +0200 @@ -162,7 +162,10 @@ void ListUserProperties(std::set& target) const; bool LookupUserProperty(std::string& value, - const std::string& key) const; + const std::string& key) const; + + bool GetBooleanUserProperty(const std::string& key, + bool defaultValue) const; bool IsAdvancedFormatNeeded() const;