changeset 3611:0ce9c1c6474f storage-commitment

test route in REST API for storage commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 Jan 2020 12:53:03 +0100
parents c85808adf04a
children 22eef03feed7
files Core/DicomNetworking/DicomUserConnection.cpp Core/DicomNetworking/DicomUserConnection.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp
diffstat 3 files changed, 46 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomNetworking/DicomUserConnection.cpp	Mon Jan 20 19:09:49 2020 +0100
+++ b/Core/DicomNetworking/DicomUserConnection.cpp	Tue Jan 21 12:53:03 2020 +0100
@@ -1541,7 +1541,7 @@
 
   
   void DicomUserConnection::RequestStorageCommitment(
-    std::string& transactionUid,
+    const std::string& transactionUid,
     const std::vector<std::string>& sopClassUids,
     const std::vector<std::string>& sopInstanceUids)
   {
@@ -1550,6 +1550,12 @@
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
 
+    if (transactionUid.size() < 5 ||
+        transactionUid.substr(0, 5) != "2.25.")
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
     if (IsOpen())
     {
       Close();
@@ -1559,8 +1565,6 @@
     {
       OpenInternal(Mode_RequestStorageCommitment);
 
-      transactionUid = Toolbox::GenerateDicomPrivateUniqueIdentifier();
-
       /**
        * N-ACTION
        * http://dicom.nema.org/medical/dicom/2019a/output/chtml/part04/sect_J.3.2.html
@@ -1575,7 +1579,8 @@
        **/
 
       LOG(INFO) << "Request to modality \"" << remoteAet_
-                << "\" about storage commitment for " << sopClassUids.size() << " instances";
+                << "\" about storage commitment for " << sopClassUids.size()
+                << " instances, with transaction UID: " << transactionUid;
       const DIC_US messageId = pimpl_->assoc_->nextMsgID++;
       
       {
--- a/Core/DicomNetworking/DicomUserConnection.h	Mon Jan 20 19:09:49 2020 +0100
+++ b/Core/DicomNetworking/DicomUserConnection.h	Tue Jan 21 12:53:03 2020 +0100
@@ -233,8 +233,9 @@
       const std::vector<std::string>& failureSopClassUids,
       const std::vector<std::string>& failureSopInstanceUids);      
 
+    // transactionUid: To be generated by Toolbox::GenerateDicomPrivateUniqueIdentifier()
     void RequestStorageCommitment(
-      std::string& transactionUid,
+      const std::string& transactionUid,
       const std::vector<std::string>& sopClassUids,
       const std::vector<std::string>& sopInstanceUids);
   };
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Mon Jan 20 19:09:49 2020 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Tue Jan 21 12:53:03 2020 +0100
@@ -1273,7 +1273,7 @@
     if (call.ParseJsonRequest(json))
     {
       const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-      RemoteModalityParameters remote =
+      const RemoteModalityParameters remote =
         MyGetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
       std::auto_ptr<ParsedDicomFile> query
@@ -1298,6 +1298,38 @@
   }
 
 
+  static void TestStorageCommitment(RestApiPostCall& call)
+  {
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
+    Json::Value json;
+    if (call.ParseJsonRequest(json))
+    {
+      const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
+      const RemoteModalityParameters remote =
+        MyGetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
+
+      {
+        DicomUserConnection scu(localAet, remote);
+
+        std::vector<std::string> sopClassUids, sopInstanceUids;
+        sopClassUids.push_back("a");
+        sopInstanceUids.push_back("b");
+
+        std::string t = Toolbox::GenerateDicomPrivateUniqueIdentifier();
+        scu.RequestStorageCommitment(t, sopClassUids, sopInstanceUids);
+      }
+
+      Json::Value result;
+      call.GetOutput().AnswerJson(result);
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object");
+    }
+  }
+
+
   void OrthancRestApi::RegisterModalities()
   {
     Register("/modalities", ListModalities);
@@ -1341,5 +1373,7 @@
     Register("/peers/{id}/system", PeerSystem);
 
     Register("/modalities/{id}/find-worklist", DicomFindWorklist);
+
+    Register("/modalities/{id}/storage-commitment", TestStorageCommitment);
   }
 }