annotate OrthancServer/ServerContext.cpp @ 1198:1169528a9a5f db-changes

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Oct 2014 13:52:01 +0200
parents 6b9b02a16e99
children f1c01451a8ee
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ServerContext.h"
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
36 #include "../Core/HttpServer/FilesystemHttpSender.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
37 #include "../Core/Lua/LuaFunctionCall.h"
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
38 #include "FromDcmtkBridge.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
39 #include "ServerToolbox.h"
771
537837f50fbb refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 730
diff changeset
40 #include "OrthancInitialization.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
41
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #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
43 #include <EmbeddedResources.h>
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
44 #include <dcmtk/dcmdata/dcfilefo.h>
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
46
1065
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
47 #include "Scheduler/CallSystemCommand.h"
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
48 #include "Scheduler/DeleteInstanceCommand.h"
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
49 #include "Scheduler/ModifyInstanceCommand.h"
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
50 #include "Scheduler/StoreScuCommand.h"
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
51 #include "Scheduler/StorePeerCommand.h"
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
52 #include "OrthancRestApi/OrthancRestApi.h"
1133
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1129
diff changeset
53 #include "../Plugins/Engine/OrthancPlugins.h"
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
54
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
55
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
56 #define ENABLE_DICOM_CACHE 1
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
57
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
58 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter";
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
59 static const char* ON_STORED_INSTANCE = "OnStoredInstance";
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
60
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
61 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
62
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
63 /**
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
64 * 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
65 * 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
66 * since the filesystem implements the required locking mechanisms,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
67 * 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
68 * useful. Conversely, "ServerIndex" already implements mutex-based
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
69 * locking.
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
70 **/
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
71
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 namespace Orthanc
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
1134
ba9fd42284d0 preparing storage plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1133
diff changeset
74 ServerContext::ServerContext(const boost::filesystem::path& indexPath) :
376
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
75 index_(*this, indexPath.string()),
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
76 compressionEnabled_(false),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
77 provider_(*this),
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
78 dicomCache_(provider_, DICOM_CACHE_SIZE),
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
79 scheduler_(Configuration::GetGlobalIntegerParameter("LimitJobs", 10)),
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
80 plugins_(NULL)
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
82 scu_.SetLocalApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC"));
774
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
83 //scu_.SetMillisecondsBeforeClose(1); // The connection is always released
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
84
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
85 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
88 void ServerContext::SetCompressionEnabled(bool enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
89 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
90 if (enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
91 LOG(WARNING) << "Disk compression is enabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
92 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
93 LOG(WARNING) << "Disk compression is disabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
94
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
95 compressionEnabled_ = enabled;
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
96 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
97
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
98 void ServerContext::RemoveFile(const std::string& fileUuid,
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
99 FileContentType type)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
100 {
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
101 accessor_.Remove(fileUuid, type);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
102 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
103
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
104
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
105 bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& simplified,
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
106 const std::string& remoteAet)
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
107 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
108 LuaContextLocker locker(*this);
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
109
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
110 if (locker.GetLua().IsExistingFunction(RECEIVED_INSTANCE_FILTER))
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
111 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
112 LuaFunctionCall call(locker.GetLua(), RECEIVED_INSTANCE_FILTER);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 996
diff changeset
113 call.PushJson(simplified);
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
114 call.PushString(remoteAet);
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
115
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
116 if (!call.ExecutePredicate())
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
117 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
118 return false;
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
119 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
120 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
121
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
122 return true;
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
123 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
124
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
125
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
126 static IServerCommand* ParseOperation(ServerContext& context,
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
127 const std::string& operation,
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
128 const Json::Value& parameters)
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
129 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
130 if (operation == "delete")
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
131 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
132 LOG(INFO) << "Lua script to delete instance " << parameters["Instance"].asString();
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
133 return new DeleteInstanceCommand(context);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
134 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
135
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
136 if (operation == "store-scu")
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
137 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
138 std::string modality = parameters["Modality"].asString();
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
139 LOG(INFO) << "Lua script to send instance " << parameters["Instance"].asString()
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
140 << " to modality " << modality << " using Store-SCU";
1165
0561f2087cc9 Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
141 return new StoreScuCommand(context, Configuration::GetModalityUsingSymbolicName(modality), true);
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
142 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
143
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
144 if (operation == "store-peer")
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
145 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
146 std::string peer = parameters["Peer"].asString();
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
147 LOG(INFO) << "Lua script to send instance " << parameters["Instance"].asString()
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
148 << " to peer " << peer << " using HTTP";
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
149
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
150 OrthancPeerParameters parameters;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
151 Configuration::GetOrthancPeer(parameters, peer);
1165
0561f2087cc9 Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1146
diff changeset
152 return new StorePeerCommand(context, parameters, true);
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
153 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
154
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
155 if (operation == "modify")
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
156 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
157 LOG(INFO) << "Lua script to modify instance " << parameters["Instance"].asString();
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
158 std::auto_ptr<ModifyInstanceCommand> command(new ModifyInstanceCommand(context));
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
159 OrthancRestApi::ParseModifyRequest(command->GetModification(), parameters);
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
160 return command.release();
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
161 }
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
162
1065
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
163 if (operation == "call-system")
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
164 {
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
165 LOG(INFO) << "Lua script to call system command on " << parameters["Instance"].asString();
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
166
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
167 const Json::Value& argsIn = parameters["Arguments"];
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
168 if (argsIn.type() != Json::arrayValue)
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
169 {
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
170 throw OrthancException(ErrorCode_BadParameterType);
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
171 }
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
172
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
173 std::vector<std::string> args;
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
174 args.reserve(argsIn.size());
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
175 for (Json::Value::ArrayIndex i = 0; i < argsIn.size(); ++i)
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
176 {
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
177 // http://jsoncpp.sourceforge.net/namespace_json.html#7d654b75c16a57007925868e38212b4e
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
178 switch (argsIn[i].type())
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
179 {
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
180 case Json::stringValue:
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
181 args.push_back(argsIn[i].asString());
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
182 break;
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
183
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
184 case Json::intValue:
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
185 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asInt()));
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
186 break;
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
187
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
188 case Json::uintValue:
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
189 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asUInt()));
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
190 break;
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
191
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
192 case Json::realValue:
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
193 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asFloat()));
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
194 break;
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
195
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
196 default:
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
197 throw OrthancException(ErrorCode_BadParameterType);
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
198 }
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
199 }
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
200
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
201 return new CallSystemCommand(context, parameters["Command"].asString(), args);
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
202 }
921532f67770 Lua scripts can invoke system commands, with CallSystem()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1010
diff changeset
203
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
204 throw OrthancException(ErrorCode_ParameterOutOfRange);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
205 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
206
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
207
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
208 void ServerContext::ApplyLuaOnStoredInstance(const std::string& instanceId,
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
209 const Json::Value& simplifiedDicom,
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
210 const Json::Value& metadata)
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
211 {
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
212 LuaContextLocker locker(*this);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
213
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
214 if (locker.GetLua().IsExistingFunction(ON_STORED_INSTANCE))
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
215 {
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
216 locker.GetLua().Execute("_InitializeJob()");
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
217
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
218 LuaFunctionCall call(locker.GetLua(), ON_STORED_INSTANCE);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
219 call.PushString(instanceId);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
220 call.PushJson(simplifiedDicom);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
221 call.PushJson(metadata);
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
222 call.Execute();
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
223
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
224 Json::Value operations;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
225 LuaFunctionCall call2(locker.GetLua(), "_AccessJob");
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
226 call2.ExecuteToJson(operations);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
227
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
228 if (operations.type() != Json::arrayValue)
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
229 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
230 throw OrthancException(ErrorCode_InternalError);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
231 }
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
232
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
233 ServerJob job;
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
234 ServerCommandInstance* previousCommand = NULL;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
235
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
236 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i)
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
237 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
238 if (operations[i].type() != Json::objectValue ||
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
239 !operations[i].isMember("Operation"))
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
240 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
241 throw OrthancException(ErrorCode_InternalError);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
242 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
243
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
244 const Json::Value& parameters = operations[i];
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
245 std::string operation = parameters["Operation"].asString();
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
246
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
247 ServerCommandInstance& command = job.AddCommand(ParseOperation(*this, operation, operations[i]));
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
248
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
249 if (!parameters.isMember("Instance"))
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
250 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
251 throw OrthancException(ErrorCode_InternalError);
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
252 }
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
253
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
254 std::string instance = parameters["Instance"].asString();
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
255 if (instance.empty())
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
256 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
257 previousCommand->ConnectOutput(command);
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
258 }
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
259 else
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
260 {
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
261 command.AddInput(instance);
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
262 }
1008
187ed107a59f modify command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1007
diff changeset
263
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
264 previousCommand = &command;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
265 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
266
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
267 job.SetDescription(std::string("Lua script: ") + ON_STORED_INSTANCE);
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
268 scheduler_.Submit(job);
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
269 }
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
270 }
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
271
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
272
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
273 StoreStatus ServerContext::Store(std::string& resultPublicId,
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
274 DicomInstanceToStore& dicom)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
275 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
276 try
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
277 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
278 DicomInstanceHasher hasher(dicom.GetSummary());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
279 resultPublicId = hasher.HashInstance();
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
280
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
281 Json::Value simplified;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
282 SimplifyTags(simplified, dicom.GetJson());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
283
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
284 // Test if the instance must be filtered out
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
285 if (!ApplyReceivedInstanceFilter(simplified, dicom.GetRemoteAet()))
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
286 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
287 LOG(INFO) << "An incoming instance has been discarded by the filter";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
288 return StoreStatus_FilteredOut;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
289 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
290
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
291 if (compressionEnabled_)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
292 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
293 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
294 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
295 else
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
296 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
297 accessor_.SetCompressionForNextOperations(CompressionType_None);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
298 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
299
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
300 FileInfo dicomInfo = accessor_.Write(dicom.GetBufferData(), dicom.GetBufferSize(), FileContentType_Dicom);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
301 FileInfo jsonInfo = accessor_.Write(dicom.GetJson().toStyledString(), FileContentType_DicomAsJson);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
302
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
303 ServerIndex::Attachments attachments;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
304 attachments.push_back(dicomInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
305 attachments.push_back(jsonInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
306
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
307 typedef std::map<MetadataType, std::string> InstanceMetadata;
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
308 InstanceMetadata instanceMetadata;
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
309 StoreStatus status = index_.Store(instanceMetadata, dicom.GetSummary(), attachments,
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
310 dicom.GetRemoteAet(), dicom.GetMetadata());
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
311
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
312 dicom.GetMetadata().clear();
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
313
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
314 for (InstanceMetadata::const_iterator it = instanceMetadata.begin();
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
315 it != instanceMetadata.end(); it++)
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
316 {
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
317 dicom.GetMetadata().insert(std::make_pair(std::make_pair(ResourceType_Instance, it->first),
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
318 it->second));
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
319 }
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
320
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
321 if (status != StoreStatus_Success)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
322 {
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
323 accessor_.Remove(dicomInfo.GetUuid(), FileContentType_Dicom);
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
324 accessor_.Remove(jsonInfo.GetUuid(), FileContentType_DicomAsJson);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
325 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
326
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
327 switch (status)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
328 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
329 case StoreStatus_Success:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
330 LOG(INFO) << "New instance stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
331 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
332
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
333 case StoreStatus_AlreadyStored:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
334 LOG(INFO) << "Already stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
335 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
336
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
337 case StoreStatus_Failure:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
338 LOG(ERROR) << "Store failure";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
339 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
340
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
341 default:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
342 // This should never happen
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
343 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
344 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
345
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
346 if (status == StoreStatus_Success ||
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
347 status == StoreStatus_AlreadyStored)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
348 {
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
349 Json::Value metadata = Json::objectValue;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
350 for (std::map<MetadataType, std::string>::const_iterator
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
351 it = instanceMetadata.begin();
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
352 it != instanceMetadata.end(); ++it)
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
353 {
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
354 metadata[EnumerationToString(it->first)] = it->second;
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
355 }
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
356
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
357 try
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
358 {
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
359 ApplyLuaOnStoredInstance(resultPublicId, simplified, metadata);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
360 }
1007
871c49c9b11d lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
361 catch (OrthancException& e)
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
362 {
1010
160dfe770618 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
363 LOG(ERROR) << "Error in OnStoredInstance callback (Lua): " << e.What();
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
364 }
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
365
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
366 if (plugins_ != NULL)
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
367 {
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
368 try
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
369 {
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
370 plugins_->SignalStoredInstance(dicom, resultPublicId);
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
371 }
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
372 catch (OrthancException& e)
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
373 {
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
374 LOG(ERROR) << "Error in OnStoredInstance callback (plugins): " << e.What();
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
375 }
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
376 }
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
377 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
378
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
379 return status;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
380 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
381 catch (OrthancException& e)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
382 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
383 if (e.GetErrorCode() == ErrorCode_InexistentTag)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
384 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
385 LogMissingRequiredTag(dicom.GetSummary());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
386 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
387
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
388 throw;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
389 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
390 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
391
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
392
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
393
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
394 void ServerContext::AnswerAttachment(RestApiOutput& output,
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
395 const std::string& instancePublicId,
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
396 FileContentType content)
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
397 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
398 FileInfo attachment;
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
399 if (!index_.LookupAttachment(attachment, instancePublicId, content))
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
400 {
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
401 throw OrthancException(ErrorCode_InternalError);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
402 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
403
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
404 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
405
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
406 std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid(), attachment.GetContentType()));
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
407 sender->SetContentType(GetMimeType(content));
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
408 sender->SetDownloadFilename(instancePublicId + ".dcm");
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
409 output.AnswerFile(*sender);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
410 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
411
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
412
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
413 void ServerContext::ReadJson(Json::Value& result,
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
414 const std::string& instancePublicId)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
415 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
416 std::string s;
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
417 ReadFile(s, instancePublicId, FileContentType_DicomAsJson);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
418
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
419 Json::Reader reader;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
420 if (!reader.parse(s, result))
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
421 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
422 throw OrthancException("Corrupted JSON file");
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
423 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
424 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
425
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
426
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
427 void ServerContext::ReadFile(std::string& result,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
428 const std::string& instancePublicId,
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
429 FileContentType content,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
430 bool uncompressIfNeeded)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
431 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
432 FileInfo attachment;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
433 if (!index_.LookupAttachment(attachment, instancePublicId, content))
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
434 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
435 throw OrthancException(ErrorCode_InternalError);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
436 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
437
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
438 if (uncompressIfNeeded)
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
439 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
440 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
441 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
442 else
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
443 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
444 accessor_.SetCompressionForNextOperations(CompressionType_None);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
445 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
446
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
447 accessor_.Read(result, attachment.GetUuid(), attachment.GetContentType());
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
448 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
449
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
450
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
451 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
452 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
453 std::string content;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
454 context_.ReadFile(content, instancePublicId, FileContentType_Dicom);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
455 return new ParsedDicomFile(content);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
456 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
457
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
458
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
459 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
460 const std::string& instancePublicId) :
1129
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
461 that_(that),
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
462 lock_(that_.dicomCacheMutex_)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
463 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
464 #if ENABLE_DICOM_CACHE == 0
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
465 static std::auto_ptr<IDynamicObject> p;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
466 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
467 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
468 #else
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
469 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
470 #endif
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
471 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
472
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
473
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
474 ServerContext::DicomCacheLocker::~DicomCacheLocker()
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
475 {
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
476 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
477
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
478
695
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
479 void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
480 {
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
481 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
482 accessor_.SetStoreMD5(storeMD5);
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
483 }
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
484
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
485
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
486 bool ServerContext::AddAttachment(const std::string& resourceId,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
487 FileContentType attachmentType,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
488 const void* data,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
489 size_t size)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
490 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
491 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
492
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
493 if (compressionEnabled_)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
494 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
495 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
496 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
497 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
498 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
499 accessor_.SetCompressionForNextOperations(CompressionType_None);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
500 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
501
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
502 FileInfo info = accessor_.Write(data, size, attachmentType);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
503 StoreStatus status = index_.AddAttachment(info, resourceId);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
504
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
505 if (status != StoreStatus_Success)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
506 {
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
507 accessor_.Remove(info.GetUuid(), info.GetContentType());
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
508 return false;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
509 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
510 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
511 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
512 return true;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
513 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
514 }
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
515
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
516
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
517 bool ServerContext::DeleteResource(Json::Value& target,
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
518 const std::string& uuid,
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
519 ResourceType expectedType)
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
520 {
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
521 return index_.DeleteResource(target, uuid, expectedType);
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
522 }
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
523
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
524
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
525 void ServerContext::SignalChange(const ServerIndexChange& change)
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
526 {
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
527 if (plugins_ != NULL)
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
528 {
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
529 try
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
530 {
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
531 plugins_->SignalChange(change);
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
532 }
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
533 catch (OrthancException& e)
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
534 {
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
535 LOG(ERROR) << "Error in OnChangeCallback (plugins): " << e.What();
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
536 }
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
537 }
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
538 }
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 }