Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4988:8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 30 Apr 2022 19:39:40 +0200 |
parents | dad71e6da406 |
children | 2f30aa99c2db |
comparison
equal
deleted
inserted
replaced
4986:a25e74fad379 | 4988:8fba26292a9f |
---|---|
55 | 55 |
56 | 56 |
57 static const std::string CHECK_REVISIONS = "CheckRevisions"; | 57 static const std::string CHECK_REVISIONS = "CheckRevisions"; |
58 | 58 |
59 static const char* const IGNORE_LENGTH = "ignore-length"; | 59 static const char* const IGNORE_LENGTH = "ignore-length"; |
60 static const char* const RECONSTRUCT_FILES = "ReconstructFiles"; | |
60 | 61 |
61 | 62 |
62 namespace Orthanc | 63 namespace Orthanc |
63 { | 64 { |
64 static std::string GetDocumentationSampleResource(ResourceType type) | 65 static std::string GetDocumentationSampleResource(ResourceType type) |
3377 } | 3378 } |
3378 | 3379 |
3379 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 3380 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
3380 } | 3381 } |
3381 | 3382 |
3383 void DocumentReconstructFilesField(RestApiPostCall& call) | |
3384 { | |
3385 call.GetDocumentation() | |
3386 .SetRequestField(RECONSTRUCT_FILES, RestApiCallDocumentation::Type_Boolean, | |
3387 "Also reconstruct the files of the resources (e.g: apply IngestTranscoding, StorageCompression). " | |
3388 "'false' by default. (New in Orthanc 1.11.0)", false); | |
3389 } | |
3390 | |
3391 bool GetReconstructFilesField(RestApiPostCall& call) | |
3392 { | |
3393 bool reconstructFiles = false; | |
3394 Json::Value request; | |
3395 | |
3396 if (call.GetBodySize() > 0 && call.ParseJsonRequest(request) && request.isMember(RECONSTRUCT_FILES)) // allow "" payload to keep backward compatibility | |
3397 { | |
3398 if (!request[RECONSTRUCT_FILES].isBool()) | |
3399 { | |
3400 throw OrthancException(ErrorCode_BadFileFormat, | |
3401 "The field " + std::string(RECONSTRUCT_FILES) + " must contain a Boolean"); | |
3402 } | |
3403 | |
3404 reconstructFiles = request[RECONSTRUCT_FILES].asBool(); | |
3405 } | |
3406 | |
3407 return reconstructFiles; | |
3408 } | |
3382 | 3409 |
3383 template <enum ResourceType type> | 3410 template <enum ResourceType type> |
3384 static void ReconstructResource(RestApiPostCall& call) | 3411 static void ReconstructResource(RestApiPostCall& call) |
3385 { | 3412 { |
3386 if (call.IsDocumentation()) | 3413 if (call.IsDocumentation()) |
3387 { | 3414 { |
3388 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */); | 3415 const std::string resource = GetResourceTypeText(type, false /* plural */, false /* lower case */); |
3389 call.GetDocumentation() | 3416 call.GetDocumentation() |
3390 .SetTag(GetResourceTypeText(type, true /* plural */, true /* upper case */)) | 3417 .SetTag(GetResourceTypeText(type, true /* plural */, true /* upper case */)) |
3391 .SetSummary("Reconstruct tags of " + resource) | 3418 .SetSummary("Reconstruct tags & optionally files of " + resource) |
3392 .SetDescription("Reconstruct the main DICOM tags of the " + resource + " whose Orthanc identifier is provided " | 3419 .SetDescription("Reconstruct the main DICOM tags in DB of the " + resource + " whose Orthanc identifier is provided " |
3393 "in the URL. This is useful if child studies/series/instances have inconsistent values for " | 3420 "in the URL. This is useful if child studies/series/instances have inconsistent values for " |
3394 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " | 3421 "higher-level tags, in order to force Orthanc to use the value from the resource of interest. " |
3395 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " | 3422 "Beware that this is a time-consuming operation, as all the children DICOM instances will be " |
3396 "parsed again, and the Orthanc index will be updated accordingly.") | 3423 "parsed again, and the Orthanc index will be updated accordingly.") |
3397 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); | 3424 .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest"); |
3425 DocumentReconstructFilesField(call); | |
3426 | |
3398 return; | 3427 return; |
3399 } | 3428 } |
3400 | 3429 |
3401 ServerContext& context = OrthancRestApi::GetContext(call); | 3430 ServerContext& context = OrthancRestApi::GetContext(call); |
3402 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", "")); | 3431 ServerToolbox::ReconstructResource(context, call.GetUriComponent("id", ""), GetReconstructFilesField(call)); |
3403 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 3432 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
3404 } | 3433 } |
3405 | 3434 |
3406 | 3435 |
3407 static void ReconstructAllResources(RestApiPostCall& call) | 3436 static void ReconstructAllResources(RestApiPostCall& call) |
3412 .SetTag("System") | 3441 .SetTag("System") |
3413 .SetSummary("Reconstruct all the index") | 3442 .SetSummary("Reconstruct all the index") |
3414 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. " | 3443 .SetDescription("Reconstruct the index of all the tags of all the DICOM instances that are stored in Orthanc. " |
3415 "This is notably useful after the deletion of resources whose children resources have inconsistent " | 3444 "This is notably useful after the deletion of resources whose children resources have inconsistent " |
3416 "values with their sibling resources. Beware that this is a highly time-consuming operation, " | 3445 "values with their sibling resources. Beware that this is a highly time-consuming operation, " |
3417 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated."); | 3446 "as all the DICOM instances will be parsed again, and as all the Orthanc index will be regenerated. " |
3447 "If you have a large database to process, it is advised to use the Housekeeper plugin to perform " | |
3448 "this action resource by resource"); | |
3449 DocumentReconstructFilesField(call); | |
3450 | |
3418 return; | 3451 return; |
3419 } | 3452 } |
3420 | 3453 |
3421 ServerContext& context = OrthancRestApi::GetContext(call); | 3454 ServerContext& context = OrthancRestApi::GetContext(call); |
3422 | 3455 |
3423 std::list<std::string> studies; | 3456 std::list<std::string> studies; |
3424 context.GetIndex().GetAllUuids(studies, ResourceType_Study); | 3457 context.GetIndex().GetAllUuids(studies, ResourceType_Study); |
3458 bool reconstructFiles = GetReconstructFilesField(call); | |
3425 | 3459 |
3426 for (std::list<std::string>::const_iterator | 3460 for (std::list<std::string>::const_iterator |
3427 study = studies.begin(); study != studies.end(); ++study) | 3461 study = studies.begin(); study != studies.end(); ++study) |
3428 { | 3462 { |
3429 ServerToolbox::ReconstructResource(context, *study); | 3463 ServerToolbox::ReconstructResource(context, *study, reconstructFiles); |
3430 } | 3464 } |
3431 | 3465 |
3432 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 3466 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
3433 } | 3467 } |
3434 | 3468 |