annotate OrthancServer/OrthancRestApi/OrthancRestChanges.cpp @ 1444:b2b09a3dbd8e

refactoring: OrthancHttpHandler inside OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 12:09:58 +0200
parents 02f5a3f5c0a0
children f967bdf8534e
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
4 * Department, University Hospital of Liege, Belgium
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * 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
8 * published by the Free Software Foundation, either version 3 of the
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * 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
18 * 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
19 * 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
20 * version. If you delete this exception statement from all source files
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * 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
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * 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
29 * 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
30 **/
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "../PrecompiledHeadersServer.h"
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancRestApi.h"
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
36 #include "../ServerContext.h"
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
37
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <glog/logging.h>
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 // Changes API --------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 static void GetSinceAndLimit(int64_t& since,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 unsigned int& limit,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 bool& last,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
47 const RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static const unsigned int MAX_RESULTS = 100;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 if (call.HasArgument("last"))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 last = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 last = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 try
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0"));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 limit = boost::lexical_cast<unsigned int>(call.GetArgument("limit", "0"));
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 catch (boost::bad_lexical_cast)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (limit == 0 || limit > MAX_RESULTS)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 limit = MAX_RESULTS;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
75 static void GetChanges(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 //std::string filter = GetArgument(getArguments, "filter", "");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 int64_t since;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 unsigned int limit;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 bool last;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 GetSinceAndLimit(since, limit, last, call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 Json::Value result;
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
86 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
88 context.GetIndex().GetLastChange(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
90 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
91 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
92 context.GetIndex().GetChanges(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
93 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
94
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
95 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
99 static void DeleteChanges(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 OrthancRestApi::GetIndex(call).DeleteChanges();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 // Exports API --------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
108 static void GetExports(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 int64_t since;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 unsigned int limit;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 bool last;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 GetSinceAndLimit(since, limit, last, call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 Json::Value result;
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
118 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
120 context.GetIndex().GetLastExportedResource(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
122 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
123 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
124 context.GetIndex().GetExportedResources(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
125 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
126
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
127 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
131 static void DeleteExports(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 OrthancRestApi::GetIndex(call).DeleteExportedResources();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 call.GetOutput().AnswerBuffer("", "text/plain");
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 void OrthancRestApi::RegisterChanges()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 Register("/changes", GetChanges);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 Register("/changes", DeleteChanges);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 Register("/exports", GetExports);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 Register("/exports", DeleteExports);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }