annotate OrthancServer/OrthancRestApi/OrthancRestArchive.cpp @ 3705:d8b214a46b91 storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Feb 2020 12:07:19 +0100
parents 94f4a18a79cc
children 2a170a8f1faf
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3240
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/HttpServer/FilesystemHttpSender.h"
3095
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
38 #include "../../Core/OrthancException.h"
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
39 #include "../../Core/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
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
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
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
47 static const char* const KEY_RESOURCES = "Resources";
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
48 static const char* const KEY_EXTENDED = "Extended";
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
49
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
50 static void AddResourcesOfInterestFromArray(ArchiveJob& job,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
51 const Json::Value& resources)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
52 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
53 if (resources.type() != Json::arrayValue)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
54 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
55 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
56 "Expected a list of strings (Orthanc identifiers)");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
57 }
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 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
60 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
61 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
62 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
63 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
64 "Expected a list of strings (Orthanc identifiers)");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
65 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
66 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
67 {
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
68 job.AddResource(resources[i].asString());
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
69 }
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
70 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
71 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
72
2966
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 static void AddResourcesOfInterest(ArchiveJob& job /* inout */,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
75 const Json::Value& body /* in */)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
76 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
77 if (body.type() == Json::arrayValue)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
78 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
79 AddResourcesOfInterestFromArray(job, body);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
80 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
81 else if (body.type() == Json::objectValue)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
82 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
83 if (body.isMember(KEY_RESOURCES))
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
84 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
85 AddResourcesOfInterestFromArray(job, body[KEY_RESOURCES]);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
86 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
87 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
88 {
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 "Missing field " + std::string(KEY_RESOURCES) +
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
91 " in the JSON body");
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
92 }
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
93 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
94 else
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
95 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
96 throw OrthancException(ErrorCode_BadFileFormat);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
97 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
98 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
99
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
100
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
101 static void GetJobParameters(bool& synchronous, /* out */
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
102 bool& extended, /* out */
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
103 int& priority, /* out */
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
104 const Json::Value& body, /* in */
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
105 const bool defaultExtended /* in */)
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
106 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
107 synchronous = OrthancRestApi::IsSynchronousJobRequest
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
108 (true /* synchronous by default */, body);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
109
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
110 priority = OrthancRestApi::GetJobRequestPriority(body);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
111
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
112 if (body.type() == Json::objectValue &&
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
113 body.isMember(KEY_EXTENDED))
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
114 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
115 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED);
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 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
118 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
119 extended = defaultExtended;
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
120 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
121 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
122
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
123
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
124 static void SubmitJob(RestApiOutput& output,
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
125 ServerContext& context,
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
126 std::auto_ptr<ArchiveJob>& job,
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
127 int priority,
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
128 bool synchronous,
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
129 const std::string& filename)
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
130 {
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
131 if (job.get() == NULL)
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
132 {
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
133 throw OrthancException(ErrorCode_NullPointer);
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
134 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
135
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
136 job->SetDescription("REST API");
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
137
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
138 if (synchronous)
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
139 {
3181
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
140 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
141
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
142 {
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
143 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
144 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
145 }
6fd38327e777 Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3161
diff changeset
146
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
147 job->SetSynchronousTarget(tmp);
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
148
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
149 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
150 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
151 (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
152
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
153 {
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
154 // 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
155 FilesystemHttpSender sender(tmp->GetPath(), MimeType_Zip);
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
156 sender.SetContentFilename(filename);
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
157
2969
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
158 // Send the ZIP
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
159 output.AnswerStream(sender);
2c16c29b287d preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
160 }
2630
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 else
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
163 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2970
diff changeset
164 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
165 }
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
166 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
167
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
168
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
169 template <bool IS_MEDIA,
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
170 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
171 static void CreateBatch(RestApiPostCall& call)
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
172 {
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
173 ServerContext& context = OrthancRestApi::GetContext(call);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
174
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
175 Json::Value body;
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
176 if (call.ParseJsonRequest(body))
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
177 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
178 bool synchronous, extended;
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
179 int priority;
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
180 GetJobParameters(synchronous, extended, priority, body, DEFAULT_IS_EXTENDED);
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
181
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
182 std::auto_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
183 AddResourcesOfInterest(*job, body);
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
184 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip");
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
185 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
186 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
187 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
188 throw OrthancException(ErrorCode_BadFileFormat,
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
189 "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
190 }
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
191 }
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
192
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
193
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
194 template <bool IS_MEDIA,
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
195 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
196 static void CreateSingleGet(RestApiGetCall& call)
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
197 {
2630
00327e989458 creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2629
diff changeset
198 ServerContext& context = OrthancRestApi::GetContext(call);
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
199
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
200 std::string id = call.GetUriComponent("id", "");
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
201
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
202 bool extended;
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
203 if (IS_MEDIA)
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
204 {
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
205 extended = call.HasArgument("extended");
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
206 }
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
207 else
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
208 {
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
209 extended = false;
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
210 }
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
211
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
212 std::auto_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2630
diff changeset
213 job->AddResource(id);
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
214
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
215 SubmitJob(call.GetOutput(), context, job, 0 /* priority */,
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
216 true /* synchronous */, id + ".zip");
1778
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
217 }
776573e592da create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1777
diff changeset
218
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
219
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
220 template <bool IS_MEDIA,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
221 bool DEFAULT_IS_EXTENDED /* only makes sense for media (i.e. not ZIP archives) */ >
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
222 static void CreateSinglePost(RestApiPostCall& call)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
223 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
224 ServerContext& context = OrthancRestApi::GetContext(call);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
225
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
226 std::string id = call.GetUriComponent("id", "");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
227
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
228 Json::Value body;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
229 if (call.ParseJsonRequest(body))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
230 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
231 bool synchronous, extended;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
232 int priority;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
233 GetJobParameters(synchronous, extended, priority, body, DEFAULT_IS_EXTENDED);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
234
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
235 std::auto_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
236 job->AddResource(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
237 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
238 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
239 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
240 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
241 throw OrthancException(ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
242 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
243 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
244
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
245
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 void OrthancRestApi::RegisterArchive()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
248 Register("/patients/{id}/archive",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
249 CreateSingleGet<false /* ZIP */, false /* extended makes no sense in ZIP */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
250 Register("/studies/{id}/archive",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
251 CreateSingleGet<false /* ZIP */, false /* extended makes no sense in ZIP */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
252 Register("/series/{id}/archive",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
253 CreateSingleGet<false /* ZIP */, false /* extended makes no sense in ZIP */>);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
254
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
255 Register("/patients/{id}/archive",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
256 CreateSinglePost<false /* ZIP */, false /* extended makes no sense in ZIP */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
257 Register("/studies/{id}/archive",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
258 CreateSinglePost<false /* ZIP */, false /* extended makes no sense in ZIP */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
259 Register("/series/{id}/archive",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
260 CreateSinglePost<false /* ZIP */, false /* extended makes no sense in ZIP */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
261
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
262 Register("/patients/{id}/media",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
263 CreateSingleGet<true /* media */, false /* not extended by default */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
264 Register("/studies/{id}/media",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
265 CreateSingleGet<true /* media */, false /* not extended by default */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
266 Register("/series/{id}/media",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
267 CreateSingleGet<true /* media */, false /* not extended by default */>);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
268
2978
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
269 Register("/patients/{id}/media",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
270 CreateSinglePost<true /* media */, false /* not extended by default */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
271 Register("/studies/{id}/media",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
272 CreateSinglePost<true /* media */, false /* not extended by default */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
273 Register("/series/{id}/media",
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
274 CreateSinglePost<true /* media */, false /* not extended by default */>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2976
diff changeset
275
2970
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
276 Register("/tools/create-archive",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
277 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
278 Register("/tools/create-media",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
279 CreateBatch<true /* media */, false /* not extended by default */>);
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
280 Register("/tools/create-media-extended",
eea66afed0db remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2969
diff changeset
281 CreateBatch<true /* media */, true /* extended by default */>);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }