diff OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 5169:8b74aa4f3515

enforce the existence of the patient/study/instance while creating its archive
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Feb 2023 18:07:35 +0100
parents 027366cae766
children 0ea402b4d901
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Wed Feb 22 11:10:40 2023 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Fri Feb 24 18:07:35 2023 +0100
@@ -1155,7 +1155,9 @@
   }
 
   
-  void ArchiveJob::AddResource(const std::string& publicId)
+  void ArchiveJob::AddResource(const std::string& publicId,
+                               bool mustExist,
+                               ResourceType expectedType)
   {
     if (writer_.get() != NULL)   // Already started
     {
@@ -1163,6 +1165,17 @@
     }
     else
     {
+      if (mustExist)
+      {
+        ResourceType type;
+        if (!context_.GetIndex().LookupResourceType(type, publicId) ||
+            type != expectedType)
+        {
+          throw OrthancException(ErrorCode_InexistentItem,
+                                 "Missing resource while creating an archive: " + publicId);
+        }
+      }
+      
       ResourceIdentifiers resource(context_.GetIndex(), publicId);
       archive_->Add(context_.GetIndex(), resource);
     }