comparison OrthancStone/Sources/Oracle/OrthancRestApiCommand.h @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Oracle/OrthancRestApiCommand.h@30deba7bc8e2
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "../Messages/IMessage.h"
25 #include "OracleCommandBase.h"
26
27 #include <Enumerations.h>
28
29 #include <map>
30 #include <json/value.h>
31
32 namespace OrthancStone
33 {
34 class OrthancRestApiCommand : public OracleCommandBase
35 {
36 public:
37 typedef std::map<std::string, std::string> HttpHeaders;
38
39 class SuccessMessage : public OriginMessage<OrthancRestApiCommand>
40 {
41 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
42
43 private:
44 const HttpHeaders& headers_;
45 const std::string& answer_;
46
47 public:
48 SuccessMessage(const OrthancRestApiCommand& command,
49 const HttpHeaders& answerHeaders,
50 const std::string& answer) :
51 OriginMessage(command),
52 headers_(answerHeaders),
53 answer_(answer)
54 {
55 }
56
57 const std::string& GetAnswer() const
58 {
59 return answer_;
60 }
61
62 void ParseJsonBody(Json::Value& target) const;
63
64 const HttpHeaders& GetAnswerHeaders() const
65 {
66 return headers_;
67 }
68 };
69
70
71 private:
72 Orthanc::HttpMethod method_;
73 std::string uri_;
74 std::string body_;
75 HttpHeaders headers_;
76 unsigned int timeout_;
77 bool applyPlugins_; // Only makes sense for Stone as an Orthanc plugin
78
79 OrthancRestApiCommand(const OrthancRestApiCommand& other) :
80 method_(other.method_),
81 uri_(other.uri_),
82 body_(other.body_),
83 headers_(other.headers_),
84 timeout_(other.timeout_),
85 applyPlugins_(other.applyPlugins_)
86 {
87 }
88
89 public:
90 OrthancRestApiCommand();
91
92 virtual Type GetType() const
93 {
94 return Type_OrthancRestApi;
95 }
96
97 virtual IOracleCommand* Clone() const
98 {
99 return new OrthancRestApiCommand(*this);
100 }
101
102 void SetMethod(Orthanc::HttpMethod method)
103 {
104 method_ = method;
105 }
106
107 void SetUri(const std::string& uri)
108 {
109 uri_ = uri;
110 }
111
112 void SetBody(const std::string& body)
113 {
114 body_ = body;
115 }
116
117 void SetBody(const Json::Value& json);
118
119 void SwapBody(std::string& body)
120 {
121 body_.swap(body);
122 }
123
124 void SetHttpHeaders(const HttpHeaders& headers)
125 {
126 headers_ = headers;
127 }
128
129 void SetHttpHeader(const std::string& key,
130 const std::string& value)
131 {
132 headers_[key] = value;
133 }
134
135 Orthanc::HttpMethod GetMethod() const
136 {
137 return method_;
138 }
139
140 const std::string& GetUri() const
141 {
142 return uri_;
143 }
144
145 const std::string& GetBody() const;
146
147 const HttpHeaders& GetHttpHeaders() const
148 {
149 return headers_;
150 }
151
152 void SetTimeout(unsigned int seconds)
153 {
154 timeout_ = seconds;
155 }
156
157 unsigned int GetTimeout() const
158 {
159 return timeout_;
160 }
161
162 void SetApplyPlugins(bool applyPlugins)
163 {
164 applyPlugins_ = applyPlugins;
165 }
166
167 bool IsApplyPlugins() const
168 {
169 return applyPlugins_;
170 }
171 };
172 }