comparison OrthancServer/ServerContext.cpp @ 1700:f5ddbd9239dd

New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Oct 2015 17:20:26 +0200
parents eb8fbcf008b5
children 4aaaecae5803
comparison
equal deleted inserted replaced
1699:8ca0e89798b2 1700:f5ddbd9239dd
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)