comparison OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp @ 4473:68f52897c119

new URIs: /tools/accepted-transfer-syntaxes and /tools/unknown-sop-class-accepted to replace Lua callbacks for transfer syntaxes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 26 Jan 2021 14:48:10 +0100
parents 22abc6851191
children f8c1d94363b6
comparison
equal deleted inserted replaced
4472:28a4baadde17 4473:68f52897c119
320 320
321 call.GetOutput().AnswerBuffer(EnumerationToString(encoding), MimeType_PlainText); 321 call.GetOutput().AnswerBuffer(EnumerationToString(encoding), MimeType_PlainText);
322 } 322 }
323 323
324 324
325 static void AnswerAcceptedTransferSyntaxes(RestApiCall& call)
326 {
327 std::set<DicomTransferSyntax> syntaxes;
328 OrthancRestApi::GetContext(call).GetAcceptedTransferSyntaxes(syntaxes);
329
330 Json::Value json = Json::arrayValue;
331 for (std::set<DicomTransferSyntax>::const_iterator
332 syntax = syntaxes.begin(); syntax != syntaxes.end(); ++syntax)
333 {
334 json.append(GetTransferSyntaxUid(*syntax));
335 }
336
337 call.GetOutput().AnswerJson(json);
338 }
339
340
341 static void GetAcceptedTransferSyntaxes(RestApiGetCall& call)
342 {
343 if (call.IsDocumentation())
344 {
345 call.GetDocumentation()
346 .SetTag("System")
347 .SetSummary("Get accepted transfer syntaxes")
348 .SetDescription("Get the list of UIDs of the DICOM transfer syntaxes that are accepted "
349 "by Orthanc C-STORE SCP. This corresponds to the configuration options "
350 "`AcceptedTransferSyntaxes` and `XXXTransferSyntaxAccepted`.")
351 .AddAnswerType(MimeType_Json, "JSON array containing the transfer syntax UIDs");
352 return;
353 }
354
355 AnswerAcceptedTransferSyntaxes(call);
356 }
357
358
359 static void SetAcceptedTransferSyntaxes(RestApiPutCall& call)
360 {
361 if (call.IsDocumentation())
362 {
363 call.GetDocumentation()
364 .SetTag("System")
365 .SetSummary("Set accepted transfer syntaxes")
366 .SetDescription("Set the DICOM transfer syntaxes that accepted by Orthanc C-STORE SCP")
367 .AddRequestType(MimeType_PlainText, "UID of the transfer syntax to be accepted. "
368 "Wildcards `?` and `*` are accepted.")
369 .AddRequestType(MimeType_Json, "JSON array containing a list of transfer syntax "
370 "UIDs to be accepted. Wildcards `?` and `*` are accepted.")
371 .AddAnswerType(MimeType_Json, "JSON array containing the now-accepted transfer syntax UIDs");
372 return;
373 }
374
375 std::string body;
376 call.BodyToString(body);
377
378 std::set<DicomTransferSyntax> syntaxes;
379 OrthancConfiguration::ParseAcceptedTransferSyntaxes(syntaxes, body);
380 OrthancRestApi::GetContext(call).SetAcceptedTransferSyntaxes(syntaxes);
381
382 AnswerAcceptedTransferSyntaxes(call);
383 }
384
385
386 static void GetUnknownSopClassAccepted(RestApiGetCall& call)
387 {
388 if (call.IsDocumentation())
389 {
390 call.GetDocumentation()
391 .SetTag("System")
392 .SetSummary("Is unknown SOP class accepted?")
393 .SetDescription("Shall Orthanc C-STORE SCP accept DICOM instances with an unknown SOP class UID?")
394 .AddAnswerType(MimeType_PlainText, "`1` if accepted, `0` if not accepted");
395 return;
396 }
397
398 const bool accepted = OrthancRestApi::GetContext(call).IsUnknownSopClassAccepted();
399 call.GetOutput().AnswerBuffer(accepted ? "1" : "0", MimeType_PlainText);
400 }
401
402
403 static void SetUnknownSopClassAccepted(RestApiPutCall& call)
404 {
405 if (call.IsDocumentation())
406 {
407 call.GetDocumentation()
408 .SetTag("System")
409 .SetSummary("Set unknown SOP class accepted")
410 .SetDescription("Set whether Orthanc C-STORE SCP should accept DICOM instances with an unknown SOP class UID")
411 .AddRequestType(MimeType_PlainText, "`1` if accepted, `0` if not accepted");
412 return;
413 }
414
415 OrthancRestApi::GetContext(call).SetUnknownSopClassAccepted(call.ParseBooleanBody());
416 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
417 }
418
419
325 420
326 // Plugins information ------------------------------------------------------ 421 // Plugins information ------------------------------------------------------
327 422
328 static void ListPlugins(RestApiGetCall& call) 423 static void ListPlugins(RestApiGetCall& call)
329 { 424 {
746 .SetDescription("Enable or disable the collection and publication of metrics at `/tools/metrics-prometheus`") 841 .SetDescription("Enable or disable the collection and publication of metrics at `/tools/metrics-prometheus`")
747 .AddRequestType(MimeType_PlainText, "`1` if metrics are collected, `0` if metrics are disabled"); 842 .AddRequestType(MimeType_PlainText, "`1` if metrics are collected, `0` if metrics are disabled");
748 return; 843 return;
749 } 844 }
750 845
751 bool enabled; 846 const bool enabled = call.ParseBooleanBody();
752
753 std::string body;
754 call.BodyToString(body);
755
756 if (body == "1")
757 {
758 enabled = true;
759 }
760 else if (body == "0")
761 {
762 enabled = false;
763 }
764 else
765 {
766 throw OrthancException(ErrorCode_ParameterOutOfRange,
767 "The HTTP body must be 0 or 1, but found: " + body);
768 }
769 847
770 // Success 848 // Success
771 OrthancRestApi::GetContext(call).GetMetricsRegistry().SetEnabled(enabled); 849 OrthancRestApi::GetContext(call).GetMetricsRegistry().SetEnabled(enabled);
772 call.GetOutput().AnswerBuffer("", MimeType_PlainText); 850 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
773 } 851 }
917 Register("/jobs/{id}/cancel", ApplyJobAction<JobAction_Cancel>); 995 Register("/jobs/{id}/cancel", ApplyJobAction<JobAction_Cancel>);
918 Register("/jobs/{id}/pause", ApplyJobAction<JobAction_Pause>); 996 Register("/jobs/{id}/pause", ApplyJobAction<JobAction_Pause>);
919 Register("/jobs/{id}/resubmit", ApplyJobAction<JobAction_Resubmit>); 997 Register("/jobs/{id}/resubmit", ApplyJobAction<JobAction_Resubmit>);
920 Register("/jobs/{id}/resume", ApplyJobAction<JobAction_Resume>); 998 Register("/jobs/{id}/resume", ApplyJobAction<JobAction_Resume>);
921 Register("/jobs/{id}/{key}", GetJobOutput); 999 Register("/jobs/{id}/{key}", GetJobOutput);
1000
1001 // New in Orthanc 1.9.0
1002 Register("/tools/accepted-transfer-syntaxes", GetAcceptedTransferSyntaxes);
1003 Register("/tools/accepted-transfer-syntaxes", SetAcceptedTransferSyntaxes);
1004 Register("/tools/unknown-sop-class-accepted", GetUnknownSopClassAccepted);
1005 Register("/tools/unknown-sop-class-accepted", SetUnknownSopClassAccepted);
922 } 1006 }
923 } 1007 }