comparison OrthancServer/DicomInstanceOrigin.cpp @ 2664:a21b244efb37 jobs

serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Jun 2018 21:37:40 +0200
parents c691fcf66071
children 46061a91c88a
comparison
equal deleted inserted replaced
2663:228e2783ce83 2664:a21b244efb37
33 33
34 #include "PrecompiledHeadersServer.h" 34 #include "PrecompiledHeadersServer.h"
35 #include "DicomInstanceOrigin.h" 35 #include "DicomInstanceOrigin.h"
36 36
37 #include "../Core/OrthancException.h" 37 #include "../Core/OrthancException.h"
38 #include "../Core/SerializationToolbox.h"
38 39
39 40
40 namespace Orthanc 41 namespace Orthanc
41 { 42 {
42 void DicomInstanceOrigin::Format(Json::Value& result) const 43 void DicomInstanceOrigin::Format(Json::Value& result) const
79 throw OrthancException(ErrorCode_InternalError); 80 throw OrthancException(ErrorCode_InternalError);
80 } 81 }
81 } 82 }
82 83
83 84
84 void DicomInstanceOrigin::SetDicomProtocolOrigin(const char* remoteIp, 85 DicomInstanceOrigin DicomInstanceOrigin::FromDicomProtocol(const char* remoteIp,
85 const char* remoteAet, 86 const char* remoteAet,
86 const char* calledAet) 87 const char* calledAet)
87 { 88 {
88 origin_ = RequestOrigin_DicomProtocol; 89 DicomInstanceOrigin result(RequestOrigin_DicomProtocol);
89 remoteIp_ = remoteIp; 90 result.remoteIp_ = remoteIp;
90 dicomRemoteAet_ = remoteAet; 91 result.dicomRemoteAet_ = remoteAet;
91 dicomCalledAet_ = calledAet; 92 result.dicomCalledAet_ = calledAet;
93 return result;
92 } 94 }
93 95
94 void DicomInstanceOrigin::SetRestOrigin(const RestApiCall& call) 96 DicomInstanceOrigin DicomInstanceOrigin::FromRest(const RestApiCall& call)
95 { 97 {
96 origin_ = call.GetRequestOrigin(); 98 DicomInstanceOrigin result(call.GetRequestOrigin());
97 99
98 if (origin_ == RequestOrigin_RestApi) 100 if (result.origin_ == RequestOrigin_RestApi)
99 { 101 {
100 remoteIp_ = call.GetRemoteIp(); 102 result.remoteIp_ = call.GetRemoteIp();
101 httpUsername_ = call.GetUsername(); 103 result.httpUsername_ = call.GetUsername();
102 } 104 }
105
106 return result;
103 } 107 }
104 108
105 void DicomInstanceOrigin::SetHttpOrigin(const char* remoteIp, 109 DicomInstanceOrigin DicomInstanceOrigin::FromHttp(const char* remoteIp,
106 const char* username) 110 const char* username)
107 { 111 {
108 origin_ = RequestOrigin_RestApi; 112 DicomInstanceOrigin result(RequestOrigin_RestApi);
109 remoteIp_ = remoteIp; 113 result.remoteIp_ = remoteIp;
110 httpUsername_ = username; 114 result.httpUsername_ = username;
115 return result;
111 } 116 }
112 117
113 void DicomInstanceOrigin::SetLuaOrigin() 118 const char* DicomInstanceOrigin::GetRemoteAetC() const
114 {
115 origin_ = RequestOrigin_Lua;
116 }
117
118 void DicomInstanceOrigin::SetPluginsOrigin()
119 {
120 origin_ = RequestOrigin_Plugins;
121 }
122
123 const char* DicomInstanceOrigin::GetRemoteAet() const
124 { 119 {
125 if (origin_ == RequestOrigin_DicomProtocol) 120 if (origin_ == RequestOrigin_DicomProtocol)
126 { 121 {
127 return dicomRemoteAet_.c_str(); 122 return dicomRemoteAet_.c_str();
128 } 123 }
129 else 124 else
130 { 125 {
131 return ""; 126 return "";
132 } 127 }
133 } 128 }
129
130 const std::string& DicomInstanceOrigin::GetRemoteIp() const
131 {
132 if (origin_ == RequestOrigin_DicomProtocol ||
133 origin_ == RequestOrigin_RestApi)
134 {
135 return remoteIp_;
136 }
137 else
138 {
139 throw OrthancException(ErrorCode_ParameterOutOfRange);
140 }
141 }
142
143 const std::string& DicomInstanceOrigin::GetCalledAet() const
144 {
145 if (origin_ == RequestOrigin_DicomProtocol)
146 {
147 return dicomCalledAet_;
148 }
149 else
150 {
151 throw OrthancException(ErrorCode_ParameterOutOfRange);
152 }
153 }
154
155 const std::string& DicomInstanceOrigin::GetHttpUsername() const
156 {
157 if (origin_ == RequestOrigin_RestApi)
158 {
159 return httpUsername_;
160 }
161 else
162 {
163 throw OrthancException(ErrorCode_ParameterOutOfRange);
164 }
165 }
166
167
168
169 static const char* ORIGIN = "Origin";
170 static const char* REMOTE_IP = "RemoteIP";
171 static const char* DICOM_REMOTE_AET = "RemoteAET";
172 static const char* DICOM_CALLED_AET = "CalledAET";
173 static const char* HTTP_USERNAME = "Username";
174
175
176 DicomInstanceOrigin::DicomInstanceOrigin(const Json::Value& serialized)
177 {
178 origin_ = StringToRequestOrigin(SerializationToolbox::ReadString(serialized, ORIGIN));
179 remoteIp_ = SerializationToolbox::ReadString(serialized, REMOTE_IP);
180 dicomRemoteAet_ = SerializationToolbox::ReadString(serialized, DICOM_REMOTE_AET);
181 dicomCalledAet_ = SerializationToolbox::ReadString(serialized, DICOM_CALLED_AET);
182 httpUsername_ = SerializationToolbox::ReadString(serialized, HTTP_USERNAME);
183 }
184
185
186 void DicomInstanceOrigin::Serialize(Json::Value& result) const
187 {
188 result = Json::objectValue;
189 result[ORIGIN] = EnumerationToString(origin_);
190 result[REMOTE_IP] = remoteIp_;
191 result[DICOM_REMOTE_AET] = dicomRemoteAet_;
192 result[DICOM_CALLED_AET] = dicomCalledAet_;
193 result[HTTP_USERNAME] = httpUsername_;
194 }
134 } 195 }