Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 2998:0a52af0c66e7
sharing strings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Dec 2018 13:21:34 +0100 |
parents | bbfd95a0c429 |
children | 7695a9c81099 |
comparison
equal
deleted
inserted
replaced
2997:5a6a2c5bf73f | 2998:0a52af0c66e7 |
---|---|
1269 } | 1269 } |
1270 | 1270 |
1271 | 1271 |
1272 static void Find(RestApiPostCall& call) | 1272 static void Find(RestApiPostCall& call) |
1273 { | 1273 { |
1274 static const char* const KEY_CASE_SENSITIVE = "CaseSensitive"; | |
1275 static const char* const KEY_EXPAND = "Expand"; | |
1276 static const char* const KEY_LEVEL = "Level"; | |
1277 static const char* const KEY_LIMIT = "Limit"; | |
1278 static const char* const KEY_QUERY = "Query"; | |
1279 static const char* const KEY_SINCE = "Since"; | |
1280 | |
1274 ServerContext& context = OrthancRestApi::GetContext(call); | 1281 ServerContext& context = OrthancRestApi::GetContext(call); |
1275 | 1282 |
1276 Json::Value request; | 1283 Json::Value request; |
1277 if (call.ParseJsonRequest(request) && | 1284 if (call.ParseJsonRequest(request) && |
1278 request.type() == Json::objectValue && | 1285 request.type() == Json::objectValue && |
1279 request.isMember("Level") && | 1286 request.isMember(KEY_LEVEL) && |
1280 request.isMember("Query") && | 1287 request.isMember(KEY_QUERY) && |
1281 request["Level"].type() == Json::stringValue && | 1288 request[KEY_LEVEL].type() == Json::stringValue && |
1282 request["Query"].type() == Json::objectValue && | 1289 request[KEY_QUERY].type() == Json::objectValue && |
1283 (!request.isMember("CaseSensitive") || request["CaseSensitive"].type() == Json::booleanValue) && | 1290 (!request.isMember(KEY_CASE_SENSITIVE) || request[KEY_CASE_SENSITIVE].type() == Json::booleanValue) && |
1284 (!request.isMember("Limit") || request["Limit"].type() == Json::intValue) && | 1291 (!request.isMember(KEY_LIMIT) || request[KEY_LIMIT].type() == Json::intValue) && |
1285 (!request.isMember("Since") || request["Since"].type() == Json::intValue)) | 1292 (!request.isMember(KEY_SINCE) || request[KEY_SINCE].type() == Json::intValue)) |
1286 { | 1293 { |
1287 bool expand = false; | 1294 bool expand = false; |
1288 if (request.isMember("Expand")) | 1295 if (request.isMember(KEY_EXPAND)) |
1289 { | 1296 { |
1290 expand = request["Expand"].asBool(); | 1297 expand = request[KEY_EXPAND].asBool(); |
1291 } | 1298 } |
1292 | 1299 |
1293 bool caseSensitive = false; | 1300 bool caseSensitive = false; |
1294 if (request.isMember("CaseSensitive")) | 1301 if (request.isMember(KEY_CASE_SENSITIVE)) |
1295 { | 1302 { |
1296 caseSensitive = request["CaseSensitive"].asBool(); | 1303 caseSensitive = request[KEY_CASE_SENSITIVE].asBool(); |
1297 } | 1304 } |
1298 | 1305 |
1299 size_t limit = 0; | 1306 size_t limit = 0; |
1300 if (request.isMember("Limit")) | 1307 if (request.isMember(KEY_LIMIT)) |
1301 { | 1308 { |
1302 int tmp = request["Limit"].asInt(); | 1309 int tmp = request[KEY_LIMIT].asInt(); |
1303 if (tmp < 0) | 1310 if (tmp < 0) |
1304 { | 1311 { |
1305 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1312 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1306 } | 1313 } |
1307 | 1314 |
1308 limit = static_cast<size_t>(tmp); | 1315 limit = static_cast<size_t>(tmp); |
1309 } | 1316 } |
1310 | 1317 |
1311 size_t since = 0; | 1318 size_t since = 0; |
1312 if (request.isMember("Since")) | 1319 if (request.isMember(KEY_SINCE)) |
1313 { | 1320 { |
1314 int tmp = request["Since"].asInt(); | 1321 int tmp = request[KEY_SINCE].asInt(); |
1315 if (tmp < 0) | 1322 if (tmp < 0) |
1316 { | 1323 { |
1317 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1324 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1318 } | 1325 } |
1319 | 1326 |
1320 since = static_cast<size_t>(tmp); | 1327 since = static_cast<size_t>(tmp); |
1321 } | 1328 } |
1322 | 1329 |
1323 std::string level = request["Level"].asString(); | 1330 std::string level = request[KEY_LEVEL].asString(); |
1324 | 1331 |
1325 LookupResource query(StringToResourceType(level.c_str())); | 1332 LookupResource query(StringToResourceType(level.c_str())); |
1326 | 1333 |
1327 Json::Value::Members members = request["Query"].getMemberNames(); | 1334 Json::Value::Members members = request[KEY_QUERY].getMemberNames(); |
1328 for (size_t i = 0; i < members.size(); i++) | 1335 for (size_t i = 0; i < members.size(); i++) |
1329 { | 1336 { |
1330 if (request["Query"][members[i]].type() != Json::stringValue) | 1337 if (request[KEY_QUERY][members[i]].type() != Json::stringValue) |
1331 { | 1338 { |
1332 throw OrthancException(ErrorCode_BadRequest); | 1339 throw OrthancException(ErrorCode_BadRequest); |
1333 } | 1340 } |
1334 | 1341 |
1335 query.AddDicomConstraint(FromDcmtkBridge::ParseTag(members[i]), | 1342 query.AddDicomConstraint(FromDcmtkBridge::ParseTag(members[i]), |
1336 request["Query"][members[i]].asString(), | 1343 request[KEY_QUERY][members[i]].asString(), |
1337 caseSensitive); | 1344 caseSensitive); |
1338 } | 1345 } |
1339 | 1346 |
1340 bool isComplete; | 1347 bool isComplete; |
1341 std::list<std::string> resources; | 1348 std::list<std::string> resources; |