changeset 3814:023b2a9f3aa1 transcoding

new enum: StoreInstanceMode
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Apr 2020 17:35:44 +0200
parents aaaa442bfe39
children 1237bd0bbdb2
files OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/ServerEnumerations.h OrthancServer/ServerJobs/MergeStudyJob.cpp OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.cpp OrthancServer/ServerJobs/ResourceModificationJob.cpp OrthancServer/ServerJobs/SplitStudyJob.cpp OrthancServer/main.cpp UnitTestsSources/MultiThreadingTests.cpp UnitTestsSources/ServerIndexTests.cpp
diffstat 12 files changed, 45 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -227,7 +227,7 @@
     toStore.SetParsedDicomFile(dicom);
 
     ServerContext& context = OrthancRestApi::GetContext(call);
-    StoreStatus status = context.Store(id, toStore);
+    StoreStatus status = context.Store(id, toStore, StoreInstanceMode_Default);
 
     if (status == StoreStatus_Failure)
     {
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -139,7 +139,7 @@
     toStore.SetBuffer(dicom);
 
     std::string publicId;
-    StoreStatus status = context.Store(publicId, toStore);
+    StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default);
 
     OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);
   }
--- a/OrthancServer/ServerContext.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -340,8 +340,28 @@
 
 
   StoreStatus ServerContext::Store(std::string& resultPublicId,
-                                   DicomInstanceToStore& dicom)
+                                   DicomInstanceToStore& dicom,
+                                   StoreInstanceMode mode)
   {
+    bool overwrite;
+    switch (mode)
+    {
+      case StoreInstanceMode_Default:
+        overwrite = overwriteInstances_;
+        break;
+        
+      case StoreInstanceMode_OverwriteDuplicate:
+        overwrite = true;
+        break;
+        
+      case StoreInstanceMode_IgnoreDuplicate:
+        overwrite = false;
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }    
+    
     try
     {
       MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
@@ -406,7 +426,7 @@
       typedef std::map<MetadataType, std::string>  InstanceMetadata;
       InstanceMetadata  instanceMetadata;
       StoreStatus status = index_.Store(
-        instanceMetadata, dicom, attachments, overwriteInstances_);
+        instanceMetadata, dicom, attachments, overwrite);
 
       // Only keep the metadata for the "instance" level
       dicom.GetMetadata().clear();
--- a/OrthancServer/ServerContext.h	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerContext.h	Tue Apr 07 17:35:44 2020 +0200
@@ -276,7 +276,8 @@
                        size_t size);
 
     StoreStatus Store(std::string& resultPublicId,
-                      DicomInstanceToStore& dicom);
+                      DicomInstanceToStore& dicom,
+                      StoreInstanceMode mode);
 
     void AnswerAttachment(RestApiOutput& output,
                           const std::string& resourceId,
--- a/OrthancServer/ServerEnumerations.h	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerEnumerations.h	Tue Apr 07 17:35:44 2020 +0200
@@ -90,6 +90,13 @@
     FindStorageAccessMode_DiskOnLookupAndAnswer
   };
 
+  enum StoreInstanceMode
+  {
+    StoreInstanceMode_Default,
+    StoreInstanceMode_OverwriteDuplicate,
+    StoreInstanceMode_IgnoreDuplicate
+  };
+
 
   /**
    * WARNING: Do not change the explicit values in the enumerations
--- a/OrthancServer/ServerJobs/MergeStudyJob.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerJobs/MergeStudyJob.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -145,7 +145,8 @@
     toStore.SetParsedDicomFile(*modified);
 
     std::string modifiedInstance;
-    if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success)
+    if (context_.Store(modifiedInstance, toStore,
+                       StoreInstanceMode_Default) != StoreStatus_Success)
     {
       LOG(ERROR) << "Error while storing a modified instance " << instance;
       return false;
--- a/OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -114,7 +114,7 @@
       toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, instance.GetId());
 
       std::string modifiedId;
-      context_.Store(modifiedId, toStore);
+      context_.Store(modifiedId, toStore, StoreInstanceMode_Default);
 
       // Only chain with other commands if this command succeeds
       outputs.Append(new DicomInstanceOperationValue(instance.GetServerContext(), modifiedId));
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -211,7 +211,8 @@
      **/
 
     std::string modifiedInstance;
-    if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success)
+    if (context_.Store(modifiedInstance, toStore,
+                       StoreInstanceMode_Default) != StoreStatus_Success)
     {
       throw OrthancException(ErrorCode_CannotStoreInstance,
                              "Error while storing a modified instance " + instance);
--- a/OrthancServer/ServerJobs/SplitStudyJob.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/ServerJobs/SplitStudyJob.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -138,7 +138,8 @@
     toStore.SetParsedDicomFile(*modified);
 
     std::string modifiedInstance;
-    if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success)
+    if (context_.Store(modifiedInstance, toStore,
+                       StoreInstanceMode_Default) != StoreStatus_Success)
     {
       LOG(ERROR) << "Error while storing a modified instance " << instance;
       return false;
--- a/OrthancServer/main.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/OrthancServer/main.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -87,7 +87,7 @@
       toStore.SetJson(dicomJson);
 
       std::string id;
-      context_.Store(id, toStore);
+      context_.Store(id, toStore, StoreInstanceMode_Default);
     }
   }
 };
--- a/UnitTestsSources/MultiThreadingTests.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -1316,7 +1316,7 @@
       DicomInstanceToStore toStore;
       toStore.SetParsedDicomFile(dicom);
 
-      return (context_->Store(id, toStore) == StoreStatus_Success);
+      return (context_->Store(id, toStore, StoreInstanceMode_Default) == StoreStatus_Success);
     }
   };
 }
--- a/UnitTestsSources/ServerIndexTests.cpp	Tue Apr 07 14:03:33 2020 +0200
+++ b/UnitTestsSources/ServerIndexTests.cpp	Tue Apr 07 17:35:44 2020 +0200
@@ -820,7 +820,7 @@
       ASSERT_EQ(id, toStore.GetHasher().HashInstance());
 
       std::string id2;
-      ASSERT_EQ(StoreStatus_Success, context.Store(id2, toStore));
+      ASSERT_EQ(StoreStatus_Success, context.Store(id2, toStore, StoreInstanceMode_Default));
       ASSERT_EQ(id, id2);
     }
 
@@ -855,7 +855,8 @@
       toStore.SetOrigin(DicomInstanceOrigin::FromPlugins());
 
       std::string id2;
-      ASSERT_EQ(overwrite ? StoreStatus_Success : StoreStatus_AlreadyStored, context.Store(id2, toStore));
+      ASSERT_EQ(overwrite ? StoreStatus_Success : StoreStatus_AlreadyStored,
+                context.Store(id2, toStore, StoreInstanceMode_Default));
       ASSERT_EQ(id, id2);
     }