changeset 7031:e3f08ad9fb57

/tools/bulk-delete new payload
author Alain Mazy <am@orthanc.team>
date Fri, 17 Jul 2026 14:51:47 +0200
parents 186b7ca8990d
children 00052ea493bd fc23f88f2f2f
files NEWS OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 3 files changed, 48 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Jul 17 11:19:44 2026 +0200
+++ b/NEWS	Fri Jul 17 14:51:47 2026 +0200
@@ -35,7 +35,7 @@
 REST API
 --------
 
-* API version upgraded to 31
+* API version upgraded to 33
 * New fields reported in the "/system" route:
   - "OverwriteInstancesMode" (Boolean field "OverwriteInstances" is kept for backward
     compatibility)
@@ -54,6 +54,9 @@
     monitoring.  These metrics have been replaced by "orthanc_jobs_total_completed", 
     "orthanc_jobs_total_success" and "orthanc_jobs_total_failed" that are now considering all the 
     jobs that have run since Orthanc started.
+* The "/tools/bulk-delete" route now also accepts a payload of this type:
+  {"Resources": [{"Level": "Study", "ID": "..."}]}.  This payload reduces the number
+  of calls to the SQL DB and is more suitable for the authorization plugin.
 
 Plugin SDK
 ----------
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Fri Jul 17 11:19:44 2026 +0200
+++ b/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Fri Jul 17 14:51:47 2026 +0200
@@ -39,7 +39,7 @@
 # Version of the Orthanc API, can be retrieved from "/system" URI in
 # order to check whether new URI endpoints are available even if using
 # the mainline version of Orthanc
-set(ORTHANC_API_VERSION "31")
+set(ORTHANC_API_VERSION "33")
 
 
 #####################################################################
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Jul 17 11:19:44 2026 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Jul 17 14:51:47 2026 +0200
@@ -4226,13 +4226,19 @@
 
   static void BulkDelete(RestApiPostCall& call)
   {
+    static const char* const KEY_RESOURCES = "Resources";
+    static const char* const KEY_LEVEL = "Level";
+    static const char* const KEY_ID = "ID";
+
     if (call.IsDocumentation())
     {
       call.GetDocumentation()
         .SetTag("System")
         .SetSummary("Delete a set of resources")
-        .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
-                         "List of the Orthanc identifiers of the patients/studies/series/instances of interest.", true)
+        .SetRequestField(KEY_RESOURCES, RestApiCallDocumentation::Type_JsonListOfStrings,
+                         "List of the Orthanc identifiers of the patients/studies/series/instances of interest.  "
+                         "Starting from Orthanc 1.13.0, this array can also contain an array of JSON objects with "
+                         "2 fields each: 'Level' and 'ID'.", true)
         .SetDescription("Delete all the DICOM patients, studies, series or instances "
                         "whose identifiers are provided in the `Resources` field.");
       return;
@@ -4249,19 +4255,44 @@
     }
     else
     {
-      std::set<std::string> resources;
-      SerializationToolbox::ReadSetOfStrings(resources, request, "Resources");
-
-      for (std::set<std::string>::const_iterator
-             it = resources.begin(); it != resources.end(); ++it)
+      if (!request.isMember(KEY_RESOURCES) || !request[KEY_RESOURCES].isArray()) 
+      {
+        throw OrthancException(ErrorCode_BadRequest, 
+                               std::string("The body must contain a ") + KEY_RESOURCES + " array");
+      }
+
+      for (Json::ArrayIndex i = 0; i < request[KEY_RESOURCES].size(); ++i)
       {
-        ResourceType type;
         Json::Value remainingAncestor;  // Unused
-        
-        if (!context.GetIndex().LookupResourceType(type, *it) ||
-            !context.DeleteResource(remainingAncestor, *it, type))
+
+        const Json::Value& resource = request[KEY_RESOURCES][i];
+        if (resource.isString())
         {
-          CLOG(INFO, HTTP) << "Unknown resource during a bulk deletion: " << *it;
+          ResourceType type;
+          
+          const std::string& resourceId = resource.asString();
+
+          if (!context.GetIndex().LookupResourceType(type, resourceId) ||
+              !context.DeleteResource(remainingAncestor, resourceId, type))
+          {
+            CLOG(INFO, HTTP) << "Unknown resource during a bulk deletion: " << resourceId;
+          }
+        }
+        else if (resource.isObject() && resource.isMember(KEY_ID) && resource[KEY_ID].isString()
+          && resource.isMember(KEY_LEVEL) && resource[KEY_LEVEL].isString())
+        {
+          ResourceType type = StringToResourceType(resource[KEY_LEVEL].asString().c_str());
+          
+          const std::string& resourceId = resource[KEY_ID].asString();
+
+          if (!context.DeleteResource(remainingAncestor, resourceId, type))
+          {
+            CLOG(INFO, HTTP) << "Unknown resource during a bulk deletion: " << resourceId;
+          }
+        }
+        else
+        {
+          throw OrthancException(ErrorCode_BadRequest, "Invalid payload");
         }
       }