Mercurial > hg > orthanc
changeset 233:c11273198cef
rename
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 14:30:05 +0100 |
parents | 5368bbe813cf |
children | 7c1faef915a4 |
files | Core/Enumerations.h Core/FileStorage/CompressedFileStorageAccessor.cpp Core/FileStorage/CompressedFileStorageAccessor.h Core/FileStorage/FileInfo.h Core/FileStorage/FileStorageAccessor.cpp Core/FileStorage/FileStorageAccessor.h Core/FileStorage/StorageAccessor.cpp Core/FileStorage/StorageAccessor.h OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/OrthancRestApi.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h UnitTests/FileStorage.cpp UnitTests/ServerIndex.cpp |
diffstat | 17 files changed, 57 insertions(+), 149 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.h Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/Enumerations.h Fri Nov 30 14:30:05 2012 +0100 @@ -77,9 +77,9 @@ CompressionType_Zlib = 2 }; - enum FileType + enum FileContentType { - FileType_Dicom = 1, - FileType_Json = 2 + FileContentType_Dicom = 1, + FileContentType_Json = 2 }; }
--- a/Core/FileStorage/CompressedFileStorageAccessor.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/CompressedFileStorageAccessor.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -40,7 +40,7 @@ { FileInfo CompressedFileStorageAccessor::WriteInternal(const void* data, size_t size, - FileType type) + FileContentType type) { switch (compressionType_) {
--- a/Core/FileStorage/CompressedFileStorageAccessor.h Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/CompressedFileStorageAccessor.h Fri Nov 30 14:30:05 2012 +0100 @@ -48,7 +48,7 @@ protected: virtual FileInfo WriteInternal(const void* data, size_t size, - FileType type); + FileContentType type); public: CompressedFileStorageAccessor(FileStorage& storage);
--- a/Core/FileStorage/FileInfo.h Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/FileInfo.h Fri Nov 30 14:30:05 2012 +0100 @@ -42,9 +42,9 @@ { private: std::string uuid_; - FileType type_; + FileContentType contentType_; uint64_t uncompressedSize_; - CompressionType compression_; + CompressionType compressionType_; uint64_t compressedSize_; public: @@ -56,12 +56,12 @@ * Constructor for an uncompressed attachment. **/ FileInfo(const std::string& uuid, - FileType type, + FileContentType contentType, uint64_t size) : uuid_(uuid), - type_(type), + contentType_(contentType), uncompressedSize_(size), - compression_(CompressionType_None), + compressionType_(CompressionType_None), compressedSize_(size) { } @@ -70,14 +70,14 @@ * Constructor for a compressed attachment. **/ FileInfo(const std::string& uuid, - FileType type, + FileContentType contentType, uint64_t uncompressedSize, - CompressionType compression, + CompressionType compressionType, uint64_t compressedSize) : uuid_(uuid), - type_(type), + contentType_(contentType), uncompressedSize_(uncompressedSize), - compression_(compression), + compressionType_(compressionType), compressedSize_(compressedSize) { } @@ -87,9 +87,9 @@ return uuid_; } - FileType GetFileType() const + FileContentType GetContentType() const { - return type_; + return contentType_; } uint64_t GetUncompressedSize() const @@ -99,7 +99,7 @@ CompressionType GetCompressionType() const { - return compression_; + return compressionType_; } uint64_t GetCompressedSize() const
--- a/Core/FileStorage/FileStorageAccessor.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/FileStorageAccessor.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -36,7 +36,7 @@ { FileInfo FileStorageAccessor::WriteInternal(const void* data, size_t size, - FileType type) + FileContentType type) { return FileInfo(storage_.Create(data, size), type, size); }
--- a/Core/FileStorage/FileStorageAccessor.h Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/FileStorageAccessor.h Fri Nov 30 14:30:05 2012 +0100 @@ -46,7 +46,7 @@ protected: virtual FileInfo WriteInternal(const void* data, size_t size, - FileType type); + FileContentType type); public: FileStorageAccessor(FileStorage& storage) : storage_(storage)
--- a/Core/FileStorage/StorageAccessor.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/StorageAccessor.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -35,7 +35,7 @@ namespace Orthanc { FileInfo StorageAccessor::Write(const std::vector<uint8_t>& content, - FileType type) + FileContentType type) { if (content.size() == 0) { @@ -48,7 +48,7 @@ } FileInfo StorageAccessor::Write(const std::string& content, - FileType type) + FileContentType type) { if (content.size() == 0) {
--- a/Core/FileStorage/StorageAccessor.h Fri Nov 30 14:22:27 2012 +0100 +++ b/Core/FileStorage/StorageAccessor.h Fri Nov 30 14:30:05 2012 +0100 @@ -47,7 +47,7 @@ protected: virtual FileInfo WriteInternal(const void* data, size_t size, - FileType type) = 0; + FileContentType type) = 0; public: virtual ~StorageAccessor() @@ -56,16 +56,16 @@ FileInfo Write(const void* data, size_t size, - FileType type) + FileContentType type) { return WriteInternal(data, size, type); } FileInfo Write(const std::vector<uint8_t>& content, - FileType type); + FileContentType type); FileInfo Write(const std::string& content, - FileType type); + FileContentType type); virtual void Read(std::string& content, const std::string& uuid) = 0;
--- a/OrthancServer/DatabaseWrapper.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -381,7 +381,7 @@ { SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)"); s.BindInt(0, id); - s.BindInt(1, attachment.GetFileType()); + s.BindInt(1, attachment.GetContentType()); s.BindString(2, attachment.GetUuid()); s.BindInt(3, attachment.GetCompressedSize()); s.BindInt(4, attachment.GetUncompressedSize()); @@ -391,7 +391,7 @@ bool DatabaseWrapper::LookupAttachment(FileInfo& attachment, int64_t id, - FileType contentType) + FileContentType contentType) { SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT uuid, uncompressedSize, compressionType, compressedSize FROM AttachedFiles WHERE id=? AND fileType=?");
--- a/OrthancServer/DatabaseWrapper.h Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.h Fri Nov 30 14:30:05 2012 +0100 @@ -113,7 +113,7 @@ bool LookupAttachment(FileInfo& attachment, int64_t id, - FileType contentType); + FileContentType contentType); void SetMainDicomTags(int64_t id, const DicomMap& tags);
--- a/OrthancServer/OrthancRestApi.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -258,7 +258,7 @@ { std::string instanceId = found["Instances"][i].asString(); std::string dicom; - context.ReadFile(dicom, instanceId, FileType_Dicom); + context.ReadFile(dicom, instanceId, FileContentType_Dicom); connection.Store(dicom); } @@ -270,7 +270,7 @@ context.GetIndex().LogExportedResource(resourceId, remote); std::string dicom; - context.ReadFile(dicom, resourceId, FileType_Dicom); + context.ReadFile(dicom, resourceId, FileContentType_Dicom); connection.Store(dicom); call.GetOutput().AnswerBuffer("{}", "application/json"); @@ -410,7 +410,7 @@ RETRIEVE_CONTEXT(call); std::string publicId = call.GetUriComponent("id", ""); - context.AnswerFile(call.GetOutput(), publicId, FileType_Dicom); + context.AnswerFile(call.GetOutput(), publicId, FileContentType_Dicom); } @@ -485,7 +485,7 @@ std::string publicId = call.GetUriComponent("id", ""); std::string dicomContent, png; - context.ReadFile(dicomContent, publicId, FileType_Dicom); + context.ReadFile(dicomContent, publicId, FileContentType_Dicom); try {
--- a/OrthancServer/ServerContext.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/ServerContext.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -68,8 +68,8 @@ { //accessor_.SetCompressionForNextOperations(CompressionType_Zlib); - FileInfo dicomInfo = accessor_.Write(dicomFile, dicomSize, FileType_Dicom); - FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileType_Json); + FileInfo dicomInfo = accessor_.Write(dicomFile, dicomSize, FileContentType_Dicom); + FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_Json); ServerIndex::Attachments attachments; attachments.push_back(dicomInfo); @@ -104,13 +104,13 @@ void ServerContext::AnswerFile(RestApiOutput& output, const std::string& instancePublicId, - FileType content) + FileContentType content) { FileInfo attachment; - if (index_.LookupAttachment(attachment, instancePublicId, FileType_Dicom)) + if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_Dicom)) { assert(attachment.GetCompressionType() == CompressionType_None); - assert(attachment.GetFileType() == FileType_Dicom); + assert(attachment.GetContentType() == FileContentType_Dicom); FilesystemHttpSender sender(storage_, attachment.GetUuid()); sender.SetDownloadFilename(attachment.GetUuid() + ".dcm"); @@ -124,7 +124,7 @@ const std::string& instancePublicId) { std::string s; - ReadFile(s, instancePublicId, FileType_Json); + ReadFile(s, instancePublicId, FileContentType_Json); Json::Reader reader; if (!reader.parse(s, result)) @@ -136,7 +136,7 @@ void ServerContext::ReadFile(std::string& result, const std::string& instancePublicId, - FileType content) + FileContentType content) { FileInfo attachment; if (!index_.LookupAttachment(attachment, instancePublicId, content))
--- a/OrthancServer/ServerContext.h Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/ServerContext.h Fri Nov 30 14:30:05 2012 +0100 @@ -69,7 +69,7 @@ void AnswerFile(RestApiOutput& output, const std::string& instancePublicId, - FileType content); + FileContentType content); void ReadJson(Json::Value& result, const std::string& instancePublicId); @@ -77,6 +77,6 @@ // TODO CACHING MECHANISM AT THIS POINT void ReadFile(std::string& result, const std::string& instancePublicId, - FileType content); + FileContentType content); }; }
--- a/OrthancServer/ServerIndex.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -548,7 +548,7 @@ result["Type"] = "Instance"; FileInfo attachment; - if (!db_->LookupAttachment(attachment, id, FileType_Dicom)) + if (!db_->LookupAttachment(attachment, id, FileContentType_Dicom)) { throw OrthancException(ErrorCode_InternalError); } @@ -579,7 +579,7 @@ bool ServerIndex::LookupAttachment(FileInfo& attachment, const std::string& instanceUuid, - FileType contentType) + FileContentType contentType) { boost::mutex::scoped_lock lock(mutex_); @@ -593,7 +593,7 @@ if (db_->LookupAttachment(attachment, id, contentType)) { - assert(attachment.GetFileType() == contentType); + assert(attachment.GetContentType() == contentType); return true; } else
--- a/OrthancServer/ServerIndex.h Fri Nov 30 14:22:27 2012 +0100 +++ b/OrthancServer/ServerIndex.h Fri Nov 30 14:30:05 2012 +0100 @@ -89,7 +89,7 @@ bool LookupAttachment(FileInfo& attachment, const std::string& instanceUuid, - FileType contentType); + FileContentType contentType); void GetAllUuids(Json::Value& target, ResourceType resourceType);
--- a/UnitTests/FileStorage.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/UnitTests/FileStorage.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -66,7 +66,7 @@ FileStorageAccessor accessor(s); std::string data = "Hello world"; - FileInfo info = accessor.Write(data, FileType_Dicom); + FileInfo info = accessor.Write(data, FileContentType_Dicom); std::string r; accessor.Read(r, info.GetUuid()); @@ -75,7 +75,7 @@ ASSERT_EQ(CompressionType_None, info.GetCompressionType()); ASSERT_EQ(11u, info.GetUncompressedSize()); ASSERT_EQ(11u, info.GetCompressedSize()); - ASSERT_EQ(FileType_Dicom, info.GetFileType()); + ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); } @@ -86,7 +86,7 @@ accessor.SetCompressionForNextOperations(CompressionType_None); std::string data = "Hello world"; - FileInfo info = accessor.Write(data, FileType_Dicom); + FileInfo info = accessor.Write(data, FileContentType_Dicom); std::string r; accessor.Read(r, info.GetUuid()); @@ -95,7 +95,7 @@ ASSERT_EQ(CompressionType_None, info.GetCompressionType()); ASSERT_EQ(11u, info.GetUncompressedSize()); ASSERT_EQ(11u, info.GetCompressedSize()); - ASSERT_EQ(FileType_Dicom, info.GetFileType()); + ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); } @@ -106,7 +106,7 @@ accessor.SetCompressionForNextOperations(CompressionType_Zlib); std::string data = "Hello world"; - FileInfo info = accessor.Write(data, FileType_Dicom); + FileInfo info = accessor.Write(data, FileContentType_Dicom); std::string r; accessor.Read(r, info.GetUuid()); @@ -114,7 +114,7 @@ ASSERT_EQ(data, r); ASSERT_EQ(CompressionType_Zlib, info.GetCompressionType()); ASSERT_EQ(11u, info.GetUncompressedSize()); - ASSERT_EQ(FileType_Dicom, info.GetFileType()); + ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); } @@ -128,10 +128,10 @@ std::string uncompressedData = "HelloWorld"; accessor.SetCompressionForNextOperations(CompressionType_Zlib); - FileInfo compressedInfo = accessor.Write(compressedData, FileType_Dicom); + FileInfo compressedInfo = accessor.Write(compressedData, FileContentType_Dicom); accessor.SetCompressionForNextOperations(CompressionType_None); - FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileType_Dicom); + FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileContentType_Dicom); accessor.SetCompressionForNextOperations(CompressionType_Zlib); accessor.Read(r, compressedInfo.GetUuid()); @@ -147,95 +147,3 @@ ASSERT_THROW(accessor.Read(r, uncompressedInfo.GetUuid()), OrthancException); */ } - - - -#if 0 -// TODO REMOVE THIS STUFF -namespace Orthanc -{ - class ServerStorageAccessor : public StorageAccessor - { - private: - CompressedFileStorageAccessor composite_; - ServerIndex& index_; - AttachedFileType contentType_; - - protected: - virtual std::string WriteInternal(const void* data, - size_t size) - { - switch (contentType_) - { - case AttachedFileType_Json: - composite_.SetCompressionForNextOperations(CompressionType_None); - break; - - case AttachedFileType_Dicom: - // TODO GLOBAL PARAMETER - composite_.SetCompressionForNextOperations(CompressionType_Zlib); - break; - - default: - throw OrthancException(ErrorCode_InternalError); - } - - std::string fileUuid = composite_.Write(data, size); - - - } - - public: - ServerStorageAccessor(FileStorage& storage, - ServerIndex& index) : - composite_(storage), - index_(index) - { - contentType_ = AttachedFileType_Dicom; - } - - void SetAttachmentType(AttachedFileType type) - { - contentType_ = type; - } - - AttachedFileType GetAttachmentType() const - { - return contentType_; - } - - virtual void Read(std::string& content, - const std::string& uuid) - { - std::string fileUuid; - CompressionType compression; - - if (index_.GetFile(fileUuid, compression, uuid, contentType_)) - { - composite_.SetCompressionForNextOperations(compression); - composite_.Read(content, fileUuid); - } - else - { - throw OrthancException(ErrorCode_InternalError); - } - } - - virtual HttpFileSender* ConstructHttpFileSender(const std::string& uuid) - { - std::string fileUuid; - CompressionType compression; - - if (index_.GetFile(fileUuid, compression, uuid, contentType_)) - { - composite_.SetCompressionForNextOperations(compression); - return composite_.ConstructHttpFileSender(fileUuid); - } - else - { - throw OrthancException(ErrorCode_InternalError); - } - } - }; -} -#endif
--- a/UnitTests/ServerIndex.cpp Fri Nov 30 14:22:27 2012 +0100 +++ b/UnitTests/ServerIndex.cpp Fri Nov 30 14:30:05 2012 +0100 @@ -125,9 +125,9 @@ ASSERT_EQ("e", l.front()); } - index.AddAttachment(a[4], FileInfo("my json file", FileType_Json, 42, CompressionType_Zlib, 21)); - index.AddAttachment(a[4], FileInfo("my dicom file", FileType_Dicom, 42)); - index.AddAttachment(a[6], FileInfo("world", FileType_Dicom, 44)); + index.AddAttachment(a[4], FileInfo("my json file", FileContentType_Json, 42, CompressionType_Zlib, 21)); + index.AddAttachment(a[4], FileInfo("my dicom file", FileContentType_Dicom, 42)); + index.AddAttachment(a[6], FileInfo("world", FileContentType_Dicom, 44)); index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); ASSERT_EQ(21u + 42u + 44u, index.GetTotalCompressedSize()); @@ -156,7 +156,7 @@ ASSERT_EQ("None", index.GetGlobalProperty(static_cast<GlobalProperty>(42), "None")); FileInfo att; - ASSERT_TRUE(index.LookupAttachment(att, a[4], FileType_Json)); + ASSERT_TRUE(index.LookupAttachment(att, a[4], FileContentType_Json)); ASSERT_EQ("my json file", att.GetUuid()); ASSERT_EQ(21u, att.GetCompressedSize()); ASSERT_EQ(42u, att.GetUncompressedSize());