# HG changeset patch # User Sebastien Jodogne # Date 1586261013 -7200 # Node ID aaaa442bfe39f125f8520accd44f99cb51dbc3ea # Parent abd3a1d114c0e9ee3a052ef213fa03ed860e3b94 moving SetOverwriteInstances from ServerIndex to ServerContext diff -r abd3a1d114c0 -r aaaa442bfe39 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Tue Apr 07 13:54:57 2020 +0200 +++ b/OrthancServer/ServerContext.cpp Tue Apr 07 14:03:33 2020 +0200 @@ -242,7 +242,8 @@ isJobsEngineUnserialized_(false), metricsRegistry_(new MetricsRegistry), isHttpServerSecure_(true), - isExecuteLuaEnabled_(false) + isExecuteLuaEnabled_(false), + overwriteInstances_(false) { { OrthancConfiguration::ReaderLock lock; @@ -404,7 +405,8 @@ typedef std::map InstanceMetadata; InstanceMetadata instanceMetadata; - StoreStatus status = index_.Store(instanceMetadata, dicom, attachments); + StoreStatus status = index_.Store( + instanceMetadata, dicom, attachments, overwriteInstances_); // Only keep the metadata for the "instance" level dicom.GetMetadata().clear(); diff -r abd3a1d114c0 -r aaaa442bfe39 OrthancServer/ServerContext.h --- a/OrthancServer/ServerContext.h Tue Apr 07 13:54:57 2020 +0200 +++ b/OrthancServer/ServerContext.h Tue Apr 07 14:03:33 2020 +0200 @@ -221,6 +221,7 @@ std::unique_ptr metricsRegistry_; bool isHttpServerSecure_; bool isExecuteLuaEnabled_; + bool overwriteInstances_; std::unique_ptr storageCommitmentReports_; @@ -426,6 +427,16 @@ return isExecuteLuaEnabled_; } + void SetOverwriteInstances(bool overwrite) + { + overwriteInstances_ = overwrite; + } + + bool IsOverwriteInstances() const + { + return overwriteInstances_; + } + virtual IStorageCommitmentFactory::ILookupHandler* CreateStorageCommitment(const std::string& jobId, const std::string& transactionUid, diff -r abd3a1d114c0 -r aaaa442bfe39 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Tue Apr 07 13:54:57 2020 +0200 +++ b/OrthancServer/ServerIndex.cpp Tue Apr 07 14:03:33 2020 +0200 @@ -675,7 +675,6 @@ db_(db), maximumStorageSize_(0), maximumPatients_(0), - overwrite_(false), mainDicomTagsRegistry_(new MainDicomTagsRegistry) { listener_.reset(new Listener(context)); @@ -753,7 +752,8 @@ StoreStatus ServerIndex::Store(std::map& instanceMetadata, DicomInstanceToStore& instanceToStore, - const Attachments& attachments) + const Attachments& attachments, + bool overwrite) { boost::mutex::scoped_lock lock(mutex_); @@ -784,7 +784,7 @@ { // The instance already exists - if (overwrite_) + if (overwrite) { // Overwrite the old instance LOG(INFO) << "Overwriting instance: " << hashInstance; @@ -1660,12 +1660,6 @@ StandaloneRecycling(); } - void ServerIndex::SetOverwriteInstances(bool overwrite) - { - boost::mutex::scoped_lock lock(mutex_); - overwrite_ = overwrite; - } - void ServerIndex::StandaloneRecycling() { diff -r abd3a1d114c0 -r aaaa442bfe39 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Tue Apr 07 13:54:57 2020 +0200 +++ b/OrthancServer/ServerIndex.h Tue Apr 07 14:03:33 2020 +0200 @@ -71,7 +71,6 @@ uint64_t maximumStorageSize_; unsigned int maximumPatients_; - bool overwrite_; std::unique_ptr mainDicomTagsRegistry_; static void FlushThread(ServerIndex* that, @@ -139,11 +138,10 @@ // "count == 0" means no limit on the number of patients void SetMaximumPatientCount(unsigned int count); - void SetOverwriteInstances(bool overwrite); - StoreStatus Store(std::map& instanceMetadata, DicomInstanceToStore& instance, - const Attachments& attachments); + const Attachments& attachments, + bool overwrite); void GetGlobalStatistics(/* out */ uint64_t& diskSize, /* out */ uint64_t& uncompressedSize, diff -r abd3a1d114c0 -r aaaa442bfe39 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Tue Apr 07 13:54:57 2020 +0200 +++ b/OrthancServer/main.cpp Tue Apr 07 14:03:33 2020 +0200 @@ -1307,7 +1307,7 @@ context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true)); // New option in Orthanc 1.4.2 - context.GetIndex().SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false)); + context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false)); try { diff -r abd3a1d114c0 -r aaaa442bfe39 UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Tue Apr 07 13:54:57 2020 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Tue Apr 07 14:03:33 2020 +0200 @@ -726,7 +726,8 @@ std::map instanceMetadata; DicomInstanceToStore toStore; toStore.SetSummary(instance); - ASSERT_EQ(StoreStatus_Success, index.Store(instanceMetadata, toStore, attachments)); + ASSERT_EQ(StoreStatus_Success, index.Store(instanceMetadata, toStore, attachments, + false /* don't overwrite */)); ASSERT_EQ(5u, instanceMetadata.size()); ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_RemoteAet) != instanceMetadata.end()); ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_ReceptionDate) != instanceMetadata.end()); @@ -803,7 +804,7 @@ DicomInstanceHasher hasher(instance); std::string id = hasher.HashInstance(); - context.GetIndex().SetOverwriteInstances(overwrite); + context.SetOverwriteInstances(overwrite); uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances; context.GetIndex().GetGlobalStatistics(diskSize, uncompressedSize, countPatients,