annotate OrthancServer/ServerJobs/ArchiveJob.cpp @ 3036:8fd203510d8b db-changes

moving LookupIdentifierQuery to the graveyard
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2018 16:27:07 +0100
parents cb5d75143da0
children 4e43e67f8ecf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeadersServer.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ArchiveJob.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/Compression/HierarchicalZipWriter.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../../Core/DicomParsing/DicomDirWriter.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../../Core/Logging.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "../../Core/OrthancException.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <stdio.h>
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #if defined(_MSC_VER)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #define snprintf _snprintf
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #endif
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 static const uint64_t MEGA_BYTES = 1024 * 1024;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 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
50
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
51 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
52 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
53 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
54 static const char* const KEY_UNCOMPRESSED_SIZE_MB = "UncompressedSizeMB";
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
55
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 namespace Orthanc
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 static bool IsZip64Required(uint64_t uncompressedSize,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 unsigned int countInstances)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; // Should be large enough to hold DICOMDIR
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 static const unsigned int FILES_MARGIN = 10;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 /**
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 * Determine whether ZIP64 is required. Original ZIP format can
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 * store up to 2GB of data (some implementation supporting up to
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 * 4GB of data), and up to 65535 files.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 **/
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN ||
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 countInstances >= 65535 - FILES_MARGIN);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size "
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 << (uncompressedSize / MEGA_BYTES) << "MB using the "
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 << (isZip64 ? "ZIP64" : "ZIP32") << " file format";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 return isZip64;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 class ArchiveJob::ResourceIdentifiers : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ResourceType level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 std::string patient_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 std::string study_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 std::string series_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 std::string instance_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 static void GoToParent(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 std::string& current)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 std::string tmp;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if (index.LookupParent(tmp, current))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 current = tmp;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 throw OrthancException(ErrorCode_UnknownResource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ResourceIdentifiers(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if (!index.LookupResourceType(level_, publicId))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 throw OrthancException(ErrorCode_UnknownResource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 std::string current = publicId;;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 switch (level_) // Do not add "break" below!
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 case ResourceType_Instance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 instance_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 series_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 study_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 patient_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 ResourceType GetLevel() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 return level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 const std::string& GetIdentifier(ResourceType level) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 // Some sanity check to ensure enumerations are not altered
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 assert(ResourceType_Patient < ResourceType_Study);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 assert(ResourceType_Study < ResourceType_Series);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 assert(ResourceType_Series < ResourceType_Instance);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if (level > level_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 switch (level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 return patient_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 return study_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 return series_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 case ResourceType_Instance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 return instance_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 class ArchiveJob::IArchiveVisitor : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 virtual ~IArchiveVisitor()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 virtual void Open(ResourceType level,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 const std::string& publicId) = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 virtual void Close() = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 virtual void AddInstance(const std::string& instanceId,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 const FileInfo& dicom) = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 class ArchiveJob::ArchiveIndex : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 struct Instance
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 std::string id_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 FileInfo dicom_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Instance(const std::string& id,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 const FileInfo& dicom) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 id_(id), dicom_(dicom)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 // A "NULL" value for ArchiveIndex indicates a non-expanded node
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 typedef std::map<std::string, ArchiveIndex*> Resources;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 ResourceType level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Resources resources_; // Only at patient/study/series level
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 std::list<Instance> instances_; // Only at instance level
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 void AddResourceToExpand(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 const std::string& id)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 FileInfo tmp;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (index.LookupAttachment(tmp, id, FileContentType_Dicom))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 instances_.push_back(Instance(id, tmp));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 resources_[id] = NULL;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 ArchiveIndex(ResourceType level) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 level_(level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 ~ArchiveIndex()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 for (Resources::iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 delete it->second;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 void Add(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 const ResourceIdentifiers& resource)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 const std::string& id = resource.GetIdentifier(level_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 Resources::iterator previous = resources_.find(id);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 AddResourceToExpand(index, id);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 else if (resource.GetLevel() == level_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 // Mark this resource for further expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 if (previous != resources_.end())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 delete previous->second;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 resources_[id] = NULL;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 else if (previous == resources_.end())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 // This is the first time we meet this resource
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 child->Add(index, resource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 resources_[id] = child.release();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 else if (previous->second != NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 previous->second->Add(index, resource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 // Nothing to do: This item is marked for further expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 void Expand(ServerIndex& index)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 // Expanding an instance node makes no sense
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 return;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 for (Resources::iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 if (it->second == NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 // This is resource is marked for expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 std::list<std::string> children;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 index.GetChildren(children, it->first);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 for (std::list<std::string>::const_iterator
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 it2 = children.begin(); it2 != children.end(); ++it2)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 child->AddResourceToExpand(index, *it2);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 it->second = child.release();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 assert(it->second != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 it->second->Expand(index);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 void Apply(IArchiveVisitor& visitor) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 for (std::list<Instance>::const_iterator
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 it = instances_.begin(); it != instances_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 visitor.AddInstance(it->id_, it->dicom_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 for (Resources::const_iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 assert(it->second != NULL); // There must have been a call to "Expand()"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 visitor.Open(level_, it->first);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 it->second->Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 visitor.Close();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 class ArchiveJob::ZipCommands : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 enum Type
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 Type_OpenDirectory,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 Type_CloseDirectory,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 Type_WriteInstance
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 class Command : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 Type type_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 std::string filename_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 std::string instanceId_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 FileInfo info_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 explicit Command(Type type) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 type_(type)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 assert(type_ == Type_CloseDirectory);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 Command(Type type,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 const std::string& filename) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 type_(type),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 filename_(filename)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 assert(type_ == Type_OpenDirectory);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 Command(Type type,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 const std::string& filename,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 const std::string& instanceId,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 const FileInfo& info) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 type_(type),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 filename_(filename),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 instanceId_(instanceId),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 info_(info)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 assert(type_ == Type_WriteInstance);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 DicomDirWriter* dicomDir,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 const std::string& dicomDirFolder) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 switch (type_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 case Type_OpenDirectory:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 writer.OpenDirectory(filename_.c_str());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 case Type_CloseDirectory:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 writer.CloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 case Type_WriteInstance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 std::string content;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 try
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 context.ReadAttachment(content, info_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 catch (OrthancException& e)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 return;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
2636
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2632
diff changeset
424
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2632
diff changeset
425 //boost::this_thread::sleep(boost::posix_time::milliseconds(300));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 writer.OpenFile(filename_.c_str());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 writer.Write(content);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (dicomDir != NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 ParsedDicomFile parsed(content);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 dicomDir->Add(dicomDirFolder, filename_, parsed);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 std::deque<Command*> commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 uint64_t uncompressedSize_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 unsigned int instancesCount_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 void ApplyInternal(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 size_t index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 DicomDirWriter* dicomDir,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 const std::string& dicomDirFolder) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (index >= commands_.size())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 throw OrthancException(ErrorCode_ParameterOutOfRange);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 commands_[index]->Apply(writer, context, dicomDir, dicomDirFolder);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 ZipCommands() :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 uncompressedSize_(0),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 instancesCount_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 ~ZipCommands()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 for (std::deque<Command*>::iterator it = commands_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 it != commands_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 assert(*it != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 delete *it;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 size_t GetSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 return commands_.size();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 unsigned int GetInstancesCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 return instancesCount_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 uint64_t GetUncompressedSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 return uncompressedSize_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 size_t index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 DicomDirWriter& dicomDir,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 const std::string& dicomDirFolder) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 ApplyInternal(writer, context, index, &dicomDir, dicomDirFolder);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 size_t index) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 ApplyInternal(writer, context, index, NULL, "");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 void AddOpenDirectory(const std::string& filename)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 commands_.push_back(new Command(Type_OpenDirectory, filename));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 void AddCloseDirectory()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 commands_.push_back(new Command(Type_CloseDirectory));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 void AddWriteInstance(const std::string& filename,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 const std::string& instanceId,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 const FileInfo& info)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId, info));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 instancesCount_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 uncompressedSize_ += info.GetUncompressedSize();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 bool IsZip64() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 return IsZip64Required(GetUncompressedSize(), GetInstancesCount());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 ZipCommands& commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 ServerContext& context_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 char instanceFormat_[24];
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 unsigned int counter_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 static std::string GetTag(const DicomMap& tags,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 const DicomTag& tag)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 const DicomValue* v = tags.TestAndGetValue(tag);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 if (v != NULL &&
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 !v->IsBinary() &&
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 !v->IsNull())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 return v->GetContent();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 return "";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 ArchiveIndexVisitor(ZipCommands& commands,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 ServerContext& context) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 commands_(commands),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 counter_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 if (commands.GetSize() != 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 virtual void Open(ResourceType level,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 std::string path;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 DicomMap tags;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 switch (level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 std::string modality = GetTag(tags, DICOM_TAG_MODALITY);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 if (modality.size() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 else if (modality.size() == 1)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm",
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 toupper(modality[0]));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 else if (modality.size() >= 2)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm",
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 toupper(modality[0]), toupper(modality[1]));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 counter_ = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 if (path.empty())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 path = std::string("Unknown ") + EnumerationToString(level);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 commands_.AddOpenDirectory(path.c_str());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 virtual void Close()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 commands_.AddCloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 virtual void AddInstance(const std::string& instanceId,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 const FileInfo& dicom)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 char filename[24];
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 counter_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 commands_.AddWriteInstance(filename, instanceId, dicom);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 ZipCommands& commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 ServerContext& context_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 unsigned int counter_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 MediaIndexVisitor(ZipCommands& commands,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 ServerContext& context) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 commands_(commands),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 counter_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 virtual void Open(ResourceType level,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 virtual void Close()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 virtual void AddInstance(const std::string& instanceId,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 const FileInfo& dicom)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 // "DICOM restricts the filenames on DICOM media to 8
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 // characters (some systems wrongly use 8.3, but this does not
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 // conform to the standard)."
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 commands_.AddWriteInstance(filename, instanceId, dicom);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 counter_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 class ArchiveJob::ZipWriterIterator : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 TemporaryFile& target_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 ServerContext& context_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 ZipCommands commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 std::auto_ptr<HierarchicalZipWriter> zip_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 std::auto_ptr<DicomDirWriter> dicomDir_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 bool isMedia_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 ZipWriterIterator(TemporaryFile& target,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 ArchiveIndex& archive,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 bool isMedia,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 bool enableExtendedSopClass) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 target_(target),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 isMedia_(isMedia)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 if (isMedia)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 MediaIndexVisitor visitor(commands_, context);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 archive.Expand(context.GetIndex());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 archive.Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 commands_.AddCloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 dicomDir_.reset(new DicomDirWriter);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 ArchiveIndexVisitor visitor(commands_, context);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 archive.Expand(context.GetIndex());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 archive.Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 zip_.reset(new HierarchicalZipWriter(target.GetPath().c_str()));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 zip_->SetZip64(commands_.IsZip64());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 size_t GetStepsCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 return commands_.GetSize() + 1;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 void RunStep(size_t index)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 if (index > commands_.GetSize())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 throw OrthancException(ErrorCode_ParameterOutOfRange);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 else if (index == commands_.GetSize())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 // Last step: Add the DICOMDIR
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 assert(dicomDir_.get() != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 std::string s;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 dicomDir_->Encode(s);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 zip_->OpenFile("DICOMDIR");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 zip_->Write(s);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 assert(dicomDir_.get() != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 commands_.Apply(*zip_, context_, index, *dicomDir_, MEDIA_IMAGES_FOLDER);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 assert(dicomDir_.get() == NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 commands_.Apply(*zip_, context_, index);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 unsigned int GetInstancesCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 return commands_.GetInstancesCount();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 uint64_t GetUncompressedSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 return commands_.GetUncompressedSize();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
786 ArchiveJob::ArchiveJob(ServerContext& context,
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 bool isMedia,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 bool enableExtendedSopClass) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 archive_(new ArchiveIndex(ResourceType_Patient)), // root
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 isMedia_(isMedia),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 enableExtendedSopClass_(enableExtendedSopClass),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 currentStep_(0),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 instancesCount_(0),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 uncompressedSize_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
797 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
798
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
799
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
800 ArchiveJob::~ArchiveJob()
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
801 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
802 if (!mediaArchiveId_.empty())
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
803 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
804 context_.GetMediaArchive().Remove(mediaArchiveId_);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
805 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
806 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
807
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
808
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
809 void ArchiveJob::SetSynchronousTarget(boost::shared_ptr<TemporaryFile>& target)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
810 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
811 if (target.get() == NULL)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 throw OrthancException(ErrorCode_NullPointer);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
815 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
816 synchronousTarget_.get() != NULL ||
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
817 asynchronousTarget_.get() != NULL)
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
818 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
819 throw OrthancException(ErrorCode_BadSequenceOfCalls);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
820 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
821 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
822 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
823 synchronousTarget_ = target;
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
824 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
828 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
829 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
830 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
831 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
832 throw OrthancException(ErrorCode_BadSequenceOfCalls);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
833 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
834 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
835 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
836 description_ = description;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
837 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
838 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
839
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
840
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 void ArchiveJob::AddResource(const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 if (writer_.get() != NULL) // Already started
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
847 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
848 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
849 ResourceIdentifiers resource(context_.GetIndex(), publicId);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
850 archive_->Add(context_.GetIndex(), resource);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
851 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
855 void ArchiveJob::Reset()
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
857 throw OrthancException(ErrorCode_BadSequenceOfCalls,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
858 "Cannot resubmit the creation of an archive");
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 void ArchiveJob::Start()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
864 TemporaryFile* target = NULL;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
865
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
866 if (synchronousTarget_.get() == NULL)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
867 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
868 asynchronousTarget_.reset(new TemporaryFile);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
869 target = asynchronousTarget_.get();
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
870 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
871 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
872 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
873 target = synchronousTarget_.get();
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
874 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
875
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 if (writer_.get() != NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
881 writer_.reset(new ZipWriterIterator(*target, context_, *archive_,
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 isMedia_, enableExtendedSopClass_));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 instancesCount_ = writer_->GetInstancesCount();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 uncompressedSize_ = writer_->GetUncompressedSize();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
888
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 namespace
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 class DynamicTemporaryFile : public IDynamicObject
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 private:
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
895 std::auto_ptr<TemporaryFile> file_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
896
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
897 public:
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
898 DynamicTemporaryFile(TemporaryFile* f) : file_(f)
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 if (f == NULL)
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 throw OrthancException(ErrorCode_NullPointer);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
903 }
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
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
906 const TemporaryFile& GetFile() const
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
907 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
908 assert(file_.get() != NULL);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
909 return *file_;
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 };
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
912 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
914
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
915 void ArchiveJob::FinalizeTarget()
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
916 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
917 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
918
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
919 if (asynchronousTarget_.get() != NULL)
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
920 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
921 // 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
922 mediaArchiveId_ = context_.GetMediaArchive().Add(
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
923 new DynamicTemporaryFile(asynchronousTarget_.release()));
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
924 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
925 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
926
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
927
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
928 JobStepResult ArchiveJob::Step()
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 assert(writer_.get() != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
932 if (synchronousTarget_.get() != NULL &&
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
933 synchronousTarget_.unique())
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 LOG(WARNING) << "A client has disconnected while creating an archive";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 return JobStepResult::Failure(ErrorCode_NetworkProtocol);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 if (writer_->GetStepsCount() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
941 FinalizeTarget();
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 return JobStepResult::Success();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 writer_->RunStep(currentStep_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 currentStep_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 if (currentStep_ == writer_->GetStepsCount())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
952 FinalizeTarget();
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 return JobStepResult::Success();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 return JobStepResult::Continue();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 float ArchiveJob::GetProgress()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 if (writer_.get() == NULL ||
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 writer_->GetStepsCount() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 return 1;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 return (static_cast<float>(currentStep_) /
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 static_cast<float>(writer_->GetStepsCount() - 1));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 void ArchiveJob::GetJobType(std::string& target)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 target = "Media";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 target = "Archive";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
990
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 void ArchiveJob::GetPublicContent(Json::Value& value)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
993 value = Json::objectValue;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
994 value[KEY_DESCRIPTION] = description_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
995 value[KEY_INSTANCES_COUNT] = instancesCount_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
996 value[KEY_UNCOMPRESSED_SIZE_MB] =
2643
56bee263645f fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2636
diff changeset
997 static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
999
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1000
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1001 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
1002 MimeType& mime,
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1003 const std::string& key)
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1004 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1005 if (key == "archive" &&
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1006 !mediaArchiveId_.empty())
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 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
1009
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1010 if (accessor.IsValid())
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1011 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1012 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
1013 f.GetFile().Read(output);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1014 mime = MimeType_Zip;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1015 return true;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1016 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1017 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1018 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1019 return false;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1020 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1021 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1022 else
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 return false;
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 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 }