annotate OrthancServer/ServerContext.cpp @ 3034:54e422fe31ce db-changes

moving LookupResource to graveyard
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2018 14:20:11 +0100
parents 5da6d1063d8f
children 8fd203510d8b
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
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1285
diff changeset
4 * Department, University Hospital of Liege, Belgium
2447
878b59270859 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2409
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * published by the Free Software Foundation, either version 3 of the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * 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
19 * 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
20 * 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
21 * version. If you delete this exception statement from all source files
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * 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
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * 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
30 * 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
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "PrecompiledHeadersServer.h"
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ServerContext.h"
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
37 #include "../Core/DicomParsing/FromDcmtkBridge.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
38 #include "../Core/FileStorage/StorageAccessor.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
39 #include "../Core/HttpServer/FilesystemHttpSender.h"
1525
f9b0169eb6bb testing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1523
diff changeset
40 #include "../Core/HttpServer/HttpStreamTranscoder.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1459
diff changeset
41 #include "../Core/Logging.h"
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
42 #include "../Plugins/Engine/OrthancPlugins.h"
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
43 #include "OrthancConfiguration.h"
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
44 #include "OrthancRestApi/OrthancRestApi.h"
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
45 #include "ServerJobs/OrthancJobUnserializer.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
46 #include "ServerToolbox.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
47
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
48 #include <EmbeddedResources.h>
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
49 #include <dcmtk/dcmdata/dcfilefo.h>
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
51
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
52
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
53 #define ENABLE_DICOM_CACHE 1
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
54
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
55 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
56
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
57 /**
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
58 * 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
59 * 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
60 * since the filesystem implements the required locking mechanisms,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
61 * 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
62 * useful. Conversely, "ServerIndex" already implements mutex-based
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
63 * locking.
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
64 **/
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
65
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 namespace Orthanc
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
68 void ServerContext::ChangeThread(ServerContext* that,
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
69 unsigned int sleepDelay)
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
70 {
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
71 while (!that->done_)
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
72 {
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
73 std::auto_ptr<IDynamicObject> obj(that->pendingChanges_.Dequeue(sleepDelay));
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
74
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
75 if (obj.get() != NULL)
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
76 {
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
77 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
78
1456
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1453
diff changeset
79 boost::recursive_mutex::scoped_lock lock(that->listenersMutex_);
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
80 for (ServerListeners::iterator it = that->listeners_.begin();
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
81 it != that->listeners_.end(); ++it)
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
82 {
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
83 try
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
84 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
85 try
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
86 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
87 it->GetListener().SignalChange(change);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
88 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
89 catch (std::bad_alloc&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
90 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
91 LOG(ERROR) << "Not enough memory while signaling a change";
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
92 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
93 catch (...)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
94 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
95 throw OrthancException(ErrorCode_InternalError);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
96 }
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
97 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
98 catch (OrthancException& e)
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
99 {
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
100 LOG(ERROR) << "Error in the " << it->GetDescription()
2135
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
101 << " callback while signaling a change: " << e.What()
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
102 << " (code " << e.GetErrorCode() << ")";
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
103 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
104 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
105 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
106 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
107 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
108
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
109
2672
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
110 void ServerContext::SaveJobsThread(ServerContext* that,
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
111 unsigned int sleepDelay)
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
112 {
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
113 static const boost::posix_time::time_duration PERIODICITY =
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
114 boost::posix_time::seconds(10);
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
115
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
116 boost::posix_time::ptime next =
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
117 boost::posix_time::microsec_clock::universal_time() + PERIODICITY;
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
118
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
119 while (!that->done_)
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
120 {
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
121 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay));
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
122
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
123 if (that->haveJobsChanged_ ||
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
124 boost::posix_time::microsec_clock::universal_time() >= next)
2672
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
125 {
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
126 that->haveJobsChanged_ = false;
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
127 that->SaveJobsEngine();
2672
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
128 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY;
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
129 }
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
130 }
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
131 }
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
132
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
133
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
134 void ServerContext::SignalJobSubmitted(const std::string& jobId)
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
135 {
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
136 haveJobsChanged_ = true;
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
137 mainLua_.SignalJobSubmitted(jobId);
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
138 }
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
139
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
140
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
141 void ServerContext::SignalJobSuccess(const std::string& jobId)
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
142 {
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
143 haveJobsChanged_ = true;
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
144 mainLua_.SignalJobSuccess(jobId);
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
145 }
2672
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
146
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
147
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
148 void ServerContext::SignalJobFailure(const std::string& jobId)
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
149 {
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
150 haveJobsChanged_ = true;
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
151 mainLua_.SignalJobFailure(jobId);
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
152 }
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
153
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
154
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
155 void ServerContext::SetupJobsEngine(bool unitTesting,
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
156 bool loadJobsFromDatabase)
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
157 {
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
158 if (loadJobsFromDatabase)
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
159 {
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
160 std::string serialized;
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
161 if (index_.LookupGlobalProperty(serialized, GlobalProperty_JobsRegistry))
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
162 {
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
163 LOG(WARNING) << "Reloading the jobs from the last execution of Orthanc";
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
164 OrthancJobUnserializer unserializer(*this);
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
165
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
166 try
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
167 {
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
168 jobsEngine_.LoadRegistryFromString(unserializer, serialized);
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
169 }
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
170 catch (OrthancException& e)
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
171 {
2925
a80ba85d89e6 Orthanc starts even if jobs from a previous execution cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2898
diff changeset
172 LOG(WARNING) << "Cannot unserialize the jobs engine, starting anyway: " << e.What();
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
173 }
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
174 }
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
175 else
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
176 {
2671
06c0a6b8a871 new command-line argument: --no-jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2668
diff changeset
177 LOG(INFO) << "The last execution of Orthanc has archived no job";
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
178 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
179 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
180 else
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
181 {
2925
a80ba85d89e6 Orthanc starts even if jobs from a previous execution cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2898
diff changeset
182 LOG(INFO) << "Not reloading the jobs from the last execution of Orthanc";
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
183 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
184
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
185 jobsEngine_.GetRegistry().SetObserver(*this);
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
186 jobsEngine_.Start();
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
187 isJobsEngineUnserialized_ = true;
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
188
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
189 saveJobsThread_ = boost::thread(SaveJobsThread, this, (unitTesting ? 20 : 100));
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
190 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
191
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
192
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
193 void ServerContext::SaveJobsEngine()
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
194 {
2716
1b4ba91fe795 reduced verbosity of repetitive message
am@osimis.io
parents: 2675
diff changeset
195 VLOG(1) << "Serializing the content of the jobs engine";
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
196
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
197 try
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
198 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
199 Json::Value value;
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
200 jobsEngine_.GetRegistry().Serialize(value);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
201
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
202 Json::FastWriter writer;
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
203 std::string serialized = writer.write(value);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
204
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
205 index_.SetGlobalProperty(GlobalProperty_JobsRegistry, serialized);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
206 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
207 catch (OrthancException& e)
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
208 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
209 LOG(ERROR) << "Cannot serialize the jobs engine: " << e.What();
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
210 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
211 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
212
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
213
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
214 ServerContext::ServerContext(IDatabaseWrapper& database,
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2626
diff changeset
215 IStorageArea& area,
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
216 bool unitTesting,
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
217 size_t maxCompletedJobs) :
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2626
diff changeset
218 index_(*this, database, (unitTesting ? 20 : 500)),
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
219 area_(area),
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
220 compressionEnabled_(false),
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
221 storeMD5_(true),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
222 provider_(*this),
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
223 dicomCache_(provider_, DICOM_CACHE_SIZE),
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
224 mainLua_(*this),
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
225 filterLua_(*this),
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
226 luaListener_(*this),
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
227 jobsEngine_(maxCompletedJobs),
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2135
diff changeset
228 #if ORTHANC_ENABLE_PLUGINS == 1
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
229 plugins_(NULL),
1632
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
230 #endif
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
231 done_(false),
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
232 haveJobsChanged_(false),
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
233 isJobsEngineUnserialized_(false)
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
235 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
236 OrthancConfiguration::ReaderLock lock;
2965
9c0b0a6d8b54 MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2956
diff changeset
237
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
238 queryRetrieveArchive_.reset(
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
239 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("QueryRetrieveSize", 10)));
2965
9c0b0a6d8b54 MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2956
diff changeset
240 mediaArchive_.reset(
9c0b0a6d8b54 MediaArchiveSize configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2956
diff changeset
241 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1)));
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
242 defaultLocalAet_ = lock.GetConfiguration().GetStringParameter("DicomAet", "ORTHANC");
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
243 jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2));
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
244 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
245
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
246 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
247
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
248 listeners_.push_back(ServerListener(luaListener_, "Lua"));
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
249 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100));
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
252
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
253
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
254 ServerContext::~ServerContext()
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
255 {
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
256 if (!done_)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
257 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
258 LOG(ERROR) << "INTERNAL ERROR: ServerContext::Stop() should be invoked manually to avoid mess in the destruction order!";
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
259 Stop();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
260 }
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
261 }
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
262
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
263
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
264 void ServerContext::Stop()
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
265 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
266 if (!done_)
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
267 {
1459
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
268 {
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
269 boost::recursive_mutex::scoped_lock lock(listenersMutex_);
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
270 listeners_.clear();
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
271 }
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
272
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
273 done_ = true;
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
274
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
275 if (changeThread_.joinable())
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
276 {
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
277 changeThread_.join();
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1436
diff changeset
278 }
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
279
2672
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
280 if (saveJobsThread_.joinable())
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
281 {
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
282 saveJobsThread_.join();
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
283 }
3efc44fac209 periodically saving jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2671
diff changeset
284
2673
8e0bc055d18c JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2672
diff changeset
285 jobsEngine_.GetRegistry().ResetObserver();
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
286
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
287 if (isJobsEngineUnserialized_)
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
288 {
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
289 // Avoid losing jobs if the JobsRegistry cannot be unserialized
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
290 SaveJobsEngine();
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2808
diff changeset
291 }
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
292
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
293 // Do not change the order below!
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2507
diff changeset
294 jobsEngine_.Stop();
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
295 index_.Stop();
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
296 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
297 }
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
298
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
299
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
300 void ServerContext::SetCompressionEnabled(bool enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
301 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
302 if (enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
303 LOG(WARNING) << "Disk compression is enabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
304 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
305 LOG(WARNING) << "Disk compression is disabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
306
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
307 compressionEnabled_ = enabled;
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
308 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
309
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
310
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
311 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
312 FileContentType type)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
313 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
314 area_.Remove(fileUuid, type);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
315 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
316
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
317
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
318 StoreStatus ServerContext::Store(std::string& resultPublicId,
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
319 DicomInstanceToStore& dicom)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
320 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
321 try
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
322 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
323 StorageAccessor accessor(area_);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
324
2898
e5e3253a1164 DicomInstanceToStore::GetHasher()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2894
diff changeset
325 resultPublicId = dicom.GetHasher().HashInstance();
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
326
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
327 Json::Value simplifiedTags;
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2069
diff changeset
328 ServerToolbox::SimplifyTags(simplifiedTags, dicom.GetJson(), DicomToJsonFormat_Human);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
329
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
330 // Test if the instance must be filtered out
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
331 bool accepted = true;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
332
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
333 {
1456
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1453
diff changeset
334 boost::recursive_mutex::scoped_lock lock(listenersMutex_);
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
335
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
336 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
337 {
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
338 try
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
339 {
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
340 if (!it->GetListener().FilterIncomingInstance(dicom, simplifiedTags))
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
341 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
342 accepted = false;
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
343 break;
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
344 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
345 }
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
346 catch (OrthancException& e)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
347 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
348 LOG(ERROR) << "Error in the " << it->GetDescription()
2135
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
349 << " callback while receiving an instance: " << e.What()
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
350 << " (code " << e.GetErrorCode() << ")";
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
351 throw;
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
352 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
353 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
354 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
355
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
356 if (!accepted)
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
357 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
358 LOG(INFO) << "An incoming instance has been discarded by the filter";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
359 return StoreStatus_FilteredOut;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
360 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
361
2825
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
362 {
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
363 // Remove the file from the DicomCache (useful if
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
364 // "OverwriteInstances" is set to "true")
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
365 boost::mutex::scoped_lock lock(dicomCacheMutex_);
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
366 dicomCache_.Invalidate(resultPublicId);
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
367 }
8aa6aef11b70 New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
368
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
369 // TODO Should we use "gzip" instead?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
370 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
371
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
372 FileInfo dicomInfo = accessor.Write(dicom.GetBufferData(), dicom.GetBufferSize(),
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
373 FileContentType_Dicom, compression, storeMD5_);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
374 FileInfo jsonInfo = accessor.Write(dicom.GetJson().toStyledString(),
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
375 FileContentType_DicomAsJson, compression, storeMD5_);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
376
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
377 ServerIndex::Attachments attachments;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
378 attachments.push_back(dicomInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
379 attachments.push_back(jsonInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
380
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
381 typedef std::map<MetadataType, std::string> InstanceMetadata;
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
382 InstanceMetadata instanceMetadata;
1822
9ed9458aa44f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1778
diff changeset
383 StoreStatus status = index_.Store(instanceMetadata, dicom, attachments);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
384
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
385 // Only keep the metadata for the "instance" level
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
386 dicom.GetMetadata().clear();
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
387
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
388 for (InstanceMetadata::const_iterator it = instanceMetadata.begin();
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
389 it != instanceMetadata.end(); ++it)
1067
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
390 {
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
391 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
392 it->second));
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
393 }
ace99e272203 access metadata in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1066
diff changeset
394
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
395 if (status != StoreStatus_Success)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
396 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
397 accessor.Remove(dicomInfo);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
398 accessor.Remove(jsonInfo);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
399 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
400
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
401 switch (status)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
402 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
403 case StoreStatus_Success:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
404 LOG(INFO) << "New instance stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
405 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
406
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
407 case StoreStatus_AlreadyStored:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
408 LOG(INFO) << "Already stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
409 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
410
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
411 case StoreStatus_Failure:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
412 LOG(ERROR) << "Store failure";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
413 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
414
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
415 default:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
416 // This should never happen
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
417 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
418 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
419
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
420 if (status == StoreStatus_Success ||
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
421 status == StoreStatus_AlreadyStored)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
422 {
1456
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1453
diff changeset
423 boost::recursive_mutex::scoped_lock lock(listenersMutex_);
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
424
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
425 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
426 {
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
427 try
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
428 {
1574
0c29ebe80ac9 give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
429 it->GetListener().SignalStoredInstance(resultPublicId, dicom, simplifiedTags);
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
430 }
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
431 catch (OrthancException& e)
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
432 {
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
433 LOG(ERROR) << "Error in the " << it->GetDescription()
2135
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
434 << " callback while receiving an instance: " << e.What()
cadfe0a2a393 fix in the sample basic plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
435 << " (code " << e.GetErrorCode() << ")";
1066
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
436 }
bb82e5e818e9 OnStoredInstance callback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1065
diff changeset
437 }
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
438 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
439
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
440 return status;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
441 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
442 catch (OrthancException& e)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
443 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
444 if (e.GetErrorCode() == ErrorCode_InexistentTag)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
445 {
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2304
diff changeset
446 dicom.GetSummary().LogMissingTagsForStore();
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
447 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
448
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
449 throw;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
450 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
451 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
452
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
453
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
454 void ServerContext::AnswerAttachment(RestApiOutput& output,
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
455 const std::string& resourceId,
1146
200fcac0deb4 optimization for access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1145
diff changeset
456 FileContentType content)
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
457 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
458 FileInfo attachment;
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
459 if (!index_.LookupAttachment(attachment, resourceId, content))
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
460 {
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
461 throw OrthancException(ErrorCode_UnknownResource);
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
462 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
463
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
464 StorageAccessor accessor(area_);
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
465 accessor.AnswerFile(output, attachment, GetFileContentMime(content));
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
466 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
467
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
468
1700
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
469 void ServerContext::ChangeAttachmentCompression(const std::string& resourceId,
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
470 FileContentType attachmentType,
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
471 CompressionType compression)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
472 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
473 LOG(INFO) << "Changing compression type for attachment "
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
474 << EnumerationToString(attachmentType)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
475 << " of resource " << resourceId << " to "
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
476 << compression;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
477
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
478 FileInfo attachment;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
479 if (!index_.LookupAttachment(attachment, resourceId, attachmentType))
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
480 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
481 throw OrthancException(ErrorCode_UnknownResource);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
482 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
483
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
484 if (attachment.GetCompressionType() == compression)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
485 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
486 // Nothing to do
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
487 return;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
488 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
489
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
490 std::string content;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
491
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
492 StorageAccessor accessor(area_);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
493 accessor.Read(content, attachment);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
494
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
495 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(),
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
496 content.size(), attachmentType, compression, storeMD5_);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
497
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
498 try
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
499 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
500 StoreStatus status = index_.AddAttachment(modified, resourceId);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
501 if (status != StoreStatus_Success)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
502 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
503 accessor.Remove(modified);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
504 throw OrthancException(ErrorCode_Database);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
505 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
506 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
507 catch (OrthancException&)
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
508 {
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
509 accessor.Remove(modified);
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
510 throw;
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
511 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
512 }
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
513
f5ddbd9239dd New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
514
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
515 void ServerContext::ReadDicomAsJsonInternal(std::string& result,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
516 const std::string& instancePublicId)
2127
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
517 {
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
518 FileInfo attachment;
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
519 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson))
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
520 {
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
521 ReadAttachment(result, attachment);
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
522 }
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
523 else
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
524 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
525 // The "DICOM as JSON" summary is not available from the Orthanc
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
526 // store (most probably deleted), reconstruct it from the DICOM file
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
527 std::string dicom;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
528 ReadDicom(dicom, instancePublicId);
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
529
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
530 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: "
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
531 << instancePublicId;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
532
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
533 ParsedDicomFile parsed(dicom);
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
534
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
535 Json::Value summary;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
536 parsed.DatasetToJson(summary);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
537
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
538 result = summary.toStyledString();
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
539
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
540 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
541 result.c_str(), result.size()))
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
542 {
2956
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2950
diff changeset
543 throw OrthancException(ErrorCode_InternalError,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2950
diff changeset
544 "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
545 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
546 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
547 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
548
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
549
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
550 void ServerContext::ReadDicomAsJson(std::string& result,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
551 const std::string& instancePublicId,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
552 const std::set<DicomTag>& ignoreTagLength)
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
553 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
554 if (ignoreTagLength.empty())
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
555 {
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
556 ReadDicomAsJsonInternal(result, instancePublicId);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
557 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
558 else
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
559 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
560 Json::Value tmp;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
561 ReadDicomAsJson(tmp, instancePublicId, ignoreTagLength);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
562 result = tmp.toStyledString();
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
563 }
2127
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
564 }
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
565
bfa92c9328d7 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
566
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
567 void ServerContext::ReadDicomAsJson(Json::Value& result,
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
568 const std::string& instancePublicId,
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
569 const std::set<DicomTag>& ignoreTagLength)
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
570 {
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
571 if (ignoreTagLength.empty())
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
572 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
573 std::string tmp;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
574 ReadDicomAsJsonInternal(tmp, instancePublicId);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
575
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
576 Json::Reader reader;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
577 if (!reader.parse(tmp, result))
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
578 {
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
579 throw OrthancException(ErrorCode_CorruptedFile);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
580 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
581 }
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
582 else
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
583 {
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
584 // The "DicomAsJson" attachment might have stored some tags as
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
585 // "too long". We are forced to re-parse the DICOM file.
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
586 std::string dicom;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
587 ReadDicom(dicom, instancePublicId);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
588
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
589 ParsedDicomFile parsed(dicom);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
590 parsed.DatasetToJson(result, ignoreTagLength);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
591 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
592 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
593
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
594
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
595 void ServerContext::ReadAttachment(std::string& result,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
596 const std::string& instancePublicId,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
597 FileContentType content,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
598 bool uncompressIfNeeded)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
599 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
600 FileInfo attachment;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
601 if (!index_.LookupAttachment(attachment, instancePublicId, content))
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
602 {
2956
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2950
diff changeset
603 throw OrthancException(ErrorCode_InternalError,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2950
diff changeset
604 "Unable to read attachment " + EnumerationToString(content) +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2950
diff changeset
605 " of instance " + instancePublicId);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
606 }
1550
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
607
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
608 if (uncompressIfNeeded)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
609 {
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
610 ReadAttachment(result, attachment);
1550
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
611 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
612 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
613 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
614 // Do not interpret the content of the storage area, return the
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
615 // raw data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
616 area_.Read(result, attachment.GetUuid(), content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
617 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
618 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
619
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
620
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
621 void ServerContext::ReadAttachment(std::string& result,
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
622 const FileInfo& attachment)
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
623 {
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
624 // This will decompress the attachment
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
625 StorageAccessor accessor(area_);
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2127
diff changeset
626 accessor.Read(result, attachment);
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
627 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
628
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
629
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
630 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
631 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
632 std::string content;
2124
2b1520efa282 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2122
diff changeset
633 context_.ReadDicom(content, instancePublicId);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
634 return new ParsedDicomFile(content);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
635 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
636
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
637
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
638 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
639 const std::string& instancePublicId) :
1129
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
640 that_(that),
8dabdc0d3007 fix possible deadlock
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
641 lock_(that_.dicomCacheMutex_)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
642 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
643 #if ENABLE_DICOM_CACHE == 0
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
644 static std::auto_ptr<IDynamicObject> p;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
645 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
646 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
647 #else
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
648 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
649 #endif
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
650 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
651
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
652
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
653 ServerContext::DicomCacheLocker::~DicomCacheLocker()
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
654 {
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
655 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
656
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
657
695
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
658 void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
659 {
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
660 LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
661 storeMD5_ = storeMD5;
695
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
662 }
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
663
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
664
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
665 bool ServerContext::AddAttachment(const std::string& resourceId,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
666 FileContentType attachmentType,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
667 const void* data,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
668 size_t size)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
669 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
670 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
671
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
672 // TODO Should we use "gzip" instead?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
673 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
674
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
675 StorageAccessor accessor(area_);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
676 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_);
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
677
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
678 StoreStatus status = index_.AddAttachment(attachment, resourceId);
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
679 if (status != StoreStatus_Success)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
680 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1548
diff changeset
681 accessor.Remove(attachment);
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
682 return false;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
683 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
684 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
685 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
686 return true;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
687 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
688 }
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
689
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
690
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
691 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
692 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
693 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
694 {
2507
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
695 if (expectedType == ResourceType_Instance)
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
696 {
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
697 // remove the file from the DicomCache
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
698 boost::mutex::scoped_lock lock(dicomCacheMutex_);
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
699 dicomCache_.Invalidate(uuid);
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
700 }
99116ed6f38c invalidate DicomCache when deleting instance
amazy
parents: 2447
diff changeset
701
1145
0479d02c6778 Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1134
diff changeset
702 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
703 }
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
704
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
705
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
706 void ServerContext::SignalChange(const ServerIndexChange& change)
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
707 {
1436
0a3e3be59094 uncoupling of SignalChange for Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1434
diff changeset
708 pendingChanges_.Enqueue(change.Clone());
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1165
diff changeset
709 }
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
710
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
711
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2135
diff changeset
712 #if ORTHANC_ENABLE_PLUGINS == 1
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
713 void ServerContext::SetPlugins(OrthancPlugins& plugins)
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
714 {
1459
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
715 boost::recursive_mutex::scoped_lock lock(listenersMutex_);
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
716
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
717 plugins_ = &plugins;
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
718
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
719 // TODO REFACTOR THIS
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
720 listeners_.clear();
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
721 listeners_.push_back(ServerListener(luaListener_, "Lua"));
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
722 listeners_.push_back(ServerListener(plugins, "plugin"));
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
723 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
724
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
725
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
726 void ServerContext::ResetPlugins()
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
727 {
1459
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
728 boost::recursive_mutex::scoped_lock lock(listenersMutex_);
040d58493998 security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1456
diff changeset
729
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
730 plugins_ = NULL;
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
731
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
732 // TODO REFACTOR THIS
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
733 listeners_.clear();
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2716
diff changeset
734 listeners_.push_back(ServerListener(luaListener_, "Lua"));
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
735 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
736
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
737
1434
f9cd40166269 refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
738 const OrthancPlugins& ServerContext::GetPlugins() const
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
739 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
740 if (HasPlugins())
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
741 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
742 return *plugins_;
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
743 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
744 else
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
745 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
746 throw OrthancException(ErrorCode_InternalError);
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
747 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
748 }
1632
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
749
1741
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
750 OrthancPlugins& ServerContext::GetPlugins()
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
751 {
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
752 if (HasPlugins())
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
753 {
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
754 return *plugins_;
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
755 }
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
756 else
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
757 {
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
758 throw OrthancException(ErrorCode_InternalError);
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
759 }
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
760 }
06addfcd1d4c OrthancStarted and OrthancStopped events in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
761
1632
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
762 #endif
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
763
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
764
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
765 bool ServerContext::HasPlugins() const
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
766 {
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2135
diff changeset
767 #if ORTHANC_ENABLE_PLUGINS == 1
1632
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
768 return (plugins_ != NULL);
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
769 #else
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
770 return false;
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
771 #endif
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
772 }
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
773
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
774
3021
2cbafb5d5a62 renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3015
diff changeset
775 void ServerContext::Apply(ILookupVisitor& visitor,
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
776 const DatabaseLookup& lookup,
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
777 ResourceType queryLevel,
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
778 size_t since,
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
779 size_t limit)
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
780 {
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
781 LookupMode mode;
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
782 unsigned int databaseLimit;
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
783
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
784 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
785 // New configuration option in 1.5.1
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
786 OrthancConfiguration::ReaderLock lock;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
787
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
788 std::string value = lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always");
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
789
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
790 if (value == "Always")
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
791 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
792 mode = LookupMode_DiskOnLookupAndAnswer;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
793 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
794 else if (value == "Never")
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
795 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
796 mode = LookupMode_DatabaseOnly;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
797 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
798 else if (value == "Answers")
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
799 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
800 mode = LookupMode_DiskOnAnswer;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
801 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
802 else
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
803 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
804 throw OrthancException(ErrorCode_ParameterOutOfRange,
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
805 "Configuration option \"StorageAccessOnFind\" "
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
806 "should be \"Always\", \"Never\" or \"Answers\": " + value);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
807 }
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
808
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
809 if (queryLevel == ResourceType_Instance)
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
810 {
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
811 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
812 }
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
813 else
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
814 {
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
815 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
816 }
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
817 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
818
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
819 std::vector<std::string> resources, instances;
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3021
diff changeset
820
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
821 const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1);
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
822 GetIndex().ApplyLookupResources(resources, instances, lookup, queryLevel, lookupLimit);
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3021
diff changeset
823
3033
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
824 bool complete = (databaseLimit == 0 ||
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
825 resources.size() > databaseLimit);
5da6d1063d8f effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3031
diff changeset
826
3005
8265a6b56100 DicomMap::FromDicomAsJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3003
diff changeset
827 LOG(INFO) << "Number of candidate resources after fast DB filtering on main DICOM tags: " << resources.size();
3003
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
828
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
829 assert(resources.size() == instances.size());
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
830
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
831 size_t countResults = 0;
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
832 size_t skipped = 0;
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
833
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
834 const bool isDicomAsJsonNeeded = visitor.IsDicomAsJsonNeeded();
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
835
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
836 for (size_t i = 0; i < instances.size(); i++)
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
837 {
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
838 // Optimization in Orthanc 1.5.1 - Don't read the full JSON from
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
839 // the disk if only "main DICOM tags" are to be returned
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
840
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
841 std::auto_ptr<Json::Value> dicomAsJson;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
842
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
843 bool hasOnlyMainDicomTags;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
844 DicomMap dicom;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
845
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
846 if (mode == LookupMode_DatabaseOnly ||
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
847 mode == LookupMode_DiskOnAnswer ||
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
848 lookup.HasOnlyMainDicomTags())
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
849 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
850 // Case (1): The main DICOM tags, as stored in the database,
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
851 // are sufficient to look for match
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
852
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
853 if (!GetIndex().GetAllMainDicomTags(dicom, instances[i]))
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
854 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
855 // The instance has been removed during the execution of the
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
856 // lookup, ignore it
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
857 continue;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
858 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
859
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
860 hasOnlyMainDicomTags = true;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
861 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
862 else
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
863 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
864 // Case (2): Need to read the "DICOM-as-JSON" attachment from
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
865 // the storage area
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
866 dicomAsJson.reset(new Json::Value);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
867 ReadDicomAsJson(*dicomAsJson, instances[i]);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
868
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
869 dicom.FromDicomAsJson(*dicomAsJson);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
870
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
871 // This map contains the entire JSON, i.e. more than the main DICOM tags
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
872 hasOnlyMainDicomTags = false;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
873 }
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
874
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
875 if (lookup.IsMatch(dicom))
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
876 {
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
877 if (skipped < since)
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
878 {
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
879 skipped++;
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
880 }
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
881 else if (limit != 0 &&
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
882 countResults >= limit)
2304
563bf878407a Argument "Since" in URI "/tools/find" (related to issue 53)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
883 {
3003
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
884 // Too many results, don't mark as complete
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
885 complete = false;
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
886 break;
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
887 }
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
888 else
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
889 {
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
890 if ((mode == LookupMode_DiskOnLookupAndAnswer ||
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
891 mode == LookupMode_DiskOnAnswer) &&
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
892 dicomAsJson.get() == NULL &&
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
893 isDicomAsJsonNeeded)
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
894 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
895 dicomAsJson.reset(new Json::Value);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
896 ReadDicomAsJson(*dicomAsJson, instances[i]);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
897 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
898
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
899 if (hasOnlyMainDicomTags)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
900 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
901 // This is Case (1): The variable "dicom" only contains the main DICOM tags
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
902 visitor.Visit(resources[i], instances[i], dicom, dicomAsJson.get());
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
903 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
904 else
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
905 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
906 // Remove the non-main DICOM tags from "dicom" if Case (2)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
907 // was used, for consistency with Case (1)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
908
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
909 DicomMap mainDicomTags;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
910 mainDicomTags.ExtractMainDicomTags(dicom);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
911 visitor.Visit(resources[i], instances[i], mainDicomTags, dicomAsJson.get());
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
912 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
913
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
914 countResults ++;
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
915 }
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
916 }
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
917 }
3001
7695a9c81099 refactoring /tools/find using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
918
3003
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
919 if (complete)
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
920 {
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
921 visitor.MarkAsComplete();
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
922 }
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
923
5ae3ff2398e9 refactoring OrthancFindRequestHandler using LookupResource::IVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3001
diff changeset
924 LOG(INFO) << "Number of matching resources: " << countResults;
1757
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
925 }
98abb8d7f905 ServerContext::Apply lookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1741
diff changeset
926
2626
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
927
3015
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
928 bool ServerContext::LookupOrReconstructMetadata(std::string& target,
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
929 const std::string& publicId,
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
930 MetadataType metadata)
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
931 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
932 // This is a backwards-compatibility function, that can
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
933 // reconstruct metadata that were not generated by an older
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
934 // release of Orthanc
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
935
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
936 if (metadata == MetadataType_Instance_SopClassUid ||
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
937 metadata == MetadataType_Instance_TransferSyntax)
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
938 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
939 if (index_.LookupMetadata(target, publicId, metadata))
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
940 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
941 return true;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
942 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
943 else
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
944 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
945 // These metadata are mandatory in DICOM instances, and were
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
946 // introduced in Orthanc 1.2.0. The fact that
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
947 // "LookupMetadata()" has failed indicates that this database
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
948 // comes from an older release of Orthanc.
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
949
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
950 DicomTag tag(0, 0);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
951
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
952 switch (metadata)
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
953 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
954 case MetadataType_Instance_SopClassUid:
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
955 tag = DICOM_TAG_SOP_CLASS_UID;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
956 break;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
957
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
958 case MetadataType_Instance_TransferSyntax:
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
959 tag = DICOM_TAG_TRANSFER_SYNTAX_UID;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
960 break;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
961
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
962 default:
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
963 throw OrthancException(ErrorCode_InternalError);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
964 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
965
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
966 Json::Value dicomAsJson;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
967 ReadDicomAsJson(dicomAsJson, publicId);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
968
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
969 DicomMap tags;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
970 tags.FromDicomAsJson(dicomAsJson);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
971
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
972 const DicomValue* value = tags.TestAndGetValue(tag);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
973
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
974 if (value != NULL &&
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
975 !value->IsNull() &&
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
976 !value->IsBinary())
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
977 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
978 target = value->GetContent();
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
979
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
980 // Store for reuse
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
981 index_.SetMetadata(publicId, metadata, target);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
982 return true;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
983 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
984 else
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
985 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
986 // Should never happen
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
987 return false;
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
988 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
989 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
990 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
991 else
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
992 {
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
993 // No backward
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
994 return index_.LookupMetadata(target, publicId, metadata);
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
995 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
996 }
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
997
abe49ca61cd5 On C-FIND, avoid accessing the storage area whenever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3012
diff changeset
998
2626
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
999 void ServerContext::AddChildInstances(SetOfInstancesJob& job,
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1000 const std::string& publicId)
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1001 {
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1002 std::list<std::string> instances;
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1003 GetIndex().GetChildInstances(instances, publicId);
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1004
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1005 job.Reserve(job.GetInstancesCount() + instances.size());
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1006
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1007 for (std::list<std::string>::const_iterator
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1008 it = instances.begin(); it != instances.end(); ++it)
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1009 {
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1010 job.AddInstance(*it);
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1011 }
e09021ddc00d cleanup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
1012 }
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1013
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1014
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1015 void ServerContext::SignalUpdatedModalities()
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1016 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1017 #if ORTHANC_ENABLE_PLUGINS == 1
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1018 if (HasPlugins())
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1019 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1020 GetPlugins().SignalUpdatedModalities();
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1021 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1022 #endif
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1023 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1024
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1025
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1026 void ServerContext::SignalUpdatedPeers()
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1027 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1028 #if ORTHANC_ENABLE_PLUGINS == 1
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1029 if (HasPlugins())
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1030 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1031 GetPlugins().SignalUpdatedPeers();
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1032 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1033 #endif
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2925
diff changeset
1034 }
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 }