changeset 1238:6c07108ff1e2

cleaning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Dec 2014 16:14:57 +0100
parents 0f3716b88af7
children 92c6b3b57699
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h UnitTestsSources/ServerIndexTests.cpp
diffstat 5 files changed, 30 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Fri Dec 05 15:33:16 2014 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Fri Dec 05 16:14:57 2014 +0100
@@ -434,23 +434,6 @@
   }
 
 
-  std::string DatabaseWrapper::GetMetadata(int64_t id,
-                                           MetadataType type,
-                                           const std::string& defaultValue)
-  {
-    std::string s;
-    if (LookupMetadata(s, id, type))
-    {
-      return s;
-    }
-    else
-    {
-      return defaultValue;
-    }
-  }
-
-
-
   void DatabaseWrapper::AddAttachment(int64_t id,
                                       const FileInfo& attachment)
   {
--- a/OrthancServer/DatabaseWrapper.h	Fri Dec 05 15:33:16 2014 +0100
+++ b/OrthancServer/DatabaseWrapper.h	Fri Dec 05 16:14:57 2014 +0100
@@ -118,10 +118,6 @@
     void ListAvailableMetadata(std::list<MetadataType>& target,
                                int64_t id);
 
-    std::string GetMetadata(int64_t id,
-                            MetadataType type,
-                            const std::string& defaultValue);
-
     void AddAttachment(int64_t id,
                        const FileInfo& attachment);
 
--- a/OrthancServer/ServerIndex.cpp	Fri Dec 05 15:33:16 2014 +0100
+++ b/OrthancServer/ServerIndex.cpp	Fri Dec 05 16:14:57 2014 +0100
@@ -420,19 +420,19 @@
 
 
 
-  bool ServerIndex::GetMetadataAsInteger(int& result,
+  bool ServerIndex::GetMetadataAsInteger(int64_t& result,
                                          int64_t id,
                                          MetadataType type)
   {
-    std::string s = db_->GetMetadata(id, type, "");
-    if (s.size() == 0)
+    std::string s;
+    if (!db_->LookupMetadata(s, id, type))
     {
       return false;
     }
 
     try
     {
-      result = boost::lexical_cast<int>(s);
+      result = boost::lexical_cast<int64_t>(s);
       return true;
     }
     catch (boost::bad_lexical_cast&)
@@ -772,14 +772,8 @@
   SeriesStatus ServerIndex::GetSeriesStatus(int64_t id)
   {
     // Get the expected number of instances in this series (from the metadata)
-    std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances, "");
-
-    size_t expected;
-    try
-    {
-      expected = boost::lexical_cast<size_t>(s);
-    }
-    catch (boost::bad_lexical_cast&)
+    int64_t expected;
+    if (!GetMetadataAsInteger(expected, id, MetadataType_Series_ExpectedNumberOfInstances))
     {
       return SeriesStatus_Unknown;
     }
@@ -788,18 +782,13 @@
     std::list<int64_t> children;
     db_->GetChildrenInternalId(children, id);
 
-    std::set<size_t> instances;
+    std::set<int64_t> instances;
     for (std::list<int64_t>::const_iterator 
            it = children.begin(); it != children.end(); ++it)
     {
       // Get the index of this instance in the series
-      s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries, "");
-      size_t index;
-      try
-      {
-        index = boost::lexical_cast<size_t>(s);
-      }
-      catch (boost::bad_lexical_cast&)
+      int64_t index;
+      if (!GetMetadataAsInteger(index, *it, MetadataType_Instance_IndexInSeries))
       {
         return SeriesStatus_Unknown;
       }
@@ -819,7 +808,7 @@
       instances.insert(index);
     }
 
-    if (instances.size() == expected)
+    if (static_cast<int64_t>(instances.size()) == expected)
     {
       return SeriesStatus_Complete;
     }
@@ -936,9 +925,9 @@
         result["Type"] = "Series";
         result["Status"] = EnumerationToString(GetSeriesStatus(id));
 
-        int i;
+        int64_t i;
         if (GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances))
-          result["ExpectedNumberOfInstances"] = i;
+          result["ExpectedNumberOfInstances"] = static_cast<int>(i);
         else
           result["ExpectedNumberOfInstances"] = Json::nullValue;
 
@@ -958,9 +947,9 @@
         result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize());
         result["FileUuid"] = attachment.GetUuid();
 
