Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5221:d0f7c742d397 db-protobuf
started implementation of labels
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Apr 2023 20:53:14 +0200 |
parents | f8f1c4a9a216 |
children | 988dab8deb1c |
comparison
equal
deleted
inserted
replaced
5220:df39c7583a49 | 5221:d0f7c742d397 |
---|---|
1969 } | 1969 } |
1970 } | 1970 } |
1971 | 1971 |
1972 | 1972 |
1973 | 1973 |
1974 // Handling of labels ------------------------------------------------------- | |
1975 | |
1976 static void ListLabels(RestApiGetCall& call) | |
1977 { | |
1978 if (call.IsDocumentation()) | |
1979 { | |
1980 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
1981 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
1982 call.GetDocumentation() | |
1983 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
1984 .SetSummary("List labels (new in Orthanc 1.12.0)") | |
1985 .SetDescription("Get the labels that are associated with the given " + r) | |
1986 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
1987 .AddAnswerType(MimeType_Json, "JSON array containing the names of the labels") | |
1988 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/labels", true); | |
1989 return; | |
1990 } | |
1991 | |
1992 assert(!call.GetFullUri().empty()); | |
1993 const std::string publicId = call.GetUriComponent("id", ""); | |
1994 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
1995 | |
1996 std::set<std::string> labels; | |
1997 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); | |
1998 | |
1999 Json::Value result = Json::arrayValue; | |
2000 | |
2001 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it) | |
2002 { | |
2003 result.append(*it); | |
2004 } | |
2005 | |
2006 call.GetOutput().AnswerJson(result); | |
2007 } | |
2008 | |
2009 | |
2010 static void GetLabel(RestApiGetCall& call) | |
2011 { | |
2012 if (call.IsDocumentation()) | |
2013 { | |
2014 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2015 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2016 call.GetDocumentation() | |
2017 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2018 .SetSummary("Test label") | |
2019 .SetDescription("Test whether the " + r + " is associated with the given label") | |
2020 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2021 .SetUriArgument("label", "The label of interest") | |
2022 .AddAnswerType(MimeType_PlainText, "Empty string is returned in the case of presence, error 404 in the case of absence"); | |
2023 return; | |
2024 } | |
2025 | |
2026 CheckValidResourceType(call); | |
2027 | |
2028 assert(!call.GetFullUri().empty()); | |
2029 const std::string publicId = call.GetUriComponent("id", ""); | |
2030 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
2031 | |
2032 std::string label = call.GetUriComponent("label", ""); | |
2033 | |
2034 std::set<std::string> labels; | |
2035 OrthancRestApi::GetIndex(call).ListLabels(labels, publicId, level); | |
2036 | |
2037 if (labels.find(label) != labels.end()) | |
2038 { | |
2039 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | |
2040 } | |
2041 } | |
2042 | |
2043 | |
2044 static void AddLabel(RestApiPutCall& call) | |
2045 { | |
2046 if (call.IsDocumentation()) | |
2047 { | |
2048 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2049 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2050 call.GetDocumentation() | |
2051 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2052 .SetSummary("Add label") | |
2053 .SetDescription("Associate a label with a " + r) | |
2054 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2055 .SetUriArgument("label", "The label to be added"); | |
2056 return; | |
2057 } | |
2058 | |
2059 CheckValidResourceType(call); | |
2060 | |
2061 std::string publicId = call.GetUriComponent("id", ""); | |
2062 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
2063 | |
2064 std::string label = call.GetUriComponent("label", ""); | |
2065 OrthancRestApi::GetIndex(call).ModifyLabel(publicId, level, label, StatelessDatabaseOperations::LabelOperation_Add); | |
2066 | |
2067 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | |
2068 } | |
2069 | |
2070 | |
2071 static void RemoveLabel(RestApiDeleteCall& call) | |
2072 { | |
2073 if (call.IsDocumentation()) | |
2074 { | |
2075 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); | |
2076 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); | |
2077 call.GetDocumentation() | |
2078 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) | |
2079 .SetSummary("Remove label") | |
2080 .SetDescription("Remove a label associated with a " + r) | |
2081 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") | |
2082 .SetUriArgument("label", "The label to be removed"); | |
2083 return; | |
2084 } | |
2085 | |
2086 CheckValidResourceType(call); | |
2087 | |
2088 std::string publicId = call.GetUriComponent("id", ""); | |
2089 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
2090 | |
2091 std::string label = call.GetUriComponent("label", ""); | |
2092 OrthancRestApi::GetIndex(call).ModifyLabel(publicId, level, label, StatelessDatabaseOperations::LabelOperation_Remove); | |
2093 | |
2094 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | |
2095 } | |
2096 | |
1974 | 2097 |
1975 // Handling of attached files ----------------------------------------------- | 2098 // Handling of attached files ----------------------------------------------- |
1976 | 2099 |
1977 static void ListAttachments(RestApiGetCall& call) | 2100 static void ListAttachments(RestApiGetCall& call) |
1978 { | 2101 { |
3852 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata); | 3975 Register("/" + resourceTypes[i] + "/{id}/metadata", ListMetadata); |
3853 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata); | 3976 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", DeleteMetadata); |
3854 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata); | 3977 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", GetMetadata); |
3855 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata); | 3978 Register("/" + resourceTypes[i] + "/{id}/metadata/{name}", SetMetadata); |
3856 | 3979 |
3980 // New in Orthanc 1.12.0 | |
3981 Register("/" + resourceTypes[i] + "/{id}/labels", ListLabels); | |
3982 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", GetLabel); | |
3983 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", RemoveLabel); | |
3984 Register("/" + resourceTypes[i] + "/{id}/labels/{label}", AddLabel); | |
3985 | |
3857 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments); | 3986 Register("/" + resourceTypes[i] + "/{id}/attachments", ListAttachments); |
3858 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment); | 3987 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", DeleteAttachment); |
3859 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations); | 3988 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", GetAttachmentOperations); |
3860 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment); | 3989 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}", UploadAttachment); |
3861 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>); | 3990 Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/compress", ChangeAttachmentCompression<CompressionType_ZlibWithSize>); |