changeset 3075:ead8576a02ef db-changes

IDatabaseWrapper::ApplyLookupResources now returns lists
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Jan 2019 18:39:25 +0100
parents 495c5edce708
children 8bc2cb1335f4
files OrthancServer/IDatabaseWrapper.h OrthancServer/SQLiteDatabaseWrapper.cpp OrthancServer/SQLiteDatabaseWrapper.h OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h OrthancServer/Search/Compatibility/DatabaseLookup.cpp OrthancServer/Search/Compatibility/DatabaseLookup.h OrthancServer/ServerIndex.cpp Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h UnitTestsSources/ServerIndexTests.cpp
diffstat 11 files changed, 89 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/IDatabaseWrapper.h	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/IDatabaseWrapper.h	Wed Jan 02 18:39:25 2019 +0100
@@ -212,8 +212,8 @@
 
     virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
 
-    virtual void ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                      std::vector<std::string>* instancesId,   // Can be NULL if not needed
+    virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                      std::list<std::string>* instancesId, // Can be NULL if not needed
                                       const std::vector<DatabaseConstraint>& lookup,
                                       ResourceType queryLevel,
                                       size_t limit) = 0;
--- a/OrthancServer/SQLiteDatabaseWrapper.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -1145,8 +1145,8 @@
   };
 
   
-  static void AnswerLookup(std::vector<std::string>& resourcesId,
-                           std::vector<std::string>& instancesId,
+  static void AnswerLookup(std::list<std::string>& resourcesId,
+                           std::list<std::string>& instancesId,
                            SQLite::Connection& db,
                            ResourceType level)
   {
@@ -1219,8 +1219,8 @@
   }
 
 
-  void SQLiteDatabaseWrapper::ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                                   std::vector<std::string>* instancesId,
+  void SQLiteDatabaseWrapper::ApplyLookupResources(std::list<std::string>& resourcesId,
+                                                   std::list<std::string>* instancesId,
                                                    const std::vector<DatabaseConstraint>& lookup,
                                                    ResourceType queryLevel,
                                                    size_t limit)
--- a/OrthancServer/SQLiteDatabaseWrapper.h	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.h	Wed Jan 02 18:39:25 2019 +0100
@@ -314,8 +314,8 @@
     virtual bool IsDiskSizeAbove(uint64_t threshold)
       ORTHANC_OVERRIDE;
 
-    virtual void ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                      std::vector<std::string>* instancesId,
+    virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                      std::list<std::string>* instancesId,
                                       const std::vector<DatabaseConstraint>& lookup,
                                       ResourceType queryLevel,
                                       size_t limit)
