Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp @ 4555:456ed3fcff81 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Mar 2021 17:13:41 +0100 |
parents | d9473bd5ed43 |
children | cdab941fe17d |
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 | 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 * In addition, as a special exception, the copyright holders of this |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * 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
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * 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
|
30 * 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
|
31 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
4045 | 37 #include "../../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" |
38 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
39 #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
|
40 #include "../OrthancConfiguration.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
41 #include "../ServerContext.h" |
2632 | 42 #include "../ServerJobs/ArchiveJob.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
44 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
2966 | 47 static const char* const KEY_RESOURCES = "Resources"; |
48 static const char* const KEY_EXTENDED = "Extended"; | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
49 static const char* const KEY_TRANSCODE = "Transcode"; |
2966 | 50 |
51 static void AddResourcesOfInterestFromArray(ArchiveJob& job, | |
52 const Json::Value& resources) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
53 { |
2966 | 54 if (resources.type() != Json::arrayValue) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
55 { |
2966 | 56 throw OrthancException(ErrorCode_BadFileFormat, |
57 "Expected a list of strings (Orthanc identifiers)"); | |
58 } | |
59 | |
60 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++) | |
61 { | |
62 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
|
63 { |
2966 | 64 throw OrthancException(ErrorCode_BadFileFormat, |
65 "Expected a list of strings (Orthanc identifiers)"); | |
66 } | |
67 else | |
68 { | |
2632 | 69 job.AddResource(resources[i].asString()); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
70 } |
2966 | 71 } |
72 } | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
73 |
2966 | 74 |
75 static void AddResourcesOfInterest(ArchiveJob& job /* inout */, | |
76 const Json::Value& body /* in */) | |
77 { | |
78 if (body.type() == Json::arrayValue) | |
79 { | |
80 AddResourcesOfInterestFromArray(job, body); | |
81 } | |
82 else if (body.type() == Json::objectValue) | |
83 { | |
84 if (body.isMember(KEY_RESOURCES)) | |
85 { | |
86 AddResourcesOfInterestFromArray(job, body[KEY_RESOURCES]); | |
87 } | |
88 else | |
89 { | |
90 throw OrthancException(ErrorCode_BadFileFormat, | |
91 "Missing field " + std::string(KEY_RESOURCES) + | |
92 " in the JSON body"); | |
93 } | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
94 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
95 else |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
96 { |
2966 | 97 throw OrthancException(ErrorCode_BadFileFormat); |
98 } | |
99 } | |
100 | |
101 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
102 static DicomTransferSyntax GetTransferSyntax(const std::string& value) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
103 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
104 DicomTransferSyntax syntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
105 if (LookupTransferSyntax(syntax, value)) |
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 return syntax; |
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 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
110 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
111 throw OrthancException(ErrorCode_ParameterOutOfRange, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
112 "Unknown transfer syntax: " + value); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
113 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
114 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
115 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
116 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
117 static void GetJobParameters(bool& synchronous, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
118 bool& extended, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
119 bool& transcode, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
120 DicomTransferSyntax& syntax, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
121 int& priority, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
122 const Json::Value& body, /* in */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
123 const bool defaultExtended /* in */) |
2966 | 124 { |
125 synchronous = OrthancRestApi::IsSynchronousJobRequest | |
126 (true /* synchronous by default */, body); | |
127 | |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
128 priority = OrthancRestApi::GetJobRequestPriority(body); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
129 |
2966 | 130 if (body.type() == Json::objectValue && |
131 body.isMember(KEY_EXTENDED)) | |
132 { | |
133 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED); | |
134 } | |
135 else | |
136 { | |
137 extended = defaultExtended; | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
138 } |
3913
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 if (body.type() == Json::objectValue && |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
141 body.isMember(KEY_TRANSCODE)) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
142 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
143 transcode = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
144 syntax = GetTransferSyntax(SerializationToolbox::ReadString(body, KEY_TRANSCODE)); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
145 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
146 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
147 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
148 transcode = false; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
149 } |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
150 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
151 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
152 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
153 static void SubmitJob(RestApiOutput& output, |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
154 ServerContext& context, |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
155 std::unique_ptr<ArchiveJob>& job, |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
156 int priority, |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
157 bool synchronous, |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
158 const std::string& filename) |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
159 { |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
160 if (job.get() == NULL) |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
161 { |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
162 throw OrthancException(ErrorCode_NullPointer); |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
163 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
164 |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
165 job->SetDescription("REST API"); |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
166 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
167 if (synchronous) |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
168 { |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
169 boost::shared_ptr<TemporaryFile> tmp; |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
170 |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
171 { |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
172 OrthancConfiguration::ReaderLock lock; |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
173 tmp.reset(lock.GetConfiguration().CreateTemporaryFile()); |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
174 } |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
175 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
176 job->SetSynchronousTarget(tmp); |
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
177 |
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
178 Json::Value publicContent; |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
diff
changeset
|
179 context.GetJobsEngine().GetRegistry().SubmitAndWait |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
diff
changeset
|
180 (publicContent, job.release(), priority); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
diff
changeset
|
181 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
182 { |
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
183 // The archive is now created: Prepare the sending of the ZIP file |
3161
5cf29046c159
removed misleading warning
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
184 FilesystemHttpSender sender(tmp->GetPath(), MimeType_Zip); |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
185 sender.SetContentFilename(filename); |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
186 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
187 // Send the ZIP |
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
188 output.AnswerStream(sender); |
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
189 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
190 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
191 else |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
192 { |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
193 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
|
194 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
195 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
196 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
197 |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
198 static void DocumentPostArguments(RestApiPostCall& call, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
199 bool isMedia, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
200 bool defaultExtended) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
201 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
202 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
203 .SetRequestField("Synchronous", RestApiCallDocumentation::Type_Boolean, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
204 "If `true`, create the archive in synchronous mode, which means that the HTTP answer will directly " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
205 "contain the ZIP file. This is the default, easy behavior, but it is *not* be desirable to archive " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
206 "large amount of data, as it might lead to network timeouts.", false) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
207 .SetRequestField("Asynchronous", RestApiCallDocumentation::Type_Boolean, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
208 "If `true`, create the archive in asynchronous mode, which means that a job is submitted to create " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
209 "the archive in background. Prefer this flavor wherever possible.", false) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
210 .SetRequestField(KEY_TRANSCODE, RestApiCallDocumentation::Type_String, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
211 "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
|
212 "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
|
213 .SetRequestField("Priority", RestApiCallDocumentation::Type_Number, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
214 "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
|
215 .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
|
216 .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
|
217 "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
|
218 .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
|
219 .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
|
220 |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
221 if (isMedia) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
222 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
223 call.GetDocumentation().SetRequestField( |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
224 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
|
225 "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
|
226 std::string(defaultExtended ? "`true`" : "`false`") + ".", false); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
227 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
228 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
229 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
230 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
231 template <bool IS_MEDIA, |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
232 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
|
233 static void CreateBatch(RestApiPostCall& call) |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
234 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
235 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
236 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
237 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
|
238 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
|
239 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
240 .SetTag("System") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
241 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
242 .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
|
243 "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
|
244 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
245 "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
|
246 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
247 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
248 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
249 ServerContext& context = OrthancRestApi::GetContext(call); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
250 |
2966 | 251 Json::Value body; |
252 if (call.ParseJsonRequest(body)) | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
253 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
254 bool synchronous, extended, transcode; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
255 DicomTransferSyntax transferSyntax; |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
256 int priority; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
257 GetJobParameters(synchronous, extended, transcode, transferSyntax, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
258 priority, body, DEFAULT_IS_EXTENDED); |
2966 | 259 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
260 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2966 | 261 AddResourcesOfInterest(*job, body); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
262 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
263 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
264 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
265 job->SetTranscode(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
266 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
267 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
268 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip"); |
2966 | 269 } |
270 else | |
271 { | |
272 throw OrthancException(ErrorCode_BadFileFormat, | |
273 "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
|
274 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
275 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
276 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
277 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
278 template <bool IS_MEDIA> |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
279 static void CreateSingleGet(RestApiGetCall& call) |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
280 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
281 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
282 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
287 .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
|
288 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
289 .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
|
290 " 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
|
291 "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
|
292 "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
|
293 .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
|
294 .SetHttpGetArgument("transcode", RestApiCallDocumentation::Type_String, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
295 "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
|
296 "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
|
297 .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
|
298 if (IS_MEDIA) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
299 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
300 call.GetDocumentation().SetHttpGetArgument( |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
301 "extended", RestApiCallDocumentation::Type_String, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
302 "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
|
303 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
304 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
305 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
306 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
307 ServerContext& context = OrthancRestApi::GetContext(call); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
308 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
309 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
310 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
311 bool extended; |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
312 if (IS_MEDIA) |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
313 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
314 extended = call.HasArgument("extended"); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
315 } |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
316 else |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
317 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
318 extended = false; |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
319 } |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
320 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
321 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2632 | 322 job->AddResource(id); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
323 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
324 static const char* const TRANSCODE = "transcode"; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
325 if (call.HasArgument(TRANSCODE)) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
326 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
327 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, ""))); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
328 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
329 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
330 SubmitJob(call.GetOutput(), context, job, 0 /* priority */, |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
331 true /* synchronous */, id + ".zip"); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
332 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
333 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
334 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
335 template <bool IS_MEDIA> |
2978 | 336 static void CreateSinglePost(RestApiPostCall& call) |
337 { | |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
338 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
339 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 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
|
344 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
345 .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
|
346 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
347 .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
|
348 " 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
|
349 .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
|
350 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
351 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
352 |
2978 | 353 ServerContext& context = OrthancRestApi::GetContext(call); |
354 | |
355 std::string id = call.GetUriComponent("id", ""); | |
356 | |
357 Json::Value body; | |
358 if (call.ParseJsonRequest(body)) | |
359 { | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
360 bool synchronous, extended, transcode; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
361 DicomTransferSyntax transferSyntax; |
2978 | 362 int priority; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
363 GetJobParameters(synchronous, extended, transcode, transferSyntax, |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
364 priority, body, false /* by default, not extented */); |
2978 | 365 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
366 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2978 | 367 job->AddResource(id); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
368 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
369 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
370 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
371 job->SetTranscode(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
372 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
373 |
2978 | 374 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip"); |
375 } | |
376 else | |
377 { | |
378 throw OrthancException(ErrorCode_BadFileFormat); | |
379 } | |
380 } | |
381 | |
382 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 void OrthancRestApi::RegisterArchive() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 Register("/studies/{id}/media", CreateSinglePost<true /* media */>); |
2978 | 397 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
398 Register("/tools/create-archive", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
399 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
400 Register("/tools/create-media", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
401 CreateBatch<true /* media */, false /* not extended by default */>); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
402 Register("/tools/create-media-extended", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
403 CreateBatch<true /* media */, true /* extended by default */>); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 } |