changeset 3638:ae866fc06df5 storage-commitment

serialization of StorageCommitmentScpJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 31 Jan 2020 16:53:23 +0100
parents 06eb59faf4da
children 0c9a8f6d2349
files Core/SerializationToolbox.cpp Core/SerializationToolbox.h OrthancServer/ServerJobs/OrthancJobUnserializer.cpp OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp OrthancServer/ServerJobs/StorageCommitmentScpJob.h
diffstat 5 files changed, 115 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Core/SerializationToolbox.cpp	Fri Jan 31 15:50:17 2020 +0100
+++ b/Core/SerializationToolbox.cpp	Fri Jan 31 16:53:23 2020 +0100
@@ -320,6 +320,28 @@
     }
 
 
+    void WriteListOfStrings(Json::Value& target,
+                            const std::list<std::string>& values,
+                            const std::string& field)
+    {
+      if (target.type() != Json::objectValue ||
+          target.isMember(field.c_str()))
+      {
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      Json::Value& value = target[field];
+
+      value = Json::arrayValue;
+
+      for (std::list<std::string>::const_iterator it = values.begin();
+           it != values.end(); ++it)
+      {
+        value.append(*it);
+      }
+    }
+
+
     void WriteSetOfStrings(Json::Value& target,
                            const std::set<std::string>& values,
                            const std::string& field)
--- a/Core/SerializationToolbox.h	Fri Jan 31 15:50:17 2020 +0100
+++ b/Core/SerializationToolbox.h	Fri Jan 31 16:53:23 2020 +0100
@@ -83,6 +83,10 @@
                              const std::vector<std::string>& values,
                              const std::string& field);
 
+    void WriteListOfStrings(Json::Value& target,
+                            const std::list<std::string>& values,
+                            const std::string& field);
+
     void WriteSetOfStrings(Json::Value& target,
                            const std::set<std::string>& values,
                            const std::string& field);
--- a/OrthancServer/ServerJobs/OrthancJobUnserializer.cpp	Fri Jan 31 15:50:17 2020 +0100
+++ b/OrthancServer/ServerJobs/OrthancJobUnserializer.cpp	Fri Jan 31 16:53:23 2020 +0100
@@ -49,10 +49,11 @@
 
 #include "DicomModalityStoreJob.h"
 #include "DicomMoveScuJob.h"
+#include "MergeStudyJob.h"
 #include "OrthancPeerStoreJob.h"
 #include "ResourceModificationJob.h"
-#include "MergeStudyJob.h"
 #include "SplitStudyJob.h"
+#include "StorageCommitmentScpJob.h"
 
 
 namespace Orthanc
@@ -96,6 +97,10 @@
     {
       return new DicomMoveScuJob(context_, source);
     }
+    else if (type == "StorageCommitmentScp")
+    {
+      return new StorageCommitmentScpJob(context_, source);
+    }
     else
     {
       return GenericJobUnserializer::UnserializeJob(source);
--- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp	Fri Jan 31 15:50:17 2020 +0100
+++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp	Fri Jan 31 16:53:23 2020 +0100
@@ -37,10 +37,26 @@
 #include "../../Core/DicomNetworking/DicomUserConnection.h"
 #include "../../Core/Logging.h"
 #include "../../Core/OrthancException.h"
+#include "../../Core/SerializationToolbox.h"
 #include "../OrthancConfiguration.h"
 #include "../ServerContext.h"
 
 
+static const char* ANSWER = "Answer";
+static const char* CALLED_AET = "CalledAet";
+static const char* FAILED_SOP_CLASS_UIDS = "FailedSopClassUids";
+static const char* FAILED_SOP_INSTANCE_UIDS = "FailedSopInstanceUids";
+static const char* LOOKUP = "Lookup";
+static const char* REMOTE_MODALITY = "RemoteModality";
+static const char* SOP_CLASS_UID = "SopClassUid";
+static const char* SOP_INSTANCE_UID = "SopInstanceUid";
+static const char* SUCCESS_SOP_CLASS_UIDS = "SuccessSopClassUids";
+static const char* SUCCESS_SOP_INSTANCE_UIDS = "SuccessSopInstanceUids";
+static const char* TRANSACTION_UID = "TransactionUid";
+static const char* TYPE = "Type";
+
+
+
 namespace Orthanc
 {
   class StorageCommitmentScpJob::LookupCommand : public SetOfCommandsJob::ICommand
@@ -69,9 +85,9 @@
     virtual void Serialize(Json::Value& target) const
     {
       target = Json::objectValue;
-      target["Type"] = "Lookup";
-      target["SopClassUid"] = sopClassUid_;
-      target["SopInstanceUid"] = sopInstanceUid_;
+      target[TYPE] = LOOKUP;
+      target[SOP_CLASS_UID] = sopClassUid_;
+      target[SOP_INSTANCE_UID] = sopInstanceUid_;
     }
   };
 
@@ -96,7 +112,7 @@
     virtual void Serialize(Json::Value& target) const
     {
       target = Json::objectValue;
-      target["Type"] = "Answer";
+      target[TYPE] = ANSWER;
     }
   };
     
