annotate Framework/Plugins/DatabaseBackendAdapterV4.cpp @ 395:a7a029043670 db-protobuf

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