-        int i;
+        int64_t i;
         if (GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries))
-          result["IndexInSeries"] = i;
+          result["IndexInSeries"] = static_cast<int>(i);
         else
           result["IndexInSeries"] = Json::nullValue;
 
@@ -977,14 +966,12 @@
 
     std::string tmp;
 
-    tmp = db_->GetMetadata(id, MetadataType_AnonymizedFrom, "");
-    if (tmp.size() != 0)
+    if (db_->LookupMetadata(tmp, id, MetadataType_AnonymizedFrom))
     {
       result["AnonymizedFrom"] = tmp;
     }
 
-    tmp = db_->GetMetadata(id, MetadataType_ModifiedFrom, "");
-    if (tmp.size() != 0)
+    if (db_->LookupMetadata(tmp, id, MetadataType_ModifiedFrom))
     {
       result["ModifiedFrom"] = tmp;
     }
@@ -995,8 +982,7 @@
     {
       result["IsStable"] = !unstableResources_.Contains(id);
 
-      tmp = db_->GetMetadata(id, MetadataType_LastUpdate, "");
-      if (tmp.size() != 0)
+      if (db_->LookupMetadata(tmp, id, MetadataType_LastUpdate))
       {
         result["LastUpdate"] = tmp;
       }
@@ -1913,7 +1899,13 @@
            it = metadata.begin(); it != metadata.end(); it++)
     {
       std::string key = EnumerationToString(*it);
-      std::string value = db_->GetMetadata(id, *it, "");
+
+      std::string value;
+      if (!db_->LookupMetadata(value, id, *it))
+      {
+        value.clear();
+      }
+
       target[key] = value;
     }
 
--- a/OrthancServer/ServerIndex.h	Fri Dec 05 15:33:16 2014 +0100
+++ b/OrthancServer/ServerIndex.h	Fri Dec 05 16:14:57 2014 +0100
@@ -103,7 +103,7 @@
                                /* in  */ int64_t id,
                                /* in  */ ResourceType type);
 
-    bool GetMetadataAsInteger(int& result,
+    bool GetMetadataAsInteger(int64_t& result,
                               int64_t id,
                               MetadataType type);
 
--- a/UnitTestsSources/ServerIndexTests.cpp	Fri Dec 05 15:33:16 2014 +0100
+++ b/UnitTestsSources/ServerIndexTests.cpp	Fri Dec 05 16:14:57 2014 +0100
@@ -268,8 +268,11 @@
   ASSERT_TRUE(index_->LookupMetadata(s, a[4], MetadataType_Instance_RemoteAet));
   ASSERT_FALSE(index_->LookupMetadata(s, a[4], MetadataType_Instance_IndexInSeries));
   ASSERT_EQ("PINNACLE", s);
-  ASSERT_EQ("PINNACLE", index_->GetMetadata(a[4], MetadataType_Instance_RemoteAet, ""));
-  ASSERT_EQ("None", index_->GetMetadata(a[4], MetadataType_Instance_IndexInSeries, "None"));
+
+  std::string u;
+  ASSERT_TRUE(index_->LookupMetadata(u, a[4], MetadataType_Instance_RemoteAet));
+  ASSERT_EQ("PINNACLE", u);
+  ASSERT_FALSE(index_->LookupMetadata(u, a[4], MetadataType_Instance_IndexInSeries));
 
   ASSERT_TRUE(index_->LookupGlobalProperty(s, GlobalProperty_FlushSleep));
   ASSERT_FALSE(index_->LookupGlobalProperty(s, static_cast<GlobalProperty>(42)));