comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 2965:9c0b0a6d8b54

MediaArchiveSize configuration option
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Dec 2018 14:33:47 +0100
parents 9d277f8ad698
children 10c610e80b15
comparison
equal deleted inserted replaced
2964:6896a7c1cbe2 2965:9c0b0a6d8b54
171 171
172 static const char* KEY_PERMISSIVE = "Permissive"; 172 static const char* KEY_PERMISSIVE = "Permissive";
173 static const char* KEY_PRIORITY = "Priority"; 173 static const char* KEY_PRIORITY = "Priority";
174 static const char* KEY_SYNCHRONOUS = "Synchronous"; 174 static const char* KEY_SYNCHRONOUS = "Synchronous";
175 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; 175 static const char* KEY_ASYNCHRONOUS = "Asynchronous";
176
176 177
177 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call, 178 bool OrthancRestApi::IsSynchronousJobRequest(bool isDefaultSynchronous,
178 SetOfCommandsJob* job, 179 const Json::Value& body) const
179 bool isDefaultSynchronous, 180 {
180 const Json::Value& body) const 181 if (body.isMember(KEY_SYNCHRONOUS))
181 { 182 {
182 std::auto_ptr<SetOfCommandsJob> raii(job); 183 return SerializationToolbox::ReadBoolean(body, KEY_SYNCHRONOUS);
184 }
185 else if (body.isMember(KEY_ASYNCHRONOUS))
186 {
187 return !SerializationToolbox::ReadBoolean(body, KEY_ASYNCHRONOUS);
188 }
189 else
190 {
191 return isDefaultSynchronous;
192 }
193 }
194
195
196 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call,
197 IJob* job,
198 bool isDefaultSynchronous,
199 const Json::Value& body) const
200 {
201 std::auto_ptr<IJob> raii(job);
183 202
184 if (job == NULL) 203 if (job == NULL)
185 { 204 {
186 throw OrthancException(ErrorCode_NullPointer); 205 throw OrthancException(ErrorCode_NullPointer);
187 } 206 }
189 if (body.type() != Json::objectValue) 208 if (body.type() != Json::objectValue)
190 { 209 {
191 throw OrthancException(ErrorCode_BadFileFormat); 210 throw OrthancException(ErrorCode_BadFileFormat);
192 } 211 }
193 212
194 job->SetDescription("REST API");
195
196 if (body.isMember(KEY_PERMISSIVE))
197 {
198 job->SetPermissive(SerializationToolbox::ReadBoolean(body, KEY_PERMISSIVE));
199 }
200 else
201 {
202 job->SetPermissive(false);
203 }
204
205 int priority = 0; 213 int priority = 0;
206 214
207 if (body.isMember(KEY_PRIORITY)) 215 if (body.isMember(KEY_PRIORITY))
208 { 216 {
209 priority = SerializationToolbox::ReadInteger(body, KEY_PRIORITY); 217 priority = SerializationToolbox::ReadInteger(body, KEY_PRIORITY);
210 } 218 }
211 219
212 bool synchronous = isDefaultSynchronous; 220 if (IsSynchronousJobRequest(isDefaultSynchronous, body))
213
214 if (body.isMember(KEY_SYNCHRONOUS))
215 {
216 synchronous = SerializationToolbox::ReadBoolean(body, KEY_SYNCHRONOUS);
217 }
218 else if (body.isMember(KEY_ASYNCHRONOUS))
219 {
220 synchronous = !SerializationToolbox::ReadBoolean(body, KEY_ASYNCHRONOUS);
221 }
222
223 if (synchronous)
224 { 221 {
225 Json::Value successContent; 222 Json::Value successContent;
226 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait 223 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait
227 (successContent, raii.release(), priority)) 224 (successContent, raii.release(), priority))
228 { 225 {
245 v["ID"] = id; 242 v["ID"] = id;
246 v["Path"] = "/jobs/" + id; 243 v["Path"] = "/jobs/" + id;
247 call.GetOutput().AnswerJson(v); 244 call.GetOutput().AnswerJson(v);
248 } 245 }
249 } 246 }
247
250 248
251
252 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call, 249 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call,
253 SetOfCommandsJob* job, 250 SetOfCommandsJob* job,
254 bool isDefaultSynchronous) const 251 bool isDefaultSynchronous,
252 const Json::Value& body) const
255 { 253 {
256 std::auto_ptr<SetOfCommandsJob> raii(job); 254 std::auto_ptr<SetOfCommandsJob> raii(job);
257 255
258 Json::Value body; 256 if (job == NULL)
259 257 {
260 if (!call.ParseJsonRequest(body)) 258 throw OrthancException(ErrorCode_NullPointer);
261 { 259 }
262 body = Json::objectValue; 260
263 } 261 if (body.type() != Json::objectValue)
264 262 {
265 SubmitCommandsJob(call, raii.release(), isDefaultSynchronous, body); 263 throw OrthancException(ErrorCode_BadFileFormat);
264 }
265
266 job->SetDescription("REST API");
267
268 if (body.isMember(KEY_PERMISSIVE))
269 {
270 job->SetPermissive(SerializationToolbox::ReadBoolean(body, KEY_PERMISSIVE));
271 }
272 else
273 {
274 job->SetPermissive(false);
275 }
276
277 SubmitGenericJob(call, raii.release(), isDefaultSynchronous, body);
266 } 278 }
267 } 279 }