@@ -114,14 +130,22 @@
 
     virtual ICommand* Unserialize(const Json::Value& source) const
     {
-      std::cout << "===================================\n";
-      std::cout << source.toStyledString();
-        
-      /*DicomMap findAnswer;
-        findAnswer.Unserialize(source);
-        return new Command(that_, findAnswer);*/
+      const std::string type = SerializationToolbox::ReadString(source, TYPE);
 
-      throw OrthancException(ErrorCode_NotImplemented);
+      if (type == LOOKUP)
+      {
+        return new LookupCommand(that_,
+                                 SerializationToolbox::ReadString(source, SOP_CLASS_UID),
+                                 SerializationToolbox::ReadString(source, SOP_INSTANCE_UID));
+      }
+      else if (type == ANSWER)
+      {
+        return new AnswerCommand(that_);
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
     }
   };
 
@@ -235,8 +259,47 @@
   {
     SetOfCommandsJob::GetPublicContent(value);
       
-    value["LocalAet"] = calledAet_;
+    value["CalledAet"] = calledAet_;
     value["RemoteAet"] = remoteModality_.GetApplicationEntityTitle();
     value["TransactionUid"] = transactionUid_;
   }
+
+
+
+  StorageCommitmentScpJob::StorageCommitmentScpJob(ServerContext& context,
+                                                   const Json::Value& serialized) :
+    SetOfCommandsJob(new Unserializer(*this), serialized),
+    context_(context),
+    ready_(false)
+  {
+    transactionUid_ = SerializationToolbox::ReadString(serialized, TRANSACTION_UID);
+    remoteModality_ = RemoteModalityParameters(serialized[REMOTE_MODALITY]);
+    calledAet_ = SerializationToolbox::ReadString(serialized, CALLED_AET);
+    SerializationToolbox::ReadListOfStrings(successSopClassUids_, serialized, SUCCESS_SOP_CLASS_UIDS);
+    SerializationToolbox::ReadListOfStrings(successSopInstanceUids_, serialized, SUCCESS_SOP_INSTANCE_UIDS);
+    SerializationToolbox::ReadListOfStrings(failedSopClassUids_, serialized, FAILED_SOP_CLASS_UIDS);
+    SerializationToolbox::ReadListOfStrings(failedSopInstanceUids_, serialized, FAILED_SOP_INSTANCE_UIDS);
+
+    MarkAsReady();
+  }
+  
+
+  bool StorageCommitmentScpJob::Serialize(Json::Value& target)
+  {
+    if (!SetOfCommandsJob::Serialize(target))
+    {
+      return false;
+    }
+    else
+    {
+      target[TRANSACTION_UID] = transactionUid_;
+      remoteModality_.Serialize(target[REMOTE_MODALITY], true /* force advanced format */);
+      target[CALLED_AET] = calledAet_;
+      SerializationToolbox::WriteListOfStrings(target, successSopClassUids_, SUCCESS_SOP_CLASS_UIDS);
+      SerializationToolbox::WriteListOfStrings(target, successSopInstanceUids_, SUCCESS_SOP_INSTANCE_UIDS);
+      SerializationToolbox::WriteListOfStrings(target, failedSopClassUids_, FAILED_SOP_CLASS_UIDS);
+      SerializationToolbox::WriteListOfStrings(target, failedSopInstanceUids_, FAILED_SOP_INSTANCE_UIDS);
+      return true;
+    }
+  }
 }
--- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.h	Fri Jan 31 15:50:17 2020 +0100
+++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.h	Fri Jan 31 16:53:23 2020 +0100
@@ -69,20 +69,25 @@
                             const std::string& remoteAet,
                             const std::string& calledAet);
 
+    StorageCommitmentScpJob(ServerContext& context,
+                            const Json::Value& serialized);
+
     void AddInstance(const std::string& sopClassUid,
                      const std::string& sopInstanceUid);
 
     void MarkAsReady();
 
-    virtual void Stop(JobStopReason reason)
+    virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE
     {
     }
 
-    virtual void GetJobType(std::string& target)
+    virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE
     {
       target = "StorageCommitmentScp";
     }
 
-    virtual void GetPublicContent(Json::Value& value);
+    virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE;
+
+    virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE;
   };
 }