comparison UnitTests/FileStorage.cpp @ 224:4eb0c7ce86c9

refactoring for store
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Nov 2012 22:22:00 +0100
parents 6f0e4a8ebb0f
children 5368bbe813cf
comparison
equal deleted inserted replaced
223:6f0e4a8ebb0f 224:4eb0c7ce86c9
2 2
3 #include <ctype.h> 3 #include <ctype.h>
4 #include <glog/logging.h> 4 #include <glog/logging.h>
5 5
6 #include "../Core/FileStorage.h" 6 #include "../Core/FileStorage.h"
7 #include "../OrthancServer/ServerIndex.h"
7 #include "../Core/Toolbox.h" 8 #include "../Core/Toolbox.h"
8 #include "../Core/OrthancException.h" 9 #include "../Core/OrthancException.h"
9 #include "../Core/Uuid.h" 10 #include "../Core/Uuid.h"
10 #include "../Core/HttpServer/FilesystemHttpSender.h" 11 #include "../Core/HttpServer/FilesystemHttpSender.h"
11 #include "../Core/HttpServer/BufferHttpSender.h" 12 #include "../Core/HttpServer/BufferHttpSender.h"
128 accessor.SetCompressionForNextOperations(CompressionType_None); 129 accessor.SetCompressionForNextOperations(CompressionType_None);
129 accessor.Read(r, compressedId); 130 accessor.Read(r, compressedId);
130 ASSERT_NE(compressedData, r); 131 ASSERT_NE(compressedData, r);
131 132
132 #if defined(__linux) 133 #if defined(__linux)
133 // This tests is too slow on Windows 134 // This test is too slow on Windows
134 accessor.SetCompressionForNextOperations(CompressionType_Zlib); 135 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
135 ASSERT_THROW(accessor.Read(r, uncompressedId), OrthancException); 136 ASSERT_THROW(accessor.Read(r, uncompressedId), OrthancException);
136 #endif 137 #endif
137 } 138 }
139
140
141
142 #if 0
143 // TODO REMOVE THIS STUFF
144 namespace Orthanc
145 {
146 class ServerStorageAccessor : public StorageAccessor
147 {
148 private:
149 CompressedFileStorageAccessor composite_;
150 ServerIndex& index_;
151 AttachedFileType contentType_;
152
153 protected:
154 virtual std::string WriteInternal(const void* data,
155 size_t size)
156 {
157 switch (contentType_)
158 {
159 case AttachedFileType_Json:
160 composite_.SetCompressionForNextOperations(CompressionType_None);
161 break;
162
163 case AttachedFileType_Dicom:
164 // TODO GLOBAL PARAMETER
165 composite_.SetCompressionForNextOperations(CompressionType_Zlib);
166 break;
167
168 default:
169 throw OrthancException(ErrorCode_InternalError);
170 }
171
172 std::string fileUuid = composite_.Write(data, size);
173
174
175 }
176
177 public:
178 ServerStorageAccessor(FileStorage& storage,
179 ServerIndex& index) :
180 composite_(storage),
181 index_(index)
182 {
183 contentType_ = AttachedFileType_Dicom;
184 }
185
186 void SetAttachmentType(AttachedFileType type)
187 {
188 contentType_ = type;
189 }
190
191 AttachedFileType GetAttachmentType() const
192 {
193 return contentType_;
194 }
195
196 virtual void Read(std::string& content,
197 const std::string& uuid)
198 {
199 std::string fileUuid;
200 CompressionType compression;
201
202 if (index_.GetFile(fileUuid, compression, uuid, contentType_))
203 {
204 composite_.SetCompressionForNextOperations(compression);
205 composite_.Read(content, fileUuid);
206 }
207 else
208 {
209 throw OrthancException(ErrorCode_InternalError);
210 }
211 }
212
213 virtual HttpFileSender* ConstructHttpFileSender(const std::string& uuid)
214 {
215 std::string fileUuid;
216 CompressionType compression;
217
218 if (index_.GetFile(fileUuid, compression, uuid, contentType_))
219 {
220 composite_.SetCompressionForNextOperations(compression);
221 return composite_.ConstructHttpFileSender(fileUuid);
222 }
223 else
224 {
225 throw OrthancException(ErrorCode_InternalError);
226 }
227 }
228 };
229 }
230 #endif