Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp @ 4805:0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 09 Nov 2021 09:51:14 +0100 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
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 | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
5 * Copyright (C) 2017-2021 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: | |
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
|
78 explicit TrailingStepCommand(SetOfInstancesJob& that) : |
2860 | 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: | |
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
|
102 explicit InstanceUnserializer(SetOfInstancesJob& that) : |
2860 | 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 | |
4304 | 130 |
131 void SetOfInstancesJob::AddParentResource(const std::string &resource) | |
132 { | |
133 parentResources_.insert(resource); | |
134 } | |
135 | |
136 | |
2585 | 137 void SetOfInstancesJob::AddInstance(const std::string& instance) |
138 { | |
2860 | 139 AddCommand(new InstanceCommand(*this, instance)); |
2585 | 140 } |
141 | |
142 | |
2860 | 143 void SetOfInstancesJob::AddTrailingStep() |
2585 | 144 { |
2860 | 145 AddCommand(new TrailingStepCommand(*this)); |
146 hasTrailingStep_ = true; | |
147 } | |
148 | |
149 | |
150 size_t SetOfInstancesJob::GetInstancesCount() const | |
151 { | |
152 if (hasTrailingStep_) | |
2585 | 153 { |
2860 | 154 assert(GetCommandsCount() > 0); |
155 return GetCommandsCount() - 1; | |
2585 | 156 } |
157 else | |
158 { | |
2860 | 159 return GetCommandsCount(); |
2585 | 160 } |
161 } | |
162 | |
2860 | 163 |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
164 const std::string& SetOfInstancesJob::GetInstance(size_t index) const |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
165 { |
2860 | 166 if (index >= GetInstancesCount()) |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
167 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
168 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 else |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
171 { |
2860 | 172 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance(); |
2585 | 173 } |
174 } | |
175 | |
4304 | 176 bool SetOfInstancesJob::HasTrailingStep() const |
177 { | |
178 return hasTrailingStep_; | |
179 } | |
180 | |
181 const std::set<std::string> &SetOfInstancesJob::GetFailedInstances() const | |
182 { | |
183 return failedInstances_; | |
184 } | |
185 | |
186 bool SetOfInstancesJob::IsFailedInstance(const std::string &instance) const | |
187 { | |
188 return failedInstances_.find(instance) != failedInstances_.end(); | |
189 } | |
190 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
191 |
2860 | 192 void SetOfInstancesJob::Start() |
193 { | |
4304 | 194 SetOfCommandsJob::Start(); |
2860 | 195 } |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
196 |
2860 | 197 |
198 void SetOfInstancesJob::Reset() | |
199 { | |
200 SetOfCommandsJob::Reset(); | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
201 |
2860 | 202 failedInstances_.clear(); |
203 } | |
204 | |
205 | |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 |
2860 | 210 void SetOfInstancesJob::GetPublicContent(Json::Value& target) |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
211 { |
2860 | 212 SetOfCommandsJob::GetPublicContent(target); |
213 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount()); | |
214 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size()); | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
215 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
216 if (!parentResources_.empty()) |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
217 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
218 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
|
219 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
220 } |
2655 | 221 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
222 |
2860 | 223 bool SetOfInstancesJob::Serialize(Json::Value& target) |
224 { | |
225 if (SetOfCommandsJob::Serialize(target)) | |
226 { | |
227 target[KEY_TRAILING_STEP] = hasTrailingStep_; | |
228 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
|
229 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
2860 | 230 return true; |
231 } | |
232 else | |
233 { | |
234 return false; | |
235 } | |
2585 | 236 } |
2860 | 237 |
2652 | 238 |
2860 | 239 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) : |
240 SetOfCommandsJob(new InstanceUnserializer(*this), source) | |
2652 | 241 { |
2860 | 242 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES); |
2652 | 243 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
244 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
|
245 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
246 // 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
|
247 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
|
248 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
249 |
2860 | 250 if (source.isMember(KEY_TRAILING_STEP)) |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
251 { |
2860 | 252 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP); |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
253 } |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
254 else |
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 // Backward compatibility with Orthanc <= 1.4.2 |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
257 hasTrailingStep_ = false; |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
258 } |
2860 | 259 } |
2585 | 260 } |