changeset 2659:c27f7ecf9b54 jobs

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Jun 2018 12:24:17 +0200
parents ce770f095092
children 27b7884512be
files Core/DicomNetworking/RemoteModalityParameters.cpp Core/WebServiceParameters.cpp OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.h OrthancServer/ServerJobs/Operations/StorePeerOperation.h OrthancServer/ServerJobs/Operations/StoreScuOperation.cpp OrthancServer/ServerJobs/Operations/StoreScuOperation.h OrthancServer/ServerJobs/Operations/SystemCallOperation.cpp OrthancServer/ServerJobs/Operations/SystemCallOperation.h UnitTestsSources/MultiThreadingTests.cpp
diffstat 9 files changed, 198 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomNetworking/RemoteModalityParameters.cpp	Wed Jun 06 18:37:43 2018 +0200
+++ b/Core/DicomNetworking/RemoteModalityParameters.cpp	Thu Jun 07 12:24:17 2018 +0200
@@ -36,6 +36,7 @@
 
 #include "../Logging.h"
 #include "../OrthancException.h"
+#include "../SerializationToolbox.h"
 
 #include <boost/lexical_cast.hpp>
 #include <stdexcept>
@@ -130,12 +131,21 @@
   
   void RemoteModalityParameters::Serialize(Json::Value& target) const
   {
-    throw OrthancException(ErrorCode_NotImplemented);
+    target = Json::objectValue;
+    target["AET"] = aet_;
+    target["Host"] = host_;
+    target["Port"] = port_;
+    target["Manufacturer"] = EnumerationToString(manufacturer_);
   }
 
   
   RemoteModalityParameters::RemoteModalityParameters(const Json::Value& serialized)
   {
-    throw OrthancException(ErrorCode_NotImplemented);
+    aet_ = SerializationToolbox::ReadString(serialized, "AET");
+    host_ = SerializationToolbox::ReadString(serialized, "Host");
+    port_ = static_cast<uint16_t>
+      (SerializationToolbox::ReadUnsignedInteger(serialized, "Port"));
+    manufacturer_ = StringToModalityManufacturer
+      (SerializationToolbox::ReadString(serialized, "Manufacturer"));
   }
 }
--- a/Core/WebServiceParameters.cpp	Wed Jun 06 18:37:43 2018 +0200
+++ b/Core/WebServiceParameters.cpp	Thu Jun 07 12:24:17 2018 +0200
@@ -34,8 +34,9 @@
 #include "PrecompiledHeaders.h"
 #include "WebServiceParameters.h"
 
-#include "../Core/Logging.h"
-#include "../Core/OrthancException.h"
+#include "Logging.h"
+#include "OrthancException.h"
+#include "SerializationToolbox.h"
 
 #if ORTHANC_SANDBOXED == 0
 #  include "../Core/SystemToolbox.h"
@@ -274,12 +275,34 @@
   
   void WebServiceParameters::Serialize(Json::Value& target) const
   {
-    throw OrthancException(ErrorCode_NotImplemented);
+    target = Json::objectValue;
+    target["URL"] = url_;
+    target["Username"] = username_;
+    target["Password"] = password_;
+    target["CertificateFile"] = certificateFile_;
+    target["CertificateKeyFile"] = certificateKeyFile_;
+    target["CertificateKeyPassword"] = certificateKeyPassword_;
+    target["PKCS11"] = pkcs11Enabled_;
   }
 
   
-  WebServiceParameters::WebServiceParameters(const Json::Value& serialized)
+  WebServiceParameters::WebServiceParameters(const Json::Value& serialized) :
+    advancedFormat_(true)
   {
-    throw OrthancException(ErrorCode_NotImplemented);
+    url_ = SerializationToolbox::ReadString(serialized, "URL");
+    username_ = SerializationToolbox::ReadString(serialized, "Username");
+    password_ = SerializationToolbox::ReadString(serialized, "Password");
+
+    std::string a, b, c;
+    a = SerializationToolbox::ReadString(serialized, "CertificateFile");
+    b = SerializationToolbox::ReadString(serialized, "CertificateKeyFile");
+    c = SerializationToolbox::ReadString(serialized, "CertificateKeyPassword");
+
+    if (!a.empty())
+    {
+      SetClientCertificate(a, b, c);
+    }
+    
+    pkcs11Enabled_ = SerializationToolbox::ReadBoolean(serialized, "PKCS11");
   }
 }
