Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp @ 1740:84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 13 Jan 2021 09:07:57 +0100 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1504 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
1504 | 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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1504 | 20 **/ |
21 | |
22 | |
23 #include "IOrthancConnection.h" | |
24 | |
25 #include <OrthancException.h> | |
1737
ef2f56c0311c
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
26 #include <Toolbox.h> |
1504 | 27 |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
28 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
29 # error You are using a version of the Orthanc framework that is too old |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
30 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
31 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
32 #if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
33 # include <json/reader.h> |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
34 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
35 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
36 |
1504 | 37 namespace OrthancStone |
38 { | |
39 void IOrthancConnection::ParseJson(Json::Value& result, | |
40 const std::string& content) | |
41 { | |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
42 bool ok; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
43 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
44 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
45 ok = Orthanc::Toolbox::ReadJson(result, content); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
46 #else |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
47 // Backward compatibility (for use in orthanc-wsi 1.0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
48 Json::Reader reader; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
49 ok = reader.parse(content, result); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
50 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
51 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
52 if (!ok) |
1504 | 53 { |
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
55 } | |
56 } | |
57 | |
58 | |
59 void IOrthancConnection::ParseJson(Json::Value& result, | |
60 const void* content, | |
61 size_t size) | |
62 { | |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
63 bool ok; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
64 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
65 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
66 ok = Orthanc::Toolbox::ReadJson(result, content, size); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
67 #else |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
68 // Backward compatibility (for use in orthanc-wsi 1.0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
69 Json::Reader reader; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
70 ok = reader.parse(reinterpret_cast<const char*>(content), |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
71 reinterpret_cast<const char*>(content) + size, result); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
72 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
73 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
74 if (!ok) |
1504 | 75 { |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
77 } | |
78 } | |
79 | |
80 | |
81 void IOrthancConnection::RestApiGet(Json::Value& result, | |
82 IOrthancConnection& orthanc, | |
83 const std::string& uri) | |
84 { | |
85 std::string content; | |
86 orthanc.RestApiGet(content, uri); | |
87 ParseJson(result, content); | |
88 } | |
89 | |
90 | |
91 void IOrthancConnection::RestApiPost(Json::Value& result, | |
92 IOrthancConnection& orthanc, | |
93 const std::string& uri, | |
94 const std::string& body) | |
95 { | |
96 std::string content; | |
97 orthanc.RestApiPost(content, uri, body); | |
98 ParseJson(result, content); | |
99 } | |
100 | |
101 | |
102 void IOrthancConnection::RestApiPut(Json::Value& result, | |
103 IOrthancConnection& orthanc, | |
104 const std::string& uri, | |
105 const std::string& body) | |
106 { | |
107 std::string content; | |
108 orthanc.RestApiPut(content, uri, body); | |
109 ParseJson(result, content); | |
110 } | |
111 } |