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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "IOrthancConnection.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 void IOrthancConnection::ParseJson(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 const std::string& content)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 void IOrthancConnection::ParseJson(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 const void* content,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 size_t size)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void IOrthancConnection::RestApiGet(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 const std::string& uri)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 orthanc.RestApiGet(content, uri);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 void IOrthancConnection::RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& body)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 orthanc.RestApiPost(content, uri, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 void IOrthancConnection::RestApiPut(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 const std::string& body)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 orthanc.RestApiPut(content, uri, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }