Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4551:350a22c094f2 db-changes
testing replay of transactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Mar 2021 19:36:59 +0100 |
parents | 5b929e6b3c36 |
children | efd90f778cd2 |
comparison
equal
deleted
inserted
replaced
4540:9c0cff7a6ca2 | 4551:350a22c094f2 |
---|---|
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 Json::Value item; | 171 ServerIndex::ExpandResourceOperation operation(*resource, level); |
172 if (index.LookupResource(item, *resource, level)) | 172 index.Apply(operation); |
173 if (operation.IsFound()) | |
173 { | 174 { |
174 answer.append(item); | 175 answer.append(operation.GetResource()); |
175 } | 176 } |
176 } | 177 } |
177 else | 178 else |
178 { | 179 { |
179 answer.append(*resource); | 180 answer.append(*resource); |
253 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") | 254 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest") |
254 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) | 255 .AddAnswerType(MimeType_Json, "Information about the DICOM " + resource) |
255 .SetHttpGetSample(GetDocumentationSampleResource(resourceType), true); | 256 .SetHttpGetSample(GetDocumentationSampleResource(resourceType), true); |
256 return; | 257 return; |
257 } | 258 } |
258 | 259 |
259 Json::Value result; | 260 ServerIndex::ExpandResourceOperation operation(call.GetUriComponent("id", ""), resourceType); |
260 if (OrthancRestApi::GetIndex(call).LookupResource(result, call.GetUriComponent("id", ""), resourceType)) | 261 OrthancRestApi::GetIndex(call).Apply(operation); |
261 { | 262 |
262 call.GetOutput().AnswerJson(result); | 263 if (operation.IsFound()) |
264 { | |
265 call.GetOutput().AnswerJson(operation.GetResource()); | |
263 } | 266 } |
264 } | 267 } |
265 | 268 |
266 template <enum ResourceType resourceType> | 269 template <enum ResourceType resourceType> |
267 static void DeleteSingleResource(RestApiDeleteCall& call) | 270 static void DeleteSingleResource(RestApiDeleteCall& call) |
1412 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") | 1415 "or JSON associative array mapping metadata to their values (if `expand` argument is provided)") |
1413 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); | 1416 .SetHttpGetSample(GetDocumentationSampleResource(t) + "/metadata", true); |
1414 return; | 1417 return; |
1415 } | 1418 } |
1416 | 1419 |
1417 std::map<MetadataType, std::string> metadata; | |
1418 | |
1419 assert(!call.GetFullUri().empty()); | 1420 assert(!call.GetFullUri().empty()); |
1420 const std::string publicId = call.GetUriComponent("id", ""); | 1421 |
1421 const ResourceType level = StringToResourceType(call.GetFullUri() [0].c_str()); | 1422 typedef std::map<MetadataType, std::string> Metadata; |
1422 | 1423 |
1423 OrthancRestApi::GetIndex(call).GetAllMetadata(metadata, publicId, level); | 1424 Metadata metadata; |
1425 | |
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); | |
1424 | 1450 |
1425 Json::Value result; | 1451 Json::Value result; |
1426 | 1452 |
1427 if (call.HasArgument("expand")) | 1453 if (call.HasArgument("expand")) |
1428 { | 1454 { |
1429 result = Json::objectValue; | 1455 result = Json::objectValue; |
1430 | 1456 |
1431 for (std::map<MetadataType, std::string>::const_iterator | 1457 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) |
1432 it = metadata.begin(); it != metadata.end(); ++it) | |
1433 { | 1458 { |
1434 std::string key = EnumerationToString(it->first); | 1459 std::string key = EnumerationToString(it->first); |
1435 result[key] = it->second; | 1460 result[key] = it->second; |
1436 } | 1461 } |
1437 } | 1462 } |
1438 else | 1463 else |
1439 { | 1464 { |
1440 result = Json::arrayValue; | 1465 result = Json::arrayValue; |
1441 | 1466 |
1442 for (std::map<MetadataType, std::string>::const_iterator | 1467 for (Metadata::const_iterator it = metadata.begin(); it != metadata.end(); ++it) |
1443 it = metadata.begin(); it != metadata.end(); ++it) | |
1444 { | 1468 { |
1445 result.append(EnumerationToString(it->first)); | 1469 result.append(EnumerationToString(it->first)); |
1446 } | 1470 } |
1447 } | 1471 } |
1448 | 1472 |
2542 Json::Value result = Json::arrayValue; | 2566 Json::Value result = Json::arrayValue; |
2543 | 2567 |
2544 for (std::list<std::string>::const_iterator | 2568 for (std::list<std::string>::const_iterator |
2545 it = a.begin(); it != a.end(); ++it) | 2569 it = a.begin(); it != a.end(); ++it) |
2546 { | 2570 { |
2547 Json::Value item; | 2571 ServerIndex::ExpandResourceOperation operation(*it, end); |
2548 | 2572 OrthancRestApi::GetIndex(call).Apply(operation); |
2549 if (OrthancRestApi::GetIndex(call).LookupResource(item, *it, end)) | 2573 |
2550 { | 2574 if (operation.IsFound()) |
2551 result.append(item); | 2575 { |
2576 result.append(operation.GetResource()); | |
2552 } | 2577 } |
2553 } | 2578 } |
2554 | 2579 |
2555 call.GetOutput().AnswerJson(result); | 2580 call.GetOutput().AnswerJson(result); |
2556 } | 2581 } |
2652 currentType = GetParentResourceType(currentType); | 2677 currentType = GetParentResourceType(currentType); |
2653 } | 2678 } |
2654 | 2679 |
2655 assert(currentType == end); | 2680 assert(currentType == end); |
2656 | 2681 |
2657 Json::Value result; | 2682 ServerIndex::ExpandResourceOperation operation(current, end); |
2658 if (index.LookupResource(result, current, end)) | 2683 OrthancRestApi::GetIndex(call).Apply(operation); |
2659 { | 2684 |
2660 call.GetOutput().AnswerJson(result); | 2685 if (operation.IsFound()) |
2686 { | |
2687 call.GetOutput().AnswerJson(operation.GetResource()); | |
2661 } | 2688 } |
2662 } | 2689 } |
2663 | 2690 |
2664 | 2691 |
2665 static void ExtractPdf(RestApiGetCall& call) | 2692 static void ExtractPdf(RestApiGetCall& call) |