Mercurial > hg > orthanc
annotate Core/JobsEngine/SetOfInstancesJob.cpp @ 3765:4a25727401cd transcoding
first transcoding to jpeg 8bpp
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Mar 2020 18:39:23 +0100 |
parents | 9201a7858cce |
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 | |
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 | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "SetOfInstancesJob.h" | |
36 | |
37 #include "../OrthancException.h" | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
38 #include "../SerializationToolbox.h" |
2585 | 39 |
2860 | 40 #include <cassert> |
41 | |
2585 | 42 namespace Orthanc |
43 { | |
2860 | 44 class SetOfInstancesJob::InstanceCommand : public SetOfInstancesJob::ICommand |
45 { | |
46 private: | |
47 SetOfInstancesJob& that_; | |
48 std::string instance_; | |
49 | |
50 public: | |
51 InstanceCommand(SetOfInstancesJob& that, | |
52 const std::string& instance) : | |
53 that_(that), | |
54 instance_(instance) | |
55 { | |
56 } | |
57 | |
58 const std::string& GetInstance() const | |
59 { | |
60 return instance_; | |
61 } | |
62 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
63 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 64 { |
65 if (!that_.HandleInstance(instance_)) | |
66 { | |
67 that_.failedInstances_.insert(instance_); | |
68 return false; | |
69 } | |
70 else | |
71 { | |
72 return true; | |
73 } | |
74 } | |
75 | |
3674
9201a7858cce
fix warnings with recent wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3658
diff
changeset
|
76 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 77 { |
78 target = instance_; | |
79 } | |
80 }; | |
81 | |
82 | |
83 class SetOfInstancesJob::TrailingStepCommand : public SetOfInstancesJob::ICommand | |
84 { | |
85 private: | |
86 SetOfInstancesJob& that_; | |
87 | |
88 public: | |
89 TrailingStepCommand(SetOfInstancesJob& that) : | |
90 that_(that) | |
91 { | |
92 } | |
93 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
94 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
2860 | 95 { |
96 return that_.HandleTrailingStep(); | |
97 } | |
98 | |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
99 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE |
2860 | 100 { |
101 target = Json::nullValue; | |
102 } | |
103 }; | |
104 | |
105 | |
106 class SetOfInstancesJob::InstanceUnserializer : | |
107 public SetOfInstancesJob::ICommandUnserializer | |
108 { | |
109 private: | |
110 SetOfInstancesJob& that_; | |
111 | |
112 public: | |
113 InstanceUnserializer(SetOfInstancesJob& that) : | |
114 that_(that) | |
115 { | |
116 } | |
117 | |
118 virtual ICommand* Unserialize(const Json::Value& source) const | |
119 { | |
120 if (source.type() == Json::nullValue) | |
121 { | |
122 return new TrailingStepCommand(that_); | |
123 } | |
124 else if (source.type() == Json::stringValue) | |
125 { | |
126 return new InstanceCommand(that_, source.asString()); | |
127 } | |
128 else | |
129 { | |
130 throw OrthancException(ErrorCode_BadFileFormat); | |
131 } | |
132 } | |
133 }; | |
134 | |
135 | |
136 SetOfInstancesJob::SetOfInstancesJob() : | |
137 hasTrailingStep_(false) | |
2585 | 138 { |
139 } | |
140 | |
141 | |
142 void SetOfInstancesJob::AddInstance(const std::string& instance) | |
143 { | |
2860 | 144 AddCommand(new InstanceCommand(*this, instance)); |
2585 | 145 } |
146 | |
147 | |
2860 | 148 void SetOfInstancesJob::AddTrailingStep() |
2585 | 149 { |
2860 | 150 AddCommand(new TrailingStepCommand(*this)); |
151 hasTrailingStep_ = true; | |
152 } | |
153 | |
154 | |
155 size_t SetOfInstancesJob::GetInstancesCount() const | |
156 { | |
157 if (hasTrailingStep_) | |
2585 | 158 { |
2860 | 159 assert(GetCommandsCount() > 0); |
160 return GetCommandsCount() - 1; | |
2585 | 161 } |
162 else | |
163 { | |
2860 | 164 return GetCommandsCount(); |
2585 | 165 } |
166 } | |
167 | |
2860 | 168 |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
169 const std::string& SetOfInstancesJob::GetInstance(size_t index) const |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
170 { |
2860 | 171 if (index >= GetInstancesCount()) |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
172 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
173 throw OrthancException(ErrorCode_ParameterOutOfRange); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
174 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
175 else |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
176 { |
2860 | 177 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance(); |
2585 | 178 } |
179 } | |
180 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
181 |
2860 | 182 void SetOfInstancesJob::Start() |
183 { | |
184 SetOfCommandsJob::Start(); | |
185 } | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
186 |
2860 | 187 |
188 void SetOfInstancesJob::Reset() | |
189 { | |
190 SetOfCommandsJob::Reset(); | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
191 |
2860 | 192 failedInstances_.clear(); |
193 } | |
194 | |
195 | |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 |
2860 | 200 void SetOfInstancesJob::GetPublicContent(Json::Value& target) |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
201 { |
2860 | 202 SetOfCommandsJob::GetPublicContent(target); |
203 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount()); | |
204 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size()); | |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2624
diff
changeset
|
205 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
206 if (!parentResources_.empty()) |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
207 { |
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); |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
209 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
210 } |
2655 | 211 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
212 |
2860 | 213 bool SetOfInstancesJob::Serialize(Json::Value& target) |
214 { | |
215 if (SetOfCommandsJob::Serialize(target)) | |
216 { | |
217 target[KEY_TRAILING_STEP] = hasTrailingStep_; | |
218 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
|
219 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
2860 | 220 return true; |
221 } | |
222 else | |
223 { | |
224 return false; | |
225 } | |
2585 | 226 } |
2860 | 227 |
2652 | 228 |
2860 | 229 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) : |
230 SetOfCommandsJob(new InstanceUnserializer(*this), source) | |
2652 | 231 { |
2860 | 232 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES); |
2652 | 233 |
3374
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
234 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
|
235 { |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
236 // 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
|
237 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
|
238 } |
d0d6bd633e4c
Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
239 |
2860 | 240 if (source.isMember(KEY_TRAILING_STEP)) |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
241 { |
2860 | 242 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP); |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
243 } |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
244 else |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
245 { |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
246 // Backward compatibility with Orthanc <= 1.4.2 |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
247 hasTrailingStep_ = false; |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
248 } |
2860 | 249 } |
250 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
251 |
2585 | 252 } |