Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp @ 5640:f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 21:19:57 +0200 |
parents | 48b8dae6dc77 |
children |
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 | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2585 | 8 * |
9 * 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
|
10 * 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
|
11 * 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
|
12 * the License, or (at your option) any later version. |
2585 | 13 * |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * 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
|
17 * Lesser General Public License for more details. |
2585 | 18 * |
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
|
19 * 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
|
20 * 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
|
21 * <http://www.gnu.org/licenses/>. |
2585 | 22 **/ |
23 | |
24 | |
25 #include "../PrecompiledHeaders.h" | |
26 #include "SetOfInstancesJob.h" | |
27 | |
28 #include "../OrthancException.h" | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
29 #include "../SerializationToolbox.h" |
2585 | 30 |
2860 | 31 #include <cassert> |
32 | |
2585 | 33 namespace Orthanc |
34 { | |
2860 | 35 class SetOfInstancesJob::InstanceCommand : public SetOfInstancesJob::ICommand |
36 { | |
37 private: | |
38 SetOfInstancesJob& that_; | |
39 std::string instance_; | |
40 | |
41 public: | |
42 InstanceCommand(SetOfInstancesJob& that, | |
43 const std::string& instance) : | |
44 that_(that), | |
45 instance_(instance) | |
46 { | |
47 } | |
48 | |
49 const std::string& GetInstance() const | |
50 { | |
51 return instance_; | |
52 } | |
53 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
54 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 55 { |
56 if (!that_.HandleInstance(instance_)) | |
57 { | |
58 that_.failedInstances_.insert(instance_); | |
59 return false; | |
60 } | |
61 else | |
62 { | |
63 return true; | |
64 } | |
65 } | |
66 | |
3674
9201a7858cce
fix warnings with recent wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3658
diff
changeset
|
67 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 68 { |
69 target = instance_; | |
70 } | |
71 }; | |
72 | |
73 | |
74 class SetOfInstancesJob::TrailingStepCommand : public SetOfInstancesJob::ICommand | |
75 { | |
76 private: | |
77 SetOfInstancesJob& that_; | |
78 | |
79 public: | |
4202
2007ab69ac16
moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
80 explicit TrailingStepCommand(SetOfInstancesJob& that) : |
2860 | 81 that_(that) |
82 { | |
83 } | |
84 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
85 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 86 { |
87 return that_.HandleTrailingStep(); | |
88 } | |
89 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
90 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 91 { |
92 target = Json::nullValue; | |
93 } | |
94 }; | |
95 | |
96 | |
97 class SetOfInstancesJob::InstanceUnserializer : | |
98 public SetOfInstancesJob::ICommandUnserializer | |
99 { | |
100 private: | |
101 SetOfInstancesJob& that_; | |
102 | |
103 public: | |
4202
2007ab69ac16
moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
104 explicit InstanceUnserializer(SetOfInstancesJob& that) : |
2860 | 105 that_(that) |
106 { | |
107 } | |
108 | |
109 virtual ICommand* Unserialize(const Json::Value& source) const | |
110 { | |
111 if (source.type() == Json::nullValue) | |
112 { | |
113 return new TrailingStepCommand(that_); | |
114 } | |
115 else if (source.type() == Json::stringValue) | |
116 { | |
117 return new InstanceCommand(that_, source.asString()); | |
118 } | |
119 else | |
120 { | |
121 throw OrthancException(ErrorCode_BadFileFormat); | |
122 } | |
123 } | |
124 }; | |
125 | |
126 | |
127 SetOfInstancesJob::SetOfInstancesJob() : | |
128 hasTrailingStep_(false) | |
2585 | 129 { |
130 } | |
131 | |
4304 | 132 |
133 void SetOfInstancesJob::AddParentResource(const std::string &resource) | |
134 { | |
135 parentResources_.insert(resource); | |
136 } | |
137 | |
138 | |
2585 | 139 void SetOfInstancesJob::AddInstance(const std::string& instance) |
140 { | |
2860 | 141 AddCommand(new InstanceCommand(*this, instance)); |
2585 | 142 } |
143 | |
144 | |
2860 | 145 void SetOfInstancesJob::AddTrailingStep() |
2585 | 146 { |
2860 | 147 AddCommand(new TrailingStepCommand(*this)); |
148 hasTrailingStep_ = true; | |
149 } | |
150 | |
151 | |
152 size_t SetOfInstancesJob::GetInstancesCount() const | |
153 { | |
154 if (hasTrailingStep_) | |
2585 | 155 { |
2860 | 156 assert(GetCommandsCount() > 0); |
157 return GetCommandsCount() - 1; | |
2585 | 158 } |
159 else | |
160 { | |
2860 | 161 return GetCommandsCount(); |
2585 | 162 } |
163 } | |
164 | |
2860 | 165 |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
166 const std::string& SetOfInstancesJob::GetInstance(size_t index) const |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
167 { |
2860 | 168 if (index >= GetInstancesCount()) |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
169 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
170 throw OrthancException(ErrorCode_ParameterOutOfRange); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
171 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
172 else |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
173 { |
2860 | 174 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance(); |
2585 | 175 } |
176 } | |
177 | |
4304 | 178 bool SetOfInstancesJob::HasTrailingStep() const |
179 { | |
180 return hasTrailingStep_; | |
181 } | |
182 | |
183 const std::set<std::string> &SetOfInstancesJob::GetFailedInstances() const | |
184 { | |
185 return failedInstances_; | |
186 } | |
187 | |
188 bool SetOfInstancesJob::IsFailedInstance(const std::string &instance) const | |
189 { | |
190 return failedInstances_.find(instance) != failedInstances_.end(); | |
191 } | |
192 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
193 |
2860 | 194 void SetOfInstancesJob::Start() |
195 { | |
4304 | 196 SetOfCommandsJob::Start(); |
2860 | 197 } |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
198 |
2860 | 199 |
200 void SetOfInstancesJob::Reset() | |
201 { | |
202 SetOfCommandsJob::Reset(); | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
203 |
2860 | 204 failedInstances_.clear(); |
205 } | |
206 | |
207 | |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 |
2860 | 212 void SetOfInstancesJob::GetPublicContent(Json::Value& target) |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
213 { |
2860 | 214 SetOfCommandsJob::GetPublicContent(target); |
215 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount()); | |
216 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size()); | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
217 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
218 if (!parentResources_.empty()) |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
219 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
220 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
|
221 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
222 } |
2655 | 223 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
224 |
2860 | 225 bool SetOfInstancesJob::Serialize(Json::Value& target) |
226 { | |
227 if (SetOfCommandsJob::Serialize(target)) | |
228 { | |
229 target[KEY_TRAILING_STEP] = hasTrailingStep_; | |
230 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
|
231 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
2860 | 232 return true; |
233 } | |
234 else | |
235 { | |
236 return false; | |
237 } | |
2585 | 238 } |
2860 | 239 |
2652 | 240 |
2860 | 241 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) : |
242 SetOfCommandsJob(new InstanceUnserializer(*this), source) | |
2652 | 243 { |
2860 | 244 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES); |
2652 | 245 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
246 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
|
247 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
248 // 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
|
249 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
|
250 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
251 |
2860 | 252 if (source.isMember(KEY_TRAILING_STEP)) |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
253 { |
2860 | 254 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP); |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
255 } |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
256 else |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
257 { |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
258 // Backward compatibility with Orthanc <= 1.4.2 |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
259 hasTrailingStep_ = false; |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
260 } |
2860 | 261 } |
2585 | 262 } |