comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 2867:251614c2edac

DicomMoveScuJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Oct 2018 16:08:51 +0200
parents a21b244efb37
children 5dd649de253d
comparison
equal deleted inserted replaced
2866:437e6ba20a5e 2867:251614c2edac
33 33
34 #include "../PrecompiledHeadersServer.h" 34 #include "../PrecompiledHeadersServer.h"
35 #include "OrthancRestApi.h" 35 #include "OrthancRestApi.h"
36 36
37 #include "../../Core/Logging.h" 37 #include "../../Core/Logging.h"
38 #include "../../Core/SerializationToolbox.h"
38 #include "../ServerContext.h" 39 #include "../ServerContext.h"
39 40
40 namespace Orthanc 41 namespace Orthanc
41 { 42 {
42 void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call, 43 void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call,
137 138
138 ServerIndex& OrthancRestApi::GetIndex(RestApiCall& call) 139 ServerIndex& OrthancRestApi::GetIndex(RestApiCall& call)
139 { 140 {
140 return GetContext(call).GetIndex(); 141 return GetContext(call).GetIndex();
141 } 142 }
143
144
145
146 static const char* KEY_PERMISSIVE = "Permissive";
147 static const char* KEY_PRIORITY = "Priority";
148 static const char* KEY_SYNCHRONOUS = "Synchronous";
149 static const char* KEY_ASYNCHRONOUS = "Asynchronous";
150
151 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call,
152 SetOfCommandsJob* job,
153 bool isDefaultSynchronous,
154 const Json::Value& body) const
155 {
156 std::auto_ptr<SetOfCommandsJob> raii(job);
157
158 if (job == NULL)
159 {
160 throw OrthancException(ErrorCode_NullPointer);
161 }
162
163 if (body.type() != Json::objectValue)
164 {
165 throw OrthancException(ErrorCode_BadFileFormat);
166 }
167
168 job->SetDescription("REST API");
169
170 if (body.isMember(KEY_PERMISSIVE))
171 {
172 job->SetPermissive(SerializationToolbox::ReadBoolean(body, KEY_PERMISSIVE));
173 }
174 else
175 {
176 job->SetPermissive(false);
177 }
178
179 int priority = 0;
180
181 if (body.isMember(KEY_PRIORITY))
182 {
183 priority = SerializationToolbox::ReadInteger(body, KEY_PRIORITY);
184 }
185
186 bool synchronous = isDefaultSynchronous;
187
188 if (body.isMember(KEY_SYNCHRONOUS))
189 {
190 synchronous = SerializationToolbox::ReadBoolean(body, KEY_SYNCHRONOUS);
191 }
192 else if (body.isMember(KEY_ASYNCHRONOUS))
193 {
194 synchronous = !SerializationToolbox::ReadBoolean(body, KEY_ASYNCHRONOUS);
195 }
196
197 if (synchronous)
198 {
199 Json::Value successContent;
200 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait
201 (successContent, raii.release(), priority))
202 {
203 // Success in synchronous execution
204 call.GetOutput().AnswerJson(successContent);
205 }
206 else
207 {
208 // Error during synchronous execution
209 call.GetOutput().SignalError(HttpStatus_500_InternalServerError);
210 }
211 }
212 else
213 {
214 // Asynchronous mode: Submit the job, but don't wait for its completion
215 std::string id;
216 context_.GetJobsEngine().GetRegistry().Submit(id, raii.release(), priority);
217
218 Json::Value v;
219 v["ID"] = id;
220 v["Path"] = "/jobs/" + id;
221 call.GetOutput().AnswerJson(v);
222 }
223 }
224
225
226 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call,
227 SetOfCommandsJob* job,
228 bool isDefaultSynchronous) const
229 {
230 std::auto_ptr<SetOfCommandsJob> raii(job);
231
232 Json::Value body;
233
234 if (!call.ParseJsonRequest(body))
235 {
236 body = Json::objectValue;
237 }
238
239 SubmitCommandsJob(call, raii.release(), isDefaultSynchronous, body);
240 }
142 } 241 }