changeset 2589:a3fdfb6979ed jobs

getting rid of ReusableDicomConnection in REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 May 2018 16:10:03 +0200
parents bf14b037731f
children 5e2730c8e23c
files Core/JobsEngine/JobInfo.cpp Core/JobsEngine/JobInfo.h OrthancExplorer/explorer.js OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/OrthancRestApi/OrthancRestSystem.cpp UnitTestsSources/MultiThreadingTests.cpp
diffstat 6 files changed, 80 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/Core/JobsEngine/JobInfo.cpp	Mon May 14 21:44:41 2018 +0200
+++ b/Core/JobsEngine/JobInfo.cpp	Tue May 15 16:10:03 2018 +0200
@@ -116,7 +116,8 @@
   }
 
 
-  void JobInfo::Serialize(Json::Value& target) const
+  void JobInfo::Serialize(Json::Value& target,
+                          bool includeInternalContent) const
   {
     target = Json::objectValue;
     target["ID"] = id_;
@@ -131,7 +132,11 @@
 
     target["Type"] = status_.GetJobType();
     target["PublicContent"] = status_.GetPublicContent();
-    target["InternalContent"] = status_.GetInternalContent();
+
+    if (includeInternalContent)
+    {
+      target["InternalContent"] = status_.GetInternalContent();
+    }
 
     if (HasEstimatedTimeOfArrival())
     {
--- a/Core/JobsEngine/JobInfo.h	Mon May 14 21:44:41 2018 +0200
+++ b/Core/JobsEngine/JobInfo.h	Tue May 15 16:10:03 2018 +0200
@@ -115,6 +115,7 @@
       return status_;
     }
 
-    void Serialize(Json::Value& target) const;
+    void Serialize(Json::Value& target,
+                   bool includeInternalContent) const;
   };
 }
--- a/OrthancExplorer/explorer.js	Mon May 14 21:44:41 2018 +0200
+++ b/OrthancExplorer/explorer.js	Tue May 15 16:10:03 2018 +0200
@@ -1181,8 +1181,14 @@
         AddJobDateField(item, 'Completion time: ', job.CompletionTime);
         AddJobDateField(item, 'ETA: ', job.EstimatedTimeOfArrival);
 
+        if (job.State == 'Running' ||
+            job.State == 'Pending' ||
+            job.State == 'Paused') {
+          AddJobField(item, 'Priority: ', job.Priority);
+          AddJobField(item, 'Progress: ', job.Progress);
+        }
+        
         if (job.State == 'Running') {
-          AddJobField(item, 'Progress: ', job.Progress);
           li.insertAfter(running);
         } else if (job.State == 'Pending' ||
                    job.State == 'Paused') {
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Mon May 14 21:44:41 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Tue May 15 16:10:03 2018 +0200
@@ -304,12 +304,15 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
     try
     {
-      if (locker.GetConnection().Echo())
+      DicomUserConnection connection(localAet, remote);
+      connection.Open();
+      
+      if (connection.Echo())
       {
         // Echo has succeeded
         call.GetOutput().AnswerBuffer("{}", "application/json");
@@ -425,11 +428,16 @@
     }
 
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
+    
+    DicomFindAnswers answers(false);
 
-    DicomFindAnswers answers(false);
-    FindPatient(answers, locker.GetConnection(), fields);
+    {
+      DicomUserConnection connection(localAet, remote);
+      connection.Open();
+      FindPatient(answers, connection, fields);
+    }
 
     Json::Value result;
     answers.ToJson(result, true);
@@ -455,11 +463,16 @@
     }        
       
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
     DicomFindAnswers answers(false);
-    FindStudy(answers, locker.GetConnection(), fields);
+
+    {
+      DicomUserConnection connection(localAet, remote);
+      connection.Open();
+      FindStudy(answers, connection, fields);
+    }
 
     Json::Value result;
     answers.ToJson(result, true);
@@ -486,11 +499,16 @@
     }        
          
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
     DicomFindAnswers answers(false);
-    FindSeries(answers, locker.GetConnection(), fields);
+
+    {
+      DicomUserConnection connection(localAet, remote);
+      connection.Open();
+      FindSeries(answers, connection, fields);
+    }
 
     Json::Value result;
     answers.ToJson(result, true);
