changeset 2646:740983056f9e jobs

StringToJobState
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 31 May 2018 17:30:22 +0200
parents 5b3bfdf6b790
children 73d7d95dd75e
files Core/Enumerations.cpp Core/Enumerations.h Core/JobsEngine/GenericJobUnserializer.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 4 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Wed May 30 10:50:57 2018 +0200
+++ b/Core/Enumerations.cpp	Thu May 31 17:30:22 2018 +0200
@@ -1464,6 +1464,39 @@
   }
 
 
+  JobState StringToJobState(const std::string& state)
+  {
+    if (state == "Pending")
+    {
+      return JobState_Pending;
+    }
+    else if (state == "Running")
+    {
+      return JobState_Running;
+    }
+    else if (state == "Success")
+    {
+      return JobState_Success;
+    }
+    else if (state == "Failure")
+    {
+      return JobState_Failure;
+    }
+    else if (state == "Paused")
+    {
+      return JobState_Paused;
+    }
+    else if (state == "Retry")
+    {
+      return JobState_Retry;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
   unsigned int GetBytesPerPixel(PixelFormat format)
   {
     switch (format)
--- a/Core/Enumerations.h	Wed May 30 10:50:57 2018 +0200
+++ b/Core/Enumerations.h	Thu May 31 17:30:22 2018 +0200
@@ -659,6 +659,8 @@
   ModalityManufacturer StringToModalityManufacturer(const std::string& manufacturer);
 
   DicomVersion StringToDicomVersion(const std::string& version);
+
+  JobState StringToJobState(const std::string& state);
   
   unsigned int GetBytesPerPixel(PixelFormat format);
 
--- a/Core/JobsEngine/GenericJobUnserializer.cpp	Wed May 30 10:50:57 2018 +0200
+++ b/Core/JobsEngine/GenericJobUnserializer.cpp	Thu May 31 17:30:22 2018 +0200
@@ -46,6 +46,7 @@
   IJob* GenericJobUnserializer::UnserializeJob(const Json::Value& source)
   {
     const std::string type = GetString(source, "Type");
+    JobState state = StringToJobState(GetString(source, "State"));
 
     LOG(ERROR) << "Cannot unserialize job of type: " << type;
     throw OrthancException(ErrorCode_BadFileFormat);
--- a/UnitTestsSources/UnitTestsMain.cpp	Wed May 30 10:50:57 2018 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Thu May 31 17:30:22 2018 +0200
@@ -677,6 +677,14 @@
   }
 
   ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException);
+
+  ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending)));
+  ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running)));
+  ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success)));
+  ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure)));
+  ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused)));
+  ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry)));
+  ASSERT_THROW(StringToJobState("nope"), OrthancException);
 }