Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 4385:92737070b301
If meta-header is missing, best-effort to extract "TransferSyntax" in "/instances/{id}/metadata"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Dec 2020 11:48:40 +0100 |
parents | 977c2759eb0a |
children | d9473bd5ed43 |
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 | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3240
diff
changeset
|
5 * Copyright (C) 2017-2020 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, | |
198 const FileInfo& dicom) = 0; | |
199 }; | |
200 | |
201 | |
202 class ArchiveJob::ArchiveIndex : public boost::noncopyable | |
203 { | |
204 private: | |
205 struct Instance | |
206 { | |
207 std::string id_; | |
208 FileInfo dicom_; | |
209 | |
210 Instance(const std::string& id, | |
211 const FileInfo& dicom) : | |
212 id_(id), dicom_(dicom) | |
213 { | |
214 } | |
215 }; | |
216 | |
217 // A "NULL" value for ArchiveIndex indicates a non-expanded node | |
218 typedef std::map<std::string, ArchiveIndex*> Resources; | |
219 | |
220 ResourceType level_; | |
221 Resources resources_; // Only at patient/study/series level | |
222 std::list<Instance> instances_; // Only at instance level | |
223 | |
224 | |
225 void AddResourceToExpand(ServerIndex& index, | |
226 const std::string& id) | |
227 { | |
228 if (level_ == ResourceType_Instance) | |
229 { | |
230 FileInfo tmp; | |
231 if (index.LookupAttachment(tmp, id, FileContentType_Dicom)) | |
232 { | |
233 instances_.push_back(Instance(id, tmp)); | |
234 } | |
235 } | |
236 else | |
237 { | |
238 resources_[id] = NULL; | |
239 } | |
240 } | |
241 | |
242 | |
243 public: | |
4205 | 244 explicit ArchiveIndex(ResourceType level) : |
2632 | 245 level_(level) |
246 { | |
247 } | |
248 | |
249 ~ArchiveIndex() | |
250 { | |
251 for (Resources::iterator it = resources_.begin(); | |
252 it != resources_.end(); ++it) | |
253 { | |
254 delete it->second; | |
255 } | |
256 } | |
257 | |
258 | |
259 void Add(ServerIndex& index, | |
260 const ResourceIdentifiers& resource) | |
261 { | |
262 const std::string& id = resource.GetIdentifier(level_); | |
263 Resources::iterator previous = resources_.find(id); | |
264 | |
265 if (level_ == ResourceType_Instance) | |
266 { | |
267 AddResourceToExpand(index, id); | |
268 } | |
269 else if (resource.GetLevel() == level_) | |
270 { | |
271 // Mark this resource for further expansion | |
272 if (previous != resources_.end()) | |
273 { | |
274 delete previous->second; | |
275 } | |
276 | |
277 resources_[id] = NULL; | |
278 } | |
279 else if (previous == resources_.end()) | |
280 { | |
281 // 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
|
282 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 283 child->Add(index, resource); |
284 resources_[id] = child.release(); | |
285 } | |
286 else if (previous->second != NULL) | |
287 { | |
288 previous->second->Add(index, resource); | |
289 } | |
290 else | |
291 { | |
292 // Nothing to do: This item is marked for further expansion | |
293 } | |
294 } | |
295 | |
296 | |
297 void Expand(ServerIndex& index) | |
298 { | |
299 if (level_ == ResourceType_Instance) | |
300 { | |
301 // Expanding an instance node makes no sense | |
302 return; | |
303 } | |
304 | |
305 for (Resources::iterator it = resources_.begin(); | |
306 it != resources_.end(); ++it) | |
307 { | |
308 if (it->second == NULL) | |
309 { | |
310 // This is resource is marked for expansion | |
311 std::list<std::string> children; | |
312 index.GetChildren(children, it->first); | |
313 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
314 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 315 |
316 for (std::list<std::string>::const_iterator | |
317 it2 = children.begin(); it2 != children.end(); ++it2) | |
318 { | |
319 child->AddResourceToExpand(index, *it2); | |
320 } | |
321 | |
322 it->second = child.release(); | |
323 } | |
324 | |
325 assert(it->second != NULL); | |
326 it->second->Expand(index); | |
327 } | |
328 } | |
329 | |
330 | |
331 void Apply(IArchiveVisitor& visitor) const | |
332 { | |
333 if (level_ == ResourceType_Instance) | |
334 { | |
335 for (std::list<Instance>::const_iterator | |
336 it = instances_.begin(); it != instances_.end(); ++it) | |
337 { | |
338 visitor.AddInstance(it->id_, it->dicom_); | |
339 } | |
340 } | |
341 else | |
342 { | |
343 for (Resources::const_iterator it = resources_.begin(); | |
344 it != resources_.end(); ++it) | |
345 { | |
346 assert(it->second != NULL); // There must have been a call to "Expand()" | |
347 visitor.Open(level_, it->first); | |
348 it->second->Apply(visitor); | |
349 visitor.Close(); | |
350 } | |
351 } | |
352 } | |
353 }; | |
354 | |
355 | |
356 | |
357 class ArchiveJob::ZipCommands : public boost::noncopyable | |
358 { | |
359 private: | |
360 enum Type | |
361 { | |
362 Type_OpenDirectory, | |
363 Type_CloseDirectory, | |
364 Type_WriteInstance | |
365 }; | |
366 | |
367 class Command : public boost::noncopyable | |
368 { | |
369 private: | |
370 Type type_; | |
371 std::string filename_; | |
372 std::string instanceId_; | |
373 FileInfo info_; | |
374 | |
375 public: | |
376 explicit Command(Type type) : | |
377 type_(type) | |
378 { | |
379 assert(type_ == Type_CloseDirectory); | |
380 } | |
381 | |
382 Command(Type type, | |
383 const std::string& filename) : | |
384 type_(type), | |
385 filename_(filename) | |
386 { | |
387 assert(type_ == Type_OpenDirectory); | |
388 } | |
389 | |
390 Command(Type type, | |
391 const std::string& filename, | |
392 const std::string& instanceId, | |
393 const FileInfo& info) : | |
394 type_(type), | |
395 filename_(filename), | |
396 instanceId_(instanceId), | |
397 info_(info) | |
398 { | |
399 assert(type_ == Type_WriteInstance); | |
400 } | |
401 | |
402 void Apply(HierarchicalZipWriter& writer, | |
403 ServerContext& context, | |
404 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
405 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
406 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
407 DicomTransferSyntax transferSyntax) const |
2632 | 408 { |
409 switch (type_) | |
410 { | |
411 case Type_OpenDirectory: | |
412 writer.OpenDirectory(filename_.c_str()); | |
413 break; | |
414 | |
415 case Type_CloseDirectory: | |
416 writer.CloseDirectory(); | |
417 break; | |
418 | |
419 case Type_WriteInstance: | |
420 { | |
421 std::string content; | |
422 | |
423 try | |
424 { | |
425 context.ReadAttachment(content, info_); | |
426 } | |
427 catch (OrthancException& e) | |
428 { | |
429 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; | |
430 return; | |
431 } | |
2636 | 432 |
433 //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
|
434 |
2632 | 435 writer.OpenFile(filename_.c_str()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
436 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
437 bool transcodeSuccess = false; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
438 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
439 std::unique_ptr<ParsedDicomFile> parsed; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
440 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
441 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
442 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
443 // New in Orthanc 1.7.0 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
444 std::set<DicomTransferSyntax> syntaxes; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
445 syntaxes.insert(transferSyntax); |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
446 |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
447 IDicomTranscoder::DicomImage source, transcoded; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
448 source.SetExternalBuffer(content); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
449 |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
450 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
|
451 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
452 writer.Write(transcoded.GetBufferData(), transcoded.GetBufferSize()); |
2632 | 453 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
454 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
455 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
456 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
457 dicomDir->Add(dicomDirFolder, filename_, *tmp); |
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 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
460 transcodeSuccess = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
461 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
462 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
463 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
464 LOG(INFO) << "Cannot transcode instance " << instanceId_ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
465 << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax); |
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 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
469 if (!transcodeSuccess) |
2632 | 470 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
471 writer.Write(content); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
472 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
473 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
474 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
475 if (parsed.get() == NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
476 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
477 parsed.reset(new ParsedDicomFile(content)); |
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 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
480 dicomDir->Add(dicomDirFolder, filename_, *parsed); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
481 } |
2632 | 482 } |
483 | |
484 break; | |
485 } | |
486 | |
487 default: | |
488 throw OrthancException(ErrorCode_InternalError); | |
489 } | |
490 } | |
491 }; | |
492 | |
493 std::deque<Command*> commands_; | |
494 uint64_t uncompressedSize_; | |
495 unsigned int instancesCount_; | |
496 | |
497 | |
498 void ApplyInternal(HierarchicalZipWriter& writer, | |
499 ServerContext& context, | |
500 size_t index, | |
501 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
502 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
503 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
504 DicomTransferSyntax transferSyntax) const |
2632 | 505 { |
506 if (index >= commands_.size()) | |
507 { | |
508 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
509 } | |
510 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
511 commands_[index]->Apply(writer, context, dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 512 } |
513 | |
514 public: | |
515 ZipCommands() : | |
516 uncompressedSize_(0), | |
517 instancesCount_(0) | |
518 { | |
519 } | |
520 | |
521 ~ZipCommands() | |
522 { | |
523 for (std::deque<Command*>::iterator it = commands_.begin(); | |
524 it != commands_.end(); ++it) | |
525 { | |
526 assert(*it != NULL); | |
527 delete *it; | |
528 } | |
529 } | |
530 | |
531 size_t GetSize() const | |
532 { | |
533 return commands_.size(); | |
534 } | |
535 | |
536 unsigned int GetInstancesCount() const | |
537 { | |
538 return instancesCount_; | |
539 } | |
540 | |
541 uint64_t GetUncompressedSize() const | |
542 { | |
543 return uncompressedSize_; | |
544 } | |
545 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
546 // "media" flavor (with DICOMDIR) |
2632 | 547 void Apply(HierarchicalZipWriter& writer, |
548 ServerContext& context, | |
549 size_t index, | |
550 DicomDirWriter& dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
551 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
552 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
553 DicomTransferSyntax transferSyntax) const |
2632 | 554 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
555 ApplyInternal(writer, context, index, &dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 556 } |
557 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
558 // "archive" flavor (without DICOMDIR) |
2632 | 559 void Apply(HierarchicalZipWriter& writer, |
560 ServerContext& context, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
561 size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
562 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
563 DicomTransferSyntax transferSyntax) const |
2632 | 564 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
565 ApplyInternal(writer, context, index, NULL, "", transcode, transferSyntax); |
2632 | 566 } |
567 | |
568 void AddOpenDirectory(const std::string& filename) | |
569 { | |
570 commands_.push_back(new Command(Type_OpenDirectory, filename)); | |
571 } | |
572 | |
573 void AddCloseDirectory() | |
574 { | |
575 commands_.push_back(new Command(Type_CloseDirectory)); | |
576 } | |
577 | |
578 void AddWriteInstance(const std::string& filename, | |
579 const std::string& instanceId, | |
580 const FileInfo& info) | |
581 { | |
582 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId, info)); | |
583 instancesCount_ ++; | |
584 uncompressedSize_ += info.GetUncompressedSize(); | |
585 } | |
586 | |
587 bool IsZip64() const | |
588 { | |
589 return IsZip64Required(GetUncompressedSize(), GetInstancesCount()); | |
590 } | |
591 }; | |
592 | |
593 | |
594 | |
595 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor | |
596 { | |
597 private: | |
598 ZipCommands& commands_; | |
599 ServerContext& context_; | |
600 char instanceFormat_[24]; | |
601 unsigned int counter_; | |
602 | |
603 static std::string GetTag(const DicomMap& tags, | |
604 const DicomTag& tag) | |
605 { | |
606 const DicomValue* v = tags.TestAndGetValue(tag); | |
607 if (v != NULL && | |
608 !v->IsBinary() && | |
609 !v->IsNull()) | |
610 { | |
611 return v->GetContent(); | |
612 } | |
613 else | |
614 { | |
615 return ""; | |
616 } | |
617 } | |
618 | |
619 public: | |
620 ArchiveIndexVisitor(ZipCommands& commands, | |
621 ServerContext& context) : | |
622 commands_(commands), | |
623 context_(context), | |
624 counter_(0) | |
625 { | |
626 if (commands.GetSize() != 0) | |
627 { | |
628 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
629 } | |
630 | |
631 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
632 } | |
633 | |
634 virtual void Open(ResourceType level, | |
4205 | 635 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 636 { |
637 std::string path; | |
638 | |
639 DicomMap tags; | |
640 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level)) | |
641 { | |
642 switch (level) | |
643 { | |
644 case ResourceType_Patient: | |
645 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME); | |
646 break; | |
647 | |
648 case ResourceType_Study: | |
649 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION); | |
650 break; | |
651 | |
652 case ResourceType_Series: | |
653 { | |
654 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); | |
655 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); | |
656 | |
657 if (modality.size() == 0) | |
658 { | |
659 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
660 } | |
661 else if (modality.size() == 1) | |
662 { | |
663 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", | |
664 toupper(modality[0])); | |
665 } | |
666 else if (modality.size() >= 2) | |
667 { | |
668 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", | |
669 toupper(modality[0]), toupper(modality[1])); | |
670 } | |
671 | |
672 counter_ = 0; | |
673 | |
674 break; | |
675 } | |
676 | |
677 default: | |
678 throw OrthancException(ErrorCode_InternalError); | |
679 } | |
680 } | |
681 | |
682 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); | |
683 | |
684 if (path.empty()) | |
685 { | |
686 path = std::string("Unknown ") + EnumerationToString(level); | |
687 } | |
688 | |
689 commands_.AddOpenDirectory(path.c_str()); | |
690 } | |
691 | |
4205 | 692 virtual void Close() ORTHANC_OVERRIDE |
2632 | 693 { |
694 commands_.AddCloseDirectory(); | |
695 } | |
696 | |
697 virtual void AddInstance(const std::string& instanceId, | |
4205 | 698 const FileInfo& dicom) ORTHANC_OVERRIDE |
2632 | 699 { |
700 char filename[24]; | |
701 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_); | |
702 counter_ ++; | |
703 | |
704 commands_.AddWriteInstance(filename, instanceId, dicom); | |
705 } | |
706 }; | |
707 | |
708 | |
709 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor | |
710 { | |
711 private: | |
712 ZipCommands& commands_; | |
713 ServerContext& context_; | |
714 unsigned int counter_; | |
715 | |
716 public: | |
717 MediaIndexVisitor(ZipCommands& commands, | |
718 ServerContext& context) : | |
719 commands_(commands), | |
720 context_(context), | |
721 counter_(0) | |
722 { | |
723 } | |
724 | |
725 virtual void Open(ResourceType level, | |
4205 | 726 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 727 { |
728 } | |
729 | |
4205 | 730 virtual void Close() ORTHANC_OVERRIDE |
2632 | 731 { |
732 } | |
733 | |
734 virtual void AddInstance(const std::string& instanceId, | |
4205 | 735 const FileInfo& dicom) ORTHANC_OVERRIDE |
2632 | 736 { |
737 // "DICOM restricts the filenames on DICOM media to 8 | |
738 // characters (some systems wrongly use 8.3, but this does not | |
739 // conform to the standard)." | |
740 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_); | |
741 commands_.AddWriteInstance(filename, instanceId, dicom); | |
742 | |
743 counter_ ++; | |
744 } | |
745 }; | |
746 | |
747 | |
748 class ArchiveJob::ZipWriterIterator : public boost::noncopyable | |
749 { | |
750 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
751 TemporaryFile& target_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
752 ServerContext& context_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
753 ZipCommands commands_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
754 std::unique_ptr<HierarchicalZipWriter> zip_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
755 std::unique_ptr<DicomDirWriter> dicomDir_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
756 bool isMedia_; |
2632 | 757 |
758 public: | |
759 ZipWriterIterator(TemporaryFile& target, | |
760 ServerContext& context, | |
761 ArchiveIndex& archive, | |
762 bool isMedia, | |
763 bool enableExtendedSopClass) : | |
764 target_(target), | |
765 context_(context), | |
766 isMedia_(isMedia) | |
767 { | |
768 if (isMedia) | |
769 { | |
770 MediaIndexVisitor visitor(commands_, context); | |
771 archive.Expand(context.GetIndex()); | |
772 | |
773 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER); | |
774 archive.Apply(visitor); | |
775 commands_.AddCloseDirectory(); | |
776 | |
777 dicomDir_.reset(new DicomDirWriter); | |
778 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass); | |
779 } | |
780 else | |
781 { | |
782 ArchiveIndexVisitor visitor(commands_, context); | |
783 archive.Expand(context.GetIndex()); | |
784 archive.Apply(visitor); | |
785 } | |
786 | |
787 zip_.reset(new HierarchicalZipWriter(target.GetPath().c_str())); | |
788 zip_->SetZip64(commands_.IsZip64()); | |
789 } | |
790 | |
791 size_t GetStepsCount() const | |
792 { | |
793 return commands_.GetSize() + 1; | |
794 } | |
795 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
796 void RunStep(size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
797 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
798 DicomTransferSyntax transferSyntax) |
2632 | 799 { |
800 if (index > commands_.GetSize()) | |
801 { | |
802 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
803 } | |
804 else if (index == commands_.GetSize()) | |
805 { | |
806 // Last step: Add the DICOMDIR | |
807 if (isMedia_) | |
808 { | |
809 assert(dicomDir_.get() != NULL); | |
810 std::string s; | |
811 dicomDir_->Encode(s); | |
812 | |
813 zip_->OpenFile("DICOMDIR"); | |
814 zip_->Write(s); | |
815 } | |
816 } | |
817 else | |
818 { | |
819 if (isMedia_) | |
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, *dicomDir_, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
823 MEDIA_IMAGES_FOLDER, transcode, transferSyntax); |
2632 | 824 } |
825 else | |
826 { | |
827 assert(dicomDir_.get() == NULL); | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
828 commands_.Apply(*zip_, context_, index, transcode, transferSyntax); |
2632 | 829 } |
830 } | |
831 } | |
832 | |
833 unsigned int GetInstancesCount() const | |
834 { | |
835 return commands_.GetInstancesCount(); | |
836 } | |
837 | |
838 uint64_t GetUncompressedSize() const | |
839 { | |
840 return commands_.GetUncompressedSize(); | |
841 } | |
842 }; | |
843 | |
844 | |
2966 | 845 ArchiveJob::ArchiveJob(ServerContext& context, |
2632 | 846 bool isMedia, |
847 bool enableExtendedSopClass) : | |
848 context_(context), | |
849 archive_(new ArchiveIndex(ResourceType_Patient)), // root | |
850 isMedia_(isMedia), | |
851 enableExtendedSopClass_(enableExtendedSopClass), | |
852 currentStep_(0), | |
853 instancesCount_(0), | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
854 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
|
855 archiveSize_(0), |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
856 transcode_(false), |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
857 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit) |
2632 | 858 { |
2966 | 859 } |
860 | |
2976
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 ArchiveJob::~ArchiveJob() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
863 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
864 if (!mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
865 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
866 context_.GetMediaArchive().Remove(mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
867 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
868 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
869 |
2966 | 870 |
871 void ArchiveJob::SetSynchronousTarget(boost::shared_ptr<TemporaryFile>& target) | |
872 { | |
873 if (target.get() == NULL) | |
2632 | 874 { |
875 throw OrthancException(ErrorCode_NullPointer); | |
876 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
877 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
|
878 synchronousTarget_.get() != NULL || |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
879 asynchronousTarget_.get() != NULL) |
2966 | 880 { |
881 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
882 } | |
883 else | |
884 { | |
885 synchronousTarget_ = target; | |
886 } | |
2632 | 887 } |
888 | |
889 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
890 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
|
891 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
892 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
|
893 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
894 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
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 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
897 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
898 description_ = description; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
899 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
900 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
901 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
902 |
2632 | 903 void ArchiveJob::AddResource(const std::string& publicId) |
904 { | |
905 if (writer_.get() != NULL) // Already started | |
906 { | |
907 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
908 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
909 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
910 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
911 ResourceIdentifiers resource(context_.GetIndex(), publicId); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
912 archive_->Add(context_.GetIndex(), resource); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
913 } |
2632 | 914 } |
915 | |
3913
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 void ArchiveJob::SetTranscode(DicomTransferSyntax transferSyntax) |
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 if (writer_.get() != NULL) // Already started |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
920 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
921 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
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 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
924 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
925 transcode_ = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
926 transferSyntax_ = transferSyntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
927 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
928 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
929 |
2632 | 930 |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2730
diff
changeset
|
931 void ArchiveJob::Reset() |
2632 | 932 { |
2955 | 933 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
934 "Cannot resubmit the creation of an archive"); | |
2632 | 935 } |
936 | |
937 | |
938 void ArchiveJob::Start() | |
939 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
940 TemporaryFile* target = NULL; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
941 |
2966 | 942 if (synchronousTarget_.get() == NULL) |
943 { | |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
944 { |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
945 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
|
946 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
|
947 } |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
948 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
949 target = asynchronousTarget_.get(); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
950 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
951 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
952 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
953 target = synchronousTarget_.get(); |
2966 | 954 } |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
955 |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
956 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
|
957 target->Touch(); // Make sure we can write to the temporary file |
2966 | 958 |
2632 | 959 if (writer_.get() != NULL) |
960 { | |
961 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
962 } | |
963 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
964 writer_.reset(new ZipWriterIterator(*target, context_, *archive_, |
2632 | 965 isMedia_, enableExtendedSopClass_)); |
966 | |
967 instancesCount_ = writer_->GetInstancesCount(); | |
968 uncompressedSize_ = writer_->GetUncompressedSize(); | |
969 } | |
970 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
971 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
972 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
973 namespace |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
974 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
975 class DynamicTemporaryFile : public IDynamicObject |
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 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
978 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
|
979 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
980 public: |
4205 | 981 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
|
982 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
983 if (f == NULL) |
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 throw OrthancException(ErrorCode_NullPointer); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
986 } |
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 const TemporaryFile& GetFile() const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
990 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
991 assert(file_.get() != NULL); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
992 return *file_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
993 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
994 }; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
995 } |
2632 | 996 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
997 |
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
|
998 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
|
999 { |
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 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
|
1001 { |
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 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
|
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 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
|
1006 { |
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
|
1007 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
|
1008 } |
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
|
1009 } |
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 |
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
|
1011 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1012 void ArchiveJob::FinalizeTarget() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1013 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1014 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
|
1015 |
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
|
1016 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
|
1017 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1018 if (asynchronousTarget_.get() != NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1019 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1020 // 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
|
1021 mediaArchiveId_ = context_.GetMediaArchive().Add( |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1022 new DynamicTemporaryFile(asynchronousTarget_.release())); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1023 } |
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 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1026 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1027 JobStepResult ArchiveJob::Step(const std::string& jobId) |
2632 | 1028 { |
1029 assert(writer_.get() != NULL); | |
1030 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1031 if (synchronousTarget_.get() != NULL && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1032 synchronousTarget_.unique()) |
2632 | 1033 { |
1034 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
|
1035 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
|
1036 "A client has disconnected while creating an archive"); |
2632 | 1037 } |
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
|
1038 |
2632 | 1039 if (writer_->GetStepsCount() == 0) |
1040 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1041 FinalizeTarget(); |
2632 | 1042 return JobStepResult::Success(); |
1043 } | |
1044 else | |
1045 { | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1046 writer_->RunStep(currentStep_, transcode_, transferSyntax_); |
2632 | 1047 |
1048 currentStep_ ++; | |
1049 | |
1050 if (currentStep_ == writer_->GetStepsCount()) | |
1051 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1052 FinalizeTarget(); |
2632 | 1053 return JobStepResult::Success(); |
1054 } | |
1055 else | |
1056 { | |
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
|
1057 RefreshArchiveSize(); |
2632 | 1058 return JobStepResult::Continue(); |
1059 } | |
1060 } | |
1061 } | |
1062 | |
1063 | |
1064 float ArchiveJob::GetProgress() | |
1065 { | |
1066 if (writer_.get() == NULL || | |
1067 writer_->GetStepsCount() == 0) | |
1068 { | |
1069 return 1; | |
1070 } | |
1071 else | |
1072 { | |
1073 return (static_cast<float>(currentStep_) / | |
1074 static_cast<float>(writer_->GetStepsCount() - 1)); | |
1075 } | |
1076 } | |
1077 | |
1078 | |
1079 void ArchiveJob::GetJobType(std::string& target) | |
1080 { | |
1081 if (isMedia_) | |
1082 { | |
1083 target = "Media"; | |
1084 } | |
1085 else | |
1086 { | |
1087 target = "Archive"; | |
1088 } | |
1089 } | |
1090 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1091 |
2632 | 1092 void ArchiveJob::GetPublicContent(Json::Value& value) |
1093 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1094 value = Json::objectValue; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1095 value[KEY_DESCRIPTION] = description_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1096 value[KEY_INSTANCES_COUNT] = instancesCount_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1097 value[KEY_UNCOMPRESSED_SIZE_MB] = |
2643 | 1098 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
|
1099 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
|
1100 static_cast<unsigned int>(archiveSize_ / MEGA_BYTES); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1101 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1102 if (transcode_) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1103 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1104 value[KEY_TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1105 } |
2632 | 1106 } |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1107 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1108 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1109 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
|
1110 MimeType& mime, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1111 const std::string& key) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1112 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1113 if (key == "archive" && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1114 !mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1115 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1116 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
|
1117 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1118 if (accessor.IsValid()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1119 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1120 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
|
1121 f.GetFile().Read(output); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1122 mime = MimeType_Zip; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1123 return true; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1124 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1125 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1126 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1127 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1128 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1129 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1130 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1131 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1132 return false; |
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 } |
2632 | 1135 } |