Mercurial > hg > orthanc
diff OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 2071:27fd34970c52
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 14:21:29 +0200 |
parents | 02c543c42e61 |
children | f8d4543e3fef |
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Thu Jul 14 09:05:22 2016 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Thu Jul 14 14:21:29 2016 +0200 @@ -683,58 +683,16 @@ return; } - static const char* LOCAL_AET = "LocalAet"; - std::string localAet = context.GetDefaultLocalApplicationEntityTitle(); - if (request.type() == Json::objectValue && - request.isMember(LOCAL_AET)) - { - if (request[LOCAL_AET].type() == Json::stringValue) - { - localAet = request[LOCAL_AET].asString(); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } - - uint16_t moveOriginatorID = 0; /* By default, not a C-MOVE */ - - static const char* MOVE_ORIGINATOR_ID = "MoveOriginatorID"; - if (request.type() == Json::objectValue && - request.isMember(MOVE_ORIGINATOR_ID)) - { - if (request[MOVE_ORIGINATOR_ID].type() != Json::intValue) - { - throw OrthancException(ErrorCode_BadFileFormat); - } + std::string localAet = Toolbox::GetJsonStringField(request, "LocalAet", context.GetDefaultLocalApplicationEntityTitle()); + bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", false); + int moveOriginatorID = Toolbox::GetJsonIntegerField(request, "MoveOriginatorID", 0 /* By default, not a C-MOVE */); - int v = request[MOVE_ORIGINATOR_ID].asInt(); - if (v <= 0 || v >= 65536) - { - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - else - { - moveOriginatorID = boost::lexical_cast<uint16_t>(v); - } + if (moveOriginatorID < 0 || + moveOriginatorID >= 65536) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); } - - static const char* PERMISSIVE = "Permissive"; - bool permissive = false; - if (request.type() == Json::objectValue && - request.isMember(PERMISSIVE)) - { - if (request[PERMISSIVE].type() == Json::booleanValue) - { - permissive = request[PERMISSIVE].asBool(); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } - + RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName(remote); ServerJob job; @@ -742,7 +700,7 @@ it = instances.begin(); it != instances.end(); ++it) { job.AddCommand(new StoreScuCommand(context, localAet, p, permissive, - moveOriginatorID)).AddInput(*it); + static_cast<uint16_t>(moveOriginatorID))).AddInput(*it); } job.SetDescription("HTTP request: Store-SCU to peer \"" + remote + "\""); @@ -784,33 +742,8 @@ ResourceType level = StringToResourceType(request["Level"].asCString()); - static const char* LOCAL_AET = "LocalAet"; - std::string localAet = context.GetDefaultLocalApplicationEntityTitle(); - if (request.isMember(LOCAL_AET)) - { - if (request[LOCAL_AET].type() == Json::stringValue) - { - localAet = request[LOCAL_AET].asString(); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } - - static const char* TARGET_AET = "TargetAet"; - std::string targetAet = context.GetDefaultLocalApplicationEntityTitle(); - if (request.isMember(TARGET_AET)) - { - if (request[TARGET_AET].type() == Json::stringValue) - { - targetAet = request[TARGET_AET].asString(); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } + std::string localAet = Toolbox::GetJsonStringField(request, "LocalAet", context.GetDefaultLocalApplicationEntityTitle()); + std::string targetAet = Toolbox::GetJsonStringField(request, "TargetAet", context.GetDefaultLocalApplicationEntityTitle()); const RemoteModalityParameters source = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));