--- a/OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.h	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.h	Thu Jun 07 12:24:17 2018 +0200
@@ -55,6 +55,11 @@
     ModifyInstanceOperation(ServerContext& context,
                             const Json::Value& serialized);
 
+    const RequestOrigin& GetRequestOrigin() const
+    {
+      return origin_;
+    }
+    
     const DicomModification& GetModification() const
     {
       return *modification_;
--- a/OrthancServer/ServerJobs/Operations/StorePeerOperation.h	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/StorePeerOperation.h	Thu Jun 07 12:24:17 2018 +0200
@@ -51,6 +51,11 @@
 
     StorePeerOperation(const Json::Value& serialized);
 
+    const WebServiceParameters& GetPeer() const
+    {
+      return peer_;
+    }
+
     virtual void Apply(JobOperationValues& outputs,
                        const JobOperationValue& input,
                        IDicomConnectionManager& connectionManager);
--- a/OrthancServer/ServerJobs/Operations/StoreScuOperation.cpp	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/StoreScuOperation.cpp	Thu Jun 07 12:24:17 2018 +0200
@@ -99,6 +99,7 @@
       throw OrthancException(ErrorCode_BadFileFormat);
     }
 
+    localAet_ = SerializationToolbox::ReadString(serialized, "LocalAET");
     modality_ = RemoteModalityParameters(serialized["Modality"]);
   }
 }
--- a/OrthancServer/ServerJobs/Operations/StoreScuOperation.h	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/StoreScuOperation.h	Thu Jun 07 12:24:17 2018 +0200
@@ -54,6 +54,16 @@
 
     StoreScuOperation(const Json::Value& serialized);
 
+    const std::string& GetLocalAet() const
+    {
+      return localAet_;
+    }
+
+    const RemoteModalityParameters& GetRemoteModality() const
+    {
+      return modality_;
+    }
+
     virtual void Apply(JobOperationValues& outputs,
                        const JobOperationValue& input,
                        IDicomConnectionManager& manager);
--- a/OrthancServer/ServerJobs/Operations/SystemCallOperation.cpp	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/SystemCallOperation.cpp	Thu Jun 07 12:24:17 2018 +0200
@@ -38,12 +38,39 @@
 
 #include "../../../Core/JobsEngine/Operations/StringOperationValue.h"
 #include "../../../Core/Logging.h"
+#include "../../../Core/OrthancException.h"
 #include "../../../Core/SerializationToolbox.h"
 #include "../../../Core/TemporaryFile.h"
 #include "../../../Core/Toolbox.h"
 
 namespace Orthanc
 {
+  const std::string& SystemCallOperation::GetPreArgument(size_t i) const
+  {
+    if (i >= preArguments_.size())
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      return preArguments_[i];
+    }
+  }
+
+  
+  const std::string& SystemCallOperation::GetPostArgument(size_t i) const
+  {
+    if (i >= postArguments_.size())
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    else
+    {
+      return postArguments_[i];
+    }
+  }
+
+
   void SystemCallOperation::Apply(JobOperationValues& outputs,
                                   const JobOperationValue& input,
                                   IDicomConnectionManager& connectionManager)
--- a/OrthancServer/ServerJobs/Operations/SystemCallOperation.h	Wed Jun 06 18:37:43 2018 +0200
+++ b/OrthancServer/ServerJobs/Operations/SystemCallOperation.h	Thu Jun 07 12:24:17 2018 +0200
@@ -73,6 +73,25 @@
       postArguments_.push_back(argument);
     }
 
+    const std::string& GetCommand() const
+    {
+      return command_;
+    }
+
+    size_t GetPreArgumentsCount() const
+    {
+      return preArguments_.size();
+    }
+
+    size_t GetPostArgumentsCount() const
+    {
+      return postArguments_.size();
+    }
+
+    const std::string& GetPreArgument(size_t i) const;
+
+    const std::string& GetPostArgument(size_t i) const;
+
     virtual void Apply(JobOperationValues& outputs,
                        const JobOperationValue& input,
                        IDicomConnectionManager& connectionManager);
--- a/UnitTestsSources/MultiThreadingTests.cpp	Wed Jun 06 18:37:43 2018 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Thu Jun 07 12:24:17 2018 +0200
@@ -979,23 +979,108 @@
 
   Json::Value s;
 
