Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4554:efd90f778cd2 db-changes
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Mar 2021 16:31:57 +0100 |
parents | 350a22c094f2 |
children | bec74e29f86b |
comparison
equal
deleted
inserted
replaced
4552:beb8ba8a0b12 | 4554:efd90f778cd2 |
---|---|
166 for (std::list<std::string>::const_iterator | 166 for (std::list<std::string>::const_iterator |
167 resource = resources.begin(); resource != resources.end(); ++resource) | 167 resource = resources.begin(); resource != resources.end(); ++resource) |
168 { | 168 { |
169 if (expand) | 169 if (expand) |
170 { | 170 { |
171 ServerIndex::ExpandResourceOperation operation(*resource, level); | 171 Json::Value expanded; |
172 index.Apply(operation); | 172 if (index.ExpandResource(expanded, *resource, level)) |
173 if (operation.IsFound()) | |
174 { | 173 { |
175 answer.append(operation.GetResource()); | 174 answer.append(expanded); |
176 } | 175 } |
177 } | 176 } |
178 else | 177 else |
179 { | 178 { |
180 answer.append(*resource); | 179 answer.append(*resource); |
255 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) | 254 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) |
256 .SetHttpGetSample(GetDocumentationSampleResource(resourceType), true); | 255 .SetHttpGetSample(GetDocumentationSampleResource(resourceType), true); |
257 return; | 256 return; |
258 } | 257 } |
259 | 258 |
260 ServerIndex::ExpandResourceOperation operation(call.GetUriComponent("id", ""), resourceType); | 259 Json::Value json; |
261 OrthancRestApi::GetIndex(call).Apply(operation); | 260 if (OrthancRestApi::GetIndex(call).ExpandResource(json, call.GetUriComponent("id", ""), resourceType)) |
262 | 261 { |
263 if (operation.IsFound()) | 262 call.GetOutput().AnswerJson(json); |
264 { | |
265 call.GetOutput().AnswerJson(operation.GetResource()); | |
266 } | 263 } |
267 } | 264 } |
268 | 265 |
269 template <enum ResourceType resourceType> | 266 template <enum ResourceType resourceType> |
270 static void DeleteSingleResource(RestApiDeleteCall& call) | 267 static void DeleteSingleResource(RestApiDeleteCall& call) |
1416 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | 1413 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); |
1417 return; | 1414 return; |
1418 } | 1415 } |
1419 | 1416 |
1420 assert(!call.GetFullUri().empty()); | 1417 assert(!call.GetFullUri().empty()); |
1418 const std::string publicId = call.GetUriComponent("id", ""); | |
1419 ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | |
1421 | 1420 |
1422 typedef std::map<MetadataType, std::string> Metadata; | 1421 typedef std::map<MetadataType, std::string> Metadata; |
1423 | 1422 |
1424 Metadata metadata; | 1423 Metadata metadata; |
1425 | 1424 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level); |
1426 class Operation : public ServerIndex::IReadOnlyOperations | |
1427 { | |
1428 private: | |
1429 Metadata& metadata_; | |
1430 std::string publicId_; | |
1431 ResourceType level_; | |
1432 | |
1433 public: | |
1434 Operation(Metadata& metadata, | |
1435 const RestApiGetCall& call) : | |
1436 metadata_(metadata), | |
1437 publicId_(call.GetUriComponent("id", "")), | |
1438 level_(StringToResourceType(call.GetFullUri() [0].c_str())) | |
1439 { | |
1440 } | |
1441 | |
1442 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
1443 { | |
1444 transaction.GetAllMetadata(metadata_, publicId_, level_); | |
1445 } | |
1446 }; | |
1447 | |
1448 Operation operation(metadata, call); | |
1449 OrthancRestApi::GetIndex(call).Apply(operation); | |
1450 | 1425 |
1451 Json::Value result; | 1426 Json::Value result; |
1452 | 1427 |
1453 if (call.HasArgument("expand")) | 1428 if (call.HasArgument("expand")) |
1454 { | 1429 { |
2566 Json::Value result = Json::arrayValue; | 2541 Json::Value result = Json::arrayValue; |
2567 | 2542 |
2568 for (std::list<std::string>::const_iterator | 2543 for (std::list<std::string>::const_iterator |
2569 it = a.begin(); it != a.end(); ++it) | 2544 it = a.begin(); it != a.end(); ++it) |
2570 { | 2545 { |
2571 ServerIndex::ExpandResourceOperation operation(*it, end); | 2546 Json::Value resource; |
2572 OrthancRestApi::GetIndex(call).Apply(operation); | 2547 if (OrthancRestApi::GetIndex(call).ExpandResource(resource, *it, end)) |
2573 | 2548 { |
2574 if (operation.IsFound()) | 2549 result.append(resource); |
2575 { | |
2576 result.append(operation.GetResource()); | |
2577 } | 2550 } |
2578 } | 2551 } |
2579 | 2552 |
2580 call.GetOutput().AnswerJson(result); | 2553 call.GetOutput().AnswerJson(result); |
2581 } | 2554 } |
2677 currentType = GetParentResourceType(currentType); | 2650 currentType = GetParentResourceType(currentType); |
2678 } | 2651 } |
2679 | 2652 |
2680 assert(currentType == end); | 2653 assert(currentType == end); |
2681 | 2654 |
2682 ServerIndex::ExpandResourceOperation operation(current, end); | 2655 Json::Value resource; |
2683 OrthancRestApi::GetIndex(call).Apply(operation); | 2656 if (OrthancRestApi::GetIndex(call).ExpandResource(resource, current, end)) |
2684 | 2657 { |
2685 if (operation.IsFound()) | 2658 call.GetOutput().AnswerJson(resource); |
2686 { | |
2687 call.GetOutput().AnswerJson(operation.GetResource()); | |
2688 } | 2659 } |
2689 } | 2660 } |
2690 | 2661 |
2691 | 2662 |
2692 static void ExtractPdf(RestApiGetCall& call) | 2663 static void ExtractPdf(RestApiGetCall& call) |