# HG changeset patch # User Sebastien Jodogne # Date 1368629470 -7200 # Node ID 7bbe77cb9e12c6569253d1567187982b9e740ff5 # Parent beca6747945e385ef391be29e9cefe31d7238481 DELETE metadata diff -r beca6747945e -r 7bbe77cb9e12 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Wed May 15 16:43:30 2013 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Wed May 15 16:51:10 2013 +0200 @@ -340,6 +340,15 @@ s.Run(); } + void DatabaseWrapper::DeleteMetadata(int64_t id, + MetadataType type) + { + SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Metadata WHERE id=? and type=?"); + s.BindInt(0, id); + s.BindInt(1, type); + s.Run(); + } + bool DatabaseWrapper::LookupMetadata(std::string& target, int64_t id, MetadataType type) diff -r beca6747945e -r 7bbe77cb9e12 OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Wed May 15 16:43:30 2013 +0200 +++ b/OrthancServer/DatabaseWrapper.h Wed May 15 16:51:10 2013 +0200 @@ -108,6 +108,9 @@ MetadataType type, const std::string& value); + void DeleteMetadata(int64_t id, + MetadataType type); + bool LookupMetadata(std::string& target, int64_t id, MetadataType type); diff -r beca6747945e -r 7bbe77cb9e12 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Wed May 15 16:43:30 2013 +0200 +++ b/OrthancServer/OrthancRestApi.cpp Wed May 15 16:51:10 2013 +0200 @@ -1536,6 +1536,24 @@ } + static void DeleteMetadata(RestApi::DeleteCall& call) + { + RETRIEVE_CONTEXT(call); + + std::string publicId = call.GetUriComponent("id", ""); + std::string name = call.GetUriComponent("name", ""); + MetadataType metadata = StringToMetadata(name); + + if (metadata >= MetadataType_StartUser && + metadata <= MetadataType_EndUser) + { + // It is forbidden to modify internal metadata + context.GetIndex().DeleteMetadata(publicId, metadata); + call.GetOutput().AnswerBuffer("", "text/plain"); + } + } + + static void SetMetadata(RestApi::PutCall& call) { RETRIEVE_CONTEXT(call); @@ -1591,15 +1609,19 @@ Register("/series/{id}/archive", GetArchive); Register("/instances/{id}/metadata", ListMetadata); + Register("/instances/{id}/metadata/{name}", DeleteMetadata); Register("/instances/{id}/metadata/{name}", GetMetadata); Register("/instances/{id}/metadata/{name}", SetMetadata); Register("/patients/{id}/metadata", ListMetadata); + Register("/patients/{id}/metadata/{name}", DeleteMetadata); Register("/patients/{id}/metadata/{name}", GetMetadata); Register("/patients/{id}/metadata/{name}", SetMetadata); Register("/series/{id}/metadata", ListMetadata); + Register("/series/{id}/metadata/{name}", DeleteMetadata); Register("/series/{id}/metadata/{name}", GetMetadata); Register("/series/{id}/metadata/{name}", SetMetadata); Register("/studies/{id}/metadata", ListMetadata); + Register("/studies/{id}/metadata/{name}", DeleteMetadata); Register("/studies/{id}/metadata/{name}", GetMetadata); Register("/studies/{id}/metadata/{name}", SetMetadata); diff -r beca6747945e -r 7bbe77cb9e12 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Wed May 15 16:43:30 2013 +0200 +++ b/OrthancServer/ServerIndex.cpp Wed May 15 16:51:10 2013 +0200 @@ -1123,6 +1123,23 @@ db_->SetMetadata(id, type, value); } + + void ServerIndex::DeleteMetadata(const std::string& publicId, + MetadataType type) + { + boost::mutex::scoped_lock lock(mutex_); + + ResourceType rtype; + int64_t id; + if (!db_->LookupResource(publicId, id, rtype)) + { + throw OrthancException(ErrorCode_UnknownResource); + } + + db_->DeleteMetadata(id, type); + } + + bool ServerIndex::LookupMetadata(std::string& target, const std::string& publicId, MetadataType type) diff -r beca6747945e -r 7bbe77cb9e12 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Wed May 15 16:43:30 2013 +0200 +++ b/OrthancServer/ServerIndex.h Wed May 15 16:51:10 2013 +0200 @@ -150,6 +150,9 @@ MetadataType type, const std::string& value); + void DeleteMetadata(const std::string& publicId, + MetadataType type); + bool LookupMetadata(std::string& target, const std::string& publicId, MetadataType type); diff -r beca6747945e -r 7bbe77cb9e12 UnitTests/ServerIndex.cpp --- a/UnitTests/ServerIndex.cpp Wed May 15 16:43:30 2013 +0200 +++ b/UnitTests/ServerIndex.cpp Wed May 15 16:51:10 2013 +0200 @@ -147,6 +147,13 @@ index.ListAvailableMetadata(md, a[4]); ASSERT_EQ(1u, md.size()); ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); + index.SetMetadata(a[4], MetadataType_ModifiedFrom, "TUTU"); + index.ListAvailableMetadata(md, a[4]); + ASSERT_EQ(2u, md.size()); + index.DeleteMetadata(a[4], MetadataType_ModifiedFrom); + index.ListAvailableMetadata(md, a[4]); + ASSERT_EQ(1u, md.size()); + ASSERT_EQ(MetadataType_Instance_RemoteAet, md.front()); ASSERT_EQ(21u + 42u + 44u, index.GetTotalCompressedSize()); ASSERT_EQ(42u + 42u + 44u, index.GetTotalUncompressedSize());