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