Mercurial > hg > orthanc-databases
annotate Framework/Plugins/DatabaseBackendAdapterV4.cpp @ 404:3cd39c8cade9 db-protobuf
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Apr 2023 20:52:09 +0200 |
parents | 91124cc8a8c7 |
children | 7c1fe5d6c12c ecd0b719cff5 |
rev | line source |
---|---|
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
389
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
384
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
384
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Affero General Public License |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Affero General Public License for more details. |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Affero General Public License |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "DatabaseBackendAdapterV4.h" |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
28 #include "IndexConnectionsPool.h" |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
29 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <OrthancDatabasePlugin.pb.h> // Include protobuf messages |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 #include <Logging.h> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #include <OrthancException.h> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include <stdexcept> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include <list> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include <string> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 #include <cassert> |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
41 #define ORTHANC_PLUGINS_DATABASE_CATCH(context) \ |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 namespace OrthancDatabases |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 static bool isBackendInUse_ = false; // Only for sanity checks |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
48 |
376 | 49 static Orthanc::DatabasePluginMessages::ResourceType Convert(OrthancPluginResourceType resourceType) |
50 { | |
51 switch (resourceType) | |
52 { | |
53 case OrthancPluginResourceType_Patient: | |
54 return Orthanc::DatabasePluginMessages::RESOURCE_PATIENT; | |
55 | |
56 case OrthancPluginResourceType_Study: | |
57 return Orthanc::DatabasePluginMessages::RESOURCE_STUDY; | |
58 | |
59 case OrthancPluginResourceType_Series: | |
60 return Orthanc::DatabasePluginMessages::RESOURCE_SERIES; | |
61 | |
62 case OrthancPluginResourceType_Instance: | |
63 return Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE; | |
64 | |
65 default: | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
67 } | |
68 } | |
69 | |
70 | |
71 static OrthancPluginResourceType Convert(Orthanc::DatabasePluginMessages::ResourceType resourceType) | |
72 { | |
73 switch (resourceType) | |
74 { | |
75 case Orthanc::DatabasePluginMessages::RESOURCE_PATIENT: | |
76 return OrthancPluginResourceType_Patient; | |
77 | |
78 case Orthanc::DatabasePluginMessages::RESOURCE_STUDY: | |
79 return OrthancPluginResourceType_Study; | |
80 | |
81 case Orthanc::DatabasePluginMessages::RESOURCE_SERIES: | |
82 return OrthancPluginResourceType_Series; | |
83 | |
84 case Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE: | |
85 return OrthancPluginResourceType_Instance; | |
86 | |
87 default: | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
89 } | |
90 } | |
91 | |
92 | |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
93 static Orthanc::ResourceType Convert2(Orthanc::DatabasePluginMessages::ResourceType resourceType) |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
94 { |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
95 switch (resourceType) |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
96 { |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
97 case Orthanc::DatabasePluginMessages::RESOURCE_PATIENT: |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
98 return Orthanc::ResourceType_Patient; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
99 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
100 case Orthanc::DatabasePluginMessages::RESOURCE_STUDY: |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
101 return Orthanc::ResourceType_Study; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
102 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
103 case Orthanc::DatabasePluginMessages::RESOURCE_SERIES: |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
104 return Orthanc::ResourceType_Series; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
105 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
106 case Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE: |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
107 return Orthanc::ResourceType_Instance; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
108 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
109 default: |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
111 } |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
112 } |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
113 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
114 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
115 class Output : public IDatabaseBackendOutput |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
116 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
117 private: |
377 | 118 Orthanc::DatabasePluginMessages::DeleteAttachment::Response* deleteAttachment_; |
119 Orthanc::DatabasePluginMessages::DeleteResource::Response* deleteResource_; | |
120 Orthanc::DatabasePluginMessages::GetChanges::Response* getChanges_; | |
121 Orthanc::DatabasePluginMessages::GetExportedResources::Response* getExportedResources_; | |
122 Orthanc::DatabasePluginMessages::GetLastChange::Response* getLastChange_; | |
123 Orthanc::DatabasePluginMessages::GetLastExportedResource::Response* getLastExportedResource_; | |
124 Orthanc::DatabasePluginMessages::GetMainDicomTags::Response* getMainDicomTags_; | |
379 | 125 Orthanc::DatabasePluginMessages::LookupAttachment::Response* lookupAttachment_; |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
126 Orthanc::DatabasePluginMessages::LookupResources::Response* lookupResources_; |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
127 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
128 void Clear() |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
129 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
130 deleteAttachment_ = NULL; |
376 | 131 deleteResource_ = NULL; |
132 getChanges_ = NULL; | |
133 getExportedResources_ = NULL; | |
134 getLastChange_ = NULL; | |
377 | 135 getLastExportedResource_ = NULL; |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
136 getMainDicomTags_ = NULL; |
379 | 137 lookupAttachment_ = NULL; |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
138 lookupResources_ = NULL; |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
139 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
140 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
141 public: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
142 Output(Orthanc::DatabasePluginMessages::DeleteAttachment::Response& deleteAttachment) |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
143 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
144 Clear(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
145 deleteAttachment_ = &deleteAttachment; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
146 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
147 |
376 | 148 Output(Orthanc::DatabasePluginMessages::DeleteResource::Response& deleteResource) |
149 { | |
150 Clear(); | |
151 deleteResource_ = &deleteResource; | |
152 } | |
153 | |
154 Output(Orthanc::DatabasePluginMessages::GetChanges::Response& getChanges) | |
155 { | |
156 Clear(); | |
157 getChanges_ = &getChanges; | |
158 } | |
159 | |
160 Output(Orthanc::DatabasePluginMessages::GetExportedResources::Response& getExportedResources) | |
161 { | |
162 Clear(); | |
163 getExportedResources_ = &getExportedResources; | |
164 } | |
165 | |
166 Output(Orthanc::DatabasePluginMessages::GetLastChange::Response& getLastChange) | |
167 { | |
168 Clear(); | |
169 getLastChange_ = &getLastChange; | |
170 } | |
171 | |
377 | 172 Output(Orthanc::DatabasePluginMessages::GetLastExportedResource::Response& getLastExportedResource) |
173 { | |
174 Clear(); | |
175 getLastExportedResource_ = &getLastExportedResource; | |
176 } | |
177 | |
178 Output(Orthanc::DatabasePluginMessages::GetMainDicomTags::Response& getMainDicomTags) | |
179 { | |
180 Clear(); | |
181 getMainDicomTags_ = &getMainDicomTags; | |
182 } | |
183 | |
379 | 184 Output(Orthanc::DatabasePluginMessages::LookupAttachment::Response& lookupAttachment) |
185 { | |
186 Clear(); | |
187 lookupAttachment_ = &lookupAttachment; | |
188 } | |
189 | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
190 Output(Orthanc::DatabasePluginMessages::LookupResources::Response& lookupResources) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
191 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
192 Clear(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
193 lookupResources_ = &lookupResources; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
194 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
195 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
196 virtual void SignalDeletedAttachment(const std::string& uuid, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
197 int32_t contentType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
198 uint64_t uncompressedSize, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
199 const std::string& uncompressedHash, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
200 int32_t compressionType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
201 uint64_t compressedSize, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
202 const std::string& compressedHash) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
203 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
204 Orthanc::DatabasePluginMessages::FileInfo* attachment; |
376 | 205 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
206 if (deleteAttachment_ != NULL) |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
207 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
208 if (deleteAttachment_->has_deleted_attachment()) |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
209 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
210 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
211 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
212 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
213 attachment = deleteAttachment_->mutable_deleted_attachment(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
214 } |
376 | 215 else if (deleteResource_ != NULL) |
216 { | |
217 attachment = deleteResource_->add_deleted_attachments(); | |
218 } | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
219 else |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
220 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
221 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
222 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
223 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
224 attachment->set_uuid(uuid); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
225 attachment->set_content_type(contentType); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
226 attachment->set_uncompressed_size(uncompressedSize); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
227 attachment->set_uncompressed_hash(uncompressedHash); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
228 attachment->set_compression_type(compressionType); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
229 attachment->set_compressed_size(compressedSize); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
230 attachment->set_compressed_hash(compressedHash); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
231 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
232 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
233 virtual void SignalDeletedResource(const std::string& publicId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
234 OrthancPluginResourceType resourceType) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
235 { |
376 | 236 if (deleteResource_ != NULL) |
237 { | |
238 Orthanc::DatabasePluginMessages::DeleteResource_Response_Resource* resource = deleteResource_->add_deleted_resources(); | |
239 resource->set_level(Convert(resourceType)); | |
240 resource->set_public_id(publicId); | |
241 } | |
242 else | |
243 { | |
244 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
245 } | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
246 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
247 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
248 virtual void SignalRemainingAncestor(const std::string& ancestorId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
249 OrthancPluginResourceType ancestorType) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
250 { |
376 | 251 if (deleteResource_ != NULL) |
252 { | |
253 if (deleteResource_->is_remaining_ancestor()) | |
254 { | |
255 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
256 } | |
257 else | |
258 { | |
259 deleteResource_->set_is_remaining_ancestor(true); | |
260 deleteResource_->mutable_remaining_ancestor()->set_level(Convert(ancestorType)); | |
261 deleteResource_->mutable_remaining_ancestor()->set_public_id(ancestorId); | |
262 } | |
263 } | |
264 else | |
265 { | |
266 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
267 } | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
268 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
269 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
270 virtual void AnswerAttachment(const std::string& uuid, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
271 int32_t contentType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
272 uint64_t uncompressedSize, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
273 const std::string& uncompressedHash, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
274 int32_t compressionType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
275 uint64_t compressedSize, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
276 const std::string& compressedHash) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
277 { |
379 | 278 if (lookupAttachment_ != NULL) |
279 { | |
280 if (lookupAttachment_->found()) | |
281 { | |
282 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
283 } | |
284 | |
285 lookupAttachment_->set_found(true); | |
286 lookupAttachment_->mutable_attachment()->set_uuid(uuid); | |
287 lookupAttachment_->mutable_attachment()->set_content_type(contentType); | |
288 lookupAttachment_->mutable_attachment()->set_uncompressed_size(uncompressedSize); | |
289 lookupAttachment_->mutable_attachment()->set_uncompressed_hash(uncompressedHash); | |
290 lookupAttachment_->mutable_attachment()->set_compression_type(compressionType); | |
291 lookupAttachment_->mutable_attachment()->set_compressed_size(compressedSize); | |
292 lookupAttachment_->mutable_attachment()->set_compressed_hash(compressedHash); | |
293 } | |
294 else | |
295 { | |
296 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
297 } | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
298 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
299 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
300 virtual void AnswerChange(int64_t seq, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
301 int32_t changeType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
302 OrthancPluginResourceType resourceType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
303 const std::string& publicId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
304 const std::string& date) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
305 { |
376 | 306 Orthanc::DatabasePluginMessages::ServerIndexChange* change; |
307 | |
308 if (getChanges_ != NULL) | |
309 { | |
310 change = getChanges_->add_changes(); | |
311 } | |
312 else if (getLastChange_ != NULL) | |
313 { | |
379 | 314 if (getLastChange_->found()) |
376 | 315 { |
316 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
317 } | |
318 | |
379 | 319 getLastChange_->set_found(true); |
376 | 320 change = getLastChange_->mutable_change(); |
321 } | |
322 else | |
323 { | |
324 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
325 } | |
326 | |
327 change->set_seq(seq); | |
328 change->set_change_type(changeType); | |
329 change->set_resource_type(Convert(resourceType)); | |
330 change->set_public_id(publicId); | |
331 change->set_date(date); | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
332 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
333 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
334 virtual void AnswerDicomTag(uint16_t group, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
335 uint16_t element, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
336 const std::string& value) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
337 { |
377 | 338 if (getMainDicomTags_ != NULL) |
339 { | |
340 Orthanc::DatabasePluginMessages::GetMainDicomTags_Response_Tag* tag = getMainDicomTags_->add_tags(); | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
341 tag->set_group(group); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
342 tag->set_element(element); |
377 | 343 tag->set_value(value); |
344 } | |
345 else | |
346 { | |
347 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
348 } | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
349 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
350 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
351 virtual void AnswerExportedResource(int64_t seq, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
352 OrthancPluginResourceType resourceType, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
353 const std::string& publicId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
354 const std::string& modality, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
355 const std::string& date, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
356 const std::string& patientId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
357 const std::string& studyInstanceUid, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
358 const std::string& seriesInstanceUid, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
359 const std::string& sopInstanceUid) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
360 { |
377 | 361 Orthanc::DatabasePluginMessages::ExportedResource* resource; |
362 | |
376 | 363 if (getExportedResources_ != NULL) |
364 { | |
377 | 365 resource = getExportedResources_->add_resources(); |
366 } | |
367 else if (getLastExportedResource_ != NULL) | |
368 { | |
379 | 369 if (getLastExportedResource_->found()) |
377 | 370 { |
371 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
372 } | |
373 | |
379 | 374 getLastExportedResource_->set_found(true); |
377 | 375 resource = getLastExportedResource_->mutable_resource(); |
376 | 376 } |
377 else | |
378 { | |
379 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
380 } | |
377 | 381 |
382 resource->set_seq(seq); | |
383 resource->set_resource_type(Convert(resourceType)); | |
384 resource->set_public_id(publicId); | |
385 resource->set_modality(modality); | |
386 resource->set_date(date); | |
387 resource->set_patient_id(patientId); | |
388 resource->set_study_instance_uid(studyInstanceUid); | |
389 resource->set_series_instance_uid(seriesInstanceUid); | |
390 resource->set_sop_instance_uid(sopInstanceUid); | |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
391 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
392 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
393 virtual void AnswerMatchingResource(const std::string& resourceId) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
394 { |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
395 if (lookupResources_ != NULL) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
396 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
397 lookupResources_->add_resources_ids(resourceId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
398 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
399 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
400 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
401 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
402 } |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
403 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
404 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
405 virtual void AnswerMatchingResource(const std::string& resourceId, |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
406 const std::string& someInstanceId) ORTHANC_OVERRIDE |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
407 { |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
408 if (lookupResources_ != NULL) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
409 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
410 lookupResources_->add_resources_ids(resourceId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
411 lookupResources_->add_instances_ids(someInstanceId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
412 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
413 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
414 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
415 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
416 } |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
417 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
418 }; |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
420 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 static void ProcessDatabaseOperation(Orthanc::DatabasePluginMessages::DatabaseResponse& response, |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 const Orthanc::DatabasePluginMessages::DatabaseRequest& request, |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
423 IndexConnectionsPool& pool) |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 switch (request.operation()) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 case Orthanc::DatabasePluginMessages::OPERATION_GET_SYSTEM_INFORMATION: |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
428 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
429 IndexConnectionsPool::Accessor accessor(pool); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
430 response.mutable_get_system_information()->set_database_version(accessor.GetBackend().GetDatabaseVersion(accessor.GetManager())); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
431 response.mutable_get_system_information()->set_supports_flush_to_disk(false); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
432 response.mutable_get_system_information()->set_supports_revisions(accessor.GetBackend().HasRevisionsSupport()); |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
433 response.mutable_get_system_information()->set_supports_labels(accessor.GetBackend().HasLabelsSupport()); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
434 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
435 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
436 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
437 case Orthanc::DatabasePluginMessages::OPERATION_OPEN: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
438 { |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
439 std::list<IdentifierTag> identifierTags; |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
440 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
441 if (request.open().identifier_tags().empty()) |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
442 { |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
443 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
444 "No identifier tag was provided by the Orthanc core"); |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
445 } |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
446 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
447 for (int i = 0; i < request.open().identifier_tags().size(); i++) |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
448 { |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
449 const Orthanc::DatabasePluginMessages::Open_Request_IdentifierTag& tag = request.open().identifier_tags(i); |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
450 identifierTags.push_back(IdentifierTag(Convert2(tag.level()), |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
451 Orthanc::DicomTag(tag.group(), tag.element()), |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
452 tag.name())); |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
453 } |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
454 |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
455 pool.OpenConnections(true, identifierTags); |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
456 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
457 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
458 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
459 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
460 case Orthanc::DatabasePluginMessages::OPERATION_CLOSE: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
461 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
462 pool.CloseConnections(); |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
463 break; |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
464 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
465 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
466 case Orthanc::DatabasePluginMessages::OPERATION_FLUSH_TO_DISK: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
467 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
468 // Raise an exception since "set_supports_flush_to_disk(false)" |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
469 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
470 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
471 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
472 case Orthanc::DatabasePluginMessages::OPERATION_START_TRANSACTION: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
473 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
474 std::unique_ptr<IndexConnectionsPool::Accessor> transaction(new IndexConnectionsPool::Accessor(pool)); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
475 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
476 switch (request.start_transaction().type()) |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
477 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
478 case Orthanc::DatabasePluginMessages::TRANSACTION_READ_ONLY: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
479 transaction->GetManager().StartTransaction(TransactionType_ReadOnly); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
480 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
481 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
482 case Orthanc::DatabasePluginMessages::TRANSACTION_READ_WRITE: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
483 transaction->GetManager().StartTransaction(TransactionType_ReadWrite); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
484 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
485 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
486 default: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
487 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
488 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
489 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
490 response.mutable_start_transaction()->set_transaction(reinterpret_cast<intptr_t>(transaction.release())); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
491 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
492 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
493 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
494 case Orthanc::DatabasePluginMessages::OPERATION_UPGRADE: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
495 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
496 IndexConnectionsPool::Accessor accessor(pool); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
497 OrthancPluginStorageArea* storageArea = reinterpret_cast<OrthancPluginStorageArea*>(request.upgrade().storage_area()); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
498 accessor.GetBackend().UpgradeDatabase(accessor.GetManager(), request.upgrade().target_version(), storageArea); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
499 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
500 } |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 |
382
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
502 case Orthanc::DatabasePluginMessages::OPERATION_FINALIZE_TRANSACTION: |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
503 { |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
504 IndexConnectionsPool::Accessor* transaction = reinterpret_cast<IndexConnectionsPool::Accessor*>(request.finalize_transaction().transaction()); |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
505 |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
506 if (transaction == NULL) |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
507 { |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
508 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
509 } |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
510 else |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
511 { |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
512 delete transaction; |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
513 } |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
514 |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
515 break; |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
516 } |
97f12bcd1826
implemented finalize_transaction()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
517 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
518 default: |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
519 LOG(ERROR) << "Not implemented database operation from protobuf: " << request.operation(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
520 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
521 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
522 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
523 |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
524 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
525 static void ApplyLookupResources(Orthanc::DatabasePluginMessages::LookupResources_Response& response, |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
526 const Orthanc::DatabasePluginMessages::LookupResources_Request& request, |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
527 IndexBackend& backend, |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
528 DatabaseManager& manager) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
529 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
530 std::vector<Orthanc::DatabaseConstraint> lookup; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
531 lookup.reserve(request.lookup().size()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
532 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
533 size_t countValues = 0; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
534 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
535 for (int i = 0; i < request.lookup().size(); i++) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
536 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
537 const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint = request.lookup(i); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
538 countValues += constraint.values().size(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
539 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
540 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
541 std::vector<const char*> values; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
542 values.reserve(countValues); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
543 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
544 for (int i = 0; i < request.lookup().size(); i++) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
545 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
546 const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint = request.lookup(i); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
547 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
548 if (constraint.tag_group() > 0xffffu || |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
549 constraint.tag_element() > 0xffffu) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
550 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
551 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
552 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
553 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
554 OrthancPluginDatabaseConstraint c; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
555 c.level = Convert(constraint.level()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
556 c.tagGroup = constraint.tag_group(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
557 c.tagElement = constraint.tag_element(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
558 c.isIdentifierTag = (constraint.is_identifier_tag() ? 1 : 0); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
559 c.isCaseSensitive = (constraint.is_case_sensitive() ? 1 : 0); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
560 c.isMandatory = (constraint.is_mandatory() ? 1 : 0); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
561 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
562 switch (constraint.type()) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
563 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
564 case Orthanc::DatabasePluginMessages::CONSTRAINT_EQUAL: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
565 c.type = OrthancPluginConstraintType_Equal; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
566 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
567 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
568 case Orthanc::DatabasePluginMessages::CONSTRAINT_SMALLER_OR_EQUAL: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
569 c.type = OrthancPluginConstraintType_SmallerOrEqual; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
570 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
571 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
572 case Orthanc::DatabasePluginMessages::CONSTRAINT_GREATER_OR_EQUAL: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
573 c.type = OrthancPluginConstraintType_GreaterOrEqual; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
574 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
575 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
576 case Orthanc::DatabasePluginMessages::CONSTRAINT_WILDCARD: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
577 c.type = OrthancPluginConstraintType_Wildcard; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
578 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
579 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
580 case Orthanc::DatabasePluginMessages::CONSTRAINT_LIST: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
581 c.type = OrthancPluginConstraintType_List; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
582 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
583 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
584 default: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
585 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
586 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
587 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
588 c.valuesCount = constraint.values().size(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
589 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
590 if (c.valuesCount == 0) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
591 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
592 c.values = NULL; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
593 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
594 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
595 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
596 c.values = &values[values.size()]; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
597 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
598 for (int j = 0; j < constraint.values().size(); j++) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
599 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
600 assert(values.size() < countValues); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
601 values.push_back(constraint.values(j).c_str()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
602 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
603 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
604 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
605 lookup.push_back(Orthanc::DatabaseConstraint(c)); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
606 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
607 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
608 assert(values.size() == countValues); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
609 |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
610 std::set<std::string> labels; |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
611 |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
612 for (int i = 0; i < request.labels().size(); i++) |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
613 { |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
614 labels.insert(request.labels(i)); |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
615 } |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
616 |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
617 Orthanc::LabelsConstraint labelsConstraint; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
618 switch (request.labels_constraint()) |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
619 { |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
620 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_ALL: |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
621 labelsConstraint = Orthanc::LabelsConstraint_All; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
622 break; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
623 |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
624 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_ANY: |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
625 labelsConstraint = Orthanc::LabelsConstraint_Any; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
626 break; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
627 |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
628 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_NONE: |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
629 labelsConstraint = Orthanc::LabelsConstraint_None; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
630 break; |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
631 |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
632 default: |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
633 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
634 } |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
635 |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
636 Output output(response); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
637 backend.LookupResources(output, manager, lookup, Convert(request.query_level()), |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
638 labels, labelsConstraint, request.limit(), request.retrieve_instances_ids()); |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
639 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
640 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
641 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
642 static void ProcessTransactionOperation(Orthanc::DatabasePluginMessages::TransactionResponse& response, |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
643 const Orthanc::DatabasePluginMessages::TransactionRequest& request, |
377 | 644 IndexBackend& backend, |
645 DatabaseManager& manager) | |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
646 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
647 switch (request.operation()) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
648 { |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
649 case Orthanc::DatabasePluginMessages::OPERATION_ROLLBACK: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
650 { |
377 | 651 manager.RollbackTransaction(); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
652 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
653 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
654 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
655 case Orthanc::DatabasePluginMessages::OPERATION_COMMIT: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
656 { |
377 | 657 manager.CommitTransaction(); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
658 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
659 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
660 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
661 case Orthanc::DatabasePluginMessages::OPERATION_ADD_ATTACHMENT: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
662 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
663 OrthancPluginAttachment attachment; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
664 attachment.uuid = request.add_attachment().attachment().uuid().c_str(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
665 attachment.contentType = request.add_attachment().attachment().content_type(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
666 attachment.uncompressedSize = request.add_attachment().attachment().uncompressed_size(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
667 attachment.uncompressedHash = request.add_attachment().attachment().uncompressed_hash().c_str(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
668 attachment.compressionType = request.add_attachment().attachment().compression_type(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
669 attachment.compressedSize = request.add_attachment().attachment().compressed_size(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
670 attachment.compressedHash = request.add_attachment().attachment().compressed_hash().c_str(); |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
671 |
377 | 672 backend.AddAttachment(manager, request.add_attachment().id(), attachment, request.add_attachment().revision()); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
673 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
674 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
675 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
676 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_CHANGES: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
677 { |
377 | 678 backend.ClearChanges(manager); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
679 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
680 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
681 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
682 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_EXPORTED_RESOURCES: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
683 { |
377 | 684 backend.ClearExportedResources(manager); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
685 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
686 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
687 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
688 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_ATTACHMENT: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
689 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
690 Output output(*response.mutable_delete_attachment()); |
377 | 691 backend.DeleteAttachment(output, manager, request.delete_attachment().id(), request.delete_attachment().type()); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
692 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
693 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
694 |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
695 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_METADATA: |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
696 { |
377 | 697 backend.DeleteMetadata(manager, request.delete_metadata().id(), request.delete_metadata().type()); |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
698 break; |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
699 } |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
700 |
376 | 701 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_RESOURCE: |
702 { | |
703 response.mutable_delete_resource()->set_is_remaining_ancestor(false); | |
704 | |
705 Output output(*response.mutable_delete_resource()); | |
377 | 706 backend.DeleteResource(output, manager, request.delete_resource().id()); |
376 | 707 break; |
708 } | |
709 | |
710 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_METADATA: | |
711 { | |
712 typedef std::map<int32_t, std::string> Values; | |
713 | |
714 Values values; | |
377 | 715 backend.GetAllMetadata(values, manager, request.get_all_metadata().id()); |
376 | 716 |
384 | 717 response.mutable_get_all_metadata()->mutable_metadata()->Reserve(values.size()); |
376 | 718 for (Values::const_iterator it = values.begin(); it != values.end(); ++it) |
719 { | |
377 | 720 Orthanc::DatabasePluginMessages::GetAllMetadata_Response_Metadata* metadata = |
721 response.mutable_get_all_metadata()->add_metadata(); | |
376 | 722 metadata->set_type(it->first); |
723 metadata->set_value(it->second); | |
724 } | |
725 | |
726 break; | |
727 } | |
728 | |
729 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS: | |
730 { | |
731 std::list<std::string> values; | |
377 | 732 backend.GetAllPublicIds(values, manager, Convert(request.get_all_public_ids().resource_type())); |
376 | 733 |
384 | 734 response.mutable_get_all_public_ids()->mutable_ids()->Reserve(values.size()); |
376 | 735 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) |
736 { | |
737 response.mutable_get_all_public_ids()->add_ids(*it); | |
738 } | |
739 | |
740 break; | |
741 } | |
742 | |
743 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS_WITH_LIMITS: | |
744 { | |
745 std::list<std::string> values; | |
377 | 746 backend.GetAllPublicIds(values, manager, Convert(request.get_all_public_ids_with_limits().resource_type()), |
747 request.get_all_public_ids_with_limits().since(), | |
748 request.get_all_public_ids_with_limits().limit()); | |
376 | 749 |
384 | 750 response.mutable_get_all_public_ids_with_limits()->mutable_ids()->Reserve(values.size()); |
376 | 751 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) |
752 { | |
753 response.mutable_get_all_public_ids_with_limits()->add_ids(*it); | |
754 } | |
755 | |
756 break; | |
757 } | |
758 | |
759 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES: | |
760 { | |
761 Output output(*response.mutable_get_changes()); | |
762 | |
763 bool done; | |
377 | 764 backend.GetChanges(output, done, manager, request.get_changes().since(), request.get_changes().limit()); |
376 | 765 |
766 response.mutable_get_changes()->set_done(done); | |
767 break; | |
768 } | |
769 | |
770 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_INTERNAL_ID: | |
771 { | |
772 std::list<int64_t> values; | |
377 | 773 backend.GetChildrenInternalId(values, manager, request.get_children_internal_id().id()); |
376 | 774 |
384 | 775 response.mutable_get_children_internal_id()->mutable_ids()->Reserve(values.size()); |
376 | 776 for (std::list<int64_t>::const_iterator it = values.begin(); it != values.end(); ++it) |
777 { | |
778 response.mutable_get_children_internal_id()->add_ids(*it); | |
779 } | |
780 | |
781 break; | |
782 } | |
783 | |
784 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_PUBLIC_ID: | |
785 { | |
786 std::list<std::string> values; | |
377 | 787 backend.GetChildrenPublicId(values, manager, request.get_children_public_id().id()); |
376 | 788 |
384 | 789 response.mutable_get_children_public_id()->mutable_ids()->Reserve(values.size()); |
376 | 790 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) |
791 { | |
792 response.mutable_get_children_public_id()->add_ids(*it); | |
793 } | |
794 | |
795 break; | |
796 } | |
797 | |
798 case Orthanc::DatabasePluginMessages::OPERATION_GET_EXPORTED_RESOURCES: | |
799 { | |
800 Output output(*response.mutable_get_exported_resources()); | |
801 | |
802 bool done; | |
377 | 803 backend.GetExportedResources(output, done, manager, request.get_exported_resources().since(), |
804 request.get_exported_resources().limit()); | |
376 | 805 |
806 response.mutable_get_exported_resources()->set_done(done); | |
807 break; | |
808 } | |
809 | |
810 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE: | |
811 { | |
379 | 812 response.mutable_get_last_change()->set_found(false); |
376 | 813 |
814 Output output(*response.mutable_get_last_change()); | |
377 | 815 backend.GetLastChange(output, manager); |
816 break; | |
817 } | |
818 | |
819 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_EXPORTED_RESOURCE: | |
820 { | |
379 | 821 response.mutable_get_last_exported_resource()->set_found(false); |
377 | 822 |
823 Output output(*response.mutable_get_last_exported_resource()); | |
824 backend.GetLastExportedResource(output, manager); | |
825 break; | |
826 } | |
827 | |
828 case Orthanc::DatabasePluginMessages::OPERATION_GET_MAIN_DICOM_TAGS: | |
829 { | |
830 Output output(*response.mutable_get_main_dicom_tags()); | |
831 backend.GetMainDicomTags(output, manager, request.get_main_dicom_tags().id()); | |
376 | 832 break; |
833 } | |
834 | |
377 | 835 case Orthanc::DatabasePluginMessages::OPERATION_GET_PUBLIC_ID: |
836 { | |
837 const std::string id = backend.GetPublicId(manager, request.get_public_id().id()); | |
838 response.mutable_get_public_id()->set_id(id); | |
839 break; | |
840 } | |
841 | |
842 case Orthanc::DatabasePluginMessages::OPERATION_GET_RESOURCES_COUNT: | |
843 { | |
844 OrthancPluginResourceType type = Convert(request.get_resources_count().type()); | |
845 uint64_t count = backend.GetResourcesCount(manager, type); | |
846 response.mutable_get_resources_count()->set_count(count); | |
847 break; | |
848 } | |
849 | |
850 case Orthanc::DatabasePluginMessages::OPERATION_GET_RESOURCE_TYPE: | |
851 { | |
384 | 852 OrthancPluginResourceType type = backend.GetResourceType(manager, request.get_resource_type().id()); |
377 | 853 response.mutable_get_resource_type()->set_type(Convert(type)); |
854 break; | |
855 } | |
856 | |
857 case Orthanc::DatabasePluginMessages::OPERATION_GET_TOTAL_COMPRESSED_SIZE: | |
858 { | |
859 response.mutable_get_total_compressed_size()->set_size(backend.GetTotalCompressedSize(manager)); | |
860 break; | |
861 } | |
862 | |
863 case Orthanc::DatabasePluginMessages::OPERATION_GET_TOTAL_UNCOMPRESSED_SIZE: | |
864 { | |
865 response.mutable_get_total_uncompressed_size()->set_size(backend.GetTotalUncompressedSize(manager)); | |
866 break; | |
867 } | |
868 | |
378
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
869 case Orthanc::DatabasePluginMessages::OPERATION_IS_PROTECTED_PATIENT: |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
870 { |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
871 bool isProtected = backend.IsProtectedPatient(manager, request.is_protected_patient().patient_id()); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
872 response.mutable_is_protected_patient()->set_protected_patient(isProtected); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
873 break; |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
874 } |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
875 |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
876 case Orthanc::DatabasePluginMessages::OPERATION_LIST_AVAILABLE_ATTACHMENTS: |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
877 { |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
878 std::list<int32_t> values; |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
879 backend.ListAvailableAttachments(values, manager, request.list_available_attachments().id()); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
880 |
384 | 881 response.mutable_list_available_attachments()->mutable_attachments()->Reserve(values.size()); |
378
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
882 for (std::list<int32_t>::const_iterator it = values.begin(); it != values.end(); ++it) |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
883 { |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
884 response.mutable_list_available_attachments()->add_attachments(*it); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
885 } |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
886 |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
887 break; |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
888 } |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
889 |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
890 case Orthanc::DatabasePluginMessages::OPERATION_LOG_CHANGE: |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
891 { |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
892 backend.LogChange(manager, request.log_change().change_type(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
893 request.log_change().resource_id(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
894 Convert(request.log_change().resource_type()), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
895 request.log_change().date().c_str()); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
896 break; |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
897 } |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
898 |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
899 case Orthanc::DatabasePluginMessages::OPERATION_LOG_EXPORTED_RESOURCE: |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
900 { |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
901 backend.LogExportedResource(manager, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
902 Convert(request.log_exported_resource().resource_type()), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
903 request.log_exported_resource().public_id().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
904 request.log_exported_resource().modality().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
905 request.log_exported_resource().date().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
906 request.log_exported_resource().patient_id().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
907 request.log_exported_resource().study_instance_uid().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
908 request.log_exported_resource().series_instance_uid().c_str(), |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
909 request.log_exported_resource().sop_instance_uid().c_str()); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
910 break; |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
911 } |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
912 |
379 | 913 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_ATTACHMENT: |
914 { | |
915 Output output(*response.mutable_lookup_attachment()); | |
916 | |
917 int64_t revision = -1; | |
918 backend.LookupAttachment(output, revision, manager, request.lookup_attachment().id(), request.lookup_attachment().content_type()); | |
919 | |
920 if (response.lookup_attachment().found()) | |
921 { | |
922 response.mutable_lookup_attachment()->set_revision(revision); | |
923 } | |
924 | |
925 break; | |
926 } | |
927 | |
928 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_GLOBAL_PROPERTY: | |
929 { | |
930 std::string value; | |
931 if (backend.LookupGlobalProperty(value, manager, request.lookup_global_property().server_id().c_str(), | |
932 request.lookup_global_property().property())) | |
933 { | |
934 response.mutable_lookup_global_property()->set_found(true); | |
935 response.mutable_lookup_global_property()->set_value(value); | |
936 } | |
937 else | |
938 { | |
939 response.mutable_lookup_global_property()->set_found(false); | |
940 } | |
941 | |
942 break; | |
943 } | |
944 | |
945 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_METADATA: | |
946 { | |
947 std::string value; | |
948 int64_t revision = -1; | |
949 if (backend.LookupMetadata(value, revision, manager, request.lookup_metadata().id(), request.lookup_metadata().metadata_type())) | |
950 { | |
951 response.mutable_lookup_metadata()->set_found(true); | |
952 response.mutable_lookup_metadata()->set_value(value); | |
953 response.mutable_lookup_metadata()->set_revision(revision); | |
954 } | |
955 else | |
956 { | |
957 response.mutable_lookup_metadata()->set_found(false); | |
958 } | |
959 | |
960 break; | |
961 } | |
962 | |
963 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_PARENT: | |
964 { | |
965 int64_t parent = -1; | |
966 if (backend.LookupParent(parent, manager, request.lookup_parent().id())) | |
967 { | |
968 response.mutable_lookup_parent()->set_found(true); | |
969 response.mutable_lookup_parent()->set_parent(parent); | |
970 } | |
971 else | |
972 { | |
973 response.mutable_lookup_parent()->set_found(false); | |
974 } | |
975 | |
976 break; | |
977 } | |
978 | |
979 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE: | |
980 { | |
981 int64_t internalId = -1; | |
982 OrthancPluginResourceType type; | |
983 if (backend.LookupResource(internalId, type, manager, request.lookup_resource().public_id().c_str())) | |
984 { | |
985 response.mutable_lookup_resource()->set_found(true); | |
986 response.mutable_lookup_resource()->set_internal_id(internalId); | |
987 response.mutable_lookup_resource()->set_type(Convert(type)); | |
988 } | |
989 else | |
990 { | |
991 response.mutable_lookup_resource()->set_found(false); | |
992 } | |
993 | |
994 break; | |
995 } | |
996 | |
997 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE: | |
998 { | |
999 int64_t patientId = -1; | |
1000 if (backend.SelectPatientToRecycle(patientId, manager)) | |
1001 { | |
1002 response.mutable_select_patient_to_recycle()->set_found(true); | |
1003 response.mutable_select_patient_to_recycle()->set_patient_id(patientId); | |
1004 } | |
1005 else | |
1006 { | |
1007 response.mutable_select_patient_to_recycle()->set_found(false); | |
1008 } | |
1009 | |
1010 break; | |
1011 } | |
1012 | |
1013 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE_WITH_AVOID: | |
1014 { | |
1015 int64_t patientId = -1; | |
1016 if (backend.SelectPatientToRecycle(patientId, manager, request.select_patient_to_recycle_with_avoid().patient_id_to_avoid())) | |
1017 { | |
1018 response.mutable_select_patient_to_recycle_with_avoid()->set_found(true); | |
1019 response.mutable_select_patient_to_recycle_with_avoid()->set_patient_id(patientId); | |
1020 } | |
1021 else | |
1022 { | |
1023 response.mutable_select_patient_to_recycle_with_avoid()->set_found(false); | |
1024 } | |
1025 | |
1026 break; | |
1027 } | |
1028 | |
1029 case Orthanc::DatabasePluginMessages::OPERATION_SET_GLOBAL_PROPERTY: | |
1030 { | |
1031 backend.SetGlobalProperty(manager, request.set_global_property().server_id().c_str(), | |
1032 request.set_global_property().property(), | |
1033 request.set_global_property().value().c_str()); | |
1034 break; | |
1035 } | |
1036 | |
1037 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_MAIN_DICOM_TAGS: | |
1038 { | |
1039 backend.ClearMainDicomTags(manager, request.clear_main_dicom_tags().id()); | |
1040 break; | |
1041 } | |
1042 | |
1043 case Orthanc::DatabasePluginMessages::OPERATION_SET_METADATA: | |
1044 { | |
1045 backend.SetMetadata(manager, request.set_metadata().id(), | |
1046 request.set_metadata().metadata_type(), | |
1047 request.set_metadata().value().c_str(), | |
1048 request.set_metadata().revision()); | |
1049 break; | |
1050 } | |
1051 | |
1052 case Orthanc::DatabasePluginMessages::OPERATION_SET_PROTECTED_PATIENT: | |
1053 { | |
1054 backend.SetProtectedPatient(manager, request.set_protected_patient().patient_id(), | |
1055 request.set_protected_patient().protected_patient()); | |
1056 break; | |
1057 } | |
1058 | |
1059 case Orthanc::DatabasePluginMessages::OPERATION_IS_DISK_SIZE_ABOVE: | |
1060 { | |
1061 bool above = (backend.GetTotalCompressedSize(manager) >= request.is_disk_size_above().threshold()); | |
1062 response.mutable_is_disk_size_above()->set_result(above); | |
1063 break; | |
1064 } | |
1065 | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1066 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCES: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1067 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1068 ApplyLookupResources(*response.mutable_lookup_resources(), request.lookup_resources(), backend, manager); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1069 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1070 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1071 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1072 case Orthanc::DatabasePluginMessages::OPERATION_CREATE_INSTANCE: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1073 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1074 const char* hashPatient = request.create_instance().patient().c_str(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1075 const char* hashStudy = request.create_instance().study().c_str(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1076 const char* hashSeries = request.create_instance().series().c_str(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1077 const char* hashInstance = request.create_instance().instance().c_str(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1078 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1079 OrthancPluginCreateInstanceResult result; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1080 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1081 if (backend.HasCreateInstance()) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1082 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1083 backend.CreateInstance(result, manager, hashPatient, hashStudy, hashSeries, hashInstance); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1084 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1085 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1086 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1087 backend.CreateInstanceGeneric(result, manager, hashPatient, hashStudy, hashSeries, hashInstance); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1088 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1089 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1090 response.mutable_create_instance()->set_is_new_instance(result.isNewInstance); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1091 response.mutable_create_instance()->set_instance_id(result.instanceId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1092 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1093 if (result.isNewInstance) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1094 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1095 response.mutable_create_instance()->set_is_new_patient(result.isNewPatient); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1096 response.mutable_create_instance()->set_is_new_study(result.isNewStudy); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1097 response.mutable_create_instance()->set_is_new_series(result.isNewSeries); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1098 response.mutable_create_instance()->set_patient_id(result.patientId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1099 response.mutable_create_instance()->set_study_id(result.studyId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1100 response.mutable_create_instance()->set_series_id(result.seriesId); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1101 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1102 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1103 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1104 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1105 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1106 case Orthanc::DatabasePluginMessages::OPERATION_SET_RESOURCES_CONTENT: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1107 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1108 std::vector<OrthancPluginResourcesContentTags> identifierTags; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1109 std::vector<OrthancPluginResourcesContentTags> mainDicomTags; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1110 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1111 identifierTags.reserve(request.set_resources_content().tags().size()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1112 mainDicomTags.reserve(request.set_resources_content().tags().size()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1113 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1114 for (int i = 0; i < request.set_resources_content().tags().size(); i++) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1115 { |
383 | 1116 if (request.set_resources_content().tags(i).group() > 0xffffu || |
1117 request.set_resources_content().tags(i).element() > 0xffffu) | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1118 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1119 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1120 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1121 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1122 OrthancPluginResourcesContentTags tag; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1123 tag.resource = request.set_resources_content().tags(i).resource_id(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1124 tag.group = request.set_resources_content().tags(i).group(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1125 tag.element = request.set_resources_content().tags(i).element(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1126 tag.value = request.set_resources_content().tags(i).value().c_str(); |
384 | 1127 |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1128 if (request.set_resources_content().tags(i).is_identifier()) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1129 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1130 identifierTags.push_back(tag); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1131 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1132 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1133 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1134 mainDicomTags.push_back(tag); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1135 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1136 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1137 |
384 | 1138 std::vector<OrthancPluginResourcesContentMetadata> metadata; |
1139 metadata.reserve(request.set_resources_content().metadata().size()); | |
1140 | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1141 for (int i = 0; i < request.set_resources_content().metadata().size(); i++) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1142 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1143 OrthancPluginResourcesContentMetadata item; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1144 item.resource = request.set_resources_content().metadata(i).resource_id(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1145 item.metadata = request.set_resources_content().metadata(i).metadata(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1146 item.value = request.set_resources_content().metadata(i).value().c_str(); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1147 metadata.push_back(item); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1148 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1149 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1150 backend.SetResourcesContent(manager, |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1151 identifierTags.size(), (identifierTags.empty() ? NULL : &identifierTags[0]), |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1152 mainDicomTags.size(), (mainDicomTags.empty() ? NULL : &mainDicomTags[0]), |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1153 metadata.size(), (metadata.empty() ? NULL : &metadata[0])); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1154 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1155 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1156 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1157 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_METADATA: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1158 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1159 std::list<std::string> values; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1160 backend.GetChildrenMetadata(values, manager, request.get_children_metadata().id(), request.get_children_metadata().metadata()); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1161 |
384 | 1162 response.mutable_get_children_metadata()->mutable_values()->Reserve(values.size()); |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1163 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1164 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1165 response.mutable_get_children_metadata()->add_values(*it); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1166 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1167 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1168 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1169 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1170 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1171 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE_INDEX: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1172 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1173 response.mutable_get_last_change_index()->set_result(backend.GetLastChangeIndex(manager)); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1174 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1175 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1176 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1177 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE_AND_PARENT: |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1178 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1179 int64_t id; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1180 OrthancPluginResourceType type; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1181 std::string parent; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1182 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1183 if (backend.LookupResourceAndParent(id, type, parent, manager, request.lookup_resource_and_parent().public_id().c_str())) |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1184 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1185 response.mutable_lookup_resource_and_parent()->set_found(true); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1186 response.mutable_lookup_resource_and_parent()->set_id(id); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1187 response.mutable_lookup_resource_and_parent()->set_type(Convert(type)); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1188 |
384 | 1189 switch (type) |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1190 { |
384 | 1191 case OrthancPluginResourceType_Study: |
1192 case OrthancPluginResourceType_Series: | |
1193 case OrthancPluginResourceType_Instance: | |
1194 if (parent.empty()) | |
1195 { | |
1196 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1197 } | |
1198 else | |
1199 { | |
1200 response.mutable_lookup_resource_and_parent()->set_parent_public_id(parent); | |
1201 } | |
1202 break; | |
1203 | |
1204 case OrthancPluginResourceType_Patient: | |
1205 if (!parent.empty()) | |
1206 { | |
1207 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1208 } | |
1209 break; | |
1210 | |
1211 default: | |
1212 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
380
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1213 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1214 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1215 else |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1216 { |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1217 response.mutable_lookup_resource_and_parent()->set_found(false); |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1218 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1219 |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1220 break; |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1221 } |
cb91096fef06
implemented full protobuf api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
379
diff
changeset
|
1222 |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1223 case Orthanc::DatabasePluginMessages::OPERATION_ADD_LABEL: |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1224 { |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1225 backend.AddLabel(manager, request.add_label().id(), request.add_label().label()); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1226 break; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1227 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1228 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1229 case Orthanc::DatabasePluginMessages::OPERATION_REMOVE_LABEL: |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1230 { |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1231 backend.RemoveLabel(manager, request.remove_label().id(), request.remove_label().label()); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1232 break; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1233 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1234 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1235 case Orthanc::DatabasePluginMessages::OPERATION_LIST_LABELS: |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1236 { |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1237 std::list<std::string> labels; |
402
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1238 |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1239 if (request.list_labels().single_resource()) |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1240 { |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1241 backend.ListLabels(labels, manager, request.list_labels().id()); |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1242 } |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1243 else |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1244 { |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1245 backend.ListAllLabels(labels, manager); |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
1246 } |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1247 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1248 response.mutable_list_available_attachments()->mutable_attachments()->Reserve(labels.size()); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1249 for (std::list<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it) |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1250 { |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1251 response.mutable_list_labels()->add_labels(*it); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1252 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1253 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1254 break; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1255 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
1256 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1257 default: |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1258 LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1259 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1260 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1261 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1262 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1263 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1264 static OrthancPluginErrorCode CallBackend(OrthancPluginMemoryBuffer64* serializedResponse, |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1265 void* rawPool, |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1266 const void* requestData, |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1267 uint64_t requestSize) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1268 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1269 Orthanc::DatabasePluginMessages::Request request; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1270 if (!request.ParseFromArray(requestData, requestSize)) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1271 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1272 LOG(ERROR) << "Cannot parse message from the Orthanc core using protobuf"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1273 return OrthancPluginErrorCode_InternalError; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1274 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1275 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1276 if (rawPool == NULL) |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1277 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1278 LOG(ERROR) << "Received a NULL pointer from the database"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1279 return OrthancPluginErrorCode_InternalError; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1280 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1281 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1282 IndexConnectionsPool& pool = *reinterpret_cast<IndexConnectionsPool*>(rawPool); |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1283 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1284 try |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1285 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1286 Orthanc::DatabasePluginMessages::Response response; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1287 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1288 switch (request.type()) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1289 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1290 case Orthanc::DatabasePluginMessages::REQUEST_DATABASE: |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1291 ProcessDatabaseOperation(*response.mutable_database_response(), request.database_request(), pool); |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1292 break; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1293 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1294 case Orthanc::DatabasePluginMessages::REQUEST_TRANSACTION: |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1295 { |
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1296 IndexConnectionsPool::Accessor& transaction = *reinterpret_cast<IndexConnectionsPool::Accessor*>(request.transaction_request().transaction()); |
377 | 1297 ProcessTransactionOperation(*response.mutable_transaction_response(), request.transaction_request(), |
1298 transaction.GetBackend(), transaction.GetManager()); | |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1299 break; |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1300 } |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1301 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1302 default: |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1303 LOG(ERROR) << "Not implemented request type from protobuf: " << request.type(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1304 break; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1305 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1306 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1307 std::string s; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1308 if (!response.SerializeToString(&s)) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1309 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1310 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Cannot serialize to protobuf"); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1311 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1312 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1313 if (OrthancPluginCreateMemoryBuffer64(pool.GetContext(), serializedResponse, s.size()) != OrthancPluginErrorCode_Success) |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1314 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1315 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory, "Cannot allocate a memory buffer"); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1316 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1317 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1318 if (!s.empty()) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1319 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1320 assert(serializedResponse->size == s.size()); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1321 memcpy(serializedResponse->data, s.c_str(), s.size()); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1322 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1323 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1324 return OrthancPluginErrorCode_Success; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1325 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1326 catch (::Orthanc::OrthancException& e) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1327 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1328 LOG(ERROR) << "Exception in database back-end: " << e.What(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1329 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1330 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1331 catch (::std::runtime_error& e) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1332 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1333 LOG(ERROR) << "Exception in database back-end: " << e.what(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1334 return OrthancPluginErrorCode_DatabasePlugin; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1335 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1336 catch (...) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1337 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1338 LOG(ERROR) << "Native exception"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1339 return OrthancPluginErrorCode_DatabasePlugin; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1340 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1341 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1342 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1343 static void FinalizeBackend(void* rawPool) |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1344 { |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1345 if (rawPool != NULL) |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1346 { |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1347 IndexConnectionsPool* pool = reinterpret_cast<IndexConnectionsPool*>(rawPool); |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1348 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1349 if (isBackendInUse_) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1350 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1351 isBackendInUse_ = false; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1352 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1353 else |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1354 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1355 LOG(ERROR) << "More than one index backend was registered, internal error"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1356 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1357 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1358 delete pool; |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1359 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1360 else |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1361 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1362 LOG(ERROR) << "Received a null pointer from the Orthanc core, internal error"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1363 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1364 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1365 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1366 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1367 void DatabaseBackendAdapterV4::Register(IndexBackend* backend, |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1368 size_t countConnections, |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1369 unsigned int maxDatabaseRetries) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1370 { |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1371 std::unique_ptr<IndexConnectionsPool> pool(new IndexConnectionsPool(backend, countConnections)); |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1372 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1373 if (isBackendInUse_) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1374 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1375 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1376 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1377 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1378 OrthancPluginContext* context = backend->GetContext(); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1379 |
375
824d70ce85ff
implemented database operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1380 if (OrthancPluginRegisterDatabaseBackendV4(context, pool.release(), maxDatabaseRetries, |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1381 CallBackend, FinalizeBackend) != OrthancPluginErrorCode_Success) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1382 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1383 delete backend; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1384 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Unable to register the database backend"); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1385 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1386 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1387 isBackendInUse_ = true; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1388 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1389 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1390 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1391 void DatabaseBackendAdapterV4::Finalize() |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1392 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1393 if (isBackendInUse_) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1394 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1395 LOG(ERROR) << "The Orthanc core has not destructed the index backend, internal error"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1396 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1397 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1398 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1399 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1400 # endif |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1401 #endif |