comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 2970:eea66afed0db

remove redundancies
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Dec 2018 10:10:58 +0100
parents 10c610e80b15
children cb5d75143da0
comparison
equal deleted inserted replaced
2969:2c16c29b287d 2970:eea66afed0db
194 { 194 {
195 return isDefaultSynchronous; 195 return isDefaultSynchronous;
196 } 196 }
197 } 197 }
198 198
199
200 unsigned int OrthancRestApi::GetJobRequestPriority(const Json::Value& body)
201 {
202 if (body.type() != Json::objectValue ||
203 !body.isMember(KEY_PRIORITY))
204 {
205 return 0; // Default priority
206 }
207 else
208 {
209 return SerializationToolbox::ReadInteger(body, KEY_PRIORITY);
210 }
211 }
212
199 213
200 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call, 214 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call,
201 IJob* job, 215 IJob* job,
202 bool isDefaultSynchronous, 216 bool isDefaultSynchronous,
203 const Json::Value& body) const 217 const Json::Value& body) const
212 if (body.type() != Json::objectValue) 226 if (body.type() != Json::objectValue)
213 { 227 {
214 throw OrthancException(ErrorCode_BadFileFormat); 228 throw OrthancException(ErrorCode_BadFileFormat);
215 } 229 }
216 230
217 int priority = 0;
218
219 if (body.isMember(KEY_PRIORITY))
220 {
221 priority = SerializationToolbox::ReadInteger(body, KEY_PRIORITY);
222 }
223
224 if (IsSynchronousJobRequest(isDefaultSynchronous, body)) 231 if (IsSynchronousJobRequest(isDefaultSynchronous, body))
225 { 232 {
226 Json::Value successContent; 233 Json::Value successContent;
227 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait 234 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait
228 (successContent, raii.release(), priority)) 235 (successContent, raii.release(), GetJobRequestPriority(body)))
229 { 236 {
230 // Success in synchronous execution 237 // Success in synchronous execution
231 call.GetOutput().AnswerJson(successContent); 238 call.GetOutput().AnswerJson(successContent);
232 } 239 }
233 else 240 else
238 } 245 }
239 else 246 else
240 { 247 {
241 // Asynchronous mode: Submit the job, but don't wait for its completion 248 // Asynchronous mode: Submit the job, but don't wait for its completion
242 std::string id; 249 std::string id;
243 context_.GetJobsEngine().GetRegistry().Submit(id, raii.release(), priority); 250 context_.GetJobsEngine().GetRegistry().Submit
251 (id, raii.release(), GetJobRequestPriority(body));
244 252
245 Json::Value v; 253 Json::Value v;
246 v["ID"] = id; 254 v["ID"] = id;
247 v["Path"] = "/jobs/" + id; 255 v["Path"] = "/jobs/" + id;
248 call.GetOutput().AnswerJson(v); 256 call.GetOutput().AnswerJson(v);