@@ -518,11 +536,16 @@
     }        
          
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
     DicomFindAnswers answers(false);
-    FindInstance(answers, locker.GetConnection(), fields);
+
+    {
+      DicomUserConnection connection(localAet, remote);
+      connection.Open();
+      FindInstance(answers, connection, fields);
+    }
 
     Json::Value result;
     answers.ToJson(result, true);
@@ -555,11 +578,14 @@
     }
  
     const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-    RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-    ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
+    RemoteModalityParameters remote =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
+    DicomUserConnection connection(localAet, remote);
+    connection.Open();
+    
     DicomFindAnswers patients(false);
-    FindPatient(patients, locker.GetConnection(), m);
+    FindPatient(patients, connection, m);
 
     // Loop over the found patients
     Json::Value result = Json::arrayValue;
@@ -577,7 +603,7 @@
       CopyTagIfExists(m, patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
 
       DicomFindAnswers studies(false);
-      FindStudy(studies, locker.GetConnection(), m);
+      FindStudy(studies, connection, m);
 
       patient["Studies"] = Json::arrayValue;
       
@@ -597,7 +623,7 @@
         CopyTagIfExists(m, studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
 
         DicomFindAnswers series(false);
-        FindSeries(series, locker.GetConnection(), m);
+        FindSeries(series, connection, m);
 
         // Loop over the found series
         study["Series"] = Json::arrayValue;
@@ -1034,15 +1060,18 @@
     std::string targetAet = Toolbox::GetJsonStringField
       (request, "TargetAet", context.GetDefaultLocalApplicationEntityTitle());
 
-    const RemoteModalityParameters source = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
-      
+    const RemoteModalityParameters source =
+      Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
+
+    DicomUserConnection connection(localAet, source);
+    connection.Open();
+    
     for (Json::Value::ArrayIndex i = 0; i < request[RESOURCES].size(); i++)
     {
       DicomMap resource;
       FromDcmtkBridge::FromJson(resource, request[RESOURCES][i]);
-
-      ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, source);
-      locker.GetConnection().Move(targetAet, level, resource);
+      
+      connection.Move(targetAet, level, resource);
     }
 
     // Move has succeeded
@@ -1236,15 +1265,17 @@
     if (call.ParseJsonRequest(json))
     {
       const std::string& localAet = context.GetDefaultLocalApplicationEntityTitle();
-      RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
+      RemoteModalityParameters remote =
+        Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
 
       std::auto_ptr<ParsedDicomFile> query(ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(0)));
 
       DicomFindAnswers answers(true);
 
       {
-        ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
-        locker.GetConnection().FindWorklist(answers, *query);
+        DicomUserConnection connection(localAet, remote);
+        connection.Open();
+        connection.FindWorklist(answers, *query);
       }
 
       Json::Value result;
--- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Mon May 14 21:44:41 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Tue May 15 16:10:03 2018 +0200
@@ -291,7 +291,7 @@
         if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().GetJobInfo(info, *it))
         {
           Json::Value tmp;
-          info.Serialize(tmp);
+          info.Serialize(tmp, false);
           v.append(tmp);
         }
       }
@@ -312,7 +312,7 @@
     if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().GetJobInfo(info, id))
     {
       Json::Value json;
-      info.Serialize(json);
+      info.Serialize(json, false);
       call.GetOutput().AnswerJson(json);
     }
   }
--- a/UnitTestsSources/MultiThreadingTests.cpp	Mon May 14 21:44:41 2018 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Tue May 15 16:10:03 2018 +0200
@@ -754,7 +754,7 @@
       if (engine.GetRegistry().GetJobInfo(info, *it))
       {
         Json::Value vv;
-        info.Serialize(vv);
+        info.Serialize(vv, true);
         v.append(vv);
       }
     }
@@ -790,7 +790,7 @@
       if (engine.GetRegistry().GetJobInfo(info, *it))
       {
         Json::Value vv;
-        info.Serialize(vv);
+        info.Serialize(vv, true);
         v.append(vv);
       }
     }