--- a/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -40,8 +40,8 @@
 {
   namespace Compatibility
   {
-    void CompatibilityDatabaseWrapper::ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                                            std::vector<std::string>* instancesId,
+    void CompatibilityDatabaseWrapper::ApplyLookupResources(std::list<std::string>& resourcesId,
+                                                            std::list<std::string>* instancesId,
                                                             const std::vector<DatabaseConstraint>& lookup,
                                                             ResourceType queryLevel,
                                                             size_t limit)
--- a/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h	Wed Jan 02 18:39:25 2019 +0100
@@ -55,8 +55,8 @@
     class CompatibilityDatabaseWrapper : public IDatabaseWrapper
     {     
     public:
-      virtual void ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                        std::vector<std::string>* instancesId,
+      virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                        std::list<std::string>* instancesId,
                                         const std::vector<DatabaseConstraint>& lookup,
                                         ResourceType queryLevel,
                                         size_t limit)
--- a/OrthancServer/Search/Compatibility/DatabaseLookup.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/Search/Compatibility/DatabaseLookup.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -312,8 +312,8 @@
     }
                            
 
-    void DatabaseLookup::ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                              std::vector<std::string>* instancesId,
+    void DatabaseLookup::ApplyLookupResources(std::list<std::string>& resourcesId,
+                                              std::list<std::string>* instancesId,
                                               const std::vector<DatabaseConstraint>& lookup,
                                               ResourceType queryLevel,
                                               size_t limit)
@@ -389,13 +389,6 @@
 
       // Get the public ID of all the selected resources
 
-      resourcesId.resize(resources.size());
-
-      if (instancesId != NULL)
-      {
-        instancesId->resize(resources.size());
-      }
-
       size_t pos = 0;
 
       for (std::list<int64_t>::const_iterator
@@ -403,18 +396,20 @@
       {
         assert(database_.GetResourceType(*it) == queryLevel);
 
-        resourcesId[pos] = database_.GetPublicId(*it);
+        const std::string resource = database_.GetPublicId(*it);
+        resourcesId.push_back(resource);
 
         if (instancesId != NULL)
         {
-          // Collect one child instance for each of the selected resources
           if (queryLevel == ResourceType_Instance)
           {
-            (*instancesId) [pos] = resourcesId[pos];
+            // The resource is itself the instance
+            instancesId->push_back(resource);
           }
           else
           {
-            (*instancesId) [pos] = GetOneInstance(database_, *it, queryLevel);
+            // Collect one child instance for each of the selected resources
+            instancesId->push_back(GetOneInstance(database_, *it, queryLevel));
           }
         }
       }
--- a/OrthancServer/Search/Compatibility/DatabaseLookup.h	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/Search/Compatibility/DatabaseLookup.h	Wed Jan 02 18:39:25 2019 +0100
@@ -50,8 +50,8 @@
       {
       }
 
-      void ApplyLookupResources(std::vector<std::string>& resourcesId,
-                                std::vector<std::string>* instancesId,
+      void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                std::list<std::string>* instancesId,
                                 const std::vector<DatabaseConstraint>& lookup,
                                 ResourceType queryLevel,
                                 size_t limit);
--- a/OrthancServer/ServerIndex.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/OrthancServer/ServerIndex.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -58,6 +58,22 @@
 
 namespace Orthanc
 {
+  static void CopyListToVector(std::vector<std::string>& target,
+                               const std::list<std::string>& source)
+  {
+    target.resize(source.size());
+
+    size_t pos = 0;
+    
+    for (std::list<std::string>::const_iterator
+           it = source.begin(); it != source.end(); ++it)
+    {
+      target[pos] = *it;
+      pos ++;
+    }      
+  }
+
+  
   class ServerIndex::Listener : public IDatabaseListener
   {
   private:
@@ -2141,10 +2157,14 @@
     std::vector<DatabaseConstraint> query;
     query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier));
 
+    std::list<std::string> tmp;
+    
     {
       boost::mutex::scoped_lock lock(mutex_);
-      db_.ApplyLookupResources(result, NULL, query, level, 0);
+      db_.ApplyLookupResources(tmp, NULL, query, level, 0);
     }
+
+    CopyListToVector(result, tmp);
   }
 
 
@@ -2570,9 +2590,26 @@
     std::vector<DatabaseConstraint> normalized;
     NormalizeLookup(normalized, lookup, queryLevel);
 
+    std::list<std::string> resourcesList, instancesList;
+    
     {
       boost::mutex::scoped_lock lock(mutex_);
-      db_.ApplyLookupResources(resourcesId, instancesId, normalized, queryLevel, limit);
+
+      if (instancesId == NULL)
+      {
+        db_.ApplyLookupResources(resourcesList, NULL, normalized, queryLevel, limit);
+      }
+      else
+      {
+        db_.ApplyLookupResources(resourcesList, &instancesList, normalized, queryLevel, limit);
+      }
+    }
+
+    CopyListToVector(resourcesId, resourcesList);
+
+    if (instancesId != NULL)
+    { 
+      CopyListToVector(*instancesId, instancesList);
     }
   }
 }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -1110,6 +1110,24 @@
   }
 
 
+  void OrthancPluginDatabase::ApplyLookupResources(std::list<std::string>& resourcesId,
+                                                   std::list<std::string>* instancesId,
+                                                   const std::vector<DatabaseConstraint>& lookup,
+                                                   ResourceType queryLevel,
+                                                   size_t limit)
+  {
+    if (extensions_.lookupResources == NULL)
+    {
+      CompatibilityDatabaseWrapper::ApplyLookupResources
+        (resourcesId, instancesId, lookup, queryLevel, limit);
+    }
+    else
+    {
+      ResetAnswers();
+    }
+  }
+
+
   void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& result,
                                                ResourceType level,
                                                const DicomTag& tag,
--- a/Plugins/Engine/OrthancPluginDatabase.h	Wed Jan 02 15:50:44 2019 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Wed Jan 02 18:39:25 2019 +0100
@@ -307,6 +307,13 @@
     virtual bool IsDiskSizeAbove(uint64_t threshold) 
       ORTHANC_OVERRIDE;
 
+    virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
+                                      std::list<std::string>* instancesId,
+                                      const std::vector<DatabaseConstraint>& lookup,
+                                      ResourceType queryLevel,
+                                      size_t limit)
+      ORTHANC_OVERRIDE;
+
     // From the "CompatibilityDatabaseWrapper" interface
     virtual void GetAllInternalIds(std::list<int64_t>& target,
                                    ResourceType resourceType) 
--- a/UnitTestsSources/ServerIndexTests.cpp	Wed Jan 02 15:50:44 2019 +0100
+++ b/UnitTestsSources/ServerIndexTests.cpp	Wed Jan 02 18:39:25 2019 +0100
@@ -249,7 +249,7 @@
     }
 
 
-    void DoLookupIdentifier(std::vector<std::string>& result,
+    void DoLookupIdentifier(std::list<std::string>& result,
                             ResourceType level,
                             const DicomTag& tag,
                             ConstraintType type,
@@ -266,7 +266,7 @@
     }
     
 
-    void DoLookupIdentifier2(std::vector<std::string>& result,
+    void DoLookupIdentifier2(std::list<std::string>& result,
                              ResourceType level,
                              const DicomTag& tag,
                              ConstraintType type1,
@@ -740,7 +740,7 @@
   index_->SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0");
   index_->SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0");
 
-  std::vector<std::string> s;
+  std::list<std::string> s;
 
   DoLookupIdentifier(s, ResourceType_Study, DICOM_TAG_STUDY_INSTANCE_UID, ConstraintType_Equal, "0");
   ASSERT_EQ(2u, s.size());