Mercurial > hg > orthanc
changeset 2304:563bf878407a
Argument "Since" in URI "/tools/find" (related to issue #53)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jul 2017 17:24:31 +0200 |
parents | 692527245856 |
children | 642d533fc2d8 |
files | NEWS OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h |
diffstat | 4 files changed, 36 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Mon Jul 10 11:31:48 2017 +0200 +++ b/NEWS Tue Jul 11 17:24:31 2017 +0200 @@ -1,6 +1,11 @@ Pending changes in the mainline =============================== +REST API +-------- + +* Argument "Since" in URI "/tools/find" (related to issue 53) + Plugins -------
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Mon Jul 10 11:31:48 2017 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Jul 11 17:24:31 2017 +0200 @@ -1154,7 +1154,8 @@ request["Level"].type() == Json::stringValue && request["Query"].type() == Json::objectValue && (!request.isMember("CaseSensitive") || request["CaseSensitive"].type() == Json::booleanValue) && - (!request.isMember("Limit") || request["Limit"].type() == Json::intValue)) + (!request.isMember("Limit") || request["Limit"].type() == Json::intValue) && + (!request.isMember("Since") || request["Since"].type() == Json::intValue)) { bool expand = false; if (request.isMember("Expand")) @@ -1180,6 +1181,18 @@ limit = static_cast<size_t>(tmp); } + size_t since = 0; + if (request.isMember("Since")) + { + int tmp = request["Since"].asInt(); + if (tmp < 0) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + since = static_cast<size_t>(tmp); + } + std::string level = request["Level"].asString(); LookupResource query(StringToResourceType(level.c_str())); @@ -1198,8 +1211,9 @@ } std::list<std::string> resources; - context.Apply(resources, query, limit); - AnswerListOfResources(call.GetOutput(), context.GetIndex(), resources, query.GetLevel(), expand); + context.Apply(resources, query, since, limit); + AnswerListOfResources(call.GetOutput(), context.GetIndex(), + resources, query.GetLevel(), expand); } else {
--- a/OrthancServer/ServerContext.cpp Mon Jul 10 11:31:48 2017 +0200 +++ b/OrthancServer/ServerContext.cpp Tue Jul 11 17:24:31 2017 +0200 @@ -601,9 +601,10 @@ } - bool ServerContext::Apply(std::list<std::string>& result, + void ServerContext::Apply(std::list<std::string>& result, const ::Orthanc::LookupResource& lookup, - size_t maxResults) + size_t since, + size_t limit) { result.clear(); @@ -612,6 +613,7 @@ assert(resources.size() == instances.size()); + size_t skipped = 0; for (size_t i = 0; i < instances.size(); i++) { Json::Value dicom; @@ -619,10 +621,14 @@ if (lookup.IsMatch(dicom)) { - if (maxResults != 0 && - result.size() >= maxResults) + if (skipped < since) { - return false; // too many results + skipped++; + } + else if (limit != 0 && + result.size() >= limit) + { + return; // too many results } else { @@ -630,8 +636,6 @@ } } } - - return true; // finished } }
--- a/OrthancServer/ServerContext.h Mon Jul 10 11:31:48 2017 +0200 +++ b/OrthancServer/ServerContext.h Tue Jul 11 17:24:31 2017 +0200 @@ -258,9 +258,10 @@ void Stop(); - bool Apply(std::list<std::string>& result, + void Apply(std::list<std::string>& result, const ::Orthanc::LookupResource& lookup, - size_t maxResults); + size_t since, + size_t limit); /**