annotate OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp @ 4760:b2417ac5055a openssl-3.x

integration mainline->openssl-3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Jul 2021 10:48:14 +0200
parents f0038043fb97 b3957ddd88f1
children 70d2a97ca8cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1121
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
22 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
25 #include "../../../OrthancFramework/Sources/Compression/ZipWriter.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
26 #include "../../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h"
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
27 #include "../../../OrthancFramework/Sources/Logging.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
28 #include "../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
29 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
3181
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
30 #include "../OrthancConfiguration.h"
3095
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
31 #include "../ServerContext.h"
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
32 #include "../ServerJobs/ArchiveJob.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
34 #include <boost/filesystem/fstream.hpp>
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
35
3095
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
36
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
39 static const char* const KEY_RESOURCES = "Resources";
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
40 static const char* const KEY_EXTENDED = "Extended";
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
41 static const char* const KEY_TRANSCODE = "Transcode";
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
42
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
43 static void AddResourcesOfInterestFromArray(ArchiveJob& job,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
44 const Json::Value& resources)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
45 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
46 if (resources.type() != Json::arrayValue)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
47 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
48 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
49 "Expected a list of strings (Orthanc identifiers)");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
50 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
51
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
52 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
53 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
54 if (resources[i].type() != Json::stringValue)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
55 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
56 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
57 "Expected a list of strings (Orthanc identifiers)");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
58 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
59 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
60 {
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
61 job.AddResource(resources[i].asString());
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
62 }
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
63 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
64 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
65
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
66
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
67 static void AddResourcesOfInterest(ArchiveJob& job /* inout */,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
68 const Json::Value& body /* in */)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
69 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
70 if (body.type() == Json::arrayValue)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
71 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
72 AddResourcesOfInterestFromArray(job, body);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
73 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
74 else if (body.type() == Json::objectValue)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
75 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
76 if (body.isMember(KEY_RESOURCES))
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
77 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
78 AddResourcesOfInterestFromArray(job, body[KEY_RESOURCES]);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
79 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
80 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
81 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
82 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
83 "Missing field " + std::string(KEY_RESOURCES) +
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
84 " in the JSON body");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
85 }
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
86 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
87 else
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
88 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
89 throw OrthancException(ErrorCode_BadFileFormat);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
90 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
91 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
92
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
93
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
94 static DicomTransferSyntax GetTransferSyntax(const std::string& value)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
95 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
96 DicomTransferSyntax syntax;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
97 if (LookupTransferSyntax(syntax, value))
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
98 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
99 return syntax;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
100 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
101 else
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
102 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
103 throw OrthancException(ErrorCode_ParameterOutOfRange,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
104 "Unknown transfer syntax: " + value);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
105 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
106 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
107
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
108
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
109 static void GetJobParameters(bool& synchronous, /* out */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
110 bool& extended, /* out */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
111 bool& transcode, /* out */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
112 DicomTransferSyntax& syntax, /* out */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
113 int& priority, /* out */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
114 const Json::Value& body, /* in */
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
115 const bool defaultExtended /* in */)
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
116 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
117 synchronous = OrthancRestApi::IsSynchronousJobRequest
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
118 (true /* synchronous by default */, body);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
119
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
120 priority = OrthancRestApi::GetJobRequestPriority(body);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
121
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
122 if (body.type() == Json::objectValue &&
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
123 body.isMember(KEY_EXTENDED))
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
124 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
125 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
126 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
127 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
128 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
129 extended = defaultExtended;
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
130 }
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
131
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
132 if (body.type() == Json::objectValue &&
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
133 body.isMember(KEY_TRANSCODE))
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
134 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
135 transcode = true;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
136 syntax = GetTransferSyntax(SerializationToolbox::ReadString(body, KEY_TRANSCODE));
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
137 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
138 else
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
139 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
140 transcode = false;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
141 }
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
142 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
143
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
144
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
145 namespace
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
146 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
147 class SynchronousZipChunk : public IDynamicObject
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
148 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
149 private:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150 std::string chunk_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
151 bool done_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
152
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
153 explicit SynchronousZipChunk(bool done) :
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
154 done_(done)
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
155 {
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
156 }
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
157
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
158 public:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
159 static SynchronousZipChunk* CreateDone()
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
160 {
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
161 return new SynchronousZipChunk(true);
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
162 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
163
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164 static SynchronousZipChunk* CreateChunk(const std::string& chunk)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
165 {
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
166 std::unique_ptr<SynchronousZipChunk> item(new SynchronousZipChunk(false));
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
167 item->chunk_ = chunk;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
168 return item.release();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
169 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
170
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
171 bool IsDone() const
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
172 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
173 return done_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
174 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
175
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
176 void SwapString(std::string& target)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
177 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
178 if (done_)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
179 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
180 throw OrthancException(ErrorCode_BadSequenceOfCalls);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
184 target.swap(chunk_);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
186 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
187 };
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 class SynchronousZipStream : public ZipWriter::IOutputStream
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 private:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 boost::shared_ptr<SharedMessageQueue> queue_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
194 uint64_t archiveSize_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
196 public:
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
197 explicit SynchronousZipStream(const boost::shared_ptr<SharedMessageQueue>& queue) :
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
198 queue_(queue),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
199 archiveSize_(0)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
200 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
201 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
202
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
203 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
204 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
205 return archiveSize_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
206 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
207
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
208 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
209 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
210 if (queue_.unique())
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
211 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
212 throw OrthancException(ErrorCode_NetworkProtocol,
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
213 "HTTP client has disconnected while creating an archive in synchronous mode");
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
214 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
215 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
216 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
217 queue_->Enqueue(SynchronousZipChunk::CreateChunk(chunk));
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
218 archiveSize_ += chunk.size();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
219 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
220 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
221
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
222 virtual void Close() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
223 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
224 queue_->Enqueue(SynchronousZipChunk::CreateDone());
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
225 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
226 };
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
227
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
228
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
229 class SynchronousZipSender : public IHttpStreamAnswer
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
230 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
231 private:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
232 ServerContext& context_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
233 std::string jobId_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
234 boost::shared_ptr<SharedMessageQueue> queue_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
235 std::string filename_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
236 bool done_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
237 std::string chunk_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
238
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
239 public:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
240 SynchronousZipSender(ServerContext& context,
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
241 const std::string& jobId,
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
242 const boost::shared_ptr<SharedMessageQueue>& queue,
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
243 const std::string& filename) :
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
244 context_(context),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
245 jobId_(jobId),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
246 queue_(queue),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
247 filename_(filename),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
248 done_(false)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
249 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
250 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
251
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
252 virtual HttpCompression SetupHttpCompression(bool gzipAllowed,
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
253 bool deflateAllowed) ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
254 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
255 // This function is not called by HttpOutput::AnswerWithoutBuffering()
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
256 throw OrthancException(ErrorCode_InternalError);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
257 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
258
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
259 virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
260 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
261 filename = filename_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
262 return true;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
263 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
264
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
265 virtual std::string GetContentType() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
266 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
267 return EnumerationToString(MimeType_Zip);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
268 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
269
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
270 virtual uint64_t GetContentLength() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
271 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
272 throw OrthancException(ErrorCode_InternalError);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
273 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
274
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
275 virtual bool ReadNextChunk() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
276 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
277 for (;;)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
278 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
279 std::unique_ptr<IDynamicObject> obj(queue_->Dequeue(100));
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
280
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
281 if (obj.get() == NULL)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
282 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
283 // Check that the job is still active, which indicates
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
284 // that more data might still be returned
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
285 JobState state;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
286 if (context_.GetJobsEngine().GetRegistry().GetState(state, jobId_) &&
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
287 (state == JobState_Pending ||
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
288 state == JobState_Running ||
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
289 state == JobState_Success))
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
290 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
291 continue;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
292 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
293 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
294 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
295 return false;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
296 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
297 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
298 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
299 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
300 SynchronousZipChunk& item = dynamic_cast<SynchronousZipChunk&>(*obj);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
301 if (item.IsDone())
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
302 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
303 done_ = true;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
304 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
305 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
306 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
307 item.SwapString(chunk_);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
308 done_ = false;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
309 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
310
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
311 return !done_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
312 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
313 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
314 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
315
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
316 virtual const char* GetChunkContent() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
317 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
318 if (done_)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
319 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
320 throw OrthancException(ErrorCode_InternalError);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
321 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
322 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
323 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
324 return (chunk_.empty() ? NULL : chunk_.c_str());
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
325 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
326 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
327
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
328 virtual size_t GetChunkSize() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
329 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
330 if (done_)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
331 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
332 throw OrthancException(ErrorCode_InternalError);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
333 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
334 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
335 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
336 return chunk_.size();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
337 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
338 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
339 };
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
340
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
341
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
342 class SynchronousTemporaryStream : public ZipWriter::IOutputStream
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
343 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
344 private:
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
345 boost::shared_ptr<TemporaryFile> temp_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
346 boost::filesystem::ofstream file_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
347 uint64_t archiveSize_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
348
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
349 public:
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
350 explicit SynchronousTemporaryStream(const boost::shared_ptr<TemporaryFile>& temp) :
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
351 temp_(temp),
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
352 archiveSize_(0)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
353 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
354 file_.open(temp_->GetPath(), std::ofstream::out | std::ofstream::binary);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
355 if (!file_.good())
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
356 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
357 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
358 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
359 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
360
4690
13efc0967cea cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4674
diff changeset
361 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
362 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
363 return archiveSize_;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
364 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
365
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
366 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
367 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
368 if (!chunk.empty())
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
369 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
370 try
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
371 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
372 file_.write(chunk.c_str(), chunk.size());
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
373
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
374 if (!file_.good())
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
375 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
376 file_.close();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
377 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
378 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
379 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
380 catch (boost::filesystem::filesystem_error&)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
381 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
382 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
383 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
384 catch (...) // To catch "std::system_error&" in C++11
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
385 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
386 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
387 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
388 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
389
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
390 archiveSize_ += chunk.size();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
391 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
392
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
393 virtual void Close() ORTHANC_OVERRIDE
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
394 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
395 try
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
396 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
397 file_.close();
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
398 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
399 catch (boost::filesystem::filesystem_error&)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
400 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
401 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
402 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
403 catch (...) // To catch "std::system_error&" in C++11
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
404 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
405 throw OrthancException(ErrorCode_CannotWriteFile);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
406 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
407 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
408 };
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
409 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
410
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
411
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
412 static void SubmitJob(RestApiOutput& output,
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
413 ServerContext& context,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
414 std::unique_ptr<ArchiveJob>& job,
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
415 int priority,
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
416 bool synchronous,
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
417 const std::string& filename)
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
418 {
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
419 if (job.get() == NULL)
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
420 {
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
421 throw OrthancException(ErrorCode_NullPointer);
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
422 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
423
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
424 job->SetDescription("REST API");
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
425
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
426 if (synchronous)
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
427 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
428 bool streaming;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
429
3181
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
430 {
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
431 OrthancConfiguration::ReaderLock lock;
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
432 streaming = lock.GetConfiguration().GetBooleanParameter("SynchronousZipStream", true); // New in Orthanc 1.9.4
3181
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
433 }
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
434
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
435 if (streaming)
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
436 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
437 LOG(INFO) << "Streaming a ZIP archive";
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
438 boost::shared_ptr<SharedMessageQueue> queue(new SharedMessageQueue);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
439
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
440 job->AcquireSynchronousTarget(new SynchronousZipStream(queue));
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
441
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
442 std::string jobId;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
443 context.GetJobsEngine().GetRegistry().Submit(jobId, job.release(), priority);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
444
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
445 SynchronousZipSender sender(context, jobId, queue, filename);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
446 output.AnswerWithoutBuffering(sender);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
447
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
448 // If we reach this line, this means that
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
449 // "SynchronousZipSender::ReadNextChunk()" has returned "false"
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
450 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
451 else
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
452 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
453 // This was the only behavior in Orthanc <= 1.9.3
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
454 LOG(INFO) << "Not streaming a ZIP archive (use of a temporary file)";
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
455 boost::shared_ptr<TemporaryFile> tmp;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
456
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
457 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
458 OrthancConfiguration::ReaderLock lock;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
459 tmp.reset(lock.GetConfiguration().CreateTemporaryFile());
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
460 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
461
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
462 job->AcquireSynchronousTarget(new SynchronousTemporaryStream(tmp));
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
463
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
464 Json::Value publicContent;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
465 context.GetJobsEngine().GetRegistry().SubmitAndWait
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
466 (publicContent, job.release(), priority);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
467
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
468 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
469 // The archive is now created: Prepare the sending of the ZIP file
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
470 FilesystemHttpSender sender(tmp->GetPath(), MimeType_Zip);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
471 sender.SetContentFilename(filename);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
472
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
473 // Send the ZIP
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
474 output.AnswerStream(sender);
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
475 }
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
476 }
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
477 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
478 else
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
479 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2970
diff changeset
480 OrthancRestApi::SubmitGenericJob(output, context, job.release(), false, priority);
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
481 }
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
482 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
483
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
484
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
485 static void DocumentPostArguments(RestApiPostCall& call,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
486 bool isMedia,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
487 bool defaultExtended)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
488 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
489 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
490 .SetRequestField("Synchronous", RestApiCallDocumentation::Type_Boolean,
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
491 "If `true`, create the archive in synchronous mode, which means that the HTTP answer will directly "
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
492 "contain the ZIP file. This is the default, easy behavior. However, if global configuration option "
4751
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4690
diff changeset
493 "\"SynchronousZipStream\" is set to \"false\", asynchronous transfers should be preferred for "
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
494 "large amount of data, as the creation of the temporary file might lead to network timeouts.", false)
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
495 .SetRequestField("Asynchronous", RestApiCallDocumentation::Type_Boolean,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
496 "If `true`, create the archive in asynchronous mode, which means that a job is submitted to create "
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
497 "the archive in background.", false)
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
498 .SetRequestField(KEY_TRANSCODE, RestApiCallDocumentation::Type_String,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
499 "If present, the DICOM files in the archive will be transcoded to the provided "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
500 "transfer syntax: https://book.orthanc-server.com/faq/transcoding.html", false)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
501 .SetRequestField("Priority", RestApiCallDocumentation::Type_Number,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
502 "In asynchronous mode, the priority of the job. The lower the value, the higher the priority.", false)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
503 .AddAnswerType(MimeType_Zip, "In synchronous mode, the ZIP file containing the archive")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
504 .AddAnswerType(MimeType_Json, "In asynchronous mode, information about the job that has been submitted to "
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
505 "generate the archive: https://book.orthanc-server.com/users/advanced-rest.html#jobs")
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
506 .SetAnswerField("ID", RestApiCallDocumentation::Type_String, "Identifier of the job")
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4416
diff changeset
507 .SetAnswerField("Path", RestApiCallDocumentation::Type_String, "Path to access the job in the REST API");
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
508
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
509 if (isMedia)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
510 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
511 call.GetDocumentation().SetRequestField(
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
512 KEY_EXTENDED, RestApiCallDocumentation::Type_Boolean, "If `true`, will include additional "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
513 "tags such as `SeriesDescription`, leading to a so-called *extended DICOMDIR*. Default value is " +
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
514 std::string(defaultExtended ? "`true`" : "`false`") + ".", false);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
515 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
516 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
517
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
518
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
519 template <bool IS_MEDIA,
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
520 bool DEFAULT_IS_EXTENDED /* only makes sense for media (i.e. not ZIP archives) */ >
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
521 static void CreateBatch(RestApiPostCall& call)
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
522 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
523 if (call.IsDocumentation())
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
524 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
525 DocumentPostArguments(call, IS_MEDIA, DEFAULT_IS_EXTENDED);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
526 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive");
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
527 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
528 .SetTag("System")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
529 .SetSummary("Create " + m)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
530 .SetDescription("Create a " + m + " containing the DICOM resources (patients, studies, series, or instances) "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
531 "whose Orthanc identifiers are provided in the body")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
532 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
533 "The list of Orthanc identifiers of interest.", false);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
534 return;
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
535 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
536
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
537 ServerContext& context = OrthancRestApi::GetContext(call);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
538
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
539 Json::Value body;
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
540 if (call.ParseJsonRequest(body))
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
541 {
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
542 bool synchronous, extended, transcode;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
543 DicomTransferSyntax transferSyntax;
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
544 int priority;
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
545 GetJobParameters(synchronous, extended, transcode, transferSyntax,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
546 priority, body, DEFAULT_IS_EXTENDED);
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
547
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
548 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
549 AddResourcesOfInterest(*job, body);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
550
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
551 if (transcode)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
552 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
553 job->SetTranscode(transferSyntax);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
554 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
555
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
556 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip");
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
557 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
558 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
559 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
560 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
561 "Expected a list of resources to archive in the body");
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
562 }
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
563 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
564
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
565
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
566 template <bool IS_MEDIA>
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
567 static void CreateSingleGet(RestApiGetCall& call)
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
568 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
569 if (call.IsDocumentation())
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
570 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
571 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
572 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
573 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive");
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
574 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
575 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
576 .SetSummary("Create " + m)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
577 .SetDescription("Synchronously create a " + m + " containing the DICOM " + r +
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
578 " whose Orthanc identifier is provided in the URL. This flavor is synchronous, "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
579 "which might *not* be desirable to archive large amount of data, as it might "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
580 "lead to network timeouts. Prefer the asynchronous version using `POST` method.")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
581 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
582 .SetHttpGetArgument("transcode", RestApiCallDocumentation::Type_String,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
583 "If present, the DICOM files in the archive will be transcoded to the provided "
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
584 "transfer syntax: https://book.orthanc-server.com/faq/transcoding.html", false)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
585 .AddAnswerType(MimeType_Zip, "ZIP file containing the archive");
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
586 if (IS_MEDIA)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
587 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
588 call.GetDocumentation().SetHttpGetArgument(
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
589 "extended", RestApiCallDocumentation::Type_String,
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
590 "If present, will include additional tags such as `SeriesDescription`, leading to a so-called *extended DICOMDIR*", false);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
591 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
592 return;
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
593 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
594
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
595 ServerContext& context = OrthancRestApi::GetContext(call);
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
596
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
597 std::string id = call.GetUriComponent("id", "");
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
598
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
599 bool extended;
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
600 if (IS_MEDIA)
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
601 {
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
602 extended = call.HasArgument("extended");
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
603 }
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
604 else
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
605 {
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
606 extended = false;
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
607 }
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
608
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
609 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
610 job->AddResource(id);
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
611
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
612 static const char* const TRANSCODE = "transcode";
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
613 if (call.HasArgument(TRANSCODE))
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
614 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
615 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, "")));
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
616 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
617
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
618 SubmitJob(call.GetOutput(), context, job, 0 /* priority */,
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
619 true /* synchronous */, id + ".zip");
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
620 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
621
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
622
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
623 template <bool IS_MEDIA>
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
624 static void CreateSinglePost(RestApiPostCall& call)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
625 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
626 if (call.IsDocumentation())
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
627 {
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
628 DocumentPostArguments(call, IS_MEDIA, false /* not extended by default */);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
629 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
630 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
631 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive");
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
632 call.GetDocumentation()
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
633 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
634 .SetSummary("Create " + m)
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
635 .SetDescription("Create a " + m + " containing the DICOM " + r +
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
636 " whose Orthanc identifier is provided in the URL")
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
637 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest");
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
638 return;
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
639 }
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
640
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
641 ServerContext& context = OrthancRestApi::GetContext(call);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
642
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
643 std::string id = call.GetUriComponent("id", "");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
644
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
645 Json::Value body;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
646 if (call.ParseJsonRequest(body))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
647 {
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
648 bool synchronous, extended, transcode;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
649 DicomTransferSyntax transferSyntax;
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
650 int priority;
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
651 GetJobParameters(synchronous, extended, transcode, transferSyntax,
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
652 priority, body, false /* by default, not extented */);
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
653
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
654 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
655 job->AddResource(id);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
656
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
657 if (transcode)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
658 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
659 job->SetTranscode(transferSyntax);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
660 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
661
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
662 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
663 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
664 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
665 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
666 throw OrthancException(ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
667 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
668 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
670
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 void OrthancRestApi::RegisterArchive()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 {
4416
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
673 Register("/patients/{id}/archive", CreateSingleGet<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
674 Register("/patients/{id}/archive", CreateSinglePost<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
675 Register("/patients/{id}/media", CreateSingleGet<true /* media */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
676 Register("/patients/{id}/media", CreateSinglePost<true /* media */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
677 Register("/series/{id}/archive", CreateSingleGet<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
678 Register("/series/{id}/archive", CreateSinglePost<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
679 Register("/series/{id}/media", CreateSingleGet<true /* media */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
680 Register("/series/{id}/media", CreateSinglePost<true /* media */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
681 Register("/studies/{id}/archive", CreateSingleGet<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
682 Register("/studies/{id}/archive", CreateSinglePost<false /* ZIP */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
683 Register("/studies/{id}/media", CreateSingleGet<true /* media */>);
0b27841950d5 openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
684 Register("/studies/{id}/media", CreateSinglePost<true /* media */>);
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
685
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
686 Register("/tools/create-archive",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
687 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
688 Register("/tools/create-media",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
689 CreateBatch<true /* media */, false /* not extended by default */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
690 Register("/tools/create-media-extended",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
691 CreateBatch<true /* media */, true /* extended by default */>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 }