changeset 5274:e5b0bd6b2242

Added option "?numeric" if listing metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Apr 2023 12:12:34 +0200
parents 7cb1b851f5c8
children 8686476e9d12
files NEWS OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Apr 14 11:49:24 2023 +0200
+++ b/NEWS	Fri Apr 14 12:12:34 2023 +0200
@@ -17,6 +17,7 @@
 * "/tools/find" now accepts the "Labels" and "LabelsConstraint" arguments
 * "/tools/labels" lists all the labels that are associated with any resource
 * "/system": added "UserMetadata" and "HasLabels"
+* Added option "?numeric" if listing metadata
 
 Plugins
 -------
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Apr 14 11:49:24 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Fri Apr 14 12:12:34 2023 +0200
@@ -1679,6 +1679,8 @@
         .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
         .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String,
                             "If present, also retrieve the value of the individual metadata", false)
+        .SetHttpGetArgument("numeric", RestApiCallDocumentation::Type_String,
+                            "If present, use the numeric identifier of the metadata instead of its symbolic name", false)
         .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, "
                        "or JSON associative array mapping metadata to their values (if `expand` argument is provided)")
         .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true);
@@ -1696,15 +1698,26 @@
 
     Json::Value result;
 
+    bool isNumeric = call.HasArgument("numeric");
+
     if (call.HasArgument("expand"))
     {
       result = Json::objectValue;
       
       for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
       {
-        std::string key = EnumerationToString(it->first);
+        std::string key;
+        if (isNumeric)
+        {
+          key = boost::lexical_cast<std::string>(it->first);
+        }
+        else
+        {
+          key = EnumerationToString(it->first);
+        }
+
         result[key] = it->second;
-      }      
+      }
     }
     else
     {
@@ -1712,7 +1725,14 @@
       
       for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it)
       {       
-        result.append(EnumerationToString(it->first));
+        if (isNumeric)
+        {
+          result.append(it->first);
+        }
+        else
+        {
+          result.append(EnumerationToString(it->first));
+        }
       }
     }