changeset 3942:5b882ad2ffd0 transcoding

"/{patients|studies|series}/.../modify": New option "KeepSource"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 18 May 2020 19:09:06 +0200
parents 771dbd9eb3bd
children b26d25d3c1c7
files NEWS OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ServerJobs/ResourceModificationJob.cpp OrthancServer/ServerJobs/ResourceModificationJob.h UnitTestsSources/MultiThreadingTests.cpp
diffstat 5 files changed, 29 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon May 18 18:20:19 2020 +0200
+++ b/NEWS	Mon May 18 19:09:06 2020 +0200
@@ -22,6 +22,7 @@
   - "/queries/.../answers/../retrieve": "TargetAet" not mandatory anymore
     (defaults to the local AET)
 * Changes:
+  - "/{patients|studies|series}/.../modify": New option "KeepSource"
   - "/instances/.../modify": New option "Transcode"
   - ".../archive", ".../media", "/tools/create-media" and
     "/tools/create-archive": New option "Transcode"
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 18 18:20:19 2020 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon May 18 19:09:06 2020 +0200
@@ -212,6 +212,17 @@
   }
 
 
+  static void SetKeepSource(CleaningInstancesJob& job,
+                            const Json::Value& body)
+  {
+    static const char* KEEP_SOURCE = "KeepSource";
+    if (body.isMember(KEEP_SOURCE))
+    {
+      job.SetKeepSource(SerializationToolbox::ReadBoolean(body, KEEP_SOURCE));
+    }
+  }
+
+
   static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification,
                                     bool isAnonymization,
                                     RestApiPostCall& call,
@@ -221,11 +232,13 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     std::unique_ptr<ResourceModificationJob> job(new ResourceModificationJob(context));
-    
+
     job->SetModification(modification.release(), level, isAnonymization);
     job->SetOrigin(call);
+    SetKeepSource(*job, body);
     
     context.AddChildInstances(*job, call.GetUriComponent("id", ""));
+    job->AddTrailingStep();
 
     OrthancRestApi::GetApi(call).SubmitCommandsJob
       (call, job.release(), true /* synchronous by default */, body);
@@ -721,14 +734,10 @@
     {
       job->AddSourceSeries(series[i]);
     }
-
+    
     job->AddTrailingStep();
 
-    static const char* KEEP_SOURCE = "KeepSource";
-    if (request.isMember(KEEP_SOURCE))
-    {
-      job->SetKeepSource(SerializationToolbox::ReadBoolean(request, KEEP_SOURCE));
-    }
+    SetKeepSource(*job, request);
 
     static const char* REMOVE = "Remove";
     if (request.isMember(REMOVE))
@@ -807,11 +816,7 @@
 
     job->AddTrailingStep();
 
-    static const char* KEEP_SOURCE = "KeepSource";
-    if (request.isMember(KEEP_SOURCE))
-    {
-      job->SetKeepSource(SerializationToolbox::ReadBoolean(request, KEEP_SOURCE));
-    }
+    SetKeepSource(*job, request);
 
     OrthancRestApi::GetApi(call).SubmitCommandsJob
       (call, job.release(), true /* synchronous by default */, request);
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Mon May 18 18:20:19 2020 +0200
+++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Mon May 18 19:09:06 2020 +0200
@@ -152,7 +152,7 @@
 
     try
     {
-      ServerContext::DicomCacheLocker locker(context_, instance);
+      ServerContext::DicomCacheLocker locker(GetContext(), instance);
       ParsedDicomFile& original = locker.GetDicom();
 
       originalHasher.reset(new DicomInstanceHasher(original.GetHasher()));
@@ -211,8 +211,8 @@
      **/
 
     std::string modifiedInstance;
-    if (context_.Store(modifiedInstance, toStore,
-                       StoreInstanceMode_Default) != StoreStatus_Success)
+    if (GetContext().Store(modifiedInstance, toStore,
+                           StoreInstanceMode_Default) != StoreStatus_Success)
     {
       throw OrthancException(ErrorCode_CannotStoreInstance,
                              "Error while storing a modified instance " + instance);
@@ -230,12 +230,6 @@
     return true;
   }
 
-  
-  bool ResourceModificationJob::HandleTrailingStep()
-  {
-    throw OrthancException(ErrorCode_InternalError);
-  }
-
 
   void ResourceModificationJob::SetModification(DicomModification* modification,
                                                 ResourceType level,
@@ -292,7 +286,7 @@
 
   void ResourceModificationJob::GetPublicContent(Json::Value& value)
   {
-    SetOfInstancesJob::GetPublicContent(value);
+    CleaningInstancesJob::GetPublicContent(value);
 
     value["IsAnonymization"] = isAnonymization_;
 
@@ -310,8 +304,7 @@
 
   ResourceModificationJob::ResourceModificationJob(ServerContext& context,
                                                    const Json::Value& serialized) :
-    SetOfInstancesJob(serialized),
-    context_(context)
+    CleaningInstancesJob(context, serialized, true /* by default, keep source */)
   {
     isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION);
     origin_ = DicomInstanceOrigin(serialized[ORIGIN]);
@@ -320,7 +313,7 @@
   
   bool ResourceModificationJob::Serialize(Json::Value& value)
   {
-    if (!SetOfInstancesJob::Serialize(value))
+    if (!CleaningInstancesJob::Serialize(value))
     {
       return false;
     }
--- a/OrthancServer/ServerJobs/ResourceModificationJob.h	Mon May 18 18:20:19 2020 +0200
+++ b/OrthancServer/ServerJobs/ResourceModificationJob.h	Mon May 18 19:09:06 2020 +0200
@@ -33,20 +33,19 @@
 
 #pragma once
 
-#include "../../Core/JobsEngine/SetOfInstancesJob.h"
 #include "../../Core/DicomParsing/DicomModification.h"
 #include "../DicomInstanceOrigin.h"
+#include "CleaningInstancesJob.h"
 
 namespace Orthanc
 {
   class ServerContext;
   
-  class ResourceModificationJob : public SetOfInstancesJob
+  class ResourceModificationJob : public CleaningInstancesJob
   {
   private:
     class Output;
     
-    ServerContext&                      context_;
     std::unique_ptr<DicomModification>  modification_;
     boost::shared_ptr<Output>           output_;
     bool                                isAnonymization_;
@@ -55,11 +54,9 @@
   protected:
     virtual bool HandleInstance(const std::string& instance);
     
-    virtual bool HandleTrailingStep();
-
   public:
     ResourceModificationJob(ServerContext& context) :
-      context_(context),
+      CleaningInstancesJob(context, true /* by default, keep source */),
       isAnonymization_(false)
     {
     }
--- a/UnitTestsSources/MultiThreadingTests.cpp	Mon May 18 18:20:19 2020 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Mon May 18 19:09:06 2020 +0200
@@ -1560,7 +1560,8 @@
     ResourceModificationJob job(GetContext());
     job.SetModification(modification.release(), ResourceType_Patient, true);
     job.SetOrigin(DicomInstanceOrigin::FromLua());
-    
+
+    job.AddTrailingStep();  // Necessary since 1.7.0
     ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
     ASSERT_TRUE(job.Serialize(s));
   }