Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 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 | a7d95f951f8a |
children | 8686476e9d12 |
comparison
equal
deleted
inserted
replaced
5273:7cb1b851f5c8 | 5274:e5b0bd6b2242 |
---|---|
1677 .SetSummary("List metadata") | 1677 .SetSummary("List metadata") |
1678 .SetDescription("Get the list of metadata that are associated with the given " + r) | 1678 .SetDescription("Get the list of metadata that are associated with the given " + r) |
1679 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | 1679 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
1680 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, | 1680 .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String, |
1681 "If present, also retrieve the value of the individual metadata", false) | 1681 "If present, also retrieve the value of the individual metadata", false) |
1682 .SetHttpGetArgument("numeric", RestApiCallDocumentation::Type_String, | |
1683 "If present, use the numeric identifier of the metadata instead of its symbolic name", false) | |
1682 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, " | 1684 .AddAnswerType(MimeType_Json, "JSON array containing the names of the available metadata, " |
1683 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") | 1685 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") |
1684 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | 1686 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); |
1685 return; | 1687 return; |
1686 } | 1688 } |
1694 Metadata metadata; | 1696 Metadata metadata; |
1695 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level); | 1697 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level); |
1696 | 1698 |
1697 Json::Value result; | 1699 Json::Value result; |
1698 | 1700 |
1701 bool isNumeric = call.HasArgument("numeric"); | |
1702 | |
1699 if (call.HasArgument("expand")) | 1703 if (call.HasArgument("expand")) |
1700 { | 1704 { |
1701 result = Json::objectValue; | 1705 result = Json::objectValue; |
1702 | 1706 |
1703 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) | 1707 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) |
1704 { | 1708 { |
1705 std::string key = EnumerationToString(it->first); | 1709 std::string key; |
1710 if (isNumeric) | |
1711 { | |
1712 key = boost::lexical_cast<std::string>(it->first); | |
1713 } | |
1714 else | |
1715 { | |
1716 key = EnumerationToString(it->first); | |
1717 } | |
1718 | |
1706 result[key] = it->second; | 1719 result[key] = it->second; |
1707 } | 1720 } |
1708 } | 1721 } |
1709 else | 1722 else |
1710 { | 1723 { |
1711 result = Json::arrayValue; | 1724 result = Json::arrayValue; |
1712 | 1725 |
1713 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) | 1726 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) |
1714 { | 1727 { |
1715 result.append(EnumerationToString(it->first)); | 1728 if (isNumeric) |
1729 { | |
1730 result.append(it->first); | |
1731 } | |
1732 else | |
1733 { | |
1734 result.append(EnumerationToString(it->first)); | |
1735 } | |
1716 } | 1736 } |
1717 } | 1737 } |
1718 | 1738 |
1719 call.GetOutput().AnswerJson(result); | 1739 call.GetOutput().AnswerJson(result); |
1720 } | 1740 } |