Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp Tue Oct 06 14:44:52 2015 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Oct 12 14:47:58 2015 +0200 @@ -307,15 +307,14 @@ } - void ServerContext::AnswerAttachment(RestApiOutput& output, - const std::string& instancePublicId, + const std::string& resourceId, FileContentType content) { FileInfo attachment; - if (!index_.LookupAttachment(attachment, instancePublicId, content)) + if (!index_.LookupAttachment(attachment, resourceId, content)) { - throw OrthancException(ErrorCode_InternalError); + throw OrthancException(ErrorCode_UnknownResource); } StorageAccessor accessor(area_); @@ -323,6 +322,52 @@ } + void ServerContext::ChangeAttachmentCompression(const std::string& resourceId, + FileContentType attachmentType, + CompressionType compression) + { + LOG(INFO) << "Changing compression type for attachment " + << EnumerationToString(attachmentType) + << " of resource " << resourceId << " to " + << compression; + + FileInfo attachment; + if (!index_.LookupAttachment(attachment, resourceId, attachmentType)) + { + throw OrthancException(ErrorCode_UnknownResource); + } + + if (attachment.GetCompressionType() == compression) + { + // Nothing to do + return; + } + + std::string content; + + StorageAccessor accessor(area_); + accessor.Read(content, attachment); + + FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), + content.size(), attachmentType, compression, storeMD5_); + + try + { + StoreStatus status = index_.AddAttachment(modified, resourceId); + if (status != StoreStatus_Success) + { + accessor.Remove(modified); + throw OrthancException(ErrorCode_Database); + } + } + catch (OrthancException&) + { + accessor.Remove(modified); + throw; + } + } + + void ServerContext::ReadJson(Json::Value& result, const std::string& instancePublicId) {