# HG changeset patch # User Sebastien Jodogne # Date 1714749627 -7200 # Node ID 1b0fc6685f5708bebe3bb3b775d49490027e13fb # Parent 0f5586c498d19d7d6dc67eedd414fa6c275e019f add index of resources into FindResponse diff -r 0f5586c498d1 -r 1b0fc6685f57 OrthancServer/Sources/Database/FindResponse.cpp --- a/OrthancServer/Sources/Database/FindResponse.cpp Fri May 03 17:06:42 2024 +0200 +++ b/OrthancServer/Sources/Database/FindResponse.cpp Fri May 03 17:20:27 2024 +0200 @@ -364,6 +364,11 @@ { throw OrthancException(ErrorCode_NullPointer); } + else if (!items_.empty() && + items_[0]->GetLevel() != item->GetLevel()) + { + throw OrthancException(ErrorCode_BadParameterType, "A find response must only contain resources of the same type"); + } else { const std::string& id = item->GetIdentifier(); @@ -395,18 +400,18 @@ } - const FindResponse::Item* FindResponse::LookupItem(const std::string& id) const + FindResponse::Item& FindResponse::GetItem(const std::string& id) { Index::const_iterator found = index_.find(id); if (found == index_.end()) { - return NULL; + throw OrthancException(ErrorCode_InexistentItem); } else { assert(found->second != NULL); - return found->second; + return *found->second; } } } diff -r 0f5586c498d1 -r 1b0fc6685f57 OrthancServer/Sources/Database/FindResponse.h --- a/OrthancServer/Sources/Database/FindResponse.h Fri May 03 17:06:42 2024 +0200 +++ b/OrthancServer/Sources/Database/FindResponse.h Fri May 03 17:20:27 2024 +0200 @@ -109,6 +109,11 @@ { } + ResourceType GetLevel() const + { + return level_; + } + const std::string& GetIdentifier() const { return identifier_; @@ -204,6 +209,16 @@ const Item& GetItem(size_t index) const; - const Item* LookupItem(const std::string& id) const; + Item& GetItem(const std::string& id); + + const Item& GetItem(const std::string& id) const + { + return const_cast(*this).GetItem(id); + } + + bool HasItem(const std::string& id) const + { + return (index_.find(id) != index_.end()); + } }; } diff -r 0f5586c498d1 -r 1b0fc6685f57 OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp --- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Fri May 03 17:06:42 2024 +0200 +++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Fri May 03 17:20:27 2024 +0200 @@ -1178,9 +1178,8 @@ } else { - std::map items; // cache to the response items - - {// first create a temporary table that with the filtered and ordered results + { + // first create a temporary table that with the filtered and ordered results sqlLookup = "CREATE TEMPORARY TABLE FilteredResourcesIds AS " + sqlLookup; SQLite::Statement statement(db_, SQLITE_FROM_HERE_DYNAMIC(sqlLookup), sqlLookup); @@ -1196,10 +1195,7 @@ while (statement.Step()) { const std::string resourceId = statement.ColumnString(0); - - FindResponse::Item* item = new FindResponse::Item(request.GetLevel(), resourceId); - items[resourceId] = item; - response.Add(item); + response.Add(new FindResponse::Item(request.GetLevel(), resourceId)); } } @@ -1215,10 +1211,11 @@ while (statement.Step()) { const std::string& resourceId = statement.ColumnString(0); - items[resourceId]->AddStringDicomTag(request.GetLevel(), - statement.ColumnInt(1), - statement.ColumnInt(2), - statement.ColumnString(3)); + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).AddStringDicomTag(request.GetLevel(), + statement.ColumnInt(1), + statement.ColumnInt(2), + statement.ColumnString(3)); } } @@ -1234,7 +1231,8 @@ while (statement.Step()) { const std::string& resourceId = statement.ColumnString(0); - items[resourceId]->AddChildIdentifier(GetChildResourceType(request.GetLevel()), statement.ColumnString(1)); + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).AddChildIdentifier(GetChildResourceType(request.GetLevel()), statement.ColumnString(1)); } } @@ -1250,7 +1248,8 @@ { const std::string& resourceId = statement.ColumnString(0); const std::string& parentId = statement.ColumnString(1); - items[resourceId]->SetParentIdentifier(parentId); + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).SetParentIdentifier(parentId); } } @@ -1264,8 +1263,9 @@ while (statement.Step()) { const std::string& resourceId = statement.ColumnString(0); - items[resourceId]->AddMetadata(static_cast(statement.ColumnInt(1)), - statement.ColumnString(2)); + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).AddMetadata(static_cast(statement.ColumnInt(1)), + statement.ColumnString(2)); } } @@ -1279,7 +1279,8 @@ while (statement.Step()) { const std::string& resourceId = statement.ColumnString(0); - items[resourceId]->AddLabel(statement.ColumnString(1)); + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).AddLabel(statement.ColumnString(1)); } } @@ -1301,7 +1302,9 @@ static_cast(statement.ColumnInt(4)), statement.ColumnInt64(5), statement.ColumnString(7)); - items[resourceId]->AddAttachment(attachment); + + assert(response.HasItem(resourceId)); + response.GetItem(resourceId).AddAttachment(attachment); }; }