# HG changeset patch # User Sebastien Jodogne # Date 1417792497 -3600 # Node ID 6c07108ff1e23985a49a9601586fb8462502968c # Parent 0f3716b88af7b3e702b60ddb9357204886830607 cleaning diff -r 0f3716b88af7 -r 6c07108ff1e2 OrthancServer/DatabaseWrapper.cpp --- 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) { diff -r 0f3716b88af7 -r 6c07108ff1e2 OrthancServer/DatabaseWrapper.h --- 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& target, int64_t id); - std::string GetMetadata(int64_t id, - MetadataType type, - const std::string& defaultValue); - void AddAttachment(int64_t id, const FileInfo& attachment); diff -r 0f3716b88af7 -r 6c07108ff1e2 OrthancServer/ServerIndex.cpp --- 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(s); + result = boost::lexical_cast(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(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 children; db_->GetChildrenInternalId(children, id); - std::set instances; + std::set instances; for (std::list::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(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(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(i); else result["ExpectedNumberOfInstances"] = Json::nullValue; @@ -958,9 +947,9 @@ result["FileSize"] = static_cast(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(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; } diff -r 0f3716b88af7 -r 6c07108ff1e2 OrthancServer/ServerIndex.h --- 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); diff -r 0f3716b88af7 -r 6c07108ff1e2 UnitTestsSources/ServerIndexTests.cpp --- 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(42)));