Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 4658:66f6fd77deaf Orthanc-1.9.3
Orthanc-1.9.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 May 2021 09:22:38 +0200 |
parents | b02dc8303cf6 |
children | cdab941fe17d |
rev | line source |
---|---|
2632 | 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:
4341
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
2632 | 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 "../PrecompiledHeadersServer.h" | |
35 #include "ArchiveJob.h" | |
36 | |
4045 | 37 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h" |
38 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h" | |
39 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h" | |
40 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
41 #include "../../../OrthancFramework/Sources/Logging.h" | |
42 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
43 #include "../OrthancConfiguration.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
44 #include "../ServerContext.h" |
2632 | 45 |
46 #include <stdio.h> | |
47 | |
48 #if defined(_MSC_VER) | |
49 #define snprintf _snprintf | |
50 #endif | |
51 | |
52 static const uint64_t MEGA_BYTES = 1024 * 1024; | |
53 static const uint64_t GIGA_BYTES = 1024 * 1024 * 1024; | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
54 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
55 static const char* const MEDIA_IMAGES_FOLDER = "IMAGES"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
56 static const char* const KEY_DESCRIPTION = "Description"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
57 static const char* const KEY_INSTANCES_COUNT = "InstancesCount"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
58 static const char* const KEY_UNCOMPRESSED_SIZE_MB = "UncompressedSizeMB"; |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
59 static const char* const KEY_ARCHIVE_SIZE_MB = "ArchiveSizeMB"; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
60 static const char* const KEY_TRANSCODE = "Transcode"; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
61 |
2632 | 62 |
63 namespace Orthanc | |
64 { | |
65 static bool IsZip64Required(uint64_t uncompressedSize, | |
66 unsigned int countInstances) | |
67 { | |
68 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; // Should be large enough to hold DICOMDIR | |
69 static const unsigned int FILES_MARGIN = 10; | |
70 | |
71 /** | |
72 * Determine whether ZIP64 is required. Original ZIP format can | |
73 * store up to 2GB of data (some implementation supporting up to | |
74 * 4GB of data), and up to 65535 files. | |
75 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64 | |
76 **/ | |
77 | |
78 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN || | |
79 countInstances >= 65535 - FILES_MARGIN); | |
80 | |
81 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size " | |
82 << (uncompressedSize / MEGA_BYTES) << "MB using the " | |
83 << (isZip64 ? "ZIP64" : "ZIP32") << " file format"; | |
84 | |
85 return isZip64; | |
86 } | |
87 | |
88 | |
89 class ArchiveJob::ResourceIdentifiers : public boost::noncopyable | |
90 { | |
91 private: | |
92 ResourceType level_; | |
93 std::string patient_; | |
94 std::string study_; | |
95 std::string series_; | |
96 std::string instance_; | |
97 | |
98 static void GoToParent(ServerIndex& index, | |
99 std::string& current) | |
100 { | |
101 std::string tmp; | |
102 | |
103 if (index.LookupParent(tmp, current)) | |
104 { | |
105 current = tmp; | |
106 } | |
107 else | |
108 { | |
109 throw OrthancException(ErrorCode_UnknownResource); | |
110 } | |
111 } | |
112 | |
113 | |
114 public: | |
115 ResourceIdentifiers(ServerIndex& index, | |
116 const std::string& publicId) | |
117 { | |
118 if (!index.LookupResourceType(level_, publicId)) | |
119 { | |
120 throw OrthancException(ErrorCode_UnknownResource); | |
121 } | |
122 | |
123 std::string current = publicId;; | |
124 switch (level_) // Do not add "break" below! | |
125 { | |
126 case ResourceType_Instance: | |
127 instance_ = current; | |
128 GoToParent(index, current); | |
129 | |
130 case ResourceType_Series: | |
131 series_ = current; | |
132 GoToParent(index, current); | |
133 | |
134 case ResourceType_Study: | |
135 study_ = current; | |
136 GoToParent(index, current); | |
137 | |
138 case ResourceType_Patient: | |
139 patient_ = current; | |
140 break; | |
141 | |
142 default: | |
143 throw OrthancException(ErrorCode_InternalError); | |
144 } | |
145 } | |
146 | |
147 ResourceType GetLevel() const | |
148 { | |
149 return level_; | |
150 } | |
151 | |
152 const std::string& GetIdentifier(ResourceType level) const | |
153 { | |
154 // Some sanity check to ensure enumerations are not altered | |
155 assert(ResourceType_Patient < ResourceType_Study); | |
156 assert(ResourceType_Study < ResourceType_Series); | |
157 assert(ResourceType_Series < ResourceType_Instance); | |
158 | |
159 if (level > level_) | |
160 { | |
161 throw OrthancException(ErrorCode_InternalError); | |
162 } | |
163 | |
164 switch (level) | |
165 { | |
166 case ResourceType_Patient: | |
167 return patient_; | |
168 | |
169 case ResourceType_Study: | |
170 return study_; | |
171 | |
172 case ResourceType_Series: | |
173 return series_; | |
174 | |
175 case ResourceType_Instance: | |
176 return instance_; | |
177 | |
178 default: | |
179 throw OrthancException(ErrorCode_InternalError); | |
180 } | |
181 } | |
182 }; | |
183 | |
184 | |
185 class ArchiveJob::IArchiveVisitor : public boost::noncopyable | |
186 { | |
187 public: | |
188 virtual ~IArchiveVisitor() | |
189 { | |
190 } | |
191 | |
192 virtual void Open(ResourceType level, | |
193 const std::string& publicId) = 0; | |
194 | |
195 virtual void Close() = 0; | |
196 | |
197 virtual void AddInstance(const std::string& instanceId, | |
4510
a3635a01a945
fix signature of virtual method
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4509
diff
changeset
|
198 uint64_t uncompressedSize) = 0; |
2632 | 199 }; |
200 | |
201 | |
202 class ArchiveJob::ArchiveIndex : public boost::noncopyable | |
203 { | |
204 private: | |
205 struct Instance | |
206 { | |
207 std::string id_; | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
208 uint64_t uncompressedSize_; |
2632 | 209 |
210 Instance(const std::string& id, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
211 uint64_t uncompressedSize) : |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
212 id_(id), |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
213 uncompressedSize_(uncompressedSize) |
2632 | 214 { |
215 } | |
216 }; | |
217 | |
218 // A "NULL" value for ArchiveIndex indicates a non-expanded node | |
219 typedef std::map<std::string, ArchiveIndex*> Resources; | |
220 | |
221 ResourceType level_; | |
222 Resources resources_; // Only at patient/study/series level | |
223 std::list<Instance> instances_; // Only at instance level | |
224 | |
225 | |
226 void AddResourceToExpand(ServerIndex& index, | |
227 const std::string& id) | |
228 { | |
229 if (level_ == ResourceType_Instance) | |
230 { | |
231 FileInfo tmp; | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
232 int64_t revision; // ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
233 if (index.LookupAttachment(tmp, revision, id, FileContentType_Dicom)) |
2632 | 234 { |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
235 instances_.push_back(Instance(id, tmp.GetUncompressedSize())); |
2632 | 236 } |
237 } | |
238 else | |
239 { | |
240 resources_[id] = NULL; | |
241 } | |
242 } | |
243 | |
244 | |
245 public: | |
4205 | 246 explicit ArchiveIndex(ResourceType level) : |
2632 | 247 level_(level) |
248 { | |
249 } | |
250 | |
251 ~ArchiveIndex() | |
252 { | |
253 for (Resources::iterator it = resources_.begin(); | |
254 it != resources_.end(); ++it) | |
255 { | |
256 delete it->second; | |
257 } | |
258 } | |
259 | |
260 | |
261 void Add(ServerIndex& index, | |
262 const ResourceIdentifiers& resource) | |
263 { | |
264 const std::string& id = resource.GetIdentifier(level_); | |
265 Resources::iterator previous = resources_.find(id); | |
266 | |
267 if (level_ == ResourceType_Instance) | |
268 { | |
269 AddResourceToExpand(index, id); | |
270 } | |
271 else if (resource.GetLevel() == level_) | |
272 { | |
273 // Mark this resource for further expansion | |
274 if (previous != resources_.end()) | |
275 { | |
276 delete previous->second; | |
277 } | |
278 | |
279 resources_[id] = NULL; | |
280 } | |
281 else if (previous == resources_.end()) | |
282 { | |
283 // This is the first time we meet this resource | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
284 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 285 child->Add(index, resource); |
286 resources_[id] = child.release(); | |
287 } | |
288 else if (previous->second != NULL) | |
289 { | |
290 previous->second->Add(index, resource); | |
291 } | |
292 else | |
293 { | |
294 // Nothing to do: This item is marked for further expansion | |
295 } | |
296 } | |
297 | |
298 | |
299 void Expand(ServerIndex& index) | |
300 { | |
301 if (level_ == ResourceType_Instance) | |
302 { | |
303 // Expanding an instance node makes no sense | |
304 return; | |
305 } | |
306 | |
307 for (Resources::iterator it = resources_.begin(); | |
308 it != resources_.end(); ++it) | |
309 { | |
310 if (it->second == NULL) | |
311 { | |
312 // This is resource is marked for expansion | |
313 std::list<std::string> children; | |
314 index.GetChildren(children, it->first); | |
315 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
316 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 317 |
318 for (std::list<std::string>::const_iterator | |
319 it2 = children.begin(); it2 != children.end(); ++it2) | |
320 { | |
321 child->AddResourceToExpand(index, *it2); | |
322 } | |
323 | |
324 it->second = child.release(); | |
325 } | |
326 | |
327 assert(it->second != NULL); | |
328 it->second->Expand(index); | |
329 } | |
330 } | |
331 | |
332 | |
333 void Apply(IArchiveVisitor& visitor) const | |
334 { | |
335 if (level_ == ResourceType_Instance) | |
336 { | |
337 for (std::list<Instance>::const_iterator | |
338 it = instances_.begin(); it != instances_.end(); ++it) | |
339 { | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
340 visitor.AddInstance(it->id_, it->uncompressedSize_); |
2632 | 341 } |
342 } | |
343 else | |
344 { | |
345 for (Resources::const_iterator it = resources_.begin(); | |
346 it != resources_.end(); ++it) | |
347 { | |
348 assert(it->second != NULL); // There must have been a call to "Expand()" | |
349 visitor.Open(level_, it->first); | |
350 it->second->Apply(visitor); | |
351 visitor.Close(); | |
352 } | |
353 } | |
354 } | |
355 }; | |
356 | |
357 | |
358 | |
359 class ArchiveJob::ZipCommands : public boost::noncopyable | |
360 { | |
361 private: | |
362 enum Type | |
363 { | |
364 Type_OpenDirectory, | |
365 Type_CloseDirectory, | |
366 Type_WriteInstance | |
367 }; | |
368 | |
369 class Command : public boost::noncopyable | |
370 { | |
371 private: | |
372 Type type_; | |
373 std::string filename_; | |
374 std::string instanceId_; | |
375 | |
376 public: | |
377 explicit Command(Type type) : | |
378 type_(type) | |
379 { | |
380 assert(type_ == Type_CloseDirectory); | |
381 } | |
382 | |
383 Command(Type type, | |
384 const std::string& filename) : | |
385 type_(type), | |
386 filename_(filename) | |
387 { | |
388 assert(type_ == Type_OpenDirectory); | |
389 } | |
390 | |
391 Command(Type type, | |
392 const std::string& filename, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
393 const std::string& instanceId) : |
2632 | 394 type_(type), |
395 filename_(filename), | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
396 instanceId_(instanceId) |
2632 | 397 { |
398 assert(type_ == Type_WriteInstance); | |
399 } | |
400 | |
401 void Apply(HierarchicalZipWriter& writer, | |
402 ServerContext& context, | |
403 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
404 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
405 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
406 DicomTransferSyntax transferSyntax) const |
2632 | 407 { |
408 switch (type_) | |
409 { | |
410 case Type_OpenDirectory: | |
411 writer.OpenDirectory(filename_.c_str()); | |
412 break; | |
413 | |
414 case Type_CloseDirectory: | |
415 writer.CloseDirectory(); | |
416 break; | |
417 | |
418 case Type_WriteInstance: | |
419 { | |
420 std::string content; | |
421 | |
422 try | |
423 { | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
424 context.ReadDicom(content, instanceId_); |
2632 | 425 } |
426 catch (OrthancException& e) | |
427 { | |
428 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; | |
429 return; | |
430 } | |
2636 | 431 |
432 //boost::this_thread::sleep(boost::posix_time::milliseconds(300)); | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
433 |
2632 | 434 writer.OpenFile(filename_.c_str()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
435 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
436 bool transcodeSuccess = false; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
437 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
438 std::unique_ptr<ParsedDicomFile> parsed; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
439 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
440 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
441 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
442 // New in Orthanc 1.7.0 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
443 std::set<DicomTransferSyntax> syntaxes; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
444 syntaxes.insert(transferSyntax); |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
445 |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
446 IDicomTranscoder::DicomImage source, transcoded; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
447 source.SetExternalBuffer(content); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
448 |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
449 if (context.Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
450 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
451 writer.Write(transcoded.GetBufferData(), transcoded.GetBufferSize()); |
2632 | 452 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
453 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
454 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
455 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
456 dicomDir->Add(dicomDirFolder, filename_, *tmp); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
457 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
458 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
459 transcodeSuccess = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
460 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
461 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
462 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
463 LOG(INFO) << "Cannot transcode instance " << instanceId_ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
464 << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
465 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
466 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
467 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
468 if (!transcodeSuccess) |
2632 | 469 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
470 writer.Write(content); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
471 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
472 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
473 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
474 if (parsed.get() == NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
475 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
476 parsed.reset(new ParsedDicomFile(content)); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
477 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
478 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
479 dicomDir->Add(dicomDirFolder, filename_, *parsed); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
480 } |
2632 | 481 } |
482 | |
483 break; | |
484 } | |
485 | |
486 default: | |
487 throw OrthancException(ErrorCode_InternalError); | |
488 } | |
489 } | |
490 }; | |
491 | |
492 std::deque<Command*> commands_; | |
493 uint64_t uncompressedSize_; | |
494 unsigned int instancesCount_; | |
495 | |
496 | |
497 void ApplyInternal(HierarchicalZipWriter& writer, | |
498 ServerContext& context, | |
499 size_t index, | |
500 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
501 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
502 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
503 DicomTransferSyntax transferSyntax) const |
2632 | 504 { |
505 if (index >= commands_.size()) | |
506 { | |
507 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
508 } | |
509 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
510 commands_[index]->Apply(writer, context, dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 511 } |
512 | |
513 public: | |
514 ZipCommands() : | |
515 uncompressedSize_(0), | |
516 instancesCount_(0) | |
517 { | |
518 } | |
519 | |
520 ~ZipCommands() | |
521 { | |
522 for (std::deque<Command*>::iterator it = commands_.begin(); | |
523 it != commands_.end(); ++it) | |
524 { | |
525 assert(*it != NULL); | |
526 delete *it; | |
527 } | |
528 } | |
529 | |
530 size_t GetSize() const | |
531 { | |
532 return commands_.size(); | |
533 } | |
534 | |
535 unsigned int GetInstancesCount() const | |
536 { | |
537 return instancesCount_; | |
538 } | |
539 | |
540 uint64_t GetUncompressedSize() const | |
541 { | |
542 return uncompressedSize_; | |
543 } | |
544 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
545 // "media" flavor (with DICOMDIR) |
2632 | 546 void Apply(HierarchicalZipWriter& writer, |
547 ServerContext& context, | |
548 size_t index, | |
549 DicomDirWriter& dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
550 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
551 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
552 DicomTransferSyntax transferSyntax) const |
2632 | 553 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
554 ApplyInternal(writer, context, index, &dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 555 } |
556 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
557 // "archive" flavor (without DICOMDIR) |
2632 | 558 void Apply(HierarchicalZipWriter& writer, |
559 ServerContext& context, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
560 size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
561 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
562 DicomTransferSyntax transferSyntax) const |
2632 | 563 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
564 ApplyInternal(writer, context, index, NULL, "", transcode, transferSyntax); |
2632 | 565 } |
566 | |
567 void AddOpenDirectory(const std::string& filename) | |
568 { | |
569 commands_.push_back(new Command(Type_OpenDirectory, filename)); | |
570 } | |
571 | |
572 void AddCloseDirectory() | |
573 { | |
574 commands_.push_back(new Command(Type_CloseDirectory)); | |
575 } | |
576 | |
577 void AddWriteInstance(const std::string& filename, | |
578 const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
579 uint64_t uncompressedSize) |
2632 | 580 { |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
581 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId)); |
2632 | 582 instancesCount_ ++; |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
583 uncompressedSize_ += uncompressedSize; |
2632 | 584 } |
585 | |
586 bool IsZip64() const | |
587 { | |
588 return IsZip64Required(GetUncompressedSize(), GetInstancesCount()); | |
589 } | |
590 }; | |
591 | |
592 | |
593 | |
594 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor | |
595 { | |
596 private: | |
597 ZipCommands& commands_; | |
598 ServerContext& context_; | |
599 char instanceFormat_[24]; | |
600 unsigned int counter_; | |
601 | |
602 static std::string GetTag(const DicomMap& tags, | |
603 const DicomTag& tag) | |
604 { | |
605 const DicomValue* v = tags.TestAndGetValue(tag); | |
606 if (v != NULL && | |
607 !v->IsBinary() && | |
608 !v->IsNull()) | |
609 { | |
610 return v->GetContent(); | |
611 } | |
612 else | |
613 { | |
614 return ""; | |
615 } | |
616 } | |
617 | |
618 public: | |
619 ArchiveIndexVisitor(ZipCommands& commands, | |
620 ServerContext& context) : | |
621 commands_(commands), | |
622 context_(context), | |
623 counter_(0) | |
624 { | |
625 if (commands.GetSize() != 0) | |
626 { | |
627 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
628 } | |
629 | |
630 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
631 } | |
632 | |
633 virtual void Open(ResourceType level, | |
4205 | 634 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 635 { |
636 std::string path; | |
637 | |
638 DicomMap tags; | |
639 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level)) | |
640 { | |
641 switch (level) | |
642 { | |
643 case ResourceType_Patient: | |
644 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME); | |
645 break; | |
646 | |
647 case ResourceType_Study: | |
648 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION); | |
649 break; | |
650 | |
651 case ResourceType_Series: | |
652 { | |
653 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); | |
654 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); | |
655 | |
656 if (modality.size() == 0) | |
657 { | |
658 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
659 } | |
660 else if (modality.size() == 1) | |
661 { | |
662 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", | |
663 toupper(modality[0])); | |
664 } | |
665 else if (modality.size() >= 2) | |
666 { | |
667 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", | |
668 toupper(modality[0]), toupper(modality[1])); | |
669 } | |
670 | |
671 counter_ = 0; | |
672 | |
673 break; | |
674 } | |
675 | |
676 default: | |
677 throw OrthancException(ErrorCode_InternalError); | |
678 } | |
679 } | |
680 | |
681 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); | |
682 | |
683 if (path.empty()) | |
684 { | |
685 path = std::string("Unknown ") + EnumerationToString(level); | |
686 } | |
687 | |
688 commands_.AddOpenDirectory(path.c_str()); | |
689 } | |
690 | |
4205 | 691 virtual void Close() ORTHANC_OVERRIDE |
2632 | 692 { |
693 commands_.AddCloseDirectory(); | |
694 } | |
695 | |
696 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
697 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 698 { |
699 char filename[24]; | |
700 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_); | |
701 counter_ ++; | |
702 | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
703 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 704 } |
705 }; | |
706 | |
707 | |
708 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor | |
709 { | |
710 private: | |
711 ZipCommands& commands_; | |
712 unsigned int counter_; | |
713 | |
714 public: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
715 explicit MediaIndexVisitor(ZipCommands& commands) : |
2632 | 716 commands_(commands), |
717 counter_(0) | |
718 { | |
719 } | |
720 | |
721 virtual void Open(ResourceType level, | |
4205 | 722 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 723 { |
724 } | |
725 | |
4205 | 726 virtual void Close() ORTHANC_OVERRIDE |
2632 | 727 { |
728 } | |
729 | |
730 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
731 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 732 { |
733 // "DICOM restricts the filenames on DICOM media to 8 | |
734 // characters (some systems wrongly use 8.3, but this does not | |
735 // conform to the standard)." | |
736 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_); | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
737 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 738 |
739 counter_ ++; | |
740 } | |
741 }; | |
742 | |
743 | |
744 class ArchiveJob::ZipWriterIterator : public boost::noncopyable | |
745 { | |
746 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
747 ServerContext& context_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
748 ZipCommands commands_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
749 std::unique_ptr<HierarchicalZipWriter> zip_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
750 std::unique_ptr<DicomDirWriter> dicomDir_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
751 bool isMedia_; |
2632 | 752 |
753 public: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
754 ZipWriterIterator(const TemporaryFile& target, |
2632 | 755 ServerContext& context, |
756 ArchiveIndex& archive, | |
757 bool isMedia, | |
758 bool enableExtendedSopClass) : | |
759 context_(context), | |
760 isMedia_(isMedia) | |
761 { | |
762 if (isMedia) | |
763 { | |
4588 | 764 MediaIndexVisitor visitor(commands_); |
2632 | 765 archive.Expand(context.GetIndex()); |
766 | |
767 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER); | |
768 archive.Apply(visitor); | |
769 commands_.AddCloseDirectory(); | |
770 | |
771 dicomDir_.reset(new DicomDirWriter); | |
772 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass); | |
773 } | |
774 else | |
775 { | |
776 ArchiveIndexVisitor visitor(commands_, context); | |
777 archive.Expand(context.GetIndex()); | |
778 archive.Apply(visitor); | |
779 } | |
780 | |
781 zip_.reset(new HierarchicalZipWriter(target.GetPath().c_str())); | |
782 zip_->SetZip64(commands_.IsZip64()); | |
783 } | |
784 | |
785 size_t GetStepsCount() const | |
786 { | |
787 return commands_.GetSize() + 1; | |
788 } | |
789 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
790 void RunStep(size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
791 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
792 DicomTransferSyntax transferSyntax) |
2632 | 793 { |
794 if (index > commands_.GetSize()) | |
795 { | |
796 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
797 } | |
798 else if (index == commands_.GetSize()) | |
799 { | |
800 // Last step: Add the DICOMDIR | |
801 if (isMedia_) | |
802 { | |
803 assert(dicomDir_.get() != NULL); | |
804 std::string s; | |
805 dicomDir_->Encode(s); | |
806 | |
807 zip_->OpenFile("DICOMDIR"); | |
808 zip_->Write(s); | |
809 } | |
810 } | |
811 else | |
812 { | |
813 if (isMedia_) | |
814 { | |
815 assert(dicomDir_.get() != NULL); | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
816 commands_.Apply(*zip_, context_, index, *dicomDir_, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
817 MEDIA_IMAGES_FOLDER, transcode, transferSyntax); |
2632 | 818 } |
819 else | |
820 { | |
821 assert(dicomDir_.get() == NULL); | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
822 commands_.Apply(*zip_, context_, index, transcode, transferSyntax); |
2632 | 823 } |
824 } | |
825 } | |
826 | |
827 unsigned int GetInstancesCount() const | |
828 { | |
829 return commands_.GetInstancesCount(); | |
830 } | |
831 | |
832 uint64_t GetUncompressedSize() const | |
833 { | |
834 return commands_.GetUncompressedSize(); | |
835 } | |
836 }; | |
837 | |
838 | |
2966 | 839 ArchiveJob::ArchiveJob(ServerContext& context, |
2632 | 840 bool isMedia, |
841 bool enableExtendedSopClass) : | |
842 context_(context), | |
843 archive_(new ArchiveIndex(ResourceType_Patient)), // root | |
844 isMedia_(isMedia), | |
845 enableExtendedSopClass_(enableExtendedSopClass), | |
846 currentStep_(0), | |
847 instancesCount_(0), | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
848 uncompressedSize_(0), |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
849 archiveSize_(0), |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
850 transcode_(false), |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
851 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit) |
2632 | 852 { |
2966 | 853 } |
854 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
855 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
856 ArchiveJob::~ArchiveJob() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
857 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
858 if (!mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
859 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
860 context_.GetMediaArchive().Remove(mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
861 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
862 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
863 |
2966 | 864 |
865 void ArchiveJob::SetSynchronousTarget(boost::shared_ptr<TemporaryFile>& target) | |
866 { | |
867 if (target.get() == NULL) | |
2632 | 868 { |
869 throw OrthancException(ErrorCode_NullPointer); | |
870 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
871 else if (writer_.get() != NULL || // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
872 synchronousTarget_.get() != NULL || |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
873 asynchronousTarget_.get() != NULL) |
2966 | 874 { |
875 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
876 } | |
877 else | |
878 { | |
879 synchronousTarget_ = target; | |
880 } | |
2632 | 881 } |
882 | |
883 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
884 void ArchiveJob::SetDescription(const std::string& description) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
885 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
886 if (writer_.get() != NULL) // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
887 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
888 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
889 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
890 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
891 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
892 description_ = description; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
893 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
894 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
895 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
896 |
2632 | 897 void ArchiveJob::AddResource(const std::string& publicId) |
898 { | |
899 if (writer_.get() != NULL) // Already started | |
900 { | |
901 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
902 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
903 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
904 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
905 ResourceIdentifiers resource(context_.GetIndex(), publicId); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
906 archive_->Add(context_.GetIndex(), resource); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
907 } |
2632 | 908 } |
909 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
910 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
911 void ArchiveJob::SetTranscode(DicomTransferSyntax transferSyntax) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
912 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
913 if (writer_.get() != NULL) // Already started |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
914 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
915 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
916 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
917 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
918 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
919 transcode_ = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
920 transferSyntax_ = transferSyntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
921 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
922 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
923 |
2632 | 924 |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2730
diff
changeset
|
925 void ArchiveJob::Reset() |
2632 | 926 { |
2955 | 927 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
928 "Cannot resubmit the creation of an archive"); | |
2632 | 929 } |
930 | |
931 | |
932 void ArchiveJob::Start() | |
933 { | |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
934 TemporaryFile* target = NULL; // (*) |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
935 |
2966 | 936 if (synchronousTarget_.get() == NULL) |
937 { | |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
938 { |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
939 OrthancConfiguration::ReaderLock lock; |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
940 asynchronousTarget_.reset(lock.GetConfiguration().CreateTemporaryFile()); |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
941 } |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
942 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
943 target = asynchronousTarget_.get(); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
944 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
945 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
946 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
947 target = synchronousTarget_.get(); |
2966 | 948 } |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
949 |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
950 assert(target != NULL); |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
951 target->Touch(); // Make sure we can write to the temporary file |
2966 | 952 |
2632 | 953 if (writer_.get() != NULL) |
954 { | |
955 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
956 } | |
957 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
958 writer_.reset(new ZipWriterIterator(*target, context_, *archive_, |
2632 | 959 isMedia_, enableExtendedSopClass_)); |
960 | |
961 instancesCount_ = writer_->GetInstancesCount(); | |
962 uncompressedSize_ = writer_->GetUncompressedSize(); | |
963 } | |
964 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
965 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
966 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
967 namespace |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
968 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
969 class DynamicTemporaryFile : public IDynamicObject |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
970 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
971 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
972 std::unique_ptr<TemporaryFile> file_; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
973 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
974 public: |
4205 | 975 explicit DynamicTemporaryFile(TemporaryFile* f) : file_(f) |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
976 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
977 if (f == NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
978 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
979 throw OrthancException(ErrorCode_NullPointer); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
980 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
981 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
982 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
983 const TemporaryFile& GetFile() const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
984 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
985 assert(file_.get() != NULL); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
986 return *file_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
987 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
988 }; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
989 } |
2632 | 990 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
991 |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
992 void ArchiveJob::RefreshArchiveSize() |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
993 { |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
994 if (synchronousTarget_.get() != NULL) |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
995 { |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
996 archiveSize_ = synchronousTarget_->GetFileSize(); |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
997 } |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
998 |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
999 if (asynchronousTarget_.get() != NULL) |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1000 { |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1001 archiveSize_ = asynchronousTarget_->GetFileSize(); |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1002 } |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1003 } |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1004 |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1005 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1006 void ArchiveJob::FinalizeTarget() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1007 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1008 writer_.reset(); // Flush all the results |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1009 |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1010 RefreshArchiveSize(); |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1011 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1012 if (synchronousTarget_.get() != NULL) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1013 { |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1014 /** |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1015 * Synchronous behavior: Release the reference to the temporary |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1016 * file. It is now up to the caller to deal with the shared |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1017 * pointer. This is a fix in Orthanc 1.9.3. |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1018 * https://groups.google.com/g/orthanc-users/c/tpP2fkRAd9o/m/5SGpEHbGCQAJ |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1019 **/ |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1020 synchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1021 } |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1022 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1023 if (asynchronousTarget_.get() != NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1024 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1025 // Asynchronous behavior: Move the resulting file into the media archive |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1026 mediaArchiveId_ = context_.GetMediaArchive().Add( |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1027 new DynamicTemporaryFile(asynchronousTarget_.release())); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1028 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1029 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1030 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1031 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1032 JobStepResult ArchiveJob::Step(const std::string& jobId) |
2632 | 1033 { |
1034 assert(writer_.get() != NULL); | |
1035 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1036 if (synchronousTarget_.get() != NULL && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1037 synchronousTarget_.unique()) |
2632 | 1038 { |
1039 LOG(WARNING) << "A client has disconnected while creating an archive"; | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
diff
changeset
|
1040 return JobStepResult::Failure(ErrorCode_NetworkProtocol, |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
diff
changeset
|
1041 "A client has disconnected while creating an archive"); |
2632 | 1042 } |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1043 |
2632 | 1044 if (writer_->GetStepsCount() == 0) |
1045 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1046 FinalizeTarget(); |
2632 | 1047 return JobStepResult::Success(); |
1048 } | |
1049 else | |
1050 { | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1051 writer_->RunStep(currentStep_, transcode_, transferSyntax_); |
2632 | 1052 |
1053 currentStep_ ++; | |
1054 | |
1055 if (currentStep_ == writer_->GetStepsCount()) | |
1056 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1057 FinalizeTarget(); |
2632 | 1058 return JobStepResult::Success(); |
1059 } | |
1060 else | |
1061 { | |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1062 RefreshArchiveSize(); |
2632 | 1063 return JobStepResult::Continue(); |
1064 } | |
1065 } | |
1066 } | |
1067 | |
1068 | |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1069 void ArchiveJob::Stop(JobStopReason reason) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1070 { |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1071 /** |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1072 * New in Orthanc 1.9.3: Remove the temporary file associated with |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1073 * the job as soon as its job gets canceled (especially visible in |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1074 * asynchronous mode). |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1075 **/ |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1076 if (reason == JobStopReason_Canceled || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1077 reason == JobStopReason_Failure || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1078 reason == JobStopReason_Retry) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1079 { |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1080 // First delete the writer, as it holds a reference to "(a)synchronousTarget_", cf. (*) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1081 writer_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1082 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1083 synchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1084 asynchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1085 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1086 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1087 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1088 |
2632 | 1089 float ArchiveJob::GetProgress() |
1090 { | |
1091 if (writer_.get() == NULL || | |
1092 writer_->GetStepsCount() == 0) | |
1093 { | |
1094 return 1; | |
1095 } | |
1096 else | |
1097 { | |
1098 return (static_cast<float>(currentStep_) / | |
1099 static_cast<float>(writer_->GetStepsCount() - 1)); | |
1100 } | |
1101 } | |
1102 | |
1103 | |
1104 void ArchiveJob::GetJobType(std::string& target) | |
1105 { | |
1106 if (isMedia_) | |
1107 { | |
1108 target = "Media"; | |
1109 } | |
1110 else | |
1111 { | |
1112 target = "Archive"; | |
1113 } | |
1114 } | |
1115 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1116 |
2632 | 1117 void ArchiveJob::GetPublicContent(Json::Value& value) |
1118 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1119 value = Json::objectValue; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1120 value[KEY_DESCRIPTION] = description_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1121 value[KEY_INSTANCES_COUNT] = instancesCount_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1122 value[KEY_UNCOMPRESSED_SIZE_MB] = |
2643 | 1123 static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES); |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1124 value[KEY_ARCHIVE_SIZE_MB] = |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1125 static_cast<unsigned int>(archiveSize_ / MEGA_BYTES); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1126 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1127 if (transcode_) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1128 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1129 value[KEY_TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1130 } |
2632 | 1131 } |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1132 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1133 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1134 bool ArchiveJob::GetOutput(std::string& output, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1135 MimeType& mime, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1136 const std::string& key) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1137 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1138 if (key == "archive" && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1139 !mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1140 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1141 SharedArchive::Accessor accessor(context_.GetMediaArchive(), mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1142 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1143 if (accessor.IsValid()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1144 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1145 const DynamicTemporaryFile& f = dynamic_cast<DynamicTemporaryFile&>(accessor.GetItem()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1146 f.GetFile().Read(output); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1147 mime = MimeType_Zip; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1148 return true; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1149 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1150 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1151 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1152 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1153 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1154 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1155 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1156 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1157 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1158 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1159 } |
2632 | 1160 } |