comparison OrthancServer/OrthancRestApi.cpp @ 210:96b7918a6a18

start of the refactoring of the Orthanc REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Nov 2012 18:03:44 +0100
parents de640de989b8
children b7aea293b965
comparison
equal deleted inserted replaced
209:9960642f0f45 210:96b7918a6a18
417 417
418 bool existingResource = false; 418 bool existingResource = false;
419 Json::Value result(Json::objectValue); 419 Json::Value result(Json::objectValue);
420 420
421 421
422 // Version information ------------------------------------------------------
423
424 if (uri.size() == 1 && uri[0] == "system")
425 {
426 if (method == "GET")
427 {
428 result = Json::Value(Json::objectValue);
429 result["Version"] = ORTHANC_VERSION;
430 result["Name"] = GetGlobalStringParameter("Name", "");
431 result["TotalCompressedSize"] = boost::lexical_cast<std::string>(index_.GetTotalCompressedSize());
432 result["TotalUncompressedSize"] = boost::lexical_cast<std::string>(index_.GetTotalUncompressedSize());
433 existingResource = true;
434 }
435 else
436 {
437 output.SendMethodNotAllowedError("GET,POST");
438 return;
439 }
440 }
441
442
443 // List all the instances --------------------------------------------------- 422 // List all the instances ---------------------------------------------------
444 423
445 if (uri.size() == 1 && uri[0] == "instances") 424 if (uri.size() == 1 && uri[0] == "instances")
446 { 425 {
447 if (method == "GET") 426 if (method == "GET")
708 } 687 }
709 } 688 }
710 } 689 }
711 690
712 691
713
714 // Changes API --------------------------------------------------------------
715
716 if (uri.size() == 1 && uri[0] == "changes")
717 {
718 if (method == "GET")
719 {
720 const static unsigned int MAX_RESULTS = 100;
721
722 //std::string filter = GetArgument(getArguments, "filter", "");
723 int64_t since;
724 unsigned int limit;
725 try
726 {
727 since = boost::lexical_cast<int64_t>(GetArgument(getArguments, "since", "0"));
728 limit = boost::lexical_cast<unsigned int>(GetArgument(getArguments, "limit", "0"));
729 }
730 catch (boost::bad_lexical_cast)
731 {
732 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
733 return;
734 }
735
736 if (limit == 0 || limit > MAX_RESULTS)
737 {
738 limit = MAX_RESULTS;
739 }
740
741 if (!index_.GetChanges(result, since, limit))
742 {
743 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
744 return;
745 }
746
747 existingResource = true;
748 }
749 else
750 {
751 output.SendMethodNotAllowedError("GET");
752 return;
753 }
754 }
755
756
757 // DICOM bridge ------------------------------------------------------------- 692 // DICOM bridge -------------------------------------------------------------
758
759 if (uri.size() == 1 &&
760 uri[0] == "modalities")
761 {
762 if (method == "GET")
763 {
764 result = Json::Value(Json::arrayValue);
765 existingResource = true;
766
767 for (Modalities::const_iterator it = modalities_.begin();
768 it != modalities_.end(); it++)
769 {
770 result.append(*it);
771 }
772 }
773 else
774 {
775 output.SendMethodNotAllowedError("GET");
776 return;
777 }
778 }
779 693
780 if ((uri.size() == 2 || 694 if ((uri.size() == 2 ||
781 uri.size() == 3) && 695 uri.size() == 3) &&
782 uri[0] == "modalities") 696 uri[0] == "modalities")
783 { 697 {