Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp @ 4121:7c9ff821063a framework-lgpl
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 19:54:53 +0200 |
parents | bf7b9edf6b81 |
children | 2007ab69ac16 |
rev | line source |
---|---|
2585 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3374
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2585 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
2585 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
2585 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
2585 | 20 **/ |
21 | |
22 | |
23 #include "../PrecompiledHeaders.h" | |
24 #include "SetOfInstancesJob.h" | |
25 | |
26 #include "../OrthancException.h" | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
27 #include "../SerializationToolbox.h" |
2585 | 28 |
2860 | 29 #include <cassert> |
30 | |
2585 | 31 namespace Orthanc |
32 { | |
2860 | 33 class SetOfInstancesJob::InstanceCommand : public SetOfInstancesJob::ICommand |
34 { | |
35 private: | |
36 SetOfInstancesJob& that_; | |
37 std::string instance_; | |
38 | |
39 public: | |
40 InstanceCommand(SetOfInstancesJob& that, | |
41 const std::string& instance) : | |
42 that_(that), | |
43 instance_(instance) | |
44 { | |
45 } | |
46 | |
47 const std::string& GetInstance() const | |
48 { | |
49 return instance_; | |
50 } | |
51 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
52 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 53 { |
54 if (!that_.HandleInstance(instance_)) | |
55 { | |
56 that_.failedInstances_.insert(instance_); | |
57 return false; | |
58 } | |
59 else | |
60 { | |
61 return true; | |
62 } | |
63 } | |
64 | |
3674
9201a7858cce
fix warnings with recent wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3658
diff
changeset
|
65 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 66 { |
67 target = instance_; | |
68 } | |
69 }; | |
70 | |
71 | |
72 class SetOfInstancesJob::TrailingStepCommand : public SetOfInstancesJob::ICommand | |
73 { | |
74 private: | |
75 SetOfInstancesJob& that_; | |
76 | |
77 public: | |
78 TrailingStepCommand(SetOfInstancesJob& that) : | |
79 that_(that) | |
80 { | |
81 } | |
82 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
83 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 84 { |
85 return that_.HandleTrailingStep(); | |
86 } | |
87 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
88 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 89 { |
90 target = Json::nullValue; | |
91 } | |
92 }; | |
93 | |
94 | |
95 class SetOfInstancesJob::InstanceUnserializer : | |
96 public SetOfInstancesJob::ICommandUnserializer | |
97 { | |
98 private: | |
99 SetOfInstancesJob& that_; | |
100 | |
101 public: | |
102 InstanceUnserializer(SetOfInstancesJob& that) : | |
103 that_(that) | |
104 { | |
105 } | |
106 | |
107 virtual ICommand* Unserialize(const Json::Value& source) const | |
108 { | |
109 if (source.type() == Json::nullValue) | |
110 { | |
111 return new TrailingStepCommand(that_); | |
112 } | |
113 else if (source.type() == Json::stringValue) | |
114 { | |
115 return new InstanceCommand(that_, source.asString()); | |
116 } | |
117 else | |
118 { | |
119 throw OrthancException(ErrorCode_BadFileFormat); | |
120 } | |
121 } | |
122 }; | |
123 | |
124 | |
125 SetOfInstancesJob::SetOfInstancesJob() : | |
126 hasTrailingStep_(false) | |
2585 | 127 { |
128 } | |
129 | |
130 | |
131 void SetOfInstancesJob::AddInstance(const std::string& instance) | |
132 { | |
2860 | 133 AddCommand(new InstanceCommand(*this, instance)); |
2585 | 134 } |
135 | |
136 | |
2860 | 137 void SetOfInstancesJob::AddTrailingStep() |
2585 | 138 { |
2860 | 139 AddCommand(new TrailingStepCommand(*this)); |
140 hasTrailingStep_ = true; | |
141 } | |
142 | |
143 | |
144 size_t SetOfInstancesJob::GetInstancesCount() const | |
145 { | |
146 if (hasTrailingStep_) | |
2585 | 147 { |
2860 | 148 assert(GetCommandsCount() > 0); |
149 return GetCommandsCount() - 1; | |
2585 | 150 } |
151 else | |
152 { | |
2860 | 153 return GetCommandsCount(); |
2585 | 154 } |
155 } | |
156 | |
2860 | 157 |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
158 const std::string& SetOfInstancesJob::GetInstance(size_t index) const |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
159 { |
2860 | 160 if (index >= GetInstancesCount()) |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
161 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
162 throw OrthancException(ErrorCode_ParameterOutOfRange); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
163 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
164 else |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
165 { |
2860 | 166 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance(); |
2585 | 167 } |
168 } | |
169 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
170 |
2860 | 171 void SetOfInstancesJob::Start() |
172 { | |
173 SetOfCommandsJob::Start(); | |
174 } | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
175 |
2860 | 176 |
177 void SetOfInstancesJob::Reset() | |
178 { | |
179 SetOfCommandsJob::Reset(); | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
180 |
2860 | 181 failedInstances_.clear(); |
182 } | |
183 | |
184 | |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
185 static const char* KEY_TRAILING_STEP = "TrailingStep"; |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
186 static const char* KEY_FAILED_INSTANCES = "FailedInstances"; |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
187 static const char* KEY_PARENT_RESOURCES = "ParentResources"; |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
188 |
2860 | 189 void SetOfInstancesJob::GetPublicContent(Json::Value& target) |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
190 { |
2860 | 191 SetOfCommandsJob::GetPublicContent(target); |
192 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount()); | |
193 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size()); | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
194 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
195 if (!parentResources_.empty()) |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
196 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
197 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
198 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
199 } |
2655 | 200 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
201 |
2860 | 202 bool SetOfInstancesJob::Serialize(Json::Value& target) |
203 { | |
204 if (SetOfCommandsJob::Serialize(target)) | |
205 { | |
206 target[KEY_TRAILING_STEP] = hasTrailingStep_; | |
207 SerializationToolbox::WriteSetOfStrings(target, failedInstances_, KEY_FAILED_INSTANCES); | |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
208 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
2860 | 209 return true; |
210 } | |
211 else | |
212 { | |
213 return false; | |
214 } | |
2585 | 215 } |
2860 | 216 |
2652 | 217 |
2860 | 218 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) : |
219 SetOfCommandsJob(new InstanceUnserializer(*this), source) | |
2652 | 220 { |
2860 | 221 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES); |
2652 | 222 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
223 if (source.isMember(KEY_PARENT_RESOURCES)) |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
224 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
225 // Backward compatibility with Orthanc <= 1.5.6 |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
226 SerializationToolbox::ReadSetOfStrings(parentResources_, source, KEY_PARENT_RESOURCES); |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
227 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
228 |
2860 | 229 if (source.isMember(KEY_TRAILING_STEP)) |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
230 { |
2860 | 231 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP); |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
232 } |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
233 else |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
234 { |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
235 // Backward compatibility with Orthanc <= 1.4.2 |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
236 hasTrailingStep_ = false; |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
237 } |
2860 | 238 } |
239 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
240 |
2585 | 241 } |