Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp @ 4474:f8c1d94363b6
new configuration options: "AcceptedTransferSyntaxes" and "H265TransferSyntaxAccepted"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 26 Jan 2021 15:50:52 +0100 |
parents | d9473bd5ed43 |
children | 97d103b57cd1 |
rev | line source |
---|---|
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1103
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4424
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "../PrecompiledHeadersServer.h" |
230 | 35 #include "OrthancRestApi.h" |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
4045 | 37 #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h" |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
38 #include "../../../OrthancFramework/Sources/Compression/ZipReader.h" |
4045 | 39 #include "../../../OrthancFramework/Sources/Logging.h" |
40 #include "../../../OrthancFramework/Sources/MetricsRegistry.h" | |
41 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
42 #include "../ServerContext.h" |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
43 |
3689
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
44 #include <boost/algorithm/string/predicate.hpp> |
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
45 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 namespace Orthanc |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
48 static void SetupResourceAnswer(Json::Value& result, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
49 const std::string& publicId, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
50 ResourceType resourceType, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
51 StoreStatus status) |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
52 { |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
53 result = Json::objectValue; |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
54 |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
55 if (status != StoreStatus_Failure) |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
56 { |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
57 result["ID"] = publicId; |
1564
1b7def486e62
creation of DICOM series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
58 result["Path"] = GetBasePath(resourceType, publicId); |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
59 } |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
60 |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
61 result["Status"] = EnumerationToString(status); |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
62 } |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
63 |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
64 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
65 static void SetupResourceAnswer(Json::Value& result, |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
66 DicomInstanceToStore& instance, |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
67 StoreStatus status, |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
68 const std::string& instanceId) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
69 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
70 SetupResourceAnswer(result, instanceId, ResourceType_Instance, status); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
71 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
72 result["ParentPatient"] = instance.GetHasher().HashPatient(); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
73 result["ParentStudy"] = instance.GetHasher().HashStudy(); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
74 result["ParentSeries"] = instance.GetHasher().HashSeries(); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
75 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
76 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
77 |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
78 void OrthancRestApi::AnswerStoredInstance(RestApiPostCall& call, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
79 DicomInstanceToStore& instance, |
3912
7610af1532c3
prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3848
diff
changeset
|
80 StoreStatus status, |
7610af1532c3
prototyping automated transcoding of incoming DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3848
diff
changeset
|
81 const std::string& instanceId) const |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
82 { |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
83 Json::Value result; |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
84 SetupResourceAnswer(result, instance, status, instanceId); |
2899
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
85 call.GetOutput().AnswerJson(result); |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
86 } |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
87 |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
88 |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
89 void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
90 const std::string& publicId, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
91 ResourceType resourceType, |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
92 StoreStatus status) const |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
93 { |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
94 Json::Value result; |
5dd649de253d
POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
95 SetupResourceAnswer(result, publicId, resourceType, status); |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
96 call.GetOutput().AnswerJson(result); |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
97 } |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
98 |
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
99 |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
100 void OrthancRestApi::ResetOrthanc(RestApiPostCall& call) |
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
101 { |
4403 | 102 if (call.IsDocumentation()) |
103 { | |
104 call.GetDocumentation() | |
105 .SetTag("System") | |
106 .SetSummary("Restart Orthanc"); | |
107 return; | |
108 } | |
109 | |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
110 OrthancRestApi::GetApi(call).leaveBarrier_ = true; |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
111 OrthancRestApi::GetApi(call).resetRequestReceived_ = true; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
112 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
113 } |
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
114 |
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
115 |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
116 void OrthancRestApi::ShutdownOrthanc(RestApiPostCall& call) |
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
117 { |
4403 | 118 if (call.IsDocumentation()) |
119 { | |
120 call.GetDocumentation() | |
121 .SetTag("System") | |
122 .SetSummary("Shutdown Orthanc"); | |
123 return; | |
124 } | |
125 | |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
126 OrthancRestApi::GetApi(call).leaveBarrier_ = true; |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
127 call.GetOutput().AnswerBuffer("{}", MimeType_Json); |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
128 LOG(WARNING) << "Shutdown request received"; |
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
129 } |
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
130 |
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
131 |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
132 |
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
133 |
796
e7b1ca0f1e04
creation of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
751
diff
changeset
|
134 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
135 // Upload of DICOM files through HTTP --------------------------------------- |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
136 |
974 | 137 static void UploadDicomFile(RestApiPostCall& call) |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
138 { |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
139 if (call.GetRequestOrigin() == RequestOrigin_Documentation) |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
140 { |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
141 Json::Value sample = Json::objectValue; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
142 sample["ID"] = "19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
143 sample["ParentPatient"] = "ef9d77db-eb3b2bef-9b31fd3e-bf42ae46-dbdb0cc3"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
144 sample["ParentSeries"] = "3774320f-ccda46d8-69ee8641-9e791cbf-3ecbbcc6"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
145 sample["ParentStudy"] = "66c8e41e-ac3a9029-0b85e42a-8195ee0a-92c2e62e"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
146 sample["Path"] = "/instances/19816330-cb02e1cf-df3a8fe8-bf510623-ccefe9f5"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
147 sample["Status"] = "Success"; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
148 |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
149 call.GetDocumentation() |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
150 .SetTag("Instances") |
4403 | 151 .SetSummary("Upload DICOM instances") |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
152 .AddRequestType(MimeType_Dicom, "DICOM file to be uploaded") |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
153 .AddRequestType(MimeType_Zip, "ZIP archive containing DICOM files (new in Orthanc 1.8.2)") |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
154 .AddAnswerType(MimeType_Json, "Information about the uploaded instance, " |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
155 "or list of information for each uploaded instance in the case of ZIP archive") |
4404 | 156 .SetAnswerField("ID", RestApiCallDocumentation::Type_String, "Orthanc identifier of the new instance") |
157 .SetAnswerField("Path", RestApiCallDocumentation::Type_String, "Path to the new instance in the REST API") | |
158 .SetAnswerField("Status", RestApiCallDocumentation::Type_String, "Can be `Success`, `AlreadyStored`, `Failure`, or `FilteredOut` (removed by some `NewInstanceFilter`)") | |
4413 | 159 .SetAnswerField("ParentPatient", RestApiCallDocumentation::Type_String, "Orthanc identifier of the parent patient") |
160 .SetAnswerField("ParentStudy", RestApiCallDocumentation::Type_String, "Orthanc identifier of the parent study") | |
161 .SetAnswerField("ParentSeries", RestApiCallDocumentation::Type_String, "Orthanc identifier of the parent series") | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
162 .SetSample(sample); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
163 return; |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
164 } |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4378
diff
changeset
|
165 |
746
478f4f9de9eb
getting rid of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
745
diff
changeset
|
166 ServerContext& context = OrthancRestApi::GetContext(call); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
167 |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4272
diff
changeset
|
168 CLOG(INFO, HTTP) << "Receiving a DICOM file of " << call.GetBodySize() << " bytes through HTTP"; |
3491
22bdb9c91ebf
Log an explicit error if uploading an empty DICOM file using REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
169 |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
170 if (call.GetBodySize() == 0) |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
171 { |
3491
22bdb9c91ebf
Log an explicit error if uploading an empty DICOM file using REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
172 throw OrthancException(ErrorCode_BadFileFormat, |
22bdb9c91ebf
Log an explicit error if uploading an empty DICOM file using REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
173 "Received an empty DICOM file"); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
174 } |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
175 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
176 if (ZipReader::IsZipMemoryBuffer(call.GetBodyData(), call.GetBodySize())) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
177 { |
4374
79ef2b6d8e76
there will be a 1.8.2 release before 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4357
diff
changeset
|
178 // New in Orthanc 1.8.2 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
179 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromMemory(call.GetBodyData(), call.GetBodySize())); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
180 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
181 Json::Value answer = Json::arrayValue; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
182 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
183 std::string filename, content; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
184 while (reader->ReadNextFile(filename, content)) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
185 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
186 if (!content.empty()) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
187 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
188 LOG(INFO) << "Uploading DICOM file from ZIP archive: " << filename; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
189 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
190 DicomInstanceToStore toStore; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
191 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call)); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
192 toStore.SetBuffer(content.c_str(), content.size()); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
193 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
194 std::string publicId; |
3689
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
195 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
196 try |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
197 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
198 StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default); |
3841
be7df7fe3d80
avoid one memcpy of the DICOM buffer on "POST /instances"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
199 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
200 Json::Value info; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
201 SetupResourceAnswer(info, toStore, status, publicId); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
202 answer.append(info); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
203 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
204 catch (OrthancException& e) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
205 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
206 if (e.GetErrorCode() == ErrorCode_BadFileFormat) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
207 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
208 LOG(ERROR) << "Cannot import non-DICOM file from ZIP archive: " << filename; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
209 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
210 else |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
211 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
212 throw; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
213 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
214 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
215 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
216 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
217 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
218 call.GetOutput().AnswerJson(answer); |
3689
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
219 } |
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
220 else |
e85bfba2d307
"/instances": Support "Content-Encoding: gzip" to upload gzip-compressed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
221 { |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
222 // The lifetime of "dicom" must be longer than "toStore", as the |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
223 // latter can possibly store a reference to the former (*) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
224 std::string dicom; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
225 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
226 DicomInstanceToStore toStore; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
227 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call)); |
1005
84b6d7bca6db
refactoring of ServerContext::Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
974
diff
changeset
|
228 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
229 if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip")) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
230 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
231 GzipCompressor compressor; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
232 compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize()); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
233 toStore.SetBuffer(dicom.c_str(), dicom.size()); // (*) |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
234 } |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
235 else |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
236 { |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
237 toStore.SetBuffer(call.GetBodyData(), call.GetBodySize()); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
238 } |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
239 |
4357
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
240 std::string publicId; |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
241 StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
242 |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
243 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status, publicId); |
886bc367aeb2
"/instances" can be used to import ZIP archives provided in the POST body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
244 } |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
245 } |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
246 |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 |
304 | 248 |
213
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
249 // Registration of the various REST handlers -------------------------------- |
4ce7fdcc8879
access to tags, simplified-tags and file of an instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
212
diff
changeset
|
250 |
4378
9e2fc6911ac8
adding option to disable orthance explorer when http server is enabled
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4374
diff
changeset
|
251 OrthancRestApi::OrthancRestApi(ServerContext& context, |
9e2fc6911ac8
adding option to disable orthance explorer when http server is enabled
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4374
diff
changeset
|
252 bool orthancExplorerEnabled) : |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
253 context_(context), |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
254 leaveBarrier_(false), |
3176
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
255 resetRequestReceived_(false), |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
256 activeRequests_(context.GetMetricsRegistry(), |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
257 "orthanc_rest_api_active_requests", |
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
258 MetricsType_MaxOver10Seconds) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 { |
4378
9e2fc6911ac8
adding option to disable orthance explorer when http server is enabled
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4374
diff
changeset
|
260 RegisterSystem(orthancExplorerEnabled); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
261 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
262 RegisterChanges(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
263 RegisterResources(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
264 RegisterModalities(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
265 RegisterAnonymizeModify(); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
750
diff
changeset
|
266 RegisterArchive(); |
211 | 267 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
268 Register("/instances", UploadDicomFile); |
1063
0332e6e8c679
Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
269 |
0332e6e8c679
Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
270 // Auto-generated directories |
0332e6e8c679
Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
271 Register("/tools", RestApi::AutoListChildren); |
1103
bec1eccf976c
Hot restart of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
272 Register("/tools/reset", ResetOrthanc); |
1730
bc34c69b594a
New URI "/tools/shutdown" to stop Orthanc from the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
273 Register("/tools/shutdown", ShutdownOrthanc); |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 } |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
275 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
276 |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
277 bool OrthancRestApi::Handle(HttpOutput& output, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
278 RequestOrigin origin, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
279 const char* remoteIp, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
280 const char* username, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
281 HttpMethod method, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
282 const UriComponents& uri, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4294
diff
changeset
|
283 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4294
diff
changeset
|
284 const HttpToolbox::GetArguments& getArguments, |
3401 | 285 const void* bodyData, |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
286 size_t bodySize) |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
287 { |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
288 MetricsRegistry::Timer timer(context_.GetMetricsRegistry(), "orthanc_rest_api_duration_ms"); |
3176
784bbb03fb54
new metrics: orthanc_rest_api_active_requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3175
diff
changeset
|
289 MetricsRegistry::ActiveCounter counter(activeRequests_); |
3175
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
290 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
291 return RestApi::Handle(output, origin, remoteIp, username, method, |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
292 uri, headers, getArguments, bodyData, bodySize); |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
293 } |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
294 |
574890d14c92
new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
295 |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
296 ServerContext& OrthancRestApi::GetContext(RestApiCall& call) |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
297 { |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
298 return GetApi(call).context_; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
299 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
300 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
301 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
302 ServerIndex& OrthancRestApi::GetIndex(RestApiCall& call) |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
303 { |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
304 return GetContext(call).GetIndex(); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
305 } |
2867 | 306 |
307 | |
308 | |
309 static const char* KEY_PERMISSIVE = "Permissive"; | |
310 static const char* KEY_PRIORITY = "Priority"; | |
311 static const char* KEY_SYNCHRONOUS = "Synchronous"; | |
312 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; | |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
313 |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
314 |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
315 bool OrthancRestApi::IsSynchronousJobRequest(bool isDefaultSynchronous, |
2966 | 316 const Json::Value& body) |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
317 { |
2966 | 318 if (body.type() != Json::objectValue) |
319 { | |
320 return isDefaultSynchronous; | |
321 } | |
322 else if (body.isMember(KEY_SYNCHRONOUS)) | |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
323 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
324 return SerializationToolbox::ReadBoolean(body, KEY_SYNCHRONOUS); |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
325 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
326 else if (body.isMember(KEY_ASYNCHRONOUS)) |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
327 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
328 return !SerializationToolbox::ReadBoolean(body, KEY_ASYNCHRONOUS); |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
329 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
330 else |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
331 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
332 return isDefaultSynchronous; |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
333 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
334 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
335 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
336 |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
337 unsigned int OrthancRestApi::GetJobRequestPriority(const Json::Value& body) |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
338 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
339 if (body.type() != Json::objectValue || |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
340 !body.isMember(KEY_PRIORITY)) |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
341 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
342 return 0; // Default priority |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
343 } |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
344 else |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
345 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
346 return SerializationToolbox::ReadInteger(body, KEY_PRIORITY); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
347 } |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
348 } |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
349 |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
350 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
351 void OrthancRestApi::SubmitGenericJob(RestApiOutput& output, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
352 ServerContext& context, |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
353 IJob* job, |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
354 bool synchronous, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
355 int priority) |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
356 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3689
diff
changeset
|
357 std::unique_ptr<IJob> raii(job); |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
358 |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
359 if (job == NULL) |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
360 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
361 throw OrthancException(ErrorCode_NullPointer); |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
362 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
363 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
364 if (synchronous) |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
365 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
366 Json::Value successContent; |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3176
diff
changeset
|
367 context.GetJobsEngine().GetRegistry().SubmitAndWait |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3176
diff
changeset
|
368 (successContent, raii.release(), priority); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3176
diff
changeset
|
369 |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3176
diff
changeset
|
370 // Success in synchronous execution |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3176
diff
changeset
|
371 output.AnswerJson(successContent); |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
372 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
373 else |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
374 { |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
375 // Asynchronous mode: Submit the job, but don't wait for its completion |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
376 std::string id; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
377 context.GetJobsEngine().GetRegistry().Submit |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
378 (id, raii.release(), priority); |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
379 |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
380 Json::Value v; |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
381 v["ID"] = id; |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
382 v["Path"] = "/jobs/" + id; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
383 output.AnswerJson(v); |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
384 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
385 } |
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
386 |
2867 | 387 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
388 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
389 IJob* job, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
390 bool isDefaultSynchronous, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
391 const Json::Value& body) const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
392 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3689
diff
changeset
|
393 std::unique_ptr<IJob> raii(job); |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
394 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
395 if (body.type() != Json::objectValue) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
396 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
397 throw OrthancException(ErrorCode_BadFileFormat); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
398 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
399 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
400 bool synchronous = IsSynchronousJobRequest(isDefaultSynchronous, body); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
401 int priority = GetJobRequestPriority(body); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
402 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
403 SubmitGenericJob(call.GetOutput(), context_, raii.release(), synchronous, priority); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
404 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
405 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
406 |
2867 | 407 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call, |
408 SetOfCommandsJob* job, | |
409 bool isDefaultSynchronous, | |
410 const Json::Value& body) const | |
411 { | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3689
diff
changeset
|
412 std::unique_ptr<SetOfCommandsJob> raii(job); |
2867 | 413 |
414 if (body.type() != Json::objectValue) | |
415 { | |
416 throw OrthancException(ErrorCode_BadFileFormat); | |
417 } | |
418 | |
419 job->SetDescription("REST API"); | |
420 | |
421 if (body.isMember(KEY_PERMISSIVE)) | |
422 { | |
423 job->SetPermissive(SerializationToolbox::ReadBoolean(body, KEY_PERMISSIVE)); | |
424 } | |
425 else | |
426 { | |
427 job->SetPermissive(false); | |
428 } | |
429 | |
2965
9c0b0a6d8b54
MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
430 SubmitGenericJob(call, raii.release(), isDefaultSynchronous, body); |
2867 | 431 } |
4419 | 432 |
433 | |
434 void OrthancRestApi::DocumentSubmitGenericJob(RestApiPostCall& call) | |
435 { | |
436 call.GetDocumentation() | |
437 .SetRequestField(KEY_SYNCHRONOUS, RestApiCallDocumentation::Type_Boolean, | |
438 "If `true`, run the job in synchronous mode, which means that the HTTP answer will directly " | |
439 "contain the result of the job. This is the default, easy behavior, but it is *not* desirable for " | |
440 "long jobs, as it might lead to network timeouts.", false) | |
441 .SetRequestField(KEY_ASYNCHRONOUS, RestApiCallDocumentation::Type_Boolean, | |
442 "If `true`, run the job in asynchronous mode, which means that the REST API call will immediately " | |
443 "return, reporting the identifier of a job. Prefer this flavor wherever possible.", false) | |
444 .SetRequestField(KEY_PRIORITY, RestApiCallDocumentation::Type_Number, | |
445 "In asynchronous mode, the priority of the job. The lower the value, the higher the priority.", false) | |
446 .SetAnswerField("ID", RestApiCallDocumentation::Type_String, "In asynchronous mode, identifier of the job") | |
447 .SetAnswerField("Path", RestApiCallDocumentation::Type_String, "In asynchronous mode, path to access the job in the REST API"); | |
448 } | |
449 | |
450 | |
451 void OrthancRestApi::DocumentSubmitCommandsJob(RestApiPostCall& call) | |
452 { | |
453 DocumentSubmitGenericJob(call); | |
454 call.GetDocumentation() | |
455 .SetRequestField(KEY_PERMISSIVE, RestApiCallDocumentation::Type_Boolean, | |
456 "If `true`, ignore errors during the individual steps of the job.", false); | |
457 } | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 } |