+  // DeleteResourceOperation
+  
   {
     DeleteResourceOperation operation(GetContext());
     operation.Serialize(s);
   }
 
-  OrthancJobUnserializer unserializer(GetContext());
-    
+  OrthancJobUnserializer unserializer(GetContext()); 
   std::auto_ptr<IJobOperation> operation;
-  operation.reset(unserializer.UnserializeOperation(s));
+
+  {
+    operation.reset(unserializer.UnserializeOperation(s));
+
+    ASSERT_THROW(dynamic_cast<LogJobOperation&>(*operation), std::bad_cast);
+    dynamic_cast<DeleteResourceOperation&>(*operation);
+  }
+
+  // StorePeerOperation
+
+  {
+    WebServiceParameters peer;
+    peer.SetUrl("http://localhost/");
+    peer.SetUsername("username");
+    peer.SetPassword("password");
+    peer.SetPkcs11Enabled(true);
+
+    StorePeerOperation operation(peer);
+    operation.Serialize(s);
+  }
+
+  {
+    operation.reset(unserializer.UnserializeOperation(s));
+
+    const StorePeerOperation& tmp = dynamic_cast<StorePeerOperation&>(*operation);
+    ASSERT_EQ("http://localhost/", tmp.GetPeer().GetUrl());
+    ASSERT_EQ("username", tmp.GetPeer().GetUsername());
+    ASSERT_EQ("password", tmp.GetPeer().GetPassword());
+    ASSERT_TRUE(tmp.GetPeer().IsPkcs11Enabled());
+  }
+
+  // StoreScuOperation
 
-  // TODO : StorePeerOperation
+  {
+    RemoteModalityParameters modality;
+    modality.SetApplicationEntityTitle("REMOTE");
+    modality.SetHost("192.168.1.1");
+    modality.SetPort(1000);
+    modality.SetManufacturer(ModalityManufacturer_StoreScp);
+
+    StoreScuOperation operation("TEST", modality);
+    operation.Serialize(s);
+  }
+
+  {
+    operation.reset(unserializer.UnserializeOperation(s));
+
+    const StoreScuOperation& tmp = dynamic_cast<StoreScuOperation&>(*operation);
+    ASSERT_EQ("REMOTE", tmp.GetRemoteModality().GetApplicationEntityTitle());
+    ASSERT_EQ("192.168.1.1", tmp.GetRemoteModality().GetHost());
+    ASSERT_EQ(1000, tmp.GetRemoteModality().GetPort());
+    ASSERT_EQ(ModalityManufacturer_StoreScp, tmp.GetRemoteModality().GetManufacturer());
+    ASSERT_EQ("TEST", tmp.GetLocalAet());
+  }
 
-  // TODO : StoreScuOperation
+  // SystemCallOperation
+
+  {
+    SystemCallOperation operation(std::string("echo"));
+    operation.AddPreArgument("a");
+    operation.AddPreArgument("b");
+    operation.AddPostArgument("c");
+    operation.Serialize(s);
+  }
 
-  // TODO : SystemCallOperation
+  {
+    operation.reset(unserializer.UnserializeOperation(s));
+
+    const SystemCallOperation& tmp = dynamic_cast<SystemCallOperation&>(*operation);
+    ASSERT_EQ("echo", tmp.GetCommand());
+    ASSERT_EQ(2u, tmp.GetPreArgumentsCount());
+    ASSERT_EQ(1u, tmp.GetPostArgumentsCount());
+    ASSERT_EQ("a", tmp.GetPreArgument(0));
+    ASSERT_EQ("b", tmp.GetPreArgument(1));
+    ASSERT_EQ("c", tmp.GetPostArgument(0));
+  }
 
   // TODO : ModifyInstanceOperation
+
+  /*
+  {
+    std::auto_ptr<DicomModification> modification(new DicomModification);
+    
+    ModifyInstanceOperation operation(GetContext(), RequestOrigin_Lua, modification.release());
+    operation.Serialize(s);
+  }
+
+  {
+    operation.reset(unserializer.UnserializeOperation(s));
+
+    const ModifyInstanceOperation& tmp = dynamic_cast<ModifyInstanceOperation&>(*operation);
+    ASSERT_EQ(RequestOrigin_Lua, tmp.GetRequestOrigin());
+    }*/
 }