comparison OrthancServer/ServerContext.cpp @ 1701:4aaaecae5803 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Oct 2015 14:47:58 +0200
parents de1413733c97 f5ddbd9239dd
children 06addfcd1d4c
comparison
equal deleted inserted replaced
1683:21d31da73374 1701:4aaaecae5803
305 throw; 305 throw;
306 } 306 }
307 } 307 }
308 308
309 309
310
311 void ServerContext::AnswerAttachment(RestApiOutput& output, 310 void ServerContext::AnswerAttachment(RestApiOutput& output,
312 const std::string& instancePublicId, 311 const std::string& resourceId,
313 FileContentType content) 312 FileContentType content)
314 { 313 {
315 FileInfo attachment; 314 FileInfo attachment;
316 if (!index_.LookupAttachment(attachment, instancePublicId, content)) 315 if (!index_.LookupAttachment(attachment, resourceId, content))
317 { 316 {
318 throw OrthancException(ErrorCode_InternalError); 317 throw OrthancException(ErrorCode_UnknownResource);
319 } 318 }
320 319
321 StorageAccessor accessor(area_); 320 StorageAccessor accessor(area_);
322 accessor.AnswerFile(output, attachment); 321 accessor.AnswerFile(output, attachment);
322 }
323
324
325 void ServerContext::ChangeAttachmentCompression(const std::string& resourceId,
326 FileContentType attachmentType,
327 CompressionType compression)
328 {
329 LOG(INFO) << "Changing compression type for attachment "
330 << EnumerationToString(attachmentType)
331 << " of resource " << resourceId << " to "
332 << compression;
333
334 FileInfo attachment;
335 if (!index_.LookupAttachment(attachment, resourceId, attachmentType))
336 {
337 throw OrthancException(ErrorCode_UnknownResource);
338 }
339
340 if (attachment.GetCompressionType() == compression)
341 {
342 // Nothing to do
343 return;
344 }
345
346 std::string content;
347
348 StorageAccessor accessor(area_);
349 accessor.Read(content, attachment);
350
351 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(),
352 content.size(), attachmentType, compression, storeMD5_);
353
354 try
355 {
356 StoreStatus status = index_.AddAttachment(modified, resourceId);
357 if (status != StoreStatus_Success)
358 {
359 accessor.Remove(modified);
360 throw OrthancException(ErrorCode_Database);
361 }
362 }
363 catch (OrthancException&)
364 {
365 accessor.Remove(modified);
366 throw;
367 }
323 } 368 }
324 369
325 370
326 void ServerContext::ReadJson(Json::Value& result, 371 void ServerContext::ReadJson(Json::Value& result,
327 const std::string& instancePublicId) 372 const std::string& instancePublicId)