annotate OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5466:dceed5e3d6a9 pg-transactions

new DB plugin primitive: UpdateAndGetStatistics
author Alain Mazy <am@osimis.io>
date Fri, 15 Dec 2023 17:15:43 +0100
parents 38f1d06875ad
children 26877f4b306f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5175
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5175
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeadersServer.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "StatelessDatabaseOperations.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #ifndef NOMINMAX
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #define NOMINMAX
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../../../OrthancFramework/Sources/Logging.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../../../OrthancFramework/Sources/OrthancException.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../OrthancConfiguration.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../Search/DatabaseLookup.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../ServerIndexChange.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../ServerToolbox.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "ResourcesContent.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <boost/lexical_cast.hpp>
4633
37357df3dc27 fix mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
41 #include <boost/thread.hpp>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <boost/tuple/tuple.hpp>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <stack>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 /**
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 * Some handy templates to reduce the verbosity in the definitions
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 * of the internal classes.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 **/
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 template <typename Operations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 typename Tuple>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 class TupleOperationsWrapper : public StatelessDatabaseOperations::IReadOnlyOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 protected:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 Operations& operations_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 const Tuple& tuple_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 TupleOperationsWrapper(Operations& operations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const Tuple& tuple) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 operations_(operations),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 tuple_(tuple)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 virtual void Apply(StatelessDatabaseOperations::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 operations_.ApplyTuple(transaction, tuple_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 template <typename T1>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 class ReadOnlyOperationsT1 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 typedef typename boost::tuple<T1> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 virtual ~ReadOnlyOperationsT1()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 T1 t1)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const Tuple tuple(t1);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 TupleOperationsWrapper<ReadOnlyOperationsT1, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 typename T2>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 class ReadOnlyOperationsT2 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 typedef typename boost::tuple<T1, T2> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 virtual ~ReadOnlyOperationsT2()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 T2 t2)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 const Tuple tuple(t1, t2);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 TupleOperationsWrapper<ReadOnlyOperationsT2, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 typename T3>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 class ReadOnlyOperationsT3 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 typedef typename boost::tuple<T1, T2, T3> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 virtual ~ReadOnlyOperationsT3()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 T3 t3)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 const Tuple tuple(t1, t2, t3);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 TupleOperationsWrapper<ReadOnlyOperationsT3, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 typename T4>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 class ReadOnlyOperationsT4 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 typedef typename boost::tuple<T1, T2, T3, T4> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 virtual ~ReadOnlyOperationsT4()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 T4 t4)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 const Tuple tuple(t1, t2, t3, t4);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 typename T4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 typename T5>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 class ReadOnlyOperationsT5 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 typedef typename boost::tuple<T1, T2, T3, T4, T5> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 virtual ~ReadOnlyOperationsT5()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 T4 t4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 T5 t5)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 const Tuple tuple(t1, t2, t3, t4, t5);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 typename T4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 typename T5,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 typename T6>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 class ReadOnlyOperationsT6 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 typedef typename boost::tuple<T1, T2, T3, T4, T5, T6> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 virtual ~ReadOnlyOperationsT6()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 T4 t4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 T5 t5,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 T6 t6)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 const Tuple tuple(t1, t2, t3, t4, t5, t6);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 template <typename T>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 static void FormatLog(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 const std::list<T>& log,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 const std::string& name,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 bool done,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 bool hasLast,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 int64_t last)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 Json::Value items = Json::arrayValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 for (typename std::list<T>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 it = log.begin(); it != log.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 Json::Value item;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 it->Format(item);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 items.append(item);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 target = Json::objectValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 target[name] = items;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 target["Done"] = done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (!hasLast)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 // Best-effort guess of the last index in the sequence
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 if (log.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 last = since;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 last = log.back().GetSeq();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 target["Last"] = static_cast<int>(last);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 static void CopyListToVector(std::vector<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 const std::list<std::string>& source)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 target.resize(source.size());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 size_t pos = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 for (std::list<std::string>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 it = source.begin(); it != source.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 target[pos] = *it;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 pos ++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 class StatelessDatabaseOperations::MainDicomTagsRegistry : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 class TagInfo
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ResourceType level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 DicomTagType type_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 TagInfo()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 TagInfo(ResourceType level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 DicomTagType type) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 level_(level),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 type_(type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ResourceType GetLevel() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 return level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 DicomTagType GetType() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 return type_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 typedef std::map<DicomTag, TagInfo> Registry;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 Registry registry_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 void LoadTags(ResourceType level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 const DicomTag* tags = NULL;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 size_t size;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ServerToolbox::LoadIdentifiers(tags, size, level);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 for (size_t i = 0; i < size; i++)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 if (registry_.find(tags[i]) == registry_.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 registry_[tags[i]] = TagInfo(level, DicomTagType_Identifier);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 // These patient-level tags are copied in the study level
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 assert(level == ResourceType_Study &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 (tags[i] == DICOM_TAG_PATIENT_ID ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 tags[i] == DICOM_TAG_PATIENT_NAME ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 tags[i] == DICOM_TAG_PATIENT_BIRTH_DATE));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 {
5175
48005e522bd6 start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5061
diff changeset
365 std::set<DicomTag> tags;
48005e522bd6 start fixing thread safety issues with DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5061
diff changeset
366 DicomMap::GetMainDicomTags(tags, level);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 for (std::set<DicomTag>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 tag = tags.begin(); tag != tags.end(); ++tag)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (registry_.find(*tag) == registry_.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 registry_[*tag] = TagInfo(level, DicomTagType_Main);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 MainDicomTagsRegistry()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 LoadTags(ResourceType_Patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 LoadTags(ResourceType_Study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 LoadTags(ResourceType_Series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 LoadTags(ResourceType_Instance);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 void LookupTag(ResourceType& level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 DicomTagType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 const DicomTag& tag) const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 Registry::const_iterator it = registry_.find(tag);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 if (it == registry_.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 // Default values
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 level = ResourceType_Instance;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 type = DicomTagType_Generic;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 level = it->second.GetLevel();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 type = it->second.GetType();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 void StatelessDatabaseOperations::ReadWriteTransaction::LogChange(int64_t internalId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 ChangeType changeType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 ResourceType resourceType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 ServerIndexChange change(changeType, resourceType, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 if (changeType <= ChangeType_INTERNAL_LastLogged)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
5216
450ac804d3af simplifying IDatabaseWrapper::LogChange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
418 transaction_.LogChange(changeType, resourceType, internalId, publicId, change.GetDate());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 GetTransactionContext().SignalChange(change);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 SeriesStatus StatelessDatabaseOperations::ReadOnlyTransaction::GetSeriesStatus(int64_t id,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 int64_t expectedNumberOfInstances)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 std::list<std::string> values;
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
429 transaction_.GetChildrenMetadata(values, id, MetadataType_Instance_IndexInSeries);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 std::set<int64_t> instances;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 for (std::list<std::string>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 it = values.begin(); it != values.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 int64_t index;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 index = boost::lexical_cast<int64_t>(*it);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 catch (boost::bad_lexical_cast&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 return SeriesStatus_Unknown;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 if (!(index > 0 && index <= expectedNumberOfInstances))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 // Out-of-range instance index
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 return SeriesStatus_Inconsistent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 if (instances.find(index) != instances.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 // Twice the same instance index
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 return SeriesStatus_Inconsistent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 instances.insert(index);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 if (static_cast<int64_t>(instances.size()) == expectedNumberOfInstances)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 return SeriesStatus_Complete;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 return SeriesStatus_Missing;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 void StatelessDatabaseOperations::NormalizeLookup(std::vector<DatabaseConstraint>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 const DatabaseLookup& source,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 ResourceType queryLevel) const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 assert(mainDicomTagsRegistry_.get() != NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 target.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 target.reserve(source.GetConstraintsCount());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 for (size_t i = 0; i < source.GetConstraintsCount(); i++)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 ResourceType level;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 DicomTagType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 mainDicomTagsRegistry_->LookupTag(level, type, source.GetConstraint(i).GetTag());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 if (type == DicomTagType_Identifier ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 type == DicomTagType_Main)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 // Use the fact that patient-level tags are copied at the study level
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 if (level == ResourceType_Patient &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 queryLevel != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 level = ResourceType_Study;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 class StatelessDatabaseOperations::Transaction : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 IDatabaseWrapper& db_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 std::unique_ptr<ITransactionContext> context_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 bool isCommitted_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 Transaction(IDatabaseWrapper& db,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 ITransactionContextFactory& factory,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 TransactionType type) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 db_(db),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 isCommitted_(false)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 context_.reset(factory.Create());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 if (context_.get() == NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 throw OrthancException(ErrorCode_NullPointer);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
4589
bec74e29f86b attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4587
diff changeset
526 transaction_.reset(db_.StartTransaction(type, *context_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 if (transaction_.get() == NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 throw OrthancException(ErrorCode_NullPointer);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 ~Transaction()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 if (!isCommitted_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 transaction_->Rollback();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 catch (OrthancException& e)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
543 LOG(INFO) << "Cannot rollback transaction: " << e.What();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
548 IDatabaseWrapper::ITransaction& GetDatabaseTransaction()
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
549 {
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
550 assert(transaction_.get() != NULL);
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
551 return *transaction_;
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
552 }
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
553
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 void Commit()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 if (isCommitted_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 throw OrthancException(ErrorCode_BadSequenceOfCalls);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 int64_t delta = context_->GetCompressedSizeDelta();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 transaction_->Commit(delta);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 context_->Commit();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 isCommitted_ = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 ITransactionContext& GetContext() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 assert(context_.get() != NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 return *context_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 void StatelessDatabaseOperations::ApplyInternal(IReadOnlyOperations* readOperations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 IReadWriteOperations* writeOperations)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
581 boost::shared_lock<boost::shared_mutex> lock(mutex_); // To protect "factory_" and "maxRetries_"
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
582
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 if ((readOperations == NULL && writeOperations == NULL) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 (readOperations != NULL && writeOperations != NULL))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 if (factory_.get() == NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 throw OrthancException(ErrorCode_BadSequenceOfCalls, "No transaction context was provided");
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
594 unsigned int attempt = 0;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 for (;;)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 if (readOperations != NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 /**
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 * IMPORTANT: In Orthanc <= 1.9.1, there was no transaction
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 * in this case. This was OK because of the presence of the
4594
d494b4f1103e removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4591
diff changeset
605 * global mutex that was protecting the database.
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 **/
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 Transaction transaction(db_, *factory_, TransactionType_ReadOnly); // TODO - Only if not "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 {
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
610 ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.GetDatabaseCapabilities());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 readOperations->Apply(t);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 transaction.Commit();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 assert(writeOperations != NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 Transaction transaction(db_, *factory_, TransactionType_ReadWrite);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 {
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
621 ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.GetDatabaseCapabilities());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 writeOperations->Apply(t);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 transaction.Commit();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 return; // Success
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 catch (OrthancException& e)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 if (e.GetErrorCode() == ErrorCode_DatabaseCannotSerialize)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
633 if (attempt >= maxRetries_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 throw;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
639 attempt++;
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
640
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
641 // The "rand()" adds some jitter to de-synchronize writers
4619
fda80844b920 separate db retries by 100ms instead of 50ms to simplify documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4613
diff changeset
642 boost::this_thread::sleep(boost::posix_time::milliseconds(100 * attempt + 5 * (rand() % 10)));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 throw;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 StatelessDatabaseOperations::StatelessDatabaseOperations(IDatabaseWrapper& db) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 db_(db),
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
656 mainDicomTagsRegistry_(new MainDicomTagsRegistry),
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
657 maxRetries_(0)
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
658 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
659 }
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
660
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
661
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
662 void StatelessDatabaseOperations::FlushToDisk()
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 {
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
664 try
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
665 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
666 db_.FlushToDisk();
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
667 }
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
668 catch (OrthancException&)
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
669 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
670 LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)";
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
671 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 void StatelessDatabaseOperations::SetTransactionContextFactory(ITransactionContextFactory* factory)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
677 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
678
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 if (factory == NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 throw OrthancException(ErrorCode_NullPointer);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 else if (factory_.get() != NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 throw OrthancException(ErrorCode_BadSequenceOfCalls);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 factory_.reset(factory);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
694 void StatelessDatabaseOperations::SetMaxDatabaseRetries(unsigned int maxRetries)
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
695 {
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
696 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
697 maxRetries_ = maxRetries;
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
698 }
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
699
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
700
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 void StatelessDatabaseOperations::Apply(IReadOnlyOperations& operations)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 ApplyInternal(&operations, NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 void StatelessDatabaseOperations::Apply(IReadWriteOperations& operations)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 ApplyInternal(NULL, &operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
713 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 const std::string& publicId,
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
715 ResourceType level,
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
716 const std::set<DicomTag>& requestedTags,
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
717 ExpandResourceFlags expandFlags)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
719 class Operations : public ReadOnlyOperationsT6<
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
720 bool&, ExpandedResource&, const std::string&, ResourceType, const std::set<DicomTag>&, ExpandResourceFlags>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 static bool LookupStringMetadata(std::string& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 const std::map<MetadataType, std::string>& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 MetadataType type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 std::map<MetadataType, std::string>::const_iterator found = metadata.find(type);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 if (found == metadata.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 result = found->second;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 static bool LookupIntegerMetadata(int64_t& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 const std::map<MetadataType, std::string>& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 MetadataType type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 std::string s;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 if (!LookupStringMetadata(s, metadata, type))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 result = boost::lexical_cast<int64_t>(s);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 catch (boost::bad_lexical_cast&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 // Lookup for the requested resource
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
769 int64_t internalId;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 std::string parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 type != tuple.get<3>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
779 ExpandedResource& target = tuple.get<1>();
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
780 ExpandResourceFlags expandFlags = tuple.get<5>();
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
781
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 // Set information about the parent resource (if it exists)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 if (type == ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 if (!parent.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 throw OrthancException(ErrorCode_DatabasePlugin);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 if (parent.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 throw OrthancException(ErrorCode_DatabasePlugin);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
797 target.parentId_ = parent;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
800 target.SetResource(type, tuple.get<2>());
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
801
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
802 if (expandFlags & ExpandResourceFlags_IncludeChildren)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
804 // List the children resources
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
805 transaction.GetChildrenPublicId(target.childrenIds_, internalId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
806 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
807
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
808 if (expandFlags & ExpandResourceFlags_IncludeMetadata)
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
809 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
810 // Extract the metadata
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
811 transaction.GetAllMetadata(target.metadata_, internalId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
812
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
813 switch (type)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
815 case ResourceType_Patient:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
816 case ResourceType_Study:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
817 break;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
818
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
819 case ResourceType_Series:
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
821 int64_t i;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
822 if (LookupIntegerMetadata(i, target.metadata_, MetadataType_Series_ExpectedNumberOfInstances))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
823 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
824 target.expectedNumberOfInstances_ = static_cast<int>(i);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
825 target.status_ = EnumerationToString(transaction.GetSeriesStatus(internalId, i));
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
826 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
827 else
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
828 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
829 target.expectedNumberOfInstances_ = -1;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
830 target.status_ = EnumerationToString(SeriesStatus_Unknown);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
831 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
832
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
833 break;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
836 case ResourceType_Instance:
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
837 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
838 FileInfo attachment;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
839 int64_t revision; // ignored
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
840 if (!transaction.LookupAttachment(attachment, revision, internalId, FileContentType_Dicom))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
841 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
842 throw OrthancException(ErrorCode_InternalError);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
843 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
844
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
845 target.fileSize_ = static_cast<unsigned int>(attachment.GetUncompressedSize());
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
846 target.fileUuid_ = attachment.GetUuid();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
847
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
848 int64_t i;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
849 if (LookupIntegerMetadata(i, target.metadata_, MetadataType_Instance_IndexInSeries))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
850 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
851 target.indexInSeries_ = static_cast<int>(i);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
852 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
853 else
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
854 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
855 target.indexInSeries_ = -1;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
856 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
857
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
858 break;
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
859 }
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
860
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
861 default:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
862 throw OrthancException(ErrorCode_InternalError);
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
863 }
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
864
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
865 // check the main dicom tags list has not changed since the resource was stored
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
866 target.mainDicomTagsSignature_ = DicomMap::GetDefaultMainDicomTagsSignature(type);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
867 LookupStringMetadata(target.mainDicomTagsSignature_, target.metadata_, MetadataType_MainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
868 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
869
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
870 if (expandFlags & ExpandResourceFlags_IncludeMainDicomTags)
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
871 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
872 // read all tags from DB
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
873 transaction.GetMainDicomTags(target.GetMainDicomTags(), internalId);
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
874
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
875 // read all main sequences from DB
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
876 std::string serializedSequences;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
877 if (LookupStringMetadata(serializedSequences, target.metadata_, MetadataType_MainDicomSequences))
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
878 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
879 Json::Value jsonMetadata;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
880 Toolbox::ReadJson(jsonMetadata, serializedSequences);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
881
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
882 assert(jsonMetadata["Version"].asInt() == 1);
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
883 target.GetMainDicomTags().FromDicomAsJson(jsonMetadata["Sequences"], true /* append */, true /* parseSequences */);
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
884 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
885
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
886 // check if we have access to all requestedTags or if we must get tags from parents
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
887 const std::set<DicomTag>& requestedTags = tuple.get<4>();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
888
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
889 if (requestedTags.size() > 0)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
890 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
891 std::set<DicomTag> savedMainDicomTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
892
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
893 FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
894
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
895 // read parent main dicom tags as long as we have not gathered all requested tags
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
896 ResourceType currentLevel = target.GetLevel();
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
897 int64_t currentInternalId = internalId;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
898 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
899
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
900 while ((target.missingRequestedTags_.size() > 0)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
901 && currentLevel != ResourceType_Patient)
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
902 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
903 currentLevel = GetParentResourceType(currentLevel);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
904
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
905 int64_t currentParentId;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
906 if (!transaction.LookupParent(currentParentId, currentInternalId))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
907 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
908 break;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
909 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
910
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
911 std::map<MetadataType, std::string> parentMetadata;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
912 transaction.GetAllMetadata(parentMetadata, currentParentId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
913
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
914 std::string parentMainDicomTagsSignature = DicomMap::GetDefaultMainDicomTagsSignature(currentLevel);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
915 LookupStringMetadata(parentMainDicomTagsSignature, parentMetadata, MetadataType_MainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
916
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
917 std::set<DicomTag> parentSavedMainDicomTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
918 FromDcmtkBridge::ParseListOfTags(parentSavedMainDicomTags, parentMainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
919
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
920 size_t previousMissingCount = target.missingRequestedTags_.size();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
921 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
922 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
923
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
924 // read the parent tags from DB only if it reduces the number of missing tags
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
925 if (target.missingRequestedTags_.size() < previousMissingCount)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
926 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
927 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
928
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
929 DicomMap parentTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
930 transaction.GetMainDicomTags(parentTags, currentParentId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
931
5222
3a61fd50f804 starting refactoring ExpandedResource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5221
diff changeset
932 target.GetMainDicomTags().Merge(parentTags);
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
933 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
934
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
935 currentInternalId = currentParentId;
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
936 }
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
937 }
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
938 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939
5237
cd2258ca7894 log about missing support for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5234
diff changeset
940 if ((expandFlags & ExpandResourceFlags_IncludeLabels) &&
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
941 transaction.GetDatabaseCapabilities().HasLabelsSupport())
5221
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
942 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
943 transaction.ListLabels(target.labels_, internalId);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
944 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
945
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 std::string tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
948 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_AnonymizedFrom))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
950 target.anonymizedFrom_ = tmp;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
953 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_ModifiedFrom))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
955 target.modifiedFrom_ = tmp;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 if (type == ResourceType_Patient ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 type == ResourceType_Study ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 type == ResourceType_Series)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
962 target.isStable_ = !transaction.GetTransactionContext().IsUnstableResource(internalId);
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
963
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
964 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_LastUpdate))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
966 target.lastUpdate_ = tmp;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 }
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
969 else
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
970 {
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
971 target.isStable_ = false;
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
972 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 Operations operations;
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
981 operations.Apply(*this, found, target, publicId, level, requestedTags, expandFlags);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 ResourceType level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 class Operations : public ReadOnlyOperationsT3<std::map<MetadataType, std::string>&, const std::string&, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 tuple.get<2>() != type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 transaction.GetAllMetadata(tuple.get<0>(), id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 operations.Apply(*this, target, publicId, level);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 bool StatelessDatabaseOperations::LookupAttachment(FileInfo& attachment,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1016 int64_t& revision,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 const std::string& instancePublicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 FileContentType contentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1020 class Operations : public ReadOnlyOperationsT5<bool&, FileInfo&, int64_t&, const std::string&, FileContentType>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 int64_t internalId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 ResourceType type;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1028 if (!transaction.LookupResource(internalId, type, tuple.get<3>()))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 }
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1032 else if (transaction.LookupAttachment(tuple.get<1>(), tuple.get<2>(), internalId, tuple.get<4>()))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1034 assert(tuple.get<1>().GetContentType() == tuple.get<4>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 Operations operations;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1046 operations.Apply(*this, found, attachment, revision, instancePublicId, contentType);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 ResourceType resourceType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 operations.Apply(*this, target, resourceType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 ResourceType resourceType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 size_t since,
5220
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
1073 uint32_t limit)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 if (limit == 0)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 target.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 class Operations : public ReadOnlyOperationsT4<std::list<std::string>&, ResourceType, size_t, size_t>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 operations.Apply(*this, target, resourceType, since, limit);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 void StatelessDatabaseOperations::GetGlobalStatistics(/* out */ uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 /* out */ uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 /* out */ uint64_t& countPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 /* out */ uint64_t& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 /* out */ uint64_t& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 /* out */ uint64_t& countInstances)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 {
5466
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1105 // new code that updates and gets all statistics.
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1106 // I.e, PostgreSQL now store "changes" to apply to the statistics to prevent row locking
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1107 // of the GlobalIntegers table while multiple clients are inserting/deleting new resources.
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1108 // Then, the statistics are updated when requested to make sure they are correct.
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1109 class Operations : public IReadWriteOperations
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1110 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1111 private:
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1112 int64_t diskSize_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1113 int64_t uncompressedSize_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1114 int64_t countPatients_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1115 int64_t countStudies_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1116 int64_t countSeries_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1117 int64_t countInstances_;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1118
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1119 public:
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1120 Operations() :
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1121 diskSize_(0),
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1122 uncompressedSize_(0),
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1123 countPatients_(0),
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1124 countStudies_(0),
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1125 countSeries_(0),
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1126 countInstances_(0)
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1127 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1128 }
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1129
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1130 void GetValues(uint64_t& diskSize,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1131 uint64_t& uncompressedSize,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1132 uint64_t& countPatients,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1133 uint64_t& countStudies,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1134 uint64_t& countSeries,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1135 uint64_t& countInstances) const
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1136 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1137 diskSize = static_cast<uint64_t>(diskSize_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1138 uncompressedSize = static_cast<uint64_t>(uncompressedSize_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1139 countPatients = static_cast<uint64_t>(countPatients_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1140 countStudies = static_cast<uint64_t>(countStudies_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1141 countSeries = static_cast<uint64_t>(countSeries_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1142 countInstances = static_cast<uint64_t>(countInstances_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1143 }
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1144
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1145 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1146 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1147 transaction.UpdateAndGetStatistics(countPatients_, countStudies_, countSeries_, countInstances_, diskSize_, uncompressedSize_);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1148 }
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1149 };
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1150
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1151 // legacy oprations that reads each entry individualy
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1152 class LegacyOperations : public ReadOnlyOperationsT6<uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 tuple.get<0>() = transaction.GetTotalCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 tuple.get<1>() = transaction.GetTotalUncompressedSize();
4595
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1160 tuple.get<2>() = transaction.GetResourcesCount(ResourceType_Patient);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1161 tuple.get<3>() = transaction.GetResourcesCount(ResourceType_Study);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1162 tuple.get<4>() = transaction.GetResourcesCount(ResourceType_Series);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1163 tuple.get<5>() = transaction.GetResourcesCount(ResourceType_Instance);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 };
5466
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1166
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1167 if (GetDatabaseCapabilities().HasUpdateAndGetStatistics())
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1168 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1169 Operations operations;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1170 Apply(operations);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1171
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1172 operations.GetValues(diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1173 }
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1174 else
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1175 {
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1176 LegacyOperations operations;
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1177 operations.Apply(*this, diskSize, uncompressedSize, countPatients,
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1178 countStudies, countSeries, countInstances);
dceed5e3d6a9 new DB plugin primitive: UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents: 5464
diff changeset
1179 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 void StatelessDatabaseOperations::GetChanges(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 unsigned int maxResults)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 class Operations : public ReadOnlyOperationsT3<Json::Value&, int64_t, unsigned int>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 // NB: In Orthanc <= 1.3.2, a transaction was missing, as
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 // "GetLastChange()" involves calls to "GetPublicId()"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 std::list<ServerIndexChange> changes;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 bool done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 bool hasLast = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 int64_t last = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 transaction.GetChanges(changes, done, tuple.get<1>(), tuple.get<2>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 if (changes.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 last = transaction.GetLastChangeIndex();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 hasLast = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 FormatLog(tuple.get<0>(), changes, "Changes", done, tuple.get<1>(), hasLast, last);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 operations.Apply(*this, target, since, maxResults);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 void StatelessDatabaseOperations::GetLastChange(Json::Value& target)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 class Operations : public ReadOnlyOperationsT1<Json::Value&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 // NB: In Orthanc <= 1.3.2, a transaction was missing, as
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 // "GetLastChange()" involves calls to "GetPublicId()"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 std::list<ServerIndexChange> changes;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 bool hasLast = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 int64_t last = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 transaction.GetLastChange(changes);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 if (changes.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 last = transaction.GetLastChangeIndex();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 hasLast = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 FormatLog(tuple.get<0>(), changes, "Changes", true, 0, hasLast, last);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 operations.Apply(*this, target);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 void StatelessDatabaseOperations::GetExportedResources(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 unsigned int maxResults)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 class Operations : public ReadOnlyOperationsT3<Json::Value&, int64_t, unsigned int>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260 std::list<ExportedResource> exported;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 bool done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 transaction.GetExportedResources(exported, done, tuple.get<1>(), tuple.get<2>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 FormatLog(tuple.get<0>(), exported, "Exports", done, tuple.get<1>(), false, -1);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 operations.Apply(*this, target, since, maxResults);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 void StatelessDatabaseOperations::GetLastExportedResource(Json::Value& target)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1273 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 class Operations : public ReadOnlyOperationsT1<Json::Value&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282 std::list<ExportedResource> exported;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 transaction.GetLastExportedResource(exported);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 FormatLog(tuple.get<0>(), exported, "Exports", true, 0, false, -1);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 operations.Apply(*this, target);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 bool StatelessDatabaseOperations::IsProtectedPatient(const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 class Operations : public ReadOnlyOperationsT2<bool&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 type != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307 throw OrthancException(ErrorCode_ParameterOutOfRange);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 tuple.get<0>() = transaction.IsProtectedPatient(id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 bool isProtected;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 operations.Apply(*this, isProtected, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 return isProtected;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 void StatelessDatabaseOperations::GetChildren(std::list<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 int64_t resource;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 if (!transaction.LookupResource(resource, type, tuple.get<1>()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 else if (type == ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 // An instance cannot have a child
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 throw OrthancException(ErrorCode_BadParameterType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 tuple.get<0>().clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 tuple.get<0>().push_back(transaction.GetPublicId(*it));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 operations.Apply(*this, result, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 void StatelessDatabaseOperations::GetChildInstances(std::list<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 tuple.get<0>().clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376 int64_t top;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377 if (!transaction.LookupResource(top, type, tuple.get<1>()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 else if (type == ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 // The resource is already an instance: Do not go down the hierarchy
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 tuple.get<0>().push_back(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 std::stack<int64_t> toExplore;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 toExplore.push(top);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 while (!toExplore.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 // Get the internal ID of the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395 int64_t resource = toExplore.top();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 toExplore.pop();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 // TODO - This could be optimized by seeing how many
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 // levels "type == transaction.GetResourceType(top)" is
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 // above the "instances level"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 if (transaction.GetResourceType(resource) == ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 tuple.get<0>().push_back(transaction.GetPublicId(resource));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 // Tag all the children of this resource as to be explored
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 toExplore.push(*it);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 operations.Apply(*this, result, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 bool StatelessDatabaseOperations::LookupMetadata(std::string& target,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1426 int64_t& revision,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 ResourceType expectedType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429 MetadataType type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1431 class Operations : public ReadOnlyOperationsT6<bool&, std::string&, int64_t&,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1432 const std::string&, ResourceType, MetadataType>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1438 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1440 if (!transaction.LookupResource(id, resourceType, tuple.get<3>()) ||
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1441 resourceType != tuple.get<4>())
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1443 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1447 tuple.get<0>() = transaction.LookupMetadata(tuple.get<1>(), tuple.get<2>(), id, tuple.get<5>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1450 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1451
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 Operations operations;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1454 operations.Apply(*this, found, target, revision, publicId, expectedType, type);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 void StatelessDatabaseOperations::ListAvailableAttachments(std::set<FileContentType>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1460 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 ResourceType expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 class Operations : public ReadOnlyOperationsT3<std::set<FileContentType>&, const std::string&, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1472 tuple.get<2>() != type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 transaction.ListAvailableAttachments(tuple.get<0>(), id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 operations.Apply(*this, target, publicId, expectedType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488 bool StatelessDatabaseOperations::LookupParent(std::string& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 class Operations : public ReadOnlyOperationsT3<bool&, std::string&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 if (!transaction.LookupResource(id, type, tuple.get<2>()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 int64_t parentId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506 if (transaction.LookupParent(parentId, id))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508 tuple.get<1>() = transaction.GetPublicId(parentId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1510 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1511 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1514 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1515 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521 operations.Apply(*this, found, target, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 void StatelessDatabaseOperations::GetResourceStatistics(/* out */ ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527 /* out */ uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528 /* out */ uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 /* out */ unsigned int& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 /* out */ unsigned int& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 /* out */ unsigned int& countInstances,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 /* out */ uint64_t& dicomDiskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 /* out */ uint64_t& dicomUncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536 class Operations : public IReadOnlyOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 ResourceType& type_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 uint64_t& diskSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 uint64_t& uncompressedSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 unsigned int& countStudies_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 unsigned int& countSeries_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 unsigned int& countInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 uint64_t& dicomDiskSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 uint64_t& dicomUncompressedSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550 explicit Operations(ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551 uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 unsigned int& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 unsigned int& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 unsigned int& countInstances,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 uint64_t& dicomDiskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 uint64_t& dicomUncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 const std::string& publicId) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 type_(type),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 diskSize_(diskSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 uncompressedSize_(uncompressedSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 countStudies_(countStudies),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 countSeries_(countSeries),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 countInstances_(countInstances),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 dicomDiskSize_(dicomDiskSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 dicomUncompressedSize_(dicomUncompressedSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 publicId_(publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573 int64_t top;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1574 if (!transaction.LookupResource(top, type_, publicId_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1575 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 countInstances_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 countSeries_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582 countStudies_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 diskSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584 uncompressedSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 dicomDiskSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 dicomUncompressedSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588 std::stack<int64_t> toExplore;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1589 toExplore.push(top);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1590
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591 while (!toExplore.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1592 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1593 // Get the internal ID of the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 int64_t resource = toExplore.top();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 toExplore.pop();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 ResourceType thisType = transaction.GetResourceType(resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1598
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1599 std::set<FileContentType> f;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600 transaction.ListAvailableAttachments(f, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1601
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 for (std::set<FileContentType>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 it = f.begin(); it != f.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1605 FileInfo attachment;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1606 int64_t revision; // ignored
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1607 if (transaction.LookupAttachment(attachment, revision, resource, *it))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609 if (attachment.GetContentType() == FileContentType_Dicom)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1610 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 dicomDiskSize_ += attachment.GetCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 dicomUncompressedSize_ += attachment.GetUncompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 diskSize_ += attachment.GetCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 uncompressedSize_ += attachment.GetUncompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1617 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1618 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1619
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1620 if (thisType == ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622 countInstances_++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1624 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1626 switch (thisType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1627 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1628 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1629 countStudies_++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632 case ResourceType_Series:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 countSeries_++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1634 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640 // Tag all the children of this resource as to be explored
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1641 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 toExplore.push(*it);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651 if (countStudies_ == 0)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1653 countStudies_ = 1;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1656 if (countSeries_ == 0)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 countSeries_ = 1;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1659 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1661 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1662 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1663
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 Operations operations(type, diskSize, uncompressedSize, countStudies, countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1666 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670 void StatelessDatabaseOperations::LookupIdentifierExact(std::vector<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671 ResourceType level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1672 const DicomTag& tag,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673 const std::string& value)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1677 (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679 (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 result.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685 std::vector<DatabaseConstraint> query;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1689 class Operations : public IReadOnlyOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1691 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1692 std::vector<std::string>& result_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1693 const std::vector<DatabaseConstraint>& query_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1694 ResourceType level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1695
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1696 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1697 Operations(std::vector<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1698 const std::vector<DatabaseConstraint>& query,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699 ResourceType level) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700 result_(result),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1701 query_(query),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1702 level_(level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1703 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1704 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1705
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1706 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1707 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1708 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709 std::list<std::string> tmp;
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
1710 std::set<std::string> labels;
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
1711 transaction.ApplyLookupResources(tmp, NULL, query_, level_, labels, LabelsConstraint_Any, 0);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1712 CopyListToVector(result_, tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1713 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1715
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 Operations operations(result, query, level);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1719
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1720
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1721 bool StatelessDatabaseOperations::LookupGlobalProperty(std::string& value,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1722 GlobalProperty property,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1723 bool shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1724 {
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1725 class Operations : public ReadOnlyOperationsT4<bool&, std::string&, GlobalProperty, bool>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1726 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1727 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1728 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1729 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1730 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1731 // TODO - CANDIDATE FOR "TransactionType_Implicit"
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1732 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>(), tuple.get<3>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1733 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1734 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1735
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1736 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1737 Operations operations;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1738 operations.Apply(*this, found, value, property, shared);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1739 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1740 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1742
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1743 std::string StatelessDatabaseOperations::GetGlobalProperty(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1744 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1745 const std::string& defaultValue)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1746 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1747 std::string s;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1748 if (LookupGlobalProperty(s, property, shared))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1749 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1750 return s;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1751 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1752 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1753 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1754 return defaultValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1755 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1756 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1757
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1758
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1759 bool StatelessDatabaseOperations::GetMainDicomTags(DicomMap& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1760 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1761 ResourceType expectedType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1762 ResourceType levelOfInterest)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1763 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1764 // Yes, the following test could be shortened, but we wish to make it as clear as possible
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765 if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1767 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1768 !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769 !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_Instance))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1770 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1771 throw OrthancException(ErrorCode_ParameterOutOfRange);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1772 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1773
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1774
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1775 class Operations : public ReadOnlyOperationsT5<bool&, DicomMap&, const std::string&, ResourceType, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1776 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1777 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1778 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1779 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1780 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1781 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1782 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1783 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1784 if (!transaction.LookupResource(id, type, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1785 type != tuple.get<3>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1786 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1787 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1789 else if (type == ResourceType_Study)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1790 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1791 DicomMap tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1792 transaction.GetMainDicomTags(tmp, id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1793
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1794 switch (tuple.get<4>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1795 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1796 case ResourceType_Patient:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1797 tmp.ExtractPatientInformation(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1798 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1799 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1800
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802 tmp.ExtractStudyInformation(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1804 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1807 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1810 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1811 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1812 transaction.GetMainDicomTags(tuple.get<1>(), id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1815 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1816 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1817
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1818 result.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1819
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1820 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1821 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1822 operations.Apply(*this, found, result, publicId, expectedType, levelOfInterest);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1823 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1824 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1825
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1826
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1827 bool StatelessDatabaseOperations::GetAllMainDicomTags(DicomMap& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1828 const std::string& instancePublicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1829 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1830 class Operations : public ReadOnlyOperationsT3<bool&, DicomMap&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1831 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1832 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1833 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1834 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1835 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1836 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1837 int64_t instance;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1838 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1839 if (!transaction.LookupResource(instance, type, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840 type != ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1843 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1844 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1845 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846 DicomMap tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1848 transaction.GetMainDicomTags(tmp, instance);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1849 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1850
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1851 int64_t series;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1852 if (!transaction.LookupParent(series, instance))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1853 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1854 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1855 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1856
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1857 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1858 transaction.GetMainDicomTags(tmp, series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1859 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1860
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1861 int64_t study;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1862 if (!transaction.LookupParent(study, series))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1863 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1864 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1865 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1866
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1867 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1868 transaction.GetMainDicomTags(tmp, study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1869 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1870
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1871 #ifndef NDEBUG
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1872 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1873 // Sanity test to check that all the main DICOM tags from the
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1874 // patient level are copied at the study level
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1875
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1876 int64_t patient;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1877 if (!transaction.LookupParent(patient, study))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1878 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1879 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1880 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1881
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1882 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1883 transaction.GetMainDicomTags(tmp, study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1884
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1885 std::set<DicomTag> patientTags;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1886 tmp.GetTags(patientTags);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1887
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1888 for (std::set<DicomTag>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1889 it = patientTags.begin(); it != patientTags.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1890 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1891 assert(tuple.get<1>().HasTag(*it));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1892 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1893 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1894 #endif
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1895
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1896 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1897 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1898 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1899 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1900
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1901 result.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1902
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1903 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1904 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1905 operations.Apply(*this, found, result, instancePublicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1906 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1907 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1908
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1909
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1910 bool StatelessDatabaseOperations::LookupResourceType(ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1911 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1912 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1913 class Operations : public ReadOnlyOperationsT3<bool&, ResourceType&, const std::string&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1914 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1915 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1916 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1917 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1918 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1919 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1920 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1921 tuple.get<0>() = transaction.LookupResource(id, tuple.get<1>(), tuple.get<2>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1922 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1923 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1924
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1925 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1926 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1927 operations.Apply(*this, found, type, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1928 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1929 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1930
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1931
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1932 bool StatelessDatabaseOperations::LookupParent(std::string& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1933 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1934 ResourceType parentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1935 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1936 class Operations : public ReadOnlyOperationsT4<bool&, std::string&, const std::string&, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1937 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1938 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1939 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1940 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1941 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1942 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1943 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1944 if (!transaction.LookupResource(id, type, tuple.get<2>()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1945 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1946 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1947 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1948
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1949 while (type != tuple.get<3>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1950 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1951 int64_t parentId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1952
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1953 if (type == ResourceType_Patient || // Cannot further go up in hierarchy
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1954 !transaction.LookupParent(parentId, id))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1955 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1956 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1957 return;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1958 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1959
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1960 id = parentId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1961 type = GetParentResourceType(type);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1962 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1963
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1964 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1965 tuple.get<1>() = transaction.GetPublicId(id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1966 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1967 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1968
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1969 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1970 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1971 operations.Apply(*this, found, target, publicId, parentType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1972 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1973 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1974
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1975
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1976 void StatelessDatabaseOperations::ApplyLookupResources(std::vector<std::string>& resourcesId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1977 std::vector<std::string>* instancesId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1978 const DatabaseLookup& lookup,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1979 ResourceType queryLevel,
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
1980 const std::set<std::string>& labels,
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
1981 LabelsConstraint labelsConstraint,
5220
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
1982 uint32_t limit)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1983 {
5220
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
1984 class Operations : public ReadOnlyOperationsT6<bool, const std::vector<DatabaseConstraint>&, ResourceType,
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
1985 const std::set<std::string>&, LabelsConstraint, size_t>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1986 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1987 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1988 std::list<std::string> resourcesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1989 std::list<std::string> instancesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1990
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1991 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1992 const std::list<std::string>& GetResourcesList() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1993 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1994 return resourcesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1995 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1996
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1997 const std::list<std::string>& GetInstancesList() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1998 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1999 return instancesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2000 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2001
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2002 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2003 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2004 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2006 if (tuple.get<0>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2007 {
5220
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
2008 transaction.ApplyLookupResources(
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
2009 resourcesList_, &instancesList_, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), tuple.get<4>(), tuple.get<5>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2010 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2011 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2012 {
5220
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
2013 transaction.ApplyLookupResources(
df39c7583a49 preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5216
diff changeset
2014 resourcesList_, NULL, tuple.get<1>(), tuple.get<2>(), tuple.get<3>(), tuple.get<4>(), tuple.get<5>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2015 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2016 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2017 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2018
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2019 if (!labels.empty() &&
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2020 !db_.GetDatabaseCapabilities().HasLabelsSupport())
5238
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
2021 {
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
2022 throw OrthancException(ErrorCode_NotImplemented, "The database backend doesn't support labels");
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
2023 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2024
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2025 for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it)
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2026 {
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2027 ServerToolbox::CheckValidLabel(*it);
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2028 }
5244
72dfa0ac84eb lookup for labels in orthanc explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5238
diff changeset
2029
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2030 std::vector<DatabaseConstraint> normalized;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2031 NormalizeLookup(normalized, lookup, queryLevel);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2032
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2033 Operations operations;
5248
a7d95f951f8a replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5244
diff changeset
2034 operations.Apply(*this, (instancesId != NULL), normalized, queryLevel, labels, labelsConstraint, limit);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2035
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2036 CopyListToVector(resourcesId, operations.GetResourcesList());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2037
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2038 if (instancesId != NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2039 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2040 CopyListToVector(*instancesId, operations.GetInstancesList());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2041 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2042 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2043
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2044
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2045 bool StatelessDatabaseOperations::DeleteResource(Json::Value& remainingAncestor,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2046 const std::string& uuid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2047 ResourceType expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2048 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2049 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2050 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2051 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2052 bool found_;
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2053 Json::Value& remainingAncestor_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2054 const std::string& uuid_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2055 ResourceType expectedType_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2056
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2057 public:
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2058 Operations(Json::Value& remainingAncestor,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2059 const std::string& uuid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2060 ResourceType expectedType) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2061 found_(false),
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2062 remainingAncestor_(remainingAncestor),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2063 uuid_(uuid),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2064 expectedType_(expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2065 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2066 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2067
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2068 bool IsFound() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2069 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2070 return found_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2071 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2072
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2073 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2074 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2075 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2076 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2077 if (!transaction.LookupResource(id, type, uuid_) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2078 expectedType_ != type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2079 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2080 found_ = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2081 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2082 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2083 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2084 found_ = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2085 transaction.DeleteResource(id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2086
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2087 std::string remainingPublicId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2088 ResourceType remainingLevel;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2089 if (transaction.GetTransactionContext().LookupRemainingLevel(remainingPublicId, remainingLevel))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2090 {
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2091 remainingAncestor_["RemainingAncestor"] = Json::Value(Json::objectValue);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2092 remainingAncestor_["RemainingAncestor"]["Path"] = GetBasePath(remainingLevel, remainingPublicId);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2093 remainingAncestor_["RemainingAncestor"]["Type"] = EnumerationToString(remainingLevel);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2094 remainingAncestor_["RemainingAncestor"]["ID"] = remainingPublicId;
5297
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2095
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2096 { // update the LastUpdate metadata of all parents
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2097 std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */);
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2098 ResourcesContent content(true);
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2099
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2100 int64_t parentId = 0;
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2101 if (transaction.LookupResource(parentId, remainingLevel, remainingPublicId))
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2102 {
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2103
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2104 do
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2105 {
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2106 content.AddMetadata(parentId, MetadataType_LastUpdate, now);
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2107 }
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2108 while (transaction.LookupParent(parentId, parentId));
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2109
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2110 transaction.SetResourcesContent(content);
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2111 }
c78138dc3889 When deleting a resource, its parents LastUpdate metadata is now updated
Alain Mazy <am@osimis.io>
parents: 5296
diff changeset
2112 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2113 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2114 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2115 {
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2116 remainingAncestor_["RemainingAncestor"] = Json::nullValue;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2117 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2118 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2119 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2120 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2121
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2122 Operations operations(remainingAncestor, uuid, expectedType);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2123 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2124 return operations.IsFound();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2125 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2127
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2128 void StatelessDatabaseOperations::LogExportedResource(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2129 const std::string& remoteModality)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2130 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2131 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2132 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2133 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2134 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2135 const std::string& remoteModality_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2136
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2137 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2138 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2139 const std::string& remoteModality) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2140 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2141 remoteModality_(remoteModality)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2142 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2143 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2144
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2145 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2146 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2147 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2148 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2149 if (!transaction.LookupResource(id, type, publicId_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2150 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2151 throw OrthancException(ErrorCode_InexistentItem);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2152 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2153
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2154 std::string patientId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2155 std::string studyInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2156 std::string seriesInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2157 std::string sopInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2158
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2159 int64_t currentId = id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2160 ResourceType currentType = type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2161
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2162 // Iteratively go up inside the patient/study/series/instance hierarchy
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2163 bool done = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2164 while (!done)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2165 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2166 DicomMap map;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2167 transaction.GetMainDicomTags(map, currentId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2168
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2169 switch (currentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2170 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2171 case ResourceType_Patient:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2172 if (map.HasTag(DICOM_TAG_PATIENT_ID))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2173 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2174 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).GetContent();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2175 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2176 done = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2177 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2178
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2179 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2180 if (map.HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2181 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2182 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).GetContent();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2183 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2184 currentType = ResourceType_Patient;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2185 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2186
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2187 case ResourceType_Series:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2188 if (map.HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2189 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2190 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).GetContent();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2191 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2192 currentType = ResourceType_Study;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2193 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2194
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2195 case ResourceType_Instance:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2196 if (map.HasTag(DICOM_TAG_SOP_INSTANCE_UID))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2197 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2198 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).GetContent();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2199 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2200 currentType = ResourceType_Series;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2201 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2202
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2203 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2204 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2205 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2206
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2207 // If we have not reached the Patient level, find the parent of
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2208 // the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2209 if (!done)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2210 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2211 bool ok = transaction.LookupParent(currentId, currentId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2212 (void) ok; // Remove warning about unused variable in release builds
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2213 assert(ok);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2214 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2215 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2216
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2217 ExportedResource resource(-1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2218 type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2219 publicId_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2220 remoteModality_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2221 SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2222 patientId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2223 studyInstanceUid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2224 seriesInstanceUid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2225 sopInstanceUid);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2226
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2227 transaction.LogExportedResource(resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2228 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2229 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2230
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2231 Operations operations(publicId, remoteModality);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2232 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2233 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2234
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2235
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2236 void StatelessDatabaseOperations::SetProtectedPatient(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2237 bool isProtected)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2238 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2239 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2240 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2241 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2242 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2243 bool isProtected_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2244
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2245 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2246 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2247 bool isProtected) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2248 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2249 isProtected_(isProtected)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2250 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2251 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2252
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2253 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2254 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2255 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2256 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2257 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2258 if (!transaction.LookupResource(id, type, publicId_) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2259 type != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2260 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2261 throw OrthancException(ErrorCode_ParameterOutOfRange);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2262 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2263 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2264 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2265 transaction.SetProtectedPatient(id, isProtected_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2266 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2267 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2268 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2269
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2270 Operations operations(publicId, isProtected);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2271 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2272
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2273 if (isProtected)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2274 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2275 LOG(INFO) << "Patient " << publicId << " has been protected";
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2276 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2277 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2278 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2279 LOG(INFO) << "Patient " << publicId << " has been unprotected";
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2280 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2281 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2282
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2283
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2284 void StatelessDatabaseOperations::SetMetadata(int64_t& newRevision,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2285 const std::string& publicId,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2286 MetadataType type,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2287 const std::string& value,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2288 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2289 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2290 const std::string& oldMD5)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2291 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2292 class Operations : public IReadWriteOperations
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2293 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2294 private:
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2295 int64_t& newRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2296 const std::string& publicId_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2297 MetadataType type_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2298 const std::string& value_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2299 bool hasOldRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2300 int64_t oldRevision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2301 const std::string& oldMD5_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2302
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2303 public:
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2304 Operations(int64_t& newRevision,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2305 const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2306 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2307 const std::string& value,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2308 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2309 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2310 const std::string& oldMD5) :
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2311 newRevision_(newRevision),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2312 publicId_(publicId),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2313 type_(type),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2314 value_(value),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2315 hasOldRevision_(hasOldRevision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2316 oldRevision_(oldRevision),
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2317 oldMD5_(oldMD5)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2318 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2319 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2320
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2321 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2322 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2323 ResourceType resourceType;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2324 int64_t id;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2325 if (!transaction.LookupResource(id, resourceType, publicId_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2326 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2327 throw OrthancException(ErrorCode_UnknownResource);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2328 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2329 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2330 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2331 std::string oldValue;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2332 int64_t expectedRevision;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2333 if (transaction.LookupMetadata(oldValue, expectedRevision, id, type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2334 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2335 if (hasOldRevision_)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2336 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2337 std::string expectedMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2338 Toolbox::ComputeMD5(expectedMD5, oldValue);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2339
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2340 if (expectedRevision != oldRevision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2341 expectedMD5 != oldMD5_)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2342 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2343 throw OrthancException(ErrorCode_Revision);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2344 }
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2345 }
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2346
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2347 newRevision_ = expectedRevision + 1;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2348 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2349 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2350 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2351 // The metadata is not existing yet: Ignore "oldRevision"
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2352 // and initialize a new sequence of revisions
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2353 newRevision_ = 0;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2354 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2355
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2356 transaction.SetMetadata(id, type_, value_, newRevision_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2357
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2358 if (IsUserMetadata(type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2359 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2360 transaction.LogChange(id, ChangeType_UpdatedMetadata, resourceType, publicId_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2361 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2362 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2363 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2364 };
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2365
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2366 Operations operations(newRevision, publicId, type, value, hasOldRevision, oldRevision, oldMD5);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2367 Apply(operations);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2368 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2369
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2370
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2371 void StatelessDatabaseOperations::OverwriteMetadata(const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2372 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2373 const std::string& value)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2374 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2375 int64_t newRevision; // Unused
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2376 SetMetadata(newRevision, publicId, type, value, false /* no old revision */, -1 /* dummy */, "" /* dummy */);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2377 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2378
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2379
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2380 bool StatelessDatabaseOperations::DeleteMetadata(const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2381 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2382 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2383 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2384 const std::string& md5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2385 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2386 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2387 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2388 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2389 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2390 MetadataType type_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2391 bool hasRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2392 int64_t revision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2393 const std::string& md5_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2394 bool found_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2395
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2396 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2397 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2398 MetadataType type,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2399 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2400 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2401 const std::string& md5) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2402 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2403 type_(type),
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2404 hasRevision_(hasRevision),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2405 revision_(revision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2406 md5_(md5),
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2407 found_(false)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2408 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2409 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2410
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2411 bool HasFound() const
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2412 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2413 return found_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2414 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2415
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2416 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2417 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2418 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2419 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2420 if (!transaction.LookupResource(id, resourceType, publicId_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2421 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2422 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2423 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2424 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2425 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2426 std::string value;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2427 int64_t expectedRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2428 if (transaction.LookupMetadata(value, expectedRevision, id, type_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2429 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2430 if (hasRevision_)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2431 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2432 std::string expectedMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2433 Toolbox::ComputeMD5(expectedMD5, value);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2434
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2435 if (expectedRevision != revision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2436 expectedMD5 != md5_)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2437 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2438 throw OrthancException(ErrorCode_Revision);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2439 }
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2440 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2441
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2442 found_ = true;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2443 transaction.DeleteMetadata(id, type_);
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2444
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2445 if (IsUserMetadata(type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2446 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2447 transaction.LogChange(id, ChangeType_UpdatedMetadata, resourceType, publicId_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2448 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2449 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2450 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2451 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2452 found_ = false;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2453 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2454 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2455 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2456 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2457
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2458 Operations operations(publicId, type, hasRevision, revision, md5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2459 Apply(operations);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2460 return operations.HasFound();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2461 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2462
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2463
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2464 uint64_t StatelessDatabaseOperations::IncrementGlobalSequence(GlobalProperty sequence,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2465 bool shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2466 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2467 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2468 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2469 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2470 uint64_t newValue_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2471 GlobalProperty sequence_;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2472 bool shared_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2473
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2474 public:
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2475 Operations(GlobalProperty sequence,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2476 bool shared) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2477 newValue_(0), // Dummy initialization
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2478 sequence_(sequence),
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2479 shared_(shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2480 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2481 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2482
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2483 uint64_t GetNewValue() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2484 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2485 return newValue_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2486 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2487
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2488 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2489 {
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2490 if (transaction.GetDatabaseCapabilities().HasAtomicIncrementGlobalProperty())
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2491 {
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2492 newValue_ = static_cast<uint64_t>(transaction.IncrementGlobalProperty(sequence_, shared_, 1));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2493 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2494 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2495 {
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2496 std::string oldString;
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2497
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2498 if (transaction.LookupGlobalProperty(oldString, sequence_, shared_))
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2499 {
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2500 uint64_t oldValue;
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2501
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2502 try
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2503 {
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2504 oldValue = boost::lexical_cast<uint64_t>(oldString);
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2505 }
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2506 catch (boost::bad_lexical_cast&)
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2507 {
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2508 LOG(ERROR) << "Cannot read the global sequence "
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2509 << boost::lexical_cast<std::string>(sequence_) << ", resetting it";
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2510 oldValue = 0;
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2511 }
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2512
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2513 newValue_ = oldValue + 1;
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2514 }
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2515 else
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2516 {
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2517 // Initialize the sequence at "1"
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2518 newValue_ = 1;
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2519 }
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2520
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
2521 transaction.SetGlobalProperty(sequence_, shared_, boost::lexical_cast<std::string>(newValue_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2522 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2523 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2524 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2525
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2526 Operations operations(sequence, shared);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2527 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2528 assert(operations.GetNewValue() != 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2529 return operations.GetNewValue();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2530 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2531
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2532
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2533 void StatelessDatabaseOperations::DeleteChanges()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2534 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2535 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2536 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2537 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2538 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2539 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2540 transaction.ClearChanges();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2541 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2542 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2543
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2544 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2545 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2546 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2547
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2548
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2549 void StatelessDatabaseOperations::DeleteExportedResources()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2550 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2551 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2552 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2553 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2554 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2555 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2556 transaction.ClearExportedResources();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2557 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2558 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2559
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2560 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2561 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2562 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2563
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2564
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2565 void StatelessDatabaseOperations::SetGlobalProperty(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2566 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2567 const std::string& value)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2568 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2569 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2570 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2571 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2572 GlobalProperty property_;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2573 bool shared_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2574 const std::string& value_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2575
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2576 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2577 Operations(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2578 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2579 const std::string& value) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2580 property_(property),
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2581 shared_(shared),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2582 value_(value)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2583 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2584 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2585
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2586 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2587 {
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2588 transaction.SetGlobalProperty(property_, shared_, value_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2589 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2590 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2591
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2592 Operations operations(property, shared, value);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2593 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2594 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2595
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2596
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2597 bool StatelessDatabaseOperations::DeleteAttachment(const std::string& publicId,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2598 FileContentType type,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2599 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2600 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2601 const std::string& md5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2602 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2603 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2604 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2605 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2606 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2607 FileContentType type_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2608 bool hasRevision_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2609 int64_t revision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2610 const std::string& md5_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2611 bool found_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2612
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2613 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2614 Operations(const std::string& publicId,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2615 FileContentType type,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2616 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2617 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2618 const std::string& md5) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2619 publicId_(publicId),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2620 type_(type),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2621 hasRevision_(hasRevision),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2622 revision_(revision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2623 md5_(md5),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2624 found_(false)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2625 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2626 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2627
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2628 bool HasFound() const
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2629 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2630 return found_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2631 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2632
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2633 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2634 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2635 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2636 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2637 if (!transaction.LookupResource(id, resourceType, publicId_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2638 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2639 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2640 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2641 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2642 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2643 FileInfo info;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2644 int64_t expectedRevision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2645 if (transaction.LookupAttachment(info, expectedRevision, id, type_))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2646 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2647 if (hasRevision_ &&
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2648 (expectedRevision != revision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2649 info.GetUncompressedMD5() != md5_))
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2650 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2651 throw OrthancException(ErrorCode_Revision);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2652 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2653
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2654 found_ = true;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2655 transaction.DeleteAttachment(id, type_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2656
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2657 if (IsUserContentType(type_))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2658 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2659 transaction.LogChange(id, ChangeType_UpdatedAttachment, resourceType, publicId_);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2660 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2661 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2662 else
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2663 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2664 found_ = false;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2665 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2666 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2667 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2668 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2669
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2670 Operations operations(publicId, type, hasRevision, revision, md5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2671 Apply(operations);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2672 return operations.HasFound();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2673 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2674
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2675
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2676 void StatelessDatabaseOperations::LogChange(int64_t internalId,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2677 ChangeType changeType,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2678 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2679 ResourceType level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2680 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2681 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2682 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2683 private:
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2684 int64_t internalId_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2685 ChangeType changeType_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2686 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2687 ResourceType level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2688
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2689 public:
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2690 Operations(int64_t internalId,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2691 ChangeType changeType,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2692 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2693 ResourceType level) :
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2694 internalId_(internalId),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2695 changeType_(changeType),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2696 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2697 level_(level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2698 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2699 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2700
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2701 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2702 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2703 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2704 ResourceType type;
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2705 if (transaction.LookupResource(id, type, publicId_) &&
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2706 id == internalId_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2707 {
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2708 /**
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2709 * Make sure that the resource is still existing, with the
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2710 * same internal ID, which indicates the absence of bouncing
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2711 * (if deleting then recreating the same resource). Don't
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2712 * throw an exception if the resource has been deleted,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2713 * because this function might e.g. be called from
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2714 * "StatelessDatabaseOperations::UnstableResourcesMonitorThread()"
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2715 * (for which a deleted resource is *not* an error case).
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2716 **/
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2717 if (type == level_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2718 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2719 transaction.LogChange(id, changeType_, type, publicId_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2720 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2721 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2722 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2723 // Consistency check
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2724 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2725 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2726 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2727 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2728 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2729
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2730 Operations operations(internalId, changeType, publicId, level);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2731 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2732 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2733
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2734
5044
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2735 static void GetMainDicomSequenceMetadataContent(std::string& result,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2736 const DicomMap& dicomSummary,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2737 ResourceType level)
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2738 {
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2739 DicomMap levelSummary;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2740 DicomMap levelSequences;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2741
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2742 dicomSummary.ExtractResourceInformation(levelSummary, level);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2743 levelSummary.ExtractSequences(levelSequences);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2744
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2745 if (levelSequences.GetSize() > 0)
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2746 {
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2747 Json::Value jsonMetadata;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2748 jsonMetadata["Version"] = 1;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2749 jsonMetadata["Sequences"] = Json::objectValue;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2750 FromDcmtkBridge::ToJson(jsonMetadata["Sequences"], levelSequences, DicomToJsonFormat_Full);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2751
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2752 Toolbox::WriteFastJson(result, jsonMetadata);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2753 }
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2754 }
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2755
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2756
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2757 void StatelessDatabaseOperations::ReconstructInstance(const ParsedDicomFile& dicom)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2758 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2759 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2760 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2761 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2762 DicomMap summary_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2763 std::unique_ptr<DicomInstanceHasher> hasher_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2764 bool hasTransferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2765 DicomTransferSyntax transferSyntax_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2766
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2767 static void ReplaceMetadata(ReadWriteTransaction& transaction,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2768 int64_t instance,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2769 MetadataType metadata,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2770 const std::string& value)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2771 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2772 std::string oldValue;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2773 int64_t oldRevision;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2774
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2775 if (transaction.LookupMetadata(oldValue, oldRevision, instance, metadata))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2776 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2777 transaction.SetMetadata(instance, metadata, value, oldRevision + 1);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2778 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2779 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2780 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2781 transaction.SetMetadata(instance, metadata, value, 0);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2782 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2783 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2784
5044
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2785 static void SetMainDicomSequenceMetadata(ReadWriteTransaction& transaction,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2786 int64_t instance,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2787 const DicomMap& dicomSummary,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2788 ResourceType level)
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2789 {
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2790 std::string serialized;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2791 GetMainDicomSequenceMetadataContent(serialized, dicomSummary, level);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2792
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2793 if (!serialized.empty())
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2794 {
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2795 ReplaceMetadata(transaction, instance, MetadataType_MainDicomSequences, serialized);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2796 }
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2797 else
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2798 {
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2799 transaction.DeleteMetadata(instance, MetadataType_MainDicomSequences);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2800 }
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2801
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2802 }
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2803
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2804 public:
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2805 explicit Operations(const ParsedDicomFile& dicom)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2806 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2807 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2808 hasher_.reset(new DicomInstanceHasher(summary_));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2809 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2810 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2811
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2812 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2813 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2814 int64_t patient = -1, study = -1, series = -1, instance = -1;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2815
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2816 ResourceType type1, type2, type3, type4;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2817 if (!transaction.LookupResource(patient, type1, hasher_->HashPatient()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2818 !transaction.LookupResource(study, type2, hasher_->HashStudy()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2819 !transaction.LookupResource(series, type3, hasher_->HashSeries()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2820 !transaction.LookupResource(instance, type4, hasher_->HashInstance()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2821 type1 != ResourceType_Patient ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2822 type2 != ResourceType_Study ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2823 type3 != ResourceType_Series ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2824 type4 != ResourceType_Instance ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2825 patient == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2826 study == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2827 series == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2828 instance == -1)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2829 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2830 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2831 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2832
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2833 transaction.ClearMainDicomTags(patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2834 transaction.ClearMainDicomTags(study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2835 transaction.ClearMainDicomTags(series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2836 transaction.ClearMainDicomTags(instance);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2837
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2838 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2839 ResourcesContent content(false /* prevent the setting of metadata */);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2840 content.AddResource(patient, ResourceType_Patient, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2841 content.AddResource(study, ResourceType_Study, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2842 content.AddResource(series, ResourceType_Series, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2843 content.AddResource(instance, ResourceType_Instance, summary_);
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2844
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2845 transaction.SetResourcesContent(content);
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2846
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2847 ReplaceMetadata(transaction, patient, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2848 ReplaceMetadata(transaction, study, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2849 ReplaceMetadata(transaction, series, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2850 ReplaceMetadata(transaction, instance, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0
5044
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2851
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2852 SetMainDicomSequenceMetadata(transaction, patient, summary_, ResourceType_Patient);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2853 SetMainDicomSequenceMetadata(transaction, study, summary_, ResourceType_Study);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2854 SetMainDicomSequenceMetadata(transaction, series, summary_, ResourceType_Series);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
2855 SetMainDicomSequenceMetadata(transaction, instance, summary_, ResourceType_Instance);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2856 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2857
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2858 if (hasTransferSyntax_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2859 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2860 ReplaceMetadata(transaction, instance, MetadataType_Instance_TransferSyntax, GetTransferSyntaxUid(transferSyntax_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2861 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2862
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2863 const DicomValue* value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2864 if ((value = summary_.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2865 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2866 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2867 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2868 ReplaceMetadata(transaction, instance, MetadataType_Instance_SopClassUid, value->GetContent());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2869 }
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2870
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2871 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2872 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2873
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2874 Operations operations(dicom);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2875 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2876 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2877
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2878
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2879 bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxStorageSize(uint64_t maximumStorageSize,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2880 uint64_t addedInstanceSize)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2881 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2882 if (maximumStorageSize != 0)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2883 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2884 if (maximumStorageSize < addedInstanceSize)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2885 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2886 throw OrthancException(ErrorCode_FullStorage, "Cannot store an instance of size " +
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2887 boost::lexical_cast<std::string>(addedInstanceSize) +
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2888 " bytes in a storage area limited to " +
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2889 boost::lexical_cast<std::string>(maximumStorageSize));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2890 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2891
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2892 if (transaction_.IsDiskSizeAbove(maximumStorageSize - addedInstanceSize))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2893 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2894 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2895 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2896 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2897
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2898 return false;
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2899 }
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2900
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2901 bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxPatientCount(unsigned int maximumPatientCount,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2902 const std::string& patientId)
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2903 {
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2904 if (maximumPatientCount != 0)
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2905 {
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2906 uint64_t patientCount = transaction_.GetResourcesCount(ResourceType_Patient); // at this time, the new patient has already been added (as part of the transaction)
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2907 return patientCount > maximumPatientCount;
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2908 }
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2909
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2910 return false;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2911 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2912
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2913 bool StatelessDatabaseOperations::ReadWriteTransaction::IsRecyclingNeeded(uint64_t maximumStorageSize,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2914 unsigned int maximumPatients,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2915 uint64_t addedInstanceSize,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2916 const std::string& newPatientId)
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2917 {
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2918 return HasReachedMaxStorageSize(maximumStorageSize, addedInstanceSize)
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2919 || HasReachedMaxPatientCount(maximumPatients, newPatientId);
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2920 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2921
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2922 void StatelessDatabaseOperations::ReadWriteTransaction::Recycle(uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2923 unsigned int maximumPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2924 uint64_t addedInstanceSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2925 const std::string& newPatientId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2926 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2927 // TODO - Performance: Avoid calls to "IsRecyclingNeeded()"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2928
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2929 if (IsRecyclingNeeded(maximumStorageSize, maximumPatients, addedInstanceSize, newPatientId))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2930 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2931 // Check whether other DICOM instances from this patient are
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2932 // already stored
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2933 int64_t patientToAvoid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2934 bool hasPatientToAvoid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2935
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2936 if (newPatientId.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2937 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2938 hasPatientToAvoid = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2939 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2940 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2941 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2942 ResourceType type;
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2943 hasPatientToAvoid = transaction_.LookupResource(patientToAvoid, type, newPatientId);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2944 if (type != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2945 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2946 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2947 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2948 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2949
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2950 // Iteratively select patient to remove until there is enough
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2951 // space in the DICOM store
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2952 int64_t patientToRecycle;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2953 while (true)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2954 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2955 // If other instances of this patient are already in the store,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2956 // we must avoid to recycle them
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2957 bool ok = (hasPatientToAvoid ?
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2958 transaction_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) :
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2959 transaction_.SelectPatientToRecycle(patientToRecycle));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2960
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2961 if (!ok)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2962 {
4801
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
2963 throw OrthancException(ErrorCode_FullStorage, "Cannot recycle more patients");
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2964 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2965
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2966 LOG(TRACE) << "Recycling one patient";
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2967 transaction_.DeleteResource(patientToRecycle);
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2968
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2969 if (!IsRecyclingNeeded(maximumStorageSize, maximumPatients, addedInstanceSize, newPatientId))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2970 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2971 // OK, we're done
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2972 return;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2973 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2974 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2975 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2976 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2977
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2978
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2979 void StatelessDatabaseOperations::StandaloneRecycling(MaxStorageMode maximumStorageMode,
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2980 uint64_t maximumStorageSize,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2981 unsigned int maximumPatientCount)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2982 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2983 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2984 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2985 private:
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2986 uint64_t maximumStorageSize_;
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
2987 unsigned int maximumPatientCount_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2988
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2989 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2990 Operations(uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2991 unsigned int maximumPatientCount) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2992 maximumStorageSize_(maximumStorageSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2993 maximumPatientCount_(maximumPatientCount)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2994 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2995 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2996
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2997 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2998 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2999 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, 0, "");
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3000 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3001 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3002
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3003 if (maximumStorageMode == MaxStorageMode_Recycle
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3004 && (maximumStorageSize != 0 || maximumPatientCount != 0))
4602
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
3005 {
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
3006 Operations operations(maximumStorageSize, maximumPatientCount);
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
3007 Apply(operations);
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
3008 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3009 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3010
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3011
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3012 StoreStatus StatelessDatabaseOperations::Store(std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3013 const DicomMap& dicomSummary,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3014 const Attachments& attachments,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3015 const MetadataMap& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3016 const DicomInstanceOrigin& origin,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3017 bool overwrite,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3018 bool hasTransferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3019 DicomTransferSyntax transferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3020 bool hasPixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3021 uint64_t pixelDataOffset,
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3022 ValueRepresentation pixelDataVR,
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3023 MaxStorageMode maximumStorageMode,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3024 uint64_t maximumStorageSize,
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3025 unsigned int maximumPatients,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3026 bool isReconstruct)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3027 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3028 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3029 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3030 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3031 StoreStatus storeStatus_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3032 std::map<MetadataType, std::string>& instanceMetadata_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3033 const DicomMap& dicomSummary_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3034 const Attachments& attachments_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3035 const MetadataMap& metadata_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3036 const DicomInstanceOrigin& origin_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3037 bool overwrite_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3038 bool hasTransferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3039 DicomTransferSyntax transferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3040 bool hasPixelDataOffset_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3041 uint64_t pixelDataOffset_;
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3042 ValueRepresentation pixelDataVR_;
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3043 MaxStorageMode maximumStorageMode_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3044 uint64_t maximumStorageSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3045 unsigned int maximumPatientCount_;
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3046 bool isReconstruct_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3047
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3048 // Auto-computed fields
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3049 bool hasExpectedInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3050 int64_t expectedInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3051 std::string hashPatient_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3052 std::string hashStudy_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3053 std::string hashSeries_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3054 std::string hashInstance_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3055
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3056
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3057 static void SetInstanceMetadata(ResourcesContent& content,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3058 std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3059 int64_t instance,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3060 MetadataType metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3061 const std::string& value)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3062 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3063 content.AddMetadata(instance, metadata, value);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3064 instanceMetadata[metadata] = value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3065 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3066
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3067 static void SetMainDicomSequenceMetadata(ResourcesContent& content,
5044
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3068 int64_t resource,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3069 const DicomMap& dicomSummary,
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3070 ResourceType level)
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3071 {
5044
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3072 std::string serialized;
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3073 GetMainDicomSequenceMetadataContent(serialized, dicomSummary, level);
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3074
6fed78e13233 Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents: 5043
diff changeset
3075 if (!serialized.empty())
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3076 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3077 content.AddMetadata(resource, MetadataType_MainDicomSequences, serialized);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3078 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3079 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3080
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3081 static bool ComputeExpectedNumberOfInstances(int64_t& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3082 const DicomMap& dicomSummary)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3083 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3084 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3085 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3086 const DicomValue* value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3087 const DicomValue* value2;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3088
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3089 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3090 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3091 !value->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3092 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3093 !value2->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3094 !value2->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3095 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3096 // Patch for series with temporal positions thanks to Will Ryder
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3097 int64_t imagesInAcquisition = boost::lexical_cast<int64_t>(value->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3098 int64_t countTemporalPositions = boost::lexical_cast<int64_t>(value2->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3099 target = imagesInAcquisition * countTemporalPositions;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3100 return (target > 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3101 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3102
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3103 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3104 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3105 !value->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3106 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3107 !value2->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3108 !value2->IsNull())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3109 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3110 // Support of Cardio-PET images
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3111 int64_t numberOfSlices = boost::lexical_cast<int64_t>(value->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3112 int64_t numberOfTimeSlices = boost::lexical_cast<int64_t>(value2->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3113 target = numberOfSlices * numberOfTimeSlices;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3114 return (target > 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3115 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3116
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3117 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3118 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3119 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3120 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3121 target = boost::lexical_cast<int64_t>(value->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3122 return (target > 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3123 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3124 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3125 catch (OrthancException&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3126 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3127 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3128 catch (boost::bad_lexical_cast&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3129 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3130 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3131
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3132 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3133 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3134
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3135 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3136 Operations(std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3137 const DicomMap& dicomSummary,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3138 const Attachments& attachments,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3139 const MetadataMap& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3140 const DicomInstanceOrigin& origin,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3141 bool overwrite,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3142 bool hasTransferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3143 DicomTransferSyntax transferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3144 bool hasPixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3145 uint64_t pixelDataOffset,
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3146 ValueRepresentation pixelDataVR,
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3147 MaxStorageMode maximumStorageMode,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3148 uint64_t maximumStorageSize,
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3149 unsigned int maximumPatientCount,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3150 bool isReconstruct) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3151 storeStatus_(StoreStatus_Failure),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3152 instanceMetadata_(instanceMetadata),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3153 dicomSummary_(dicomSummary),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3154 attachments_(attachments),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3155 metadata_(metadata),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3156 origin_(origin),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3157 overwrite_(overwrite),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3158 hasTransferSyntax_(hasTransferSyntax),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3159 transferSyntax_(transferSyntax),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3160 hasPixelDataOffset_(hasPixelDataOffset),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3161 pixelDataOffset_(pixelDataOffset),
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3162 pixelDataVR_(pixelDataVR),
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3163 maximumStorageMode_(maximumStorageMode),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3164 maximumStorageSize_(maximumStorageSize),
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3165 maximumPatientCount_(maximumPatientCount),
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3166 isReconstruct_(isReconstruct)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3167 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3168 hasExpectedInstances_ = ComputeExpectedNumberOfInstances(expectedInstances_, dicomSummary);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3169
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3170 instanceMetadata_.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3171
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3172 DicomInstanceHasher hasher(dicomSummary);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3173 hashPatient_ = hasher.HashPatient();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3174 hashStudy_ = hasher.HashStudy();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3175 hashSeries_ = hasher.HashSeries();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3176 hashInstance_ = hasher.HashInstance();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3177 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3178
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3179 StoreStatus GetStoreStatus() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3180 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3181 return storeStatus_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3182 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3183
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3184 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3185 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3186 IDatabaseWrapper::CreateInstanceResult status;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3187 int64_t instanceId;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3188
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3189 bool isNewInstance = transaction.CreateInstance(status, instanceId, hashPatient_,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3190 hashStudy_, hashSeries_, hashInstance_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3191
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3192 if (isReconstruct_ && isNewInstance)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3193 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3194 // In case of reconstruct, we just want to modify the attachments and some metadata like the TransferSyntex
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3195 // The DicomTags and many metadata have already been updated before we get here in ReconstructInstance
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3196 throw OrthancException(ErrorCode_InternalError, "New instance while reconstructing; this should not happen.");
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3197 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3198
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3199 // Check whether this instance is already stored
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3200 if (!isNewInstance && !isReconstruct_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3201 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3202 // The instance already exists
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3203 if (overwrite_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3204 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3205 // Overwrite the old instance
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3206 LOG(INFO) << "Overwriting instance: " << hashInstance_;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3207 transaction.DeleteResource(instanceId);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3208
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3209 // Re-create the instance, now that the old one is removed
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3210 if (!transaction.CreateInstance(status, instanceId, hashPatient_,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3211 hashStudy_, hashSeries_, hashInstance_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3212 {
5456
06eb8bc9f024 raise 409 if multiple clients are writing the same instance at the same time
Alain Mazy <am@osimis.io>
parents: 5455
diff changeset
3213 // Note that, sometime, it does not create a new instance,
06eb8bc9f024 raise 409 if multiple clients are writing the same instance at the same time
Alain Mazy <am@osimis.io>
parents: 5455
diff changeset
3214 // in very rare occasions in READ COMMITTED mode when multiple clients are pushing the same instance at the same time,
06eb8bc9f024 raise 409 if multiple clients are writing the same instance at the same time
Alain Mazy <am@osimis.io>
parents: 5455
diff changeset
3215 // this thread will not create the instance because another thread has created it in the meantime.
06eb8bc9f024 raise 409 if multiple clients are writing the same instance at the same time
Alain Mazy <am@osimis.io>
parents: 5455
diff changeset
3216 // At the end, there is always a thread that creates the instance and this is what we expect.
5464
38f1d06875ad delete attachment in case of same instance being uploaded multiple times at the same time
Alain Mazy <am@osimis.io>
parents: 5456
diff changeset
3217
38f1d06875ad delete attachment in case of same instance being uploaded multiple times at the same time
Alain Mazy <am@osimis.io>
parents: 5456
diff changeset
3218 // Note, we must delete the attachments that have already been stored from this failed insertion (they have not yet been added into the DB)
38f1d06875ad delete attachment in case of same instance being uploaded multiple times at the same time
Alain Mazy <am@osimis.io>
parents: 5456
diff changeset
3219 throw OrthancException(ErrorCode_DuplicateResource, "No new instance while overwriting; this might happen if another client has pushed the same instance at the same time.");
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3220 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3221 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3222 else
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3223 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3224 // Do nothing if the instance already exists and overwriting is disabled
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3225 transaction.GetAllMetadata(instanceMetadata_, instanceId);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3226 storeStatus_ = StoreStatus_AlreadyStored;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3227 return;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3228 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3229 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3230
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3231
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3232 if (!isReconstruct_) // don't signal new resources if this is a reconstruction
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3233 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3234 // Warn about the creation of new resources. The order must be
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3235 // from instance to patient.
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3236
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3237 // NB: In theory, could be sped up by grouping the underlying
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3238 // calls to "transaction.LogChange()". However, this would only have an
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3239 // impact when new patient/study/series get created, which
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3240 // occurs far less often that creating new instances. The
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3241 // positive impact looks marginal in practice.
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3242 transaction.LogChange(instanceId, ChangeType_NewInstance, ResourceType_Instance, hashInstance_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3243
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3244 if (status.isNewSeries_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3245 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3246 transaction.LogChange(status.seriesId_, ChangeType_NewSeries, ResourceType_Series, hashSeries_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3247 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3248
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3249 if (status.isNewStudy_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3250 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3251 transaction.LogChange(status.studyId_, ChangeType_NewStudy, ResourceType_Study, hashStudy_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3252 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3253
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3254 if (status.isNewPatient_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3255 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3256 transaction.LogChange(status.patientId_, ChangeType_NewPatient, ResourceType_Patient, hashPatient_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3257 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3258 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3259
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3260 // Ensure there is enough room in the storage for the new instance
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3261 uint64_t instanceSize = 0;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3262 for (Attachments::const_iterator it = attachments_.begin();
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3263 it != attachments_.end(); ++it)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3264 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3265 instanceSize += it->GetCompressedSize();
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3266 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3267
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3268 if (!isReconstruct_) // reconstruction should not affect recycling
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3269 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3270 if (maximumStorageMode_ == MaxStorageMode_Reject)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3271 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3272 if (transaction.HasReachedMaxStorageSize(maximumStorageSize_, instanceSize))
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3273 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3274 storeStatus_ = StoreStatus_StorageFull;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3275 throw OrthancException(ErrorCode_FullStorage, HttpStatus_507_InsufficientStorage, "Maximum storage size reached"); // throw to cancel the transaction
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3276 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3277 if (transaction.HasReachedMaxPatientCount(maximumPatientCount_, hashPatient_))
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3278 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3279 storeStatus_ = StoreStatus_StorageFull;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3280 throw OrthancException(ErrorCode_FullStorage, HttpStatus_507_InsufficientStorage, "Maximum patient count reached"); // throw to cancel the transaction
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3281 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3282 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3283 else
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3284 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3285 transaction.Recycle(maximumStorageSize_, maximumPatientCount_,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3286 instanceSize, hashPatient_ /* don't consider the current patient for recycling */);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3287 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3288 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3289
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3290 // Attach the files to the newly created instance
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3291 for (Attachments::const_iterator it = attachments_.begin();
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3292 it != attachments_.end(); ++it)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3293 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3294 if (isReconstruct_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3295 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3296 // we are replacing attachments during a reconstruction
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3297 transaction.DeleteAttachment(instanceId, it->GetContentType());
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3298 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3299
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3300 transaction.AddAttachment(instanceId, *it, 0 /* this is the first revision */);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3301 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3302
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3303 if (!isReconstruct_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3304 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3305 ResourcesContent content(true /* new resource, metadata can be set */);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3306
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3307 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3308 for (MetadataMap::const_iterator
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3309 it = metadata_.begin(); it != metadata_.end(); ++it)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3310 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3311 switch (it->first.first)
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3312 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3313 case ResourceType_Patient:
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3314 content.AddMetadata(status.patientId_, it->first.second, it->second);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3315 break;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3316
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3317 case ResourceType_Study:
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3318 content.AddMetadata(status.studyId_, it->first.second, it->second);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3319 break;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3320
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3321 case ResourceType_Series:
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3322 content.AddMetadata(status.seriesId_, it->first.second, it->second);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3323 break;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3324
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3325 case ResourceType_Instance:
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3326 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3327 it->first.second, it->second);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3328 break;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3329
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3330 default:
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3331 throw OrthancException(ErrorCode_ParameterOutOfRange);
5061
e95fadefeb72 new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents: 5044
diff changeset
3332 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3333 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3334
5224
feba2b0e91bc Fix a crash in /tools/reconstruct triggered by the Housekeeper plugin when only changing the StorageCompression.
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
3335 if (!isReconstruct_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3336 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3337 // Populate the tags of the newly-created resources
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3338 content.AddResource(instanceId, ResourceType_Instance, dicomSummary_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3339 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3340 SetMainDicomSequenceMetadata(content, instanceId, dicomSummary_, ResourceType_Instance); // new in Orthanc 1.11.1
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3341
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3342 if (status.isNewSeries_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3343 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3344 content.AddResource(status.seriesId_, ResourceType_Series, dicomSummary_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3345 content.AddMetadata(status.seriesId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3346 SetMainDicomSequenceMetadata(content, status.seriesId_, dicomSummary_, ResourceType_Series); // new in Orthanc 1.11.1
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3347 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3348
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3349 if (status.isNewStudy_)
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3350 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3351 content.AddResource(status.studyId_, ResourceType_Study, dicomSummary_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3352 content.AddMetadata(status.studyId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3353 SetMainDicomSequenceMetadata(content, status.studyId_, dicomSummary_, ResourceType_Study); // new in Orthanc 1.11.1
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3354 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3355
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3356 if (status.isNewPatient_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3357 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3358 content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3359 content.AddMetadata(status.patientId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3360 SetMainDicomSequenceMetadata(content, status.patientId_, dicomSummary_, ResourceType_Patient); // new in Orthanc 1.11.1
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3361 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3362
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3363 // Attach the auto-computed metadata for the patient/study/series levels
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3364 std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3365 content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3366 content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3367 content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3368
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3369 if (status.isNewSeries_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3370 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3371 if (hasExpectedInstances_)
5224
feba2b0e91bc Fix a crash in /tools/reconstruct triggered by the Housekeeper plugin when only changing the StorageCompression.
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
3372 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3373 content.AddMetadata(status.seriesId_, MetadataType_Series_ExpectedNumberOfInstances,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3374 boost::lexical_cast<std::string>(expectedInstances_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3375 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3376
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3377 // New in Orthanc 1.9.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3378 content.AddMetadata(status.seriesId_, MetadataType_RemoteAet,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3379 origin_.GetRemoteAetC());
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3380 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3381 // Attach the auto-computed metadata for the instance level,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3382 // reflecting these additions into the input metadata map
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3383 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3384 MetadataType_Instance_ReceptionDate, now);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3385 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_RemoteAet,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3386 origin_.GetRemoteAetC());
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3387 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_Instance_Origin,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3388 EnumerationToString(origin_.GetRequestOrigin()));
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3389
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3390 std::string s;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3391
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3392 if (origin_.LookupRemoteIp(s))
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3393 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3394 // New in Orthanc 1.4.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3395 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3396 MetadataType_Instance_RemoteIp, s);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3397 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3398
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3399 if (origin_.LookupCalledAet(s))
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3400 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3401 // New in Orthanc 1.4.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3402 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3403 MetadataType_Instance_CalledAet, s);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3404 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3405
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3406 if (origin_.LookupHttpUsername(s))
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3407 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3408 // New in Orthanc 1.4.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3409 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3410 MetadataType_Instance_HttpUsername, s);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3411 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3412 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3413
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3414 // Following metadatas are also updated if reconstructing the instance.
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3415 // They might be missing since they have been introduced along Orthanc versions.
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3416
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3417 if (hasTransferSyntax_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3418 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3419 // New in Orthanc 1.2.0
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3420 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3421 MetadataType_Instance_TransferSyntax,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3422 GetTransferSyntaxUid(transferSyntax_));
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3423 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3424
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3425 if (hasPixelDataOffset_)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3426 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3427 // New in Orthanc 1.9.1
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3428 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3429 MetadataType_Instance_PixelDataOffset,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3430 boost::lexical_cast<std::string>(pixelDataOffset_));
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3431
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3432 // New in Orthanc 1.12.1
5324
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3433 if (dicomSummary_.GuessPixelDataValueRepresentation(transferSyntax_) != pixelDataVR_)
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3434 {
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3435 // Store the VR of pixel data if it doesn't comply with the standard
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3436 SetInstanceMetadata(content, instanceMetadata_, instanceId,
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3437 MetadataType_Instance_PixelDataVR,
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3438 EnumerationToString(pixelDataVR_));
e95caa87fed8 only store PixelDataVR metadata if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5316
diff changeset
3439 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3440 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3441
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3442 const DicomValue* value;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3443 if ((value = dicomSummary_.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL &&
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3444 !value->IsNull() &&
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3445 !value->IsBinary())
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3446 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3447 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3448 MetadataType_Instance_SopClassUid, value->GetContent());
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3449 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3450
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3451
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3452 if ((value = dicomSummary_.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL ||
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3453 (value = dicomSummary_.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3454 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3455 if (!value->IsNull() &&
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3456 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3457 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3458 SetInstanceMetadata(content, instanceMetadata_, instanceId,
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3459 MetadataType_Instance_IndexInSeries, Toolbox::StripSpaces(value->GetContent()));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3460 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3461 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3462
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3463
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3464 transaction.SetResourcesContent(content);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3465 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3466
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3467
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3468 // Check whether the series of this new instance is now completed
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3469 int64_t expectedNumberOfInstances;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3470 if (ComputeExpectedNumberOfInstances(expectedNumberOfInstances, dicomSummary_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3471 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3472 SeriesStatus seriesStatus = transaction.GetSeriesStatus(status.seriesId_, expectedNumberOfInstances);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3473 if (seriesStatus == SeriesStatus_Complete)
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3474 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3475 transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_);
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3476 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3477 }
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3478
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3479 transaction.LogChange(status.seriesId_, ChangeType_NewChildInstance, ResourceType_Series, hashSeries_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3480 transaction.LogChange(status.studyId_, ChangeType_NewChildInstance, ResourceType_Study, hashStudy_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3481 transaction.LogChange(status.patientId_, ChangeType_NewChildInstance, ResourceType_Patient, hashPatient_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3482
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3483 // Mark the parent resources of this instance as unstable
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3484 transaction.GetTransactionContext().MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3485 transaction.GetTransactionContext().MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3486 transaction.GetTransactionContext().MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3487 transaction.GetTransactionContext().SignalAttachmentsAdded(instanceSize);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3488
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3489 storeStatus_ = StoreStatus_Success;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3490 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3491 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3492
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3493
5316
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3494 Operations operations(instanceMetadata, dicomSummary, attachments, metadata, origin, overwrite,
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3495 hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset,
03501a258d9e added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5297
diff changeset
3496 pixelDataVR, maximumStorageMode, maximumStorageSize, maximumPatients, isReconstruct);
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3497
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3498 try
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3499 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3500 Apply(operations);
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3501 return operations.GetStoreStatus();
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3502 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3503 catch (OrthancException& e)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3504 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3505 if (e.GetErrorCode() == ErrorCode_FullStorage)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3506 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3507 return StoreStatus_StorageFull;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3508 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3509 else
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3510 {
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3511 // the transaction has failed -> do not commit the current transaction (and retry)
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3512 throw;
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3513 }
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3514 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3515 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3516
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3517
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3518 StoreStatus StatelessDatabaseOperations::AddAttachment(int64_t& newRevision,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3519 const FileInfo& attachment,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3520 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3521 uint64_t maximumStorageSize,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3522 unsigned int maximumPatients,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3523 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3524 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3525 const std::string& oldMD5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3526 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3527 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3528 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3529 private:
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3530 int64_t& newRevision_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3531 StoreStatus status_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3532 const FileInfo& attachment_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3533 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3534 uint64_t maximumStorageSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3535 unsigned int maximumPatientCount_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3536 bool hasOldRevision_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3537 int64_t oldRevision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3538 const std::string& oldMD5_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3539
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3540 public:
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3541 Operations(int64_t& newRevision,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3542 const FileInfo& attachment,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3543 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3544 uint64_t maximumStorageSize,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3545 unsigned int maximumPatientCount,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3546 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3547 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3548 const std::string& oldMD5) :
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3549 newRevision_(newRevision),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3550 status_(StoreStatus_Failure),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3551 attachment_(attachment),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3552 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3553 maximumStorageSize_(maximumStorageSize),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3554 maximumPatientCount_(maximumPatientCount),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3555 hasOldRevision_(hasOldRevision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3556 oldRevision_(oldRevision),
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3557 oldMD5_(oldMD5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3558 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3559 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3560
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3561 StoreStatus GetStatus() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3562 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3563 return status_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3564 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3565
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3566 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3567 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3568 ResourceType resourceType;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3569 int64_t resourceId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3570 if (!transaction.LookupResource(resourceId, resourceType, publicId_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3571 {
5296
5053a10da5a2 Fix orphan files remaining in storage when working with MaximumStorageSize
Alain Mazy <am@osimis.io>
parents: 5249
diff changeset
3572 throw OrthancException(ErrorCode_InexistentItem, HttpStatus_404_NotFound);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3573 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3574 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3575 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3576 // Possibly remove previous attachment
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3577 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3578 FileInfo oldFile;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3579 int64_t expectedRevision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3580 if (transaction.LookupAttachment(oldFile, expectedRevision, resourceId, attachment_.GetContentType()))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3581 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3582 if (hasOldRevision_ &&
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3583 (expectedRevision != oldRevision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3584 oldFile.GetUncompressedMD5() != oldMD5_))
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3585 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3586 throw OrthancException(ErrorCode_Revision);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3587 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3588 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3589 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3590 newRevision_ = expectedRevision + 1;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3591 transaction.DeleteAttachment(resourceId, attachment_.GetContentType());
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3592 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3593 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3594 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3595 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3596 // The attachment is not existing yet: Ignore "oldRevision"
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3597 // and initialize a new sequence of revisions
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3598 newRevision_ = 0;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3599 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3600 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3601
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3602 // Locate the patient of the target resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3603 int64_t patientId = resourceId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3604 for (;;)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3605 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3606 int64_t parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3607 if (transaction.LookupParent(parent, patientId))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3608 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3609 // We have not reached the patient level yet
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3610 patientId = parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3611 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3612 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3613 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3614 // We have reached the patient level
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3615 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3616 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3617 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3618
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3619 // Possibly apply the recycling mechanism while preserving this patient
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3620 assert(transaction.GetResourceType(patientId) == ResourceType_Patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3621 transaction.Recycle(maximumStorageSize_, maximumPatientCount_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3622 attachment_.GetCompressedSize(), transaction.GetPublicId(patientId));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3623
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3624 transaction.AddAttachment(resourceId, attachment_, newRevision_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3625
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3626 if (IsUserContentType(attachment_.GetContentType()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3627 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3628 transaction.LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3629 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3630
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3631 transaction.GetTransactionContext().SignalAttachmentsAdded(attachment_.GetCompressedSize());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3632
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3633 status_ = StoreStatus_Success;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3634 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3635 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3636 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3637
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3638
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3639 Operations operations(newRevision, attachment, publicId, maximumStorageSize, maximumPatients,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3640 hasOldRevision, oldRevision, oldMD5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3641 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3642 return operations.GetStatus();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3643 }
5221
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3644
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3645
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3646 void StatelessDatabaseOperations::ListLabels(std::set<std::string>& target,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3647 const std::string& publicId,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3648 ResourceType level)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3649 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3650 class Operations : public ReadOnlyOperationsT3<std::set<std::string>&, const std::string&, ResourceType>
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3651 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3652 public:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3653 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3654 const Tuple& tuple) ORTHANC_OVERRIDE
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3655 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3656 ResourceType type;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3657 int64_t id;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3658 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3659 tuple.get<2>() != type)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3660 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3661 throw OrthancException(ErrorCode_UnknownResource);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3662 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3663 else
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3664 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3665 transaction.ListLabels(tuple.get<0>(), id);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3666 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3667 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3668 };
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3669
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3670 Operations operations;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3671 operations.Apply(*this, target, publicId, level);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3672 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3673
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3674
5249
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3675 void StatelessDatabaseOperations::ListAllLabels(std::set<std::string>& target)
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3676 {
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3677 class Operations : public ReadOnlyOperationsT1<std::set<std::string>& >
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3678 {
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3679 public:
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3680 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3681 const Tuple& tuple) ORTHANC_OVERRIDE
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3682 {
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3683 transaction.ListAllLabels(tuple.get<0>());
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3684 }
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3685 };
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3686
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3687 Operations operations;
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3688 operations.Apply(*this, target);
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3689 }
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3690
f22c8fac764b added "/tools/labels" to list all the labels that are associated with any resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5248
diff changeset
3691
5221
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3692 void StatelessDatabaseOperations::ModifyLabel(const std::string& publicId,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3693 ResourceType level,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3694 const std::string& label,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3695 LabelOperation operation)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3696 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3697 class Operations : public IReadWriteOperations
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3698 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3699 private:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3700 const std::string& publicId_;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3701 ResourceType level_;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3702 const std::string& label_;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3703 LabelOperation operation_;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3704
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3705 public:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3706 Operations(const std::string& publicId,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3707 ResourceType level,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3708 const std::string& label,
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3709 LabelOperation operation) :
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3710 publicId_(publicId),
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3711 level_(level),
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3712 label_(label),
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3713 operation_(operation)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3714 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3715 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3716
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3717 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3718 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3719 ResourceType type;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3720 int64_t id;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3721 if (!transaction.LookupResource(id, type, publicId_) ||
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3722 level_ != type)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3723 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3724 throw OrthancException(ErrorCode_UnknownResource);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3725 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3726 else
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3727 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3728 switch (operation_)
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3729 {
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3730 case LabelOperation_Add:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3731 transaction.AddLabel(id, label_);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3732 break;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3733
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3734 case LabelOperation_Remove:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3735 transaction.RemoveLabel(id, label_);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3736 break;
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3737
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3738 default:
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3739 throw OrthancException(ErrorCode_ParameterOutOfRange);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3740 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3741 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3742 }
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3743 };
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3744
5244
72dfa0ac84eb lookup for labels in orthanc explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5238
diff changeset
3745 ServerToolbox::CheckValidLabel(label);
5221
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3746
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3747 Operations operations(publicId, level, label, operation);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3748 Apply(operations);
d0f7c742d397 started implementation of labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5220
diff changeset
3749 }
5238
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3750
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3751
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3752 bool StatelessDatabaseOperations::HasLabelsSupport()
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3753 {
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3754 boost::shared_lock<boost::shared_mutex> lock(mutex_);
5455
176bc05f85f4 DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents: 5324
diff changeset
3755 return db_.GetDatabaseCapabilities().HasLabelsSupport();
5238
367e8af46cfd added "HasLabels" in /system
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5237
diff changeset
3756 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3757 }