Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 1010:160dfe770618 lua-scripting
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 17:05:00 +0200 |
parents | 26642cecd36d |
children | 921532f67770 |
comparison
equal
deleted
inserted
replaced
1009:26642cecd36d | 1010:160dfe770618 |
---|---|
46 | 46 |
47 #include "Scheduler/DeleteInstanceCommand.h" | 47 #include "Scheduler/DeleteInstanceCommand.h" |
48 #include "Scheduler/ModifyInstanceCommand.h" | 48 #include "Scheduler/ModifyInstanceCommand.h" |
49 #include "Scheduler/StoreScuCommand.h" | 49 #include "Scheduler/StoreScuCommand.h" |
50 #include "Scheduler/StorePeerCommand.h" | 50 #include "Scheduler/StorePeerCommand.h" |
51 #include "OrthancRestApi/OrthancRestApi.h" | |
51 | 52 |
52 | 53 |
53 | 54 |
54 #define ENABLE_DICOM_CACHE 1 | 55 #define ENABLE_DICOM_CACHE 1 |
55 | 56 |
126 const std::string& operation, | 127 const std::string& operation, |
127 const Json::Value& parameters) | 128 const Json::Value& parameters) |
128 { | 129 { |
129 if (operation == "delete") | 130 if (operation == "delete") |
130 { | 131 { |
131 LOG(INFO) << "Lua script to delete instance " << parameters["instance"].asString(); | 132 LOG(INFO) << "Lua script to delete instance " << parameters["Instance"].asString(); |
132 return new DeleteInstanceCommand(context); | 133 return new DeleteInstanceCommand(context); |
133 } | 134 } |
134 | 135 |
135 if (operation == "store-scu") | 136 if (operation == "store-scu") |
136 { | 137 { |
137 std::string modality = parameters["modality"].asString(); | 138 std::string modality = parameters["Modality"].asString(); |
138 LOG(INFO) << "Lua script to send instance " << parameters["instance"].asString() | 139 LOG(INFO) << "Lua script to send instance " << parameters["Instance"].asString() |
139 << " to modality " << modality << " using Store-SCU"; | 140 << " to modality " << modality << " using Store-SCU"; |
140 return new StoreScuCommand(context, Configuration::GetModalityUsingSymbolicName(modality)); | 141 return new StoreScuCommand(context, Configuration::GetModalityUsingSymbolicName(modality)); |
141 } | 142 } |
142 | 143 |
143 if (operation == "store-peer") | 144 if (operation == "store-peer") |
144 { | 145 { |
145 std::string peer = parameters["peer"].asString(); | 146 std::string peer = parameters["Peer"].asString(); |
146 LOG(INFO) << "Lua script to send instance " << parameters["instance"].asString() | 147 LOG(INFO) << "Lua script to send instance " << parameters["Instance"].asString() |
147 << " to peer " << peer << " using HTTP"; | 148 << " to peer " << peer << " using HTTP"; |
148 | 149 |
149 OrthancPeerParameters parameters; | 150 OrthancPeerParameters parameters; |
150 Configuration::GetOrthancPeer(parameters, peer); | 151 Configuration::GetOrthancPeer(parameters, peer); |
151 return new StorePeerCommand(context, parameters); | 152 return new StorePeerCommand(context, parameters); |
152 } | 153 } |
153 | 154 |
154 if (operation == "modify") | 155 if (operation == "modify") |
155 { | 156 { |
156 LOG(INFO) << "Lua script to modify instance " << parameters["instance"].asString(); | 157 LOG(INFO) << "Lua script to modify instance " << parameters["Instance"].asString(); |
157 std::auto_ptr<ModifyInstanceCommand> command(new ModifyInstanceCommand(context)); | 158 std::auto_ptr<ModifyInstanceCommand> command(new ModifyInstanceCommand(context)); |
158 | 159 OrthancRestApi::ParseModifyRequest(command->GetModification(), parameters); |
159 if (parameters.isMember("replacements")) | |
160 { | |
161 const Json::Value& replacements = parameters["replacements"]; | |
162 if (replacements.type() != Json::objectValue) | |
163 { | |
164 throw OrthancException(ErrorCode_BadParameterType); | |
165 } | |
166 | |
167 Json::Value::Members members = replacements.getMemberNames(); | |
168 for (Json::Value::Members::const_iterator | |
169 it = members.begin(); it != members.end(); ++it) | |
170 { | |
171 command->GetModification().Replace(FromDcmtkBridge::ParseTag(*it), | |
172 replacements[*it].asString()); | |
173 } | |
174 | |
175 // TODO OTHER PARAMETERS OF MODIFY | |
176 } | |
177 | |
178 return command.release(); | 160 return command.release(); |
179 } | 161 } |
180 | 162 |
181 throw OrthancException(ErrorCode_ParameterOutOfRange); | 163 throw OrthancException(ErrorCode_ParameterOutOfRange); |
182 } | 164 } |
211 ServerCommandInstance* previousCommand = NULL; | 193 ServerCommandInstance* previousCommand = NULL; |
212 | 194 |
213 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i) | 195 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i) |
214 { | 196 { |
215 if (operations[i].type() != Json::objectValue || | 197 if (operations[i].type() != Json::objectValue || |
216 !operations[i].isMember("operation")) | 198 !operations[i].isMember("Operation")) |
217 { | 199 { |
218 throw OrthancException(ErrorCode_InternalError); | 200 throw OrthancException(ErrorCode_InternalError); |
219 } | 201 } |
220 | 202 |
221 const Json::Value& parameters = operations[i]; | 203 const Json::Value& parameters = operations[i]; |
222 std::string operation = parameters["operation"].asString(); | 204 std::string operation = parameters["Operation"].asString(); |
223 | 205 |
224 ServerCommandInstance& command = job.AddCommand(ParseOperation(*this, operation, operations[i])); | 206 ServerCommandInstance& command = job.AddCommand(ParseOperation(*this, operation, operations[i])); |
225 | 207 |
226 if (parameters.isMember("instance") && | 208 if (!parameters.isMember("Instance")) |
227 parameters["instance"].asString() != "") | 209 { |
228 { | 210 throw OrthancException(ErrorCode_InternalError); |
229 command.AddInput(parameters["instance"].asString()); | 211 } |
230 } | 212 |
231 else if (previousCommand != NULL) | 213 std::string instance = parameters["Instance"].asString(); |
214 if (instance.empty()) | |
232 { | 215 { |
233 previousCommand->ConnectOutput(command); | 216 previousCommand->ConnectOutput(command); |
234 } | 217 } |
235 else | 218 else |
236 { | 219 { |
237 throw OrthancException(ErrorCode_InternalError); | 220 command.AddInput(instance); |
238 } | 221 } |
239 | |
240 /* | |
241 TODO | |
242 if (previousCommand != NULL) | |
243 { | |
244 previousCommand->ConnectNext(command); | |
245 }*/ | |
246 | 222 |
247 previousCommand = &command; | 223 previousCommand = &command; |
248 } | 224 } |
249 | 225 |
250 job.SetDescription(std::string("Lua script: ") + ON_STORED_INSTANCE); | 226 job.SetDescription(std::string("Lua script: ") + ON_STORED_INSTANCE); |
331 { | 307 { |
332 ApplyOnStoredInstance(resultPublicId, simplified, metadata); | 308 ApplyOnStoredInstance(resultPublicId, simplified, metadata); |
333 } | 309 } |
334 catch (OrthancException& e) | 310 catch (OrthancException& e) |
335 { | 311 { |
336 LOG(ERROR) << "Lua error in OnStoredInstance: " << e.What(); | 312 LOG(ERROR) << "Error in OnStoredInstance callback (Lua): " << e.What(); |
337 } | 313 } |
338 } | 314 } |
339 | 315 |
340 return status; | 316 return status; |
341 } | 317 } |