comparison OrthancServer/Sources/LuaScripting.cpp @ 4551:350a22c094f2 db-changes

testing replay of transactions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Mar 2021 19:36:59 +0100
parents b4c58795f3a8
children efd90f778cd2
comparison
equal deleted inserted replaced
4540:9c0cff7a6ca2 4551:350a22c094f2
124 class LuaScripting::StableResourceEvent : public LuaScripting::IEvent 124 class LuaScripting::StableResourceEvent : public LuaScripting::IEvent
125 { 125 {
126 private: 126 private:
127 ServerIndexChange change_; 127 ServerIndexChange change_;
128 128
129 class GetInfoOperations : public ServerIndex::IReadOnlyOperations
130 {
131 private:
132 const ServerIndexChange& change_;
133 bool ok_;
134 Json::Value tags_;
135 std::map<MetadataType, std::string> metadata_;
136
137 public:
138 GetInfoOperations(const ServerIndexChange& change) :
139 change_(change),
140 ok_(false)
141 {
142 }
143
144 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
145 {
146 if (transaction.LookupResource(tags_, change_.GetPublicId(), change_.GetResourceType()))
147 {
148 transaction.GetAllMetadata(metadata_, change_.GetPublicId(), change_.GetResourceType());
149 ok_ = true;
150 }
151 }
152
153 void CallLua(LuaScripting& that,
154 const char* name) const
155 {
156 if (ok_)
157 {
158 Json::Value formattedMetadata = Json::objectValue;
159
160 for (std::map<MetadataType, std::string>::const_iterator
161 it = metadata_.begin(); it != metadata_.end(); ++it)
162 {
163 std::string key = EnumerationToString(it->first);
164 formattedMetadata[key] = it->second;
165 }
166
167 {
168 LuaScripting::Lock lock(that);
169
170 if (lock.GetLua().IsExistingFunction(name))
171 {
172 that.InitializeJob();
173
174 LuaFunctionCall call(lock.GetLua(), name);
175 call.PushString(change_.GetPublicId());
176 call.PushJson(tags_["MainDicomTags"]);
177 call.PushJson(formattedMetadata);
178 call.Execute();
179
180 that.SubmitJob();
181 }
182 }
183 }
184 }
185 };
186
187
129 public: 188 public:
130 explicit StableResourceEvent(const ServerIndexChange& change) : 189 explicit StableResourceEvent(const ServerIndexChange& change) :
131 change_(change) 190 change_(change)
132 { 191 {
133 } 192 }
162 { 221 {
163 return; 222 return;
164 } 223 }
165 } 224 }
166 225
167 Json::Value tags; 226 GetInfoOperations operations(change_);
168 227 that.context_.GetIndex().Apply(operations);
169 if (that.context_.GetIndex().LookupResource(tags, change_.GetPublicId(), change_.GetResourceType())) 228 operations.CallLua(that, name);
170 {
171 std::map<MetadataType, std::string> metadata;
172 that.context_.GetIndex().GetAllMetadata(metadata, change_.GetPublicId(), change_.GetResourceType());
173
174 Json::Value formattedMetadata = Json::objectValue;
175
176 for (std::map<MetadataType, std::string>::const_iterator
177 it = metadata.begin(); it != metadata.end(); ++it)
178 {
179 std::string key = EnumerationToString(it->first);
180 formattedMetadata[key] = it->second;
181 }
182
183 {
184 LuaScripting::Lock lock(that);
185
186 if (lock.GetLua().IsExistingFunction(name))
187 {
188 that.InitializeJob();
189
190 LuaFunctionCall call(lock.GetLua(), name);
191 call.PushString(change_.GetPublicId());
192 call.PushJson(tags["MainDicomTags"]);
193 call.PushJson(formattedMetadata);
194 call.Execute();
195
196 that.SubmitJob();
197 }
198 }
199 }
200 } 229 }
201 }; 230 };
202 231
203 232
204 class LuaScripting::JobEvent : public LuaScripting::IEvent 233 class LuaScripting::JobEvent : public LuaScripting::IEvent