annotate OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5213:055428d92772 db-protobuf

clarifying types of since/limit in IDatabaseWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Apr 2023 11:18:55 +0200
parents 27e6ec2811e3
children a9d00b17a48e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../../Sources/PrecompiledHeadersServer.h"
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "OrthancPluginDatabaseV4.h"
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if ORTHANC_ENABLE_PLUGINS != 1
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # error The plugin support is disabled
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../../OrthancFramework/Sources/Logging.h"
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../../../OrthancFramework/Sources/OrthancException.h"
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
32 #include "../../Sources/Database/ResourcesContent.h"
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "PluginsEnumerations.h"
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
35 #include "OrthancDatabasePlugin.pb.h" // Auto-generated file
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <cassert>
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
42 static void CheckSuccess(PluginsErrorDictionary& errorDictionary,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
43 OrthancPluginErrorCode code)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
44 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
45 if (code != OrthancPluginErrorCode_Success)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
46 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
47 errorDictionary.LogError(code, true);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
48 throw OrthancException(static_cast<ErrorCode>(code));
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
49 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
50 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
51
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
52
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
53 static ResourceType Convert(DatabasePluginMessages::ResourceType type)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
54 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
55 switch (type)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
56 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
57 case DatabasePluginMessages::RESOURCE_PATIENT:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
58 return ResourceType_Patient;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
59
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
60 case DatabasePluginMessages::RESOURCE_STUDY:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
61 return ResourceType_Study;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
62
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
63 case DatabasePluginMessages::RESOURCE_SERIES:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
64 return ResourceType_Series;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
65
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
66 case DatabasePluginMessages::RESOURCE_INSTANCE:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
67 return ResourceType_Instance;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
68
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
69 default:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
70 throw OrthancException(ErrorCode_ParameterOutOfRange);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
71 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
72 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
73
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
74
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
75 static DatabasePluginMessages::ResourceType Convert(ResourceType type)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
76 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
77 switch (type)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
78 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
79 case ResourceType_Patient:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
80 return DatabasePluginMessages::RESOURCE_PATIENT;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
81
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
82 case ResourceType_Study:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
83 return DatabasePluginMessages::RESOURCE_STUDY;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
84
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
85 case ResourceType_Series:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
86 return DatabasePluginMessages::RESOURCE_SERIES;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
87
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
88 case ResourceType_Instance:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
89 return DatabasePluginMessages::RESOURCE_INSTANCE;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
90
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
91 default:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
92 throw OrthancException(ErrorCode_ParameterOutOfRange);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
93 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
94 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
95
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
96
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
97 static FileInfo Convert(const DatabasePluginMessages::FileInfo& source)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
98 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
99 return FileInfo(source.uuid(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
100 static_cast<FileContentType>(source.content_type()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
101 source.uncompressed_size(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
102 source.uncompressed_hash(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
103 static_cast<CompressionType>(source.compression_type()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
104 source.compressed_size(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
105 source.compressed_hash());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
106 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
107
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
108
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
109 static ServerIndexChange Convert(const DatabasePluginMessages::ServerIndexChange& source)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
110 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
111 return ServerIndexChange(source.seq(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
112 static_cast<ChangeType>(source.change_type()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
113 Convert(source.resource_type()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
114 source.public_id(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
115 source.date());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
116 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
117
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
118
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
119 static ExportedResource Convert(const DatabasePluginMessages::ExportedResource& source)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
120 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
121 return ExportedResource(source.seq(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
122 Convert(source.resource_type()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
123 source.public_id(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
124 source.modality(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
125 source.date(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
126 source.patient_id(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
127 source.study_instance_uid(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
128 source.series_instance_uid(),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
129 source.sop_instance_uid());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
130 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
131
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
132
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
133 static void Execute(DatabasePluginMessages::Response& response,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
134 const OrthancPluginDatabaseV4& database,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
135 const DatabasePluginMessages::Request& request)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
136 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
137 std::string requestSerialized;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
138 request.SerializeToString(&requestSerialized);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
139
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
140 OrthancPluginMemoryBuffer64 responseSerialized;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
141 CheckSuccess(database.GetErrorDictionary(), database.GetDefinition().operations(
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
142 &responseSerialized, database.GetDefinition().backend,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
143 requestSerialized.empty() ? NULL : requestSerialized.c_str(),
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
144 requestSerialized.size()));
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
145
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
146 bool success = response.ParseFromArray(responseSerialized.data, responseSerialized.size);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
147
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
148 if (responseSerialized.size > 0)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
149 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
150 free(responseSerialized.data);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
151 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
152
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
153 if (!success)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
154 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
155 throw OrthancException(ErrorCode_DatabasePlugin, "Cannot unserialize protobuf originating from the database plugin");
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
156 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
157 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
158
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
159
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
160 static void ExecuteDatabase(DatabasePluginMessages::DatabaseResponse& response,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
161 const OrthancPluginDatabaseV4& database,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
162 DatabasePluginMessages::DatabaseOperation operation,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
163 const DatabasePluginMessages::DatabaseRequest& request)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
164 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
165 DatabasePluginMessages::Request fullRequest;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
166 fullRequest.set_type(DatabasePluginMessages::REQUEST_DATABASE);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
167 fullRequest.mutable_database_request()->CopyFrom(request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
168 fullRequest.mutable_database_request()->set_operation(operation);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
169
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
170 DatabasePluginMessages::Response fullResponse;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
171 Execute(fullResponse, database, fullRequest);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
172
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
173 response.CopyFrom(fullResponse.database_response());
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
174 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
175
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
176
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 class OrthancPluginDatabaseV4::Transaction : public IDatabaseWrapper::ITransaction
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 private:
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
180 OrthancPluginDatabaseV4& database_;
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 IDatabaseListener& listener_;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 void* transaction_;
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
183
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
184 void ExecuteTransaction(DatabasePluginMessages::TransactionResponse& response,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
185 DatabasePluginMessages::TransactionOperation operation,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
186 const DatabasePluginMessages::TransactionRequest& request)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
187 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
188 DatabasePluginMessages::Request fullRequest;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
189 fullRequest.set_type(DatabasePluginMessages::REQUEST_TRANSACTION);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
190 fullRequest.mutable_transaction_request()->CopyFrom(request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
191 fullRequest.mutable_transaction_request()->set_transaction(reinterpret_cast<intptr_t>(transaction_));
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
192 fullRequest.mutable_transaction_request()->set_operation(operation);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
194 DatabasePluginMessages::Response fullResponse;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
195 Execute(fullResponse, database_, fullRequest);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
196
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
197 response.CopyFrom(fullResponse.transaction_response());
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
200
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
201 void ExecuteTransaction(DatabasePluginMessages::TransactionResponse& response,
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
202 DatabasePluginMessages::TransactionOperation operation)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
203 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
204 DatabasePluginMessages::TransactionRequest request; // Ignored
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
205 ExecuteTransaction(response, operation, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
206 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
207
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
208
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
209 void ExecuteTransaction(DatabasePluginMessages::TransactionOperation operation,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
210 const DatabasePluginMessages::TransactionRequest& request)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
211 {
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
212 DatabasePluginMessages::TransactionResponse response; // Ignored
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
213 ExecuteTransaction(response, operation, request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
214 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
215
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
216
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
217 void ExecuteTransaction(DatabasePluginMessages::TransactionOperation operation)
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
219 DatabasePluginMessages::TransactionResponse response; // Ignored
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
220 DatabasePluginMessages::TransactionRequest request; // Ignored
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
221 ExecuteTransaction(response, operation, request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
222 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
223
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
224
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
225 public:
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
226 Transaction(OrthancPluginDatabaseV4& database,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
227 IDatabaseListener& listener,
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
228 void* transaction) :
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
229 database_(database),
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
230 listener_(listener),
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
231 transaction_(transaction)
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
232 {
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 virtual ~Transaction()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
238 DatabasePluginMessages::DatabaseRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
239 request.mutable_finalize_transaction()->set_transaction(reinterpret_cast<intptr_t>(transaction_));
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
240
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
241 DatabasePluginMessages::DatabaseResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
242 ExecuteDatabase(response, database_, DatabasePluginMessages::OPERATION_FINALIZE_TRANSACTION, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 virtual void Rollback() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
248 ExecuteTransaction(DatabasePluginMessages::OPERATION_ROLLBACK);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 virtual void Commit(int64_t fileSizeDelta) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
254 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
255 request.mutable_commit()->set_file_size_delta(fileSizeDelta);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
256
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
257 ExecuteTransaction(DatabasePluginMessages::OPERATION_COMMIT, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 virtual void AddAttachment(int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 const FileInfo& attachment,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 int64_t revision) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
265 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
266 request.mutable_add_attachment()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
267 request.mutable_add_attachment()->mutable_attachment()->set_uuid(attachment.GetUuid());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
268 request.mutable_add_attachment()->mutable_attachment()->set_content_type(attachment.GetContentType());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
269 request.mutable_add_attachment()->mutable_attachment()->set_uncompressed_size(attachment.GetUncompressedSize());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
270 request.mutable_add_attachment()->mutable_attachment()->set_uncompressed_hash(attachment.GetUncompressedMD5());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
271 request.mutable_add_attachment()->mutable_attachment()->set_compression_type(attachment.GetCompressionType());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
272 request.mutable_add_attachment()->mutable_attachment()->set_compressed_size(attachment.GetCompressedSize());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
273 request.mutable_add_attachment()->mutable_attachment()->set_compressed_hash(attachment.GetCompressedMD5());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
274 request.mutable_add_attachment()->set_revision(revision);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
275
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
276 ExecuteTransaction(DatabasePluginMessages::OPERATION_ADD_ATTACHMENT, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 virtual void ClearChanges() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
282 ExecuteTransaction(DatabasePluginMessages::OPERATION_CLEAR_CHANGES);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 virtual void ClearExportedResources() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
288 ExecuteTransaction(DatabasePluginMessages::OPERATION_CLEAR_EXPORTED_RESOURCES);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
291
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 virtual void DeleteAttachment(int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 FileContentType attachment) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
295 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
296 request.mutable_delete_attachment()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
297 request.mutable_delete_attachment()->set_type(attachment);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
298
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
299 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
300 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_DELETE_ATTACHMENT, request);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
301
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
302 listener_.SignalAttachmentDeleted(Convert(response.delete_attachment().deleted_attachment()));
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 virtual void DeleteMetadata(int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 MetadataType type) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
309 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
310 request.mutable_delete_metadata()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
311 request.mutable_delete_metadata()->set_type(type);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
312
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
313 ExecuteTransaction(DatabasePluginMessages::OPERATION_DELETE_METADATA, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 virtual void DeleteResource(int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
319 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
320 request.mutable_delete_resource()->set_id(id);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
321
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
322 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
323 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_DELETE_RESOURCE, request);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
324
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
325 for (int i = 0; i < response.delete_resource().deleted_attachments().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
326 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
327 listener_.SignalAttachmentDeleted(Convert(response.delete_resource().deleted_attachments(i)));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
328 }
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
329
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
330 for (int i = 0; i < response.delete_resource().deleted_resources().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
331 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
332 listener_.SignalResourceDeleted(Convert(response.delete_resource().deleted_resources(i).level()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
333 response.delete_resource().deleted_resources(i).public_id());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
334 }
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
335
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
336 if (response.delete_resource().is_remaining_ancestor())
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
337 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
338 listener_.SignalRemainingAncestor(Convert(response.delete_resource().remaining_ancestor().level()),
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
339 response.delete_resource().remaining_ancestor().public_id());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
340 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
347 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
348 request.mutable_get_all_metadata()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
349
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
350 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
351 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_ALL_METADATA, request);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
352
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
353 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
354 for (int i = 0; i < response.get_all_metadata().metadata().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
355 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
356 MetadataType key = static_cast<MetadataType>(response.get_all_metadata().metadata(i).type());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
357
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
358 if (target.find(key) == target.end())
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
359 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
360 target[key] = response.get_all_metadata().metadata(i).value();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
361 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
362 else
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
363 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
364 throw OrthancException(ErrorCode_DatabasePlugin);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
365 }
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
366 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 virtual void GetAllPublicIds(std::list<std::string>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 ResourceType resourceType) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
373 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
374 request.mutable_get_all_public_ids()->set_resource_type(Convert(resourceType));
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
375
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
376 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
377 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS, request);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
378
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
379 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
380 for (int i = 0; i < response.get_all_public_ids().ids().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
381 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
382 target.push_back(response.get_all_public_ids().ids(i));
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
383 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 virtual void GetAllPublicIds(std::list<std::string>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 ResourceType resourceType,
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
389 int64_t since,
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
390 uint32_t limit) ORTHANC_OVERRIDE
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
392 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
393 request.mutable_get_all_public_ids_with_limits()->set_resource_type(Convert(resourceType));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
394 request.mutable_get_all_public_ids_with_limits()->set_since(since);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
395 request.mutable_get_all_public_ids_with_limits()->set_limit(limit);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
396
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
397 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
398 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS_WITH_LIMITS, request);
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
399
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
400 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
401 for (int i = 0; i < response.get_all_public_ids_with_limits().ids().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
402 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
403 target.push_back(response.get_all_public_ids_with_limits().ids(i));
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
404 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 bool& done /*out*/,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 int64_t since,
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
411 uint32_t limit) ORTHANC_OVERRIDE
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
413 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
414 request.mutable_get_changes()->set_since(since);
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
415 request.mutable_get_changes()->set_limit(limit);
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
416
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
417 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
418 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_CHANGES, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
419
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
420 done = response.get_changes().done();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
421
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
422 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
423 for (int i = 0; i < response.get_changes().changes().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
424 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
425 target.push_back(Convert(response.get_changes().changes(i)));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
426 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 virtual void GetChildrenInternalId(std::list<int64_t>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
433 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
434 request.mutable_get_children_internal_id()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
435
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
436 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
437 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_CHILDREN_INTERNAL_ID, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
438
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
439 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
440 for (int i = 0; i < response.get_children_internal_id().ids().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
441 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
442 target.push_back(response.get_children_internal_id().ids(i));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
443 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 virtual void GetChildrenPublicId(std::list<std::string>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
450 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
451 request.mutable_get_children_public_id()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
452
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
453 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
454 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_CHILDREN_PUBLIC_ID, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
455
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
456 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
457 for (int i = 0; i < response.get_children_public_id().ids().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
458 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
459 target.push_back(response.get_children_public_id().ids(i));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
460 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 bool& done /*out*/,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 int64_t since,
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
467 uint32_t limit) ORTHANC_OVERRIDE
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
469 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
470 request.mutable_get_exported_resources()->set_since(since);
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
471 request.mutable_get_exported_resources()->set_limit(limit);
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
472
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
473 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
474 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_EXPORTED_RESOURCES, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
475
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
476 done = response.get_exported_resources().done();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
477
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
478 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
479 for (int i = 0; i < response.get_exported_resources().resources().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
480 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
481 target.push_back(Convert(response.get_exported_resources().resources(i)));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
482 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
485
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
486 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) ORTHANC_OVERRIDE
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
487 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
488 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
489 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_LAST_CHANGE);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
490
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
491 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
492 if (response.get_last_change().found())
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
493 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
494 target.push_back(Convert(response.get_last_change().change()));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
495 }
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
496 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
498
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
501 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
502 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_LAST_EXPORTED_RESOURCE);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
503
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
504 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
505 if (response.get_last_exported_resource().found())
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
506 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
507 target.push_back(Convert(response.get_last_exported_resource().resource()));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
508 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 virtual void GetMainDicomTags(DicomMap& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
515 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
516 request.mutable_get_main_dicom_tags()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
517
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
518 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
519 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_MAIN_DICOM_TAGS, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
520
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
521 target.Clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
522
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
523 for (int i = 0; i < response.get_main_dicom_tags().tags().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
524 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
525 const DatabasePluginMessages::GetMainDicomTags_Response_Tag& tag = response.get_main_dicom_tags().tags(i);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
526 if (tag.group() > 0xffffu ||
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
527 tag.element() > 0xffffu)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
528 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
529 throw OrthancException(ErrorCode_ParameterOutOfRange);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
530 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
531 else
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
532 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
533 target.SetValue(tag.group(), tag.element(), tag.value(), false);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
534 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
535 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 virtual std::string GetPublicId(int64_t resourceId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
541 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
542 request.mutable_get_public_id()->set_id(resourceId);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
543
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
544 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
545 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_PUBLIC_ID, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
546 return response.get_public_id().id();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 virtual uint64_t GetResourcesCount(ResourceType resourceType) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
552 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
553 request.mutable_get_resources_count()->set_type(Convert(resourceType));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
554
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
555 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
556 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_RESOURCES_COUNT, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
557 return response.get_resources_count().count();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 virtual ResourceType GetResourceType(int64_t resourceId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
563 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
564 request.mutable_get_resource_type()->set_id(resourceId);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
565
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
566 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
567 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_RESOURCE_TYPE, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
568 return Convert(response.get_resource_type().type());
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 virtual uint64_t GetTotalCompressedSize() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
574 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
575 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_TOTAL_COMPRESSED_SIZE);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
576 return response.get_total_compressed_size().size();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 virtual uint64_t GetTotalUncompressedSize() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
582 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
583 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_TOTAL_UNCOMPRESSED_SIZE);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
584 return response.get_total_uncompressed_size().size();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 virtual bool IsProtectedPatient(int64_t internalId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
590 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
591 request.mutable_is_protected_patient()->set_patient_id(internalId);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
592
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
593 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
594 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_IS_PROTECTED_PATIENT, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
595 return response.is_protected_patient().protected_patient();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 virtual void ListAvailableAttachments(std::set<FileContentType>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
602 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
603 request.mutable_list_available_attachments()->set_id(id);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
604
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
605 DatabasePluginMessages::TransactionResponse response;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
606 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LIST_AVAILABLE_ATTACHMENTS, request);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
607
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
608 target.clear();
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
609 for (int i = 0; i < response.list_available_attachments().attachments().size(); i++)
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
610 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
611 FileContentType attachment = static_cast<FileContentType>(response.list_available_attachments().attachments(i));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
612
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
613 if (target.find(attachment) == target.end())
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
614 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
615 target.insert(attachment);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
616 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
617 else
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
618 {
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
619 throw OrthancException(ErrorCode_DatabasePlugin);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
620 }
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
621 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 virtual void LogChange(int64_t internalId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 const ServerIndexChange& change) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
628 // TODO => Simplify "IDatabaseWrapper"
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
629
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
630 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
631 request.mutable_log_change()->set_change_type(change.GetChangeType());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
632 request.mutable_log_change()->set_resource_id(internalId);
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
633 request.mutable_log_change()->set_resource_type(Convert(change.GetResourceType()));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
634 request.mutable_log_change()->set_date(change.GetDate());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
635
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
636 ExecuteTransaction(DatabasePluginMessages::OPERATION_LOG_CHANGE, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 virtual void LogExportedResource(const ExportedResource& resource) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 {
5210
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
642 // TODO: "seq" is ignored, could be simplified in "ExportedResource"
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
643
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
644 DatabasePluginMessages::TransactionRequest request;
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
645 request.mutable_log_exported_resource()->set_resource_type(Convert(resource.GetResourceType()));
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
646 request.mutable_log_exported_resource()->set_public_id(resource.GetPublicId());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
647 request.mutable_log_exported_resource()->set_modality(resource.GetModality());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
648 request.mutable_log_exported_resource()->set_date(resource.GetDate());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
649 request.mutable_log_exported_resource()->set_patient_id(resource.GetPatientId());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
650 request.mutable_log_exported_resource()->set_study_instance_uid(resource.GetStudyInstanceUid());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
651 request.mutable_log_exported_resource()->set_series_instance_uid(resource.GetSeriesInstanceUid());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
652 request.mutable_log_exported_resource()->set_sop_instance_uid(resource.GetSopInstanceUid());
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
653
6a7a244c777d cont OrthancPluginDatabaseV4::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5209
diff changeset
654 ExecuteTransaction(DatabasePluginMessages::OPERATION_LOG_EXPORTED_RESOURCE, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 virtual bool LookupAttachment(FileInfo& attachment,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 int64_t& revision,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 FileContentType contentType) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
663 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
664 request.mutable_lookup_attachment()->set_id(id);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
665 request.mutable_lookup_attachment()->set_content_type(contentType);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
666
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
667 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
668 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_ATTACHMENT, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
669
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
670 if (response.lookup_attachment().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
671 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
672 attachment = Convert(response.lookup_attachment().attachment());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
673 revision = response.lookup_attachment().revision();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
674 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
675 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
676 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
677 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
678 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
679 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 virtual bool LookupGlobalProperty(std::string& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 GlobalProperty property,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 bool shared) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
687 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
688 request.mutable_lookup_global_property()->set_server_id(shared ? "" : database_.GetServerIdentifier());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
689 request.mutable_lookup_global_property()->set_property(property);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
690
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
691 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
692 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_GLOBAL_PROPERTY, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
693
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
694 if (response.lookup_global_property().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
695 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
696 target = response.lookup_global_property().value();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
697 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
698 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
699 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
700 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
701 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
702 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 virtual bool LookupMetadata(std::string& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 int64_t& revision,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 MetadataType type) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
711 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
712 request.mutable_lookup_metadata()->set_id(id);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
713 request.mutable_lookup_metadata()->set_metadata_type(type);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
714
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
715 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
716 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_METADATA, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
717
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
718 if (response.lookup_metadata().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
719 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
720 target = response.lookup_metadata().value();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
721 revision = response.lookup_metadata().revision();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
722 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
723 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
724 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
725 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
726 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
727 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 virtual bool LookupParent(int64_t& parentId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 int64_t resourceId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
734 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
735 request.mutable_lookup_parent()->set_id(resourceId);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
736
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
737 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
738 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_PARENT, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
739
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
740 if (response.lookup_parent().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
741 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
742 parentId = response.lookup_parent().parent();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
743 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
744 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
745 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
746 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
747 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
748 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 virtual bool LookupResource(int64_t& id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 ResourceType& type,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 const std::string& publicId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
756 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
757 request.mutable_lookup_resource()->set_public_id(publicId);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
758
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
759 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
760 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
761
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
762 if (response.lookup_resource().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
763 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
764 id = response.lookup_resource().internal_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
765 type = Convert(response.lookup_resource().type());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
766 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
767 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
768 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
769 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
770 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
771 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 virtual bool SelectPatientToRecycle(int64_t& internalId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
777 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
778 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
779
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
780 if (response.select_patient_to_recycle().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
781 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
782 internalId = response.select_patient_to_recycle().patient_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
783 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
784 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
785 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
786 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
787 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
788 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 virtual bool SelectPatientToRecycle(int64_t& internalId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 int64_t patientIdToAvoid) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
795 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
796 request.mutable_select_patient_to_recycle_with_avoid()->set_patient_id_to_avoid(patientIdToAvoid);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
797
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
798 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
799 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE_WITH_AVOID, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
800
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
801 if (response.select_patient_to_recycle_with_avoid().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
802 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
803 internalId = response.select_patient_to_recycle_with_avoid().patient_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
804 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
805 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
806 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
807 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
808 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
809 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 virtual void SetGlobalProperty(GlobalProperty property,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 bool shared,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 const std::string& value) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
817 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
818 request.mutable_set_global_property()->set_server_id(shared ? "" : database_.GetServerIdentifier());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
819 request.mutable_set_global_property()->set_property(property);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
820 request.mutable_set_global_property()->set_value(value);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
821
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
822 ExecuteTransaction(DatabasePluginMessages::OPERATION_SET_GLOBAL_PROPERTY, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 virtual void ClearMainDicomTags(int64_t id) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
828 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
829 request.mutable_clear_main_dicom_tags()->set_id(id);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
830
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
831 ExecuteTransaction(DatabasePluginMessages::OPERATION_CLEAR_MAIN_DICOM_TAGS, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 virtual void SetMetadata(int64_t id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 MetadataType type,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 const std::string& value,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 int64_t revision) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
840 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
841 request.mutable_set_metadata()->set_id(id);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
842 request.mutable_set_metadata()->set_metadata_type(type);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
843 request.mutable_set_metadata()->set_value(value);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
844 request.mutable_set_metadata()->set_revision(revision);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
845
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
846 ExecuteTransaction(DatabasePluginMessages::OPERATION_SET_METADATA, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 virtual void SetProtectedPatient(int64_t internalId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 bool isProtected) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
853 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
854 request.mutable_set_protected_patient()->set_patient_id(internalId);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
855 request.mutable_set_protected_patient()->set_protected_patient(isProtected);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
856
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
857 ExecuteTransaction(DatabasePluginMessages::OPERATION_SET_PROTECTED_PATIENT, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 virtual bool IsDiskSizeAbove(uint64_t threshold) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
863 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
864 request.mutable_is_disk_size_above()->set_threshold(threshold);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
865
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
866 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
867 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_IS_DISK_SIZE_ABOVE, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
868
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
869 return response.is_disk_size_above().result();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 std::list<std::string>* instancesId, // Can be NULL if not needed
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 const std::vector<DatabaseConstraint>& lookup,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 ResourceType queryLevel,
5213
055428d92772 clarifying types of since/limit in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5211
diff changeset
877 uint32_t limit) ORTHANC_OVERRIDE
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
879 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
880 request.mutable_lookup_resources()->set_query_level(Convert(queryLevel));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
881 request.mutable_lookup_resources()->set_limit(limit);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
882 request.mutable_lookup_resources()->set_retrieve_instances_ids(instancesId != NULL);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
883
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
884 request.mutable_lookup_resources()->mutable_lookup()->Reserve(lookup.size());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
885
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
886 for (size_t i = 0; i < lookup.size(); i++)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
887 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
888 DatabasePluginMessages::DatabaseConstraint* constraint = request.mutable_lookup_resources()->add_lookup();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
889 constraint->set_level(Convert(lookup[i].GetLevel()));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
890 constraint->set_tag_group(lookup[i].GetTag().GetGroup());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
891 constraint->set_tag_element(lookup[i].GetTag().GetElement());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
892 constraint->set_is_identifier_tag(lookup[i].IsIdentifier());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
893 constraint->set_is_case_sensitive(lookup[i].IsCaseSensitive());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
894 constraint->set_is_mandatory(lookup[i].IsMandatory());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
895
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
896 constraint->mutable_values()->Reserve(lookup[i].GetValuesCount());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
897 for (size_t j = 0; j < lookup[i].GetValuesCount(); j++)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
898 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
899 constraint->add_values(lookup[i].GetValue(j));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
900 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
901
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
902 switch (lookup[i].GetConstraintType())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
903 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
904 case ConstraintType_Equal:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
905 constraint->set_type(DatabasePluginMessages::CONSTRAINT_EQUAL);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
906 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
907
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
908 case ConstraintType_SmallerOrEqual:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
909 constraint->set_type(DatabasePluginMessages::CONSTRAINT_SMALLER_OR_EQUAL);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
910 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
911
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
912 case ConstraintType_GreaterOrEqual:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
913 constraint->set_type(DatabasePluginMessages::CONSTRAINT_GREATER_OR_EQUAL);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
914 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
915
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
916 case ConstraintType_Wildcard:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
917 constraint->set_type(DatabasePluginMessages::CONSTRAINT_WILDCARD);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
918 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
919
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
920 case ConstraintType_List:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
921 constraint->set_type(DatabasePluginMessages::CONSTRAINT_LIST);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
922 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
923
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
924 default:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
925 throw OrthancException(ErrorCode_ParameterOutOfRange);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
926 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
927 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
928
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
929 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
930 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_RESOURCES, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
931
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
932 for (int i = 0; i < response.lookup_resources().resources_ids().size(); i++)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
933 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
934 resourcesId.push_back(response.lookup_resources().resources_ids(i));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
935 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
936
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
937 if (instancesId != NULL)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
938 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
939 if (response.lookup_resources().resources_ids().size() != response.lookup_resources().instances_ids().size())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
940 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
941 throw OrthancException(ErrorCode_DatabasePlugin);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
942 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
943 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
944 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
945 for (int i = 0; i < response.lookup_resources().instances_ids().size(); i++)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
946 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
947 instancesId->push_back(response.lookup_resources().instances_ids(i));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
948 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
949 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
950 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 virtual bool CreateInstance(CreateInstanceResult& result, /* out */
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 int64_t& instanceId, /* out */
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 const std::string& patient,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 const std::string& study,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 const std::string& series,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 const std::string& instance) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
961 // TODO: "CreateInstanceResult" => constructor and getters
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
962
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
963 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
964 request.mutable_create_instance()->set_patient(patient);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
965 request.mutable_create_instance()->set_study(study);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
966 request.mutable_create_instance()->set_series(series);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
967 request.mutable_create_instance()->set_instance(instance);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
968
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
969 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
970 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_CREATE_INSTANCE, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
971
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
972 instanceId = response.create_instance().instance_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
973
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
974 if (response.create_instance().is_new_instance())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
975 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
976 result.isNewPatient_ = response.create_instance().is_new_patient();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
977 result.isNewStudy_ = response.create_instance().is_new_study();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
978 result.isNewSeries_ = response.create_instance().is_new_series();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
979 result.patientId_ = response.create_instance().patient_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
980 result.studyId_ = response.create_instance().study_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
981 result.seriesId_ = response.create_instance().series_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
982 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
983 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
984 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
985 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
986 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
987 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 virtual void SetResourcesContent(const ResourcesContent& content) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
993 // TODO: "ResourcesContent" => getters
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
994
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
995 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
996
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
997 request.mutable_set_resources_content()->mutable_tags()->Reserve(content.GetListTags().size());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
998 for (ResourcesContent::ListTags::const_iterator it = content.GetListTags().begin(); it != content.GetListTags().end(); ++it)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
999 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1000 DatabasePluginMessages::SetResourcesContent_Request_Tag* tag = request.mutable_set_resources_content()->add_tags();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1001 tag->set_resource_id(it->resourceId_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1002 tag->set_is_identifier(it->isIdentifier_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1003 tag->set_group(it->tag_.GetGroup());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1004 tag->set_element(it->tag_.GetElement());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1005 tag->set_value(it->value_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1006 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1007
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1008 request.mutable_set_resources_content()->mutable_metadata()->Reserve(content.GetListMetadata().size());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1009 for (ResourcesContent::ListMetadata::const_iterator it = content.GetListMetadata().begin(); it != content.GetListMetadata().end(); ++it)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1010 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1011 DatabasePluginMessages::SetResourcesContent_Request_Metadata* metadata = request.mutable_set_resources_content()->add_metadata();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1012 metadata->set_resource_id(it->resourceId_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1013 metadata->set_metadata(it->metadata_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1014 metadata->set_value(it->value_);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1015 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1016
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1017 ExecuteTransaction(DatabasePluginMessages::OPERATION_SET_RESOURCES_CONTENT, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 virtual void GetChildrenMetadata(std::list<std::string>& target,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 int64_t resourceId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 MetadataType metadata) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1025 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1026 request.mutable_get_children_metadata()->set_id(resourceId);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1027 request.mutable_get_children_metadata()->set_metadata(metadata);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1028
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1029 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1030 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_CHILDREN_METADATA, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1031
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1032 for (int i = 0; i < response.get_children_metadata().values().size(); i++)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1033 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1034 target.push_back(response.get_children_metadata().values(i));
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1035 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1041 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1042 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_GET_LAST_CHANGE_INDEX);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1043 return response.get_last_change_index().result();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 virtual bool LookupResourceAndParent(int64_t& id,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 ResourceType& type,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 std::string& parentPublicId,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 const std::string& publicId) ORTHANC_OVERRIDE
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 {
5211
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1052 DatabasePluginMessages::TransactionRequest request;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1053 request.mutable_lookup_resource_and_parent()->set_public_id(publicId);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1054
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1055 DatabasePluginMessages::TransactionResponse response;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1056 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE_AND_PARENT, request);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1057
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1058 if (response.lookup_resource_and_parent().found())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1059 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1060 id = response.lookup_resource_and_parent().id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1061 type = Convert(response.lookup_resource_and_parent().type());
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1062
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1063 switch (type)
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1064 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1065 case ResourceType_Patient:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1066 if (!response.lookup_resource_and_parent().parent_public_id().empty())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1067 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1068 throw OrthancException(ErrorCode_DatabasePlugin);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1069 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1070 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1071
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1072 case ResourceType_Study:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1073 case ResourceType_Series:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1074 case ResourceType_Instance:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1075 if (response.lookup_resource_and_parent().parent_public_id().empty())
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1076 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1077 throw OrthancException(ErrorCode_DatabasePlugin);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1078 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1079 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1080 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1081 parentPublicId = response.lookup_resource_and_parent().parent_public_id();
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1082 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1083 break;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1084
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1085 default:
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1086 throw OrthancException(ErrorCode_ParameterOutOfRange);
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1087 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1088
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1089 return true;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1090 }
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1091 else
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1092 {
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1093 return false;
27e6ec2811e3 completed first implementation of OrthancPluginDatabaseV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5210
diff changeset
1094 }
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 };
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 OrthancPluginDatabaseV4::OrthancPluginDatabaseV4(SharedLibrary& library,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 PluginsErrorDictionary& errorDictionary,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 const _OrthancPluginRegisterDatabaseBackendV4& database,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 const std::string& serverIdentifier) :
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 library_(library),
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 errorDictionary_(errorDictionary),
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1105 definition_(database),
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 serverIdentifier_(serverIdentifier),
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 open_(false),
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 databaseVersion_(0),
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 hasFlushToDisk_(false),
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 hasRevisionsSupport_(false)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 CLOG(INFO, PLUGINS) << "Identifier of this Orthanc server for the global properties "
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 << "of the custom database: \"" << serverIdentifier << "\"";
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1115 if (definition_.backend == NULL ||
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1116 definition_.operations == NULL ||
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1117 definition_.finalize == NULL)
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 throw OrthancException(ErrorCode_NullPointer);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 OrthancPluginDatabaseV4::~OrthancPluginDatabaseV4()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 {
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1126 definition_.finalize(definition_.backend);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 void OrthancPluginDatabaseV4::Open()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 if (open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 DatabasePluginMessages::DatabaseRequest request;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 DatabasePluginMessages::DatabaseResponse response;
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1140 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_OPEN, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 DatabasePluginMessages::DatabaseRequest request;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 DatabasePluginMessages::DatabaseResponse response;
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1146 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_GET_SYSTEM_INFORMATION, request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1147 databaseVersion_ = response.get_system_information().database_version();
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 hasFlushToDisk_ = response.get_system_information().supports_flush_to_disk();
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 hasRevisionsSupport_ = response.get_system_information().supports_revisions();
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 open_ = true;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 void OrthancPluginDatabaseV4::Close()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 DatabasePluginMessages::DatabaseRequest request;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 DatabasePluginMessages::DatabaseResponse response;
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1166 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_CLOSE, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 bool OrthancPluginDatabaseV4::HasFlushToDisk() const
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 return hasFlushToDisk_;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 void OrthancPluginDatabaseV4::FlushToDisk()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 if (!open_ ||
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 !hasFlushToDisk_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 DatabasePluginMessages::DatabaseRequest request;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 DatabasePluginMessages::DatabaseResponse response;
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1195 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_FLUSH_TO_DISK, request);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 IDatabaseWrapper::ITransaction* OrthancPluginDatabaseV4::StartTransaction(TransactionType type,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 IDatabaseListener& listener)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1208 DatabasePluginMessages::DatabaseRequest request;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1209
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 switch (type)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 case TransactionType_ReadOnly:
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1213 request.mutable_start_transaction()->set_type(DatabasePluginMessages::TRANSACTION_READ_ONLY);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1214 break;
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 case TransactionType_ReadWrite:
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1217 request.mutable_start_transaction()->set_type(DatabasePluginMessages::TRANSACTION_READ_WRITE);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1218 break;
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 default:
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 throw OrthancException(ErrorCode_InternalError);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 }
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1223
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1224 DatabasePluginMessages::DatabaseResponse response;
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1225 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_START_TRANSACTION, request);
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1226
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1227 return new Transaction(*this, listener, reinterpret_cast<void*>(response.start_transaction().transaction()));
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 unsigned int OrthancPluginDatabaseV4::GetDatabaseVersion()
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 return databaseVersion_;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 void OrthancPluginDatabaseV4::Upgrade(unsigned int targetVersion,
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 IStorageArea& storageArea)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 // TODO
5209
154d37a56500 started implementation of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5207
diff changeset
1254 throw OrthancException(ErrorCode_NotImplemented);
5207
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 bool OrthancPluginDatabaseV4::HasRevisionsSupport() const
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 if (!open_)
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 else
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 {
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 return hasRevisionsSupport_;
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 }
e7529e6241d2 first successful protobuf communication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 }