annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5080:d7274e43ea7c attach-custom-data

allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
author Alain Mazy <am@osimis.io>
date Thu, 08 Sep 2022 17:42:08 +0200
parents 5c997c72603c
children 8279eaab0d1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
24 #include "../PrecompiledHeaders.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "StorageAccessor.h"
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
26 #include "StorageCache.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
28 #include "../Logging.h"
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
29 #include "../StringMemoryBuffer.h"
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
30 #include "../Compatibility.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
31 #include "../Compression/ZlibCompressor.h"
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
32 #include "../MetricsRegistry.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
33 #include "../OrthancException.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
34 #include "../Toolbox.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
35
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
36 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
37 # include "../HttpServer/HttpStreamTranscoder.h"
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
38 #endif
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
39
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
40
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
41 static const std::string METRICS_CREATE = "orthanc_storage_create_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
42 static const std::string METRICS_READ = "orthanc_storage_read_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
43 static const std::string METRICS_REMOVE = "orthanc_storage_remove_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
44
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
45
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
48 class StorageAccessor::MetricsTimer : public boost::noncopyable
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
49 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
51 std::unique_ptr<MetricsRegistry::Timer> timer_;
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
52
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
53 public:
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
54 MetricsTimer(StorageAccessor& that,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
55 const std::string& name)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
56 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
57 if (that.metrics_ != NULL)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
58 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
59 timer_.reset(new MetricsRegistry::Timer(*that.metrics_, name));
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
60 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
61 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
62 };
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
63
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
64
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
65 StorageAccessor::StorageAccessor(IStorageArea &area, StorageCache* cache) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
66 area_(area),
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
67 cache_(cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
68 metrics_(NULL)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
69 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
70 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
71
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
72 StorageAccessor::StorageAccessor(IStorageArea &area,
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
73 StorageCache* cache,
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
74 MetricsRegistry &metrics) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
75 area_(area),
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
76 cache_(cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
77 metrics_(&metrics)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
78 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
79 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
80
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
81
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
82 FileInfo StorageAccessor::WriteInstance(std::string& customData,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
83 const DicomInstanceToStore& instance,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
84 const void* data,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
85 size_t size,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
86 FileContentType type,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
87 CompressionType compression,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
88 bool storeMd5,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
89 const std::string& uuid)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
91 std::string md5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
92
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
93 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
94 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
95 Toolbox::ComputeMD5(md5, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
96 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
97
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
98 switch (compression)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
100 case CompressionType_None:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
101 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
102 MetricsTimer timer(*this, METRICS_CREATE);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
103
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
104 area_.CreateInstance(customData, instance, uuid, data, size, type, false);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
105
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
106 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
107 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
108 cache_->Add(uuid, type, data, size);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
109 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
110
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
111 return FileInfo(uuid, type, size, md5, customData);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
112 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
114 case CompressionType_ZlibWithSize:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
115 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 ZlibCompressor zlib;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
118 std::string compressed;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
119 zlib.Compress(compressed, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
120
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
121 std::string compressedMD5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
122
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
123 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
124 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
125 Toolbox::ComputeMD5(compressedMD5, compressed);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
126 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
127
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
128 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
129 MetricsTimer timer(*this, METRICS_CREATE);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
130
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
131 if (compressed.size() > 0)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
132 {
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
133 area_.CreateInstance(customData, instance, uuid, &compressed[0], compressed.size(), type, true);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
134 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
135 else
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
136 {
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
137 area_.CreateInstance(customData, instance, uuid, NULL, 0, type, true);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
138 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
139 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
140
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
141 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
142 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
143 cache_->Add(uuid, type, data, size); // always add uncompressed data to cache
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
144 }
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
145
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
146 return FileInfo(uuid, type, size, md5,
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
147 CompressionType_ZlibWithSize, compressed.size(), compressedMD5, customData);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
148 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
149
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
150 default:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
151 throw OrthancException(ErrorCode_NotImplemented);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
155 FileInfo StorageAccessor::WriteAttachment(std::string& customData,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
156 const std::string& resourceId,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
157 ResourceType resourceType,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
158 const void* data,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
159 size_t size,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
160 FileContentType type,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
161 CompressionType compression,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
162 bool storeMd5,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
163 const std::string& uuid)
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
164 {
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
165 std::string md5;
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
166
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
167 if (storeMd5)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
168 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
169 Toolbox::ComputeMD5(md5, data, size);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
170 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
171
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
172 switch (compression)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
173 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
174 case CompressionType_None:
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
175 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
176 MetricsTimer timer(*this, METRICS_CREATE);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
177
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
178 area_.CreateAttachment(customData, resourceId, resourceType, uuid, data, size, type, false);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
179
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
180 if (cache_ != NULL)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
181 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
182 cache_->Add(uuid, type, data, size);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
183 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
184
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
185 return FileInfo(uuid, type, size, md5, customData);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
186 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
187
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
188 case CompressionType_ZlibWithSize:
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
189 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
190 ZlibCompressor zlib;
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
191
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
192 std::string compressed;
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
193 zlib.Compress(compressed, data, size);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
194
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
195 std::string compressedMD5;
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
196
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
197 if (storeMd5)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
198 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
199 Toolbox::ComputeMD5(compressedMD5, compressed);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
200 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
201
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
202 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
203 MetricsTimer timer(*this, METRICS_CREATE);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
204
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
205 if (compressed.size() > 0)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
206 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
207 area_.CreateAttachment(customData, resourceId, resourceType, uuid, &compressed[0], compressed.size(), type, true);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
208 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
209 else
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
210 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
211 area_.CreateAttachment(customData, resourceId, resourceType, uuid, NULL, 0, type, true);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
212 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
213 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
214
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
215 if (cache_ != NULL)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
216 {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
217 cache_->Add(uuid, type, data, size); // always add uncompressed data to cache
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
218 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
219
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
220 return FileInfo(uuid, type, size, md5,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
221 CompressionType_ZlibWithSize, compressed.size(), compressedMD5, customData);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
222 }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
223
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
224 default:
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
225 throw OrthancException(ErrorCode_NotImplemented);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
226 }
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
227 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
228
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
229
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
230 void StorageAccessor::Read(std::string& content,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
231 const FileInfo& info)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
233 if (cache_ == NULL ||
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
234 !cache_->Fetch(content, info.GetUuid(), info.GetContentType()))
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
236 switch (info.GetCompressionType())
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
237 {
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
238 case CompressionType_None:
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
239 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
240 MetricsTimer timer(*this, METRICS_READ);
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
241 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType(), info.GetCustomData()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
242 buffer->MoveToString(content);
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
243
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
244 break;
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
245 }
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
246
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
247 case CompressionType_ZlibWithSize:
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
248 {
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
249 ZlibCompressor zlib;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
250
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
251 std::unique_ptr<IMemoryBuffer> compressed;
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
252
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
253 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
254 MetricsTimer timer(*this, METRICS_READ);
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
255 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType(), info.GetCustomData()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
256 }
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
257
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
258 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize());
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
259
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
260 break;
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
261 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
262
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
263 default:
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
264 {
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
265 throw OrthancException(ErrorCode_NotImplemented);
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
266 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
267 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
268
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
269 // always store the uncompressed data in cache
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
270 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
271 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
272 cache_->Add(info.GetUuid(), info.GetContentType(), content);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
273 }
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
275
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
276 // TODO Check the validity of the uncompressed MD5?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
277 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
278
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
279
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
280 void StorageAccessor::ReadRaw(std::string& content,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
281 const FileInfo& info)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
282 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
283 if (cache_ == NULL || !cache_->Fetch(content, info.GetUuid(), info.GetContentType()))
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
284 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
285 MetricsTimer timer(*this, METRICS_READ);
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
286 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType(), info.GetCustomData()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
287 buffer->MoveToString(content);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
288 }
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
289 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
290
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
291
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
292 void StorageAccessor::Remove(const std::string& fileUuid,
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
293 FileContentType type,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
294 const std::string& customData)
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
295 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
296 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
297 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
298 cache_->Invalidate(fileUuid, type);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
299 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
300
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
301 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
302 MetricsTimer timer(*this, METRICS_REMOVE);
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
303 area_.Remove(fileUuid, type, customData);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
304 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
305 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
306
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
307
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
308 void StorageAccessor::Remove(const FileInfo &info)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
309 {
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
310 Remove(info.GetUuid(), info.GetContentType(), info.GetCustomData());
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
311 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
312
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
313
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
314 void StorageAccessor::ReadStartRange(std::string& target,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
315 const std::string& fileUuid,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
316 FileContentType contentType,
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
317 uint64_t end /* exclusive */,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
318 const std::string& customData)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
319 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
320 if (cache_ == NULL || !cache_->FetchStartRange(target, fileUuid, contentType, end))
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
321 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
322 MetricsTimer timer(*this, METRICS_READ);
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
323 std::unique_ptr<IMemoryBuffer> buffer(area_.ReadRange(fileUuid, contentType, 0, end, customData));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
324 assert(buffer->GetSize() == end);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
325 buffer->MoveToString(target);
4906
f656fb878b50 reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents: 4901
diff changeset
326
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
327 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
328 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
329 cache_->AddStartRange(fileUuid, contentType, target);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
330 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
331 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
332 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
333
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
334
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
335 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
336 void StorageAccessor::SetupSender(BufferHttpSender& sender,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
337 const FileInfo& info,
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
338 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
339 {
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
340 Read(sender.GetBuffer(), info);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
341
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
342 sender.SetContentType(mime);
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
343
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
344 const char* extension;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
345 switch (info.GetContentType())
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
346 {
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
347 case FileContentType_Dicom:
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
348 case FileContentType_DicomUntilPixelData:
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
349 extension = ".dcm";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
350 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
351
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
352 case FileContentType_DicomAsJson:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
353 extension = ".json";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
354 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
355
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
356 default:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
357 // Non-standard content type
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
358 extension = "";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
359 }
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
360
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
361 sender.SetContentFilename(info.GetUuid() + std::string(extension));
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
362 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
363 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
364
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
365
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
366 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
367 void StorageAccessor::AnswerFile(HttpOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
368 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
369 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
370 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
371 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
372 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
373 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
374
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
375
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
376 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
377 void StorageAccessor::AnswerFile(HttpOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
378 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
379 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
380 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
381 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
382 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
383
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
384 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
385 output.Answer(transcoder);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
386 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
387 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
388
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
389
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
390 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
391 void StorageAccessor::AnswerFile(RestApiOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
392 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
393 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
394 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
395 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
396 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
397 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
398
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
399
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
400 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
401 void StorageAccessor::AnswerFile(RestApiOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
402 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
403 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
404 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
405 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
406 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
407
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
408 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
409 output.AnswerStream(transcoder);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
411 #endif
5080
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
412
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
413 // bool StorageAccessor::HandlesCustomData()
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
414 // {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
415 // return area_.HandlesCustomData();
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
416 // }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
417
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
418 // void StorageAccessor::GetCustomData(std::string& customData,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
419 // const std::string& uuid,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
420 // const DicomInstanceToStore* instance,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
421 // const void* content,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
422 // size_t size,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
423 // FileContentType type,
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
424 // bool compression)
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
425 // {
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
426 // area_.GetCustomData(customData, uuid, instance, content, size, type, compression);
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
427 // }
d7274e43ea7c allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents: 5059
diff changeset
428
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }