changeset 4245:c70df925151e

RequestOrigin_WebDav
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 10 Oct 2020 11:23:11 +0200
parents 416c35da7d25
children 6c3721ff284c
files OrthancFramework/Sources/Enumerations.cpp OrthancFramework/Sources/Enumerations.h OrthancServer/Plugins/Engine/PluginsEnumerations.cpp OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h OrthancServer/Sources/DicomInstanceOrigin.cpp OrthancServer/Sources/DicomInstanceOrigin.h OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/UnitTestsSources/ServerJobsTests.cpp
diffstat 8 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/Enumerations.cpp	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancFramework/Sources/Enumerations.cpp	Sat Oct 10 11:23:11 2020 +0200
@@ -738,6 +738,9 @@
       case RequestOrigin_Lua:
         return "Lua";
 
+      case RequestOrigin_WebDav:
+        return "WebDav";
+
       default:
         throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
@@ -1662,6 +1665,10 @@
     {
       return RequestOrigin_Lua;
     }
+    else if (origin == "WebDav")
+    {
+      return RequestOrigin_WebDav;
+    }
     else
     {
       throw OrthancException(ErrorCode_ParameterOutOfRange);
--- a/OrthancFramework/Sources/Enumerations.h	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancFramework/Sources/Enumerations.h	Sat Oct 10 11:23:11 2020 +0200
@@ -497,7 +497,8 @@
     RequestOrigin_DicomProtocol,
     RequestOrigin_RestApi,
     RequestOrigin_Plugins,
-    RequestOrigin_Lua
+    RequestOrigin_Lua,
+    RequestOrigin_WebDav   // New in Orthanc 1.8.0
   };
 
   enum ServerBarrierEvent
--- a/OrthancServer/Plugins/Engine/PluginsEnumerations.cpp	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/Plugins/Engine/PluginsEnumerations.cpp	Sat Oct 10 11:23:11 2020 +0200
@@ -288,6 +288,9 @@
         case RequestOrigin_Unknown:
           return OrthancPluginInstanceOrigin_Unknown;
 
+        case RequestOrigin_WebDav:
+          return OrthancPluginInstanceOrigin_WebDav;
+
         default:
           throw OrthancException(ErrorCode_ParameterOutOfRange);
       }
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Sat Oct 10 11:23:11 2020 +0200
@@ -116,8 +116,8 @@
 #endif
 
 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER     1
-#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER     7
-#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER  2
+#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER     8
+#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER  0
 
 
 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
@@ -891,6 +891,7 @@
     OrthancPluginInstanceOrigin_RestApi = 3,        /*!< Instance received through REST API of Orthanc */
     OrthancPluginInstanceOrigin_Plugin = 4,         /*!< Instance added to Orthanc by a plugin */
     OrthancPluginInstanceOrigin_Lua = 5,            /*!< Instance added to Orthanc by a Lua script */
+    OrthancPluginInstanceOrigin_WebDav = 6,         /*!< Instance received through WebDAV (new in 1.8.0) */
 
     _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
   } OrthancPluginInstanceOrigin;
--- a/OrthancServer/Sources/DicomInstanceOrigin.cpp	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/Sources/DicomInstanceOrigin.cpp	Sat Oct 10 11:23:11 2020 +0200
@@ -70,6 +70,7 @@
 
       case RequestOrigin_Lua:
       case RequestOrigin_Plugins:
+      case RequestOrigin_WebDav:
       {
         // No additional information available for these kinds of requests
         break;
--- a/OrthancServer/Sources/DicomInstanceOrigin.h	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/Sources/DicomInstanceOrigin.h	Sat Oct 10 11:23:11 2020 +0200
@@ -78,6 +78,11 @@
       return DicomInstanceOrigin(RequestOrigin_Plugins);
     }
 
+    static DicomInstanceOrigin FromWebDav()
+    {
+      return DicomInstanceOrigin(RequestOrigin_WebDav);
+    }
+
     RequestOrigin GetRequestOrigin() const
     {
       return origin_;
--- a/OrthancServer/Sources/OrthancWebDav.cpp	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/Sources/OrthancWebDav.cpp	Sat Oct 10 11:23:11 2020 +0200
@@ -1199,9 +1199,14 @@
         that->Upload(reinterpret_cast<const SingleValueObject<std::string>&>(*obj).GetValue());
         lastModification = GetNow();
       }
-      else if (GetNow() - lastModification > boost::posix_time::seconds(10))
+      else if (GetNow() - lastModification > boost::posix_time::seconds(30))
       {
-        // After every 10 seconds of inactivity, remove the empty folders
+        /**
+         * After every 30 seconds of inactivity, remove the empty
+         * folders. This delay is needed to avoid removing
+         * just-created folders before the remote WebDAV has time to
+         * write files into it.
+         **/
         LOG(INFO) << "Cleaning up the empty WebDAV upload folders";
         that->uploads_.RemoveEmptyFolders();
         lastModification = GetNow();
@@ -1223,7 +1228,7 @@
     if (uploads_.GetFileContent(mime, content, time, uri))
     {
       DicomInstanceToStore instance;
-      // instance.SetOrigin(DicomInstanceOrigin_WebDav);   // TODO
+      instance.SetOrigin(DicomInstanceOrigin::FromWebDav());
       instance.SetBuffer(content.c_str(), content.size());
 
       bool success = false;
@@ -1235,7 +1240,8 @@
         if (status == StoreStatus_Success ||
             status == StoreStatus_AlreadyStored)
         {
-          LOG(INFO) << "Successfully imported DICOM instance from WebDAV: " << path << " (Orthanc ID: " << publicId << ")";
+          LOG(INFO) << "Successfully imported DICOM instance from WebDAV: "
+                    << path << " (Orthanc ID: " << publicId << ")";
           success = true;
         }
       }
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Sat Oct 10 10:38:45 2020 +0200
+++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Sat Oct 10 11:23:11 2020 +0200
@@ -478,6 +478,23 @@
     ASSERT_FALSE(origin.LookupCalledAet(t));
     ASSERT_FALSE(origin.LookupHttpUsername(t));
   }
+
+  {
+    DicomInstanceOrigin origin(DicomInstanceOrigin::FromWebDav());
+
+    s = 42;
+    origin.Serialize(s);
+  }
+
+  {
+    DicomInstanceOrigin origin(s);
+    ASSERT_EQ(RequestOrigin_WebDav, origin.GetRequestOrigin());
+    ASSERT_EQ("", std::string(origin.GetRemoteAetC()));
+    ASSERT_FALSE(origin.LookupRemoteIp(t));
+    ASSERT_FALSE(origin.LookupRemoteAet(t));
+    ASSERT_FALSE(origin.LookupCalledAet(t));
+    ASSERT_FALSE(origin.LookupHttpUsername(t));
+  }
 }