annotate OrthancServer/ServerContext.cpp @ 778:aebf0071020e

refactoring of the mutex for the dicom cache
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 May 2014 11:02:23 +0200
parents 4e3593c3511d
children 381f90e2b69d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "ServerContext.h"
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
35 #include "../Core/HttpServer/FilesystemHttpSender.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
36 #include "../Core/Lua/LuaFunctionCall.h"
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
37 #include "ServerToolbox.h"
771
537837f50fbb refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 730
diff changeset
38 #include "OrthancInitialization.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
39
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <glog/logging.h>
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
41 #include <EmbeddedResources.h>
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
43 #define ENABLE_DICOM_CACHE 1
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
44
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
45 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter";
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
46
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
47 static const size_t DICOM_CACHE_SIZE = 2;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
48
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
49 /**
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
50 * IMPORTANT: We make the assumption that the same instance of
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
51 * FileStorage can be accessed from multiple threads. This seems OK
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
52 * since the filesystem implements the required locking mechanisms,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
53 * but maybe a read-writer lock on the "FileStorage" could be
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
54 * useful. Conversely, "ServerIndex" already implements mutex-based
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
55 * locking.
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
56 **/
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
57
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 namespace Orthanc
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
376
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
60 ServerContext::ServerContext(const boost::filesystem::path& storagePath,
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
61 const boost::filesystem::path& indexPath) :
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
62 storage_(storagePath.string()),
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
63 index_(*this, indexPath.string()),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
64 accessor_(storage_),
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
65 compressionEnabled_(false),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
66 provider_(*this),
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
67 dicomCache_(provider_, DICOM_CACHE_SIZE)
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
771
537837f50fbb refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 730
diff changeset
69 scu_.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC"));
774
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
70 //scu_.SetMillisecondsBeforeClose(1); // The connection is always released
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
71
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
72 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
75 void ServerContext::SetCompressionEnabled(bool enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
76 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
77 if (enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
78 LOG(WARNING) << "Disk compression is enabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
79 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
80 LOG(WARNING) << "Disk compression is disabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
81
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
82 compressionEnabled_ = enabled;
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
83 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
84
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
85 void ServerContext::RemoveFile(const std::string& fileUuid)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
86 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
87 storage_.Remove(fileUuid);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
88 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
89
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
90 StoreStatus ServerContext::Store(const char* dicomInstance,
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 size_t dicomSize,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const DicomMap& dicomSummary,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const Json::Value& dicomJson,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& remoteAet)
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
96 // Test if the instance must be filtered out
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
97 if (lua_.IsExistingFunction(RECEIVED_INSTANCE_FILTER))
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
98 {
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
99 Json::Value simplified;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
100 SimplifyTags(simplified, dicomJson);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
101
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
102 LuaFunctionCall call(lua_, RECEIVED_INSTANCE_FILTER);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
103 call.PushJSON(simplified);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
104 call.PushString(remoteAet);
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
105
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
106 if (!call.ExecutePredicate())
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
107 {
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 407
diff changeset
108 LOG(INFO) << "An incoming instance has been discarded by the filter";
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
109 return StoreStatus_FilteredOut;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
110 }
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
111 }
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
112
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
113 if (compressionEnabled_)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
114 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
115 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
116 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
117 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
118 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
119 accessor_.SetCompressionForNextOperations(CompressionType_None);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
120 }
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
121
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
122 FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom);
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
123 FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_DicomAsJson);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
124
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
125 ServerIndex::Attachments attachments;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
126 attachments.push_back(dicomInfo);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
127 attachments.push_back(jsonInfo);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
128
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
129 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet);
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if (status != StoreStatus_Success)
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
133 storage_.Remove(dicomInfo.GetUuid());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
134 storage_.Remove(jsonInfo.GetUuid());
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 switch (status)
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
139 case StoreStatus_Success:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
140 LOG(INFO) << "New instance stored";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
141 break;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
142
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
143 case StoreStatus_AlreadyStored:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
144 LOG(INFO) << "Already stored";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
145 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
147 case StoreStatus_Failure:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
148 LOG(ERROR) << "Store failure";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
149 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
151 default:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
152 // This should never happen
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
153 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 return status;
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
158
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
159
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
160 void ServerContext::AnswerDicomFile(RestApiOutput& output,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
161 const std::string& instancePublicId,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
162 FileContentType content)
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
163 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
164 FileInfo attachment;
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
165 if (!index_.LookupAttachment(attachment, instancePublicId, content))
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
166 {
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
167 throw OrthancException(ErrorCode_InternalError);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
168 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
169
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
170 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
171
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
172 std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid()));
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
173 sender->SetContentType("application/dicom");
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
174 sender->SetDownloadFilename(instancePublicId + ".dcm");
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
175 output.AnswerFile(*sender);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
176 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
177
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
178
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
179 void ServerContext::ReadJson(Json::Value& result,
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
180 const std::string& instancePublicId)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
181 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
182 std::string s;
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
183 ReadFile(s, instancePublicId, FileContentType_DicomAsJson);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
184
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
185 Json::Reader reader;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
186 if (!reader.parse(s, result))
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
187 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
188 throw OrthancException("Corrupted JSON file");
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
189 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
190 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
191
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
192
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
193 void ServerContext::ReadFile(std::string& result,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
194 const std::string& instancePublicId,
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
195 FileContentType content,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
196 bool uncompressIfNeeded)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
197 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
198 FileInfo attachment;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
199 if (!index_.LookupAttachment(attachment, instancePublicId, content))
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
200 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
201 throw OrthancException(ErrorCode_InternalError);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
202 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
203
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
204 if (uncompressIfNeeded)
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
205 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
206 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
207 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
208 else
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
209 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
210 accessor_.SetCompressionForNextOperations(CompressionType_None);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
211 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
212
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
213 accessor_.Read(result, attachment.GetUuid());
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
214 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
215
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
216
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
217 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
218 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
219 std::string content;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
220 context_.ReadFile(content, instancePublicId, FileContentType_Dicom);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
221 return new ParsedDicomFile(content);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
222 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
223
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
224
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
225 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
226 const std::string& instancePublicId) :
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
227 that_(that)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
228 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
229 #if ENABLE_DICOM_CACHE == 0
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
230 static std::auto_ptr<IDynamicObject> p;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
231 p.reset(provider_.Provide(instancePublicId));
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
232 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
233 #else
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
234 that_.dicomCacheMutex_.lock();
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
235 dicom_ = &dynamic_cast<ParsedDicomFile&>(that_.dicomCache_.Access(instancePublicId));
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
236 #endif
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
237 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
238
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
239
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
240 ServerContext::DicomCacheLocker::~DicomCacheLocker()
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
241 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
242 #if ENABLE_DICOM_CACHE == 0
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
243 #else
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
244 that_.dicomCacheMutex_.unlock();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
245 #endif
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
246 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
247
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
248
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
249 StoreStatus ServerContext::Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
250 DcmFileFormat& dicomInstance,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
251 const char* dicomBuffer,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
252 size_t dicomSize)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
253 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
254 DicomMap dicomSummary;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
255 FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.getDataset());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
256
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
257 try
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
258 {
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
259 DicomInstanceHasher hasher(dicomSummary);
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
260 resultPublicId = hasher.HashInstance();
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
261
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
262 Json::Value dicomJson;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
263 FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset());
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
264
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
265 StoreStatus status = StoreStatus_Failure;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
266 if (dicomSize > 0)
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
267 {
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
268 status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, "");
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
269 }
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
270
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
271 return status;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
272 }
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
273 catch (OrthancException& e)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
274 {
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
275 if (e.GetErrorCode() == ErrorCode_InexistentTag)
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
276 {
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
277 LogMissingRequiredTag(dicomSummary);
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
278 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
279
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
280 throw e;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
281 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
282 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
283
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
284
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
285 StoreStatus ServerContext::Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
286 DcmFileFormat& dicomInstance)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
287 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
288 std::string buffer;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
289 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, dicomInstance.getDataset()))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
290 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
291 throw OrthancException(ErrorCode_InternalError);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
292 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
293
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
294 if (buffer.size() == 0)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
295 return Store(resultPublicId, dicomInstance, NULL, 0);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
296 else
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
297 return Store(resultPublicId, dicomInstance, &buffer[0], buffer.size());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
298 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
299
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
300
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
301 StoreStatus ServerContext::Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
302 const char* dicomBuffer,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
303 size_t dicomSize)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
304 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
305 ParsedDicomFile dicom(dicomBuffer, dicomSize);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
306 return Store(resultPublicId, dicom.GetDicom(), dicomBuffer, dicomSize);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
307 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
308
695
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
309 void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
310 {
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
311 LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
312 accessor_.SetStoreMD5(storeMD5);
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
313 }
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
314
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
315
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
316 bool ServerContext::AddAttachment(const std::string& resourceId,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
317 FileContentType attachmentType,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
318 const void* data,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
319 size_t size)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
320 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
321 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
322
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
323 if (compressionEnabled_)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
324 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
325 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
326 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
327 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
328 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
329 accessor_.SetCompressionForNextOperations(CompressionType_None);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
330 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
331
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
332 FileInfo info = accessor_.Write(data, size, attachmentType);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
333 StoreStatus status = index_.AddAttachment(info, resourceId);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
334
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
335 if (status != StoreStatus_Success)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
336 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
337 storage_.Remove(info.GetUuid());
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
338 return false;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
339 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
340 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
341 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
342 return true;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
343 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
344 }
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }