Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 2585:4c809711149e jobs
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 May 2018 21:24:51 +0200 |
parents | 38b5045f2bff |
children | ec09641d6f41 |
comparison
equal
deleted
inserted
replaced
2584:38b5045f2bff | 2585:4c809711149e |
---|---|
42 #include "../Scheduler/StoreScuCommand.h" | 42 #include "../Scheduler/StoreScuCommand.h" |
43 #include "../Scheduler/StorePeerCommand.h" | 43 #include "../Scheduler/StorePeerCommand.h" |
44 #include "../QueryRetrieveHandler.h" | 44 #include "../QueryRetrieveHandler.h" |
45 #include "../ServerToolbox.h" | 45 #include "../ServerToolbox.h" |
46 | 46 |
47 #include "../../Core/JobsEngine/SetOfInstancesJob.h" | |
47 | 48 |
48 | 49 |
49 namespace Orthanc | 50 namespace Orthanc |
50 { | 51 { |
51 class SetOfInstancesJob : public IJob | |
52 { | |
53 private: | |
54 bool started_; | |
55 std::vector<std::string> instances_; | |
56 bool permissive_; | |
57 size_t position_; | |
58 std::set<std::string> failedInstances_; | |
59 | |
60 protected: | |
61 virtual bool HandleInstance(const std::string& instance) = 0; | |
62 | |
63 public: | |
64 SetOfInstancesJob() : | |
65 started_(false), | |
66 permissive_(false), | |
67 position_(0) | |
68 { | |
69 } | |
70 | |
71 void Reserve(size_t size) | |
72 { | |
73 if (started_) | |
74 { | |
75 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
76 } | |
77 else | |
78 { | |
79 instances_.reserve(size); | |
80 } | |
81 } | |
82 | |
83 size_t GetInstancesCount() const | |
84 { | |
85 return instances_.size(); | |
86 } | |
87 | |
88 void AddInstance(const std::string& instance) | |
89 { | |
90 if (started_) | |
91 { | |
92 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
93 } | |
94 else | |
95 { | |
96 instances_.push_back(instance); | |
97 } | |
98 } | |
99 | |
100 bool IsPermissive() const | |
101 { | |
102 return permissive_; | |
103 } | |
104 | |
105 void SetPermissive(bool permissive) | |
106 { | |
107 if (IsStarted()) | |
108 { | |
109 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
110 } | |
111 else | |
112 { | |
113 permissive_ = permissive; | |
114 } | |
115 } | |
116 | |
117 virtual void SignalResubmit() | |
118 { | |
119 if (started_) | |
120 { | |
121 position_ = 0; | |
122 failedInstances_.clear(); | |
123 } | |
124 else | |
125 { | |
126 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
127 } | |
128 } | |
129 | |
130 virtual void Start() | |
131 { | |
132 started_ = true; | |
133 } | |
134 | |
135 virtual float GetProgress() | |
136 { | |
137 if (instances_.size() == 0) | |
138 { | |
139 return 0; | |
140 } | |
141 else | |
142 { | |
143 return (static_cast<float>(position_) / | |
144 static_cast<float>(instances_.size())); | |
145 } | |
146 } | |
147 | |
148 bool IsStarted() const | |
149 { | |
150 return started_; | |
151 } | |
152 | |
153 bool IsDone() const | |
154 { | |
155 return (position_ >= instances_.size()); | |
156 } | |
157 | |
158 void Next() | |
159 { | |
160 if (IsDone()) | |
161 { | |
162 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
163 } | |
164 else | |
165 { | |
166 position_ += 1; | |
167 } | |
168 } | |
169 | |
170 const std::string& GetCurrentInstance() const | |
171 { | |
172 if (IsDone()) | |
173 { | |
174 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
175 } | |
176 else | |
177 { | |
178 return instances_[position_]; | |
179 } | |
180 } | |
181 | |
182 | |
183 const std::vector<std::string>& GetInstances() const | |
184 { | |
185 return instances_; | |
186 } | |
187 | |
188 | |
189 const std::set<std::string>& GetFailedInstances() const | |
190 { | |
191 return failedInstances_; | |
192 } | |
193 | |
194 | |
195 virtual JobStepResult* ExecuteStep() | |
196 { | |
197 if (IsDone()) | |
198 { | |
199 return new JobStepResult(JobStepCode_Failure); | |
200 } | |
201 | |
202 bool ok; | |
203 | |
204 try | |
205 { | |
206 ok = HandleInstance(GetCurrentInstance()); | |
207 | |
208 if (!ok && !permissive_) | |
209 { | |
210 throw OrthancException(ErrorCode_InternalError); | |
211 } | |
212 } | |
213 catch (OrthancException& e) | |
214 { | |
215 if (permissive_) | |
216 { | |
217 ok = false; | |
218 } | |
219 else | |
220 { | |
221 throw; | |
222 } | |
223 } | |
224 | |
225 if (!ok) | |
226 { | |
227 failedInstances_.insert(GetCurrentInstance()); | |
228 } | |
229 | |
230 Next(); | |
231 | |
232 if (IsDone()) | |
233 { | |
234 return new JobStepResult(JobStepCode_Success); | |
235 } | |
236 else | |
237 { | |
238 return new JobStepResult(JobStepCode_Continue); | |
239 } | |
240 } | |
241 | |
242 virtual void GetInternalContent(Json::Value& value) | |
243 { | |
244 Json::Value v = Json::arrayValue; | |
245 | |
246 for (size_t i = 0; i < instances_.size(); i++) | |
247 { | |
248 v.append(instances_[i]); | |
249 } | |
250 | |
251 value["Instances"] = v; | |
252 | |
253 | |
254 v = Json::arrayValue; | |
255 | |
256 for (std::set<std::string>::const_iterator it = failedInstances_.begin(); | |
257 it != failedInstances_.end(); ++it) | |
258 { | |
259 v.append(*it); | |
260 } | |
261 | |
262 value["FailedInstances"] = v; | |
263 } | |
264 }; | |
265 | |
266 | |
267 class DicomStoreJob : public SetOfInstancesJob | 52 class DicomStoreJob : public SetOfInstancesJob |
268 { | 53 { |
269 private: | 54 private: |
270 ServerContext& context_; | 55 ServerContext& context_; |
271 std::string localAet_; | 56 std::string localAet_; |