Newer
Older
* Npcf_SMPolicyControl API
* Session Management Policy Control Service © 2020, 3GPP Organizational
* Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.1.alpha-5
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "sm_policy/pcf_smpc_status_code.hpp"
#include "3gpp_29.500.h"
namespace oai {
namespace pcf {
namespace api {
using namespace oai::pcf::model;
using namespace oai::pcf::app;
using namespace oai::pcf::app::sm_policy;
IndividualSMPolicyDocumentApiImpl::IndividualSMPolicyDocumentApiImpl(
const std::shared_ptr<Pistache::Rest::Router>& rtr,
std::shared_ptr<pcf_smpc> smpc_service, std::string address)
: IndividualSMPolicyDocumentApi(rtr) {
m_address = address;
m_smpc_service = smpc_service;
}
void IndividualSMPolicyDocumentApiImpl::delete_sm_policy(
const std::string& smPolicyId, const SmPolicyDeleteData& smPolicyDeleteData,
Pistache::Http::ResponseWriter& response) {
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
ProblemDetails problem_details;
std::string problem_description;
std::string content_type = "application/problem+json";
nlohmann::json json_data;
int http_code = 0;
status_code res = m_smpc_service->delete_sm_policy_handler(
smPolicyId, smPolicyDeleteData, problem_description);
switch (res) {
case status_code::OK:
http_code = HTTP_STATUS_CODE_204_NO_CONTENT;
break;
case status_code::NOT_FOUND:
problem_details.setDetail(problem_description);
// This is not defined in the standard
problem_details.setCause("SM_POLICY_ID_NOT_FOUND");
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
break;
default:
problem_details.setDetail("Internal Service Error: Unknown return code.");
problem_details.setCause("INTERNAL_ERROR");
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
}
if (res == status_code::OK) {
response.send(Pistache::Http::Code(http_code));
} else {
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
to_json(json_data, problem_details);
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
void IndividualSMPolicyDocumentApiImpl::get_sm_policy(
const std::string& smPolicyId, Pistache::Http::ResponseWriter& response) {
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
ProblemDetails problem_details;
std::string problem_description;
std::string content_type = "application/problem+json";
nlohmann::json json_data;
int http_code = 0;
SmPolicyControl sm_policy_control;
status_code res = m_smpc_service->get_sm_policy_handler(
smPolicyId, sm_policy_control, problem_description);
switch (res) {
case status_code::OK:
http_code = HTTP_STATUS_CODE_200_OK;
content_type = "application/json";
break;
case status_code::NOT_FOUND:
problem_details.setDetail(problem_description);
// This is not defined in the standard
problem_details.setCause("SM_POLICY_ID_NOT_FOUND");
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
break;
default:
problem_details.setDetail("Internal Service Error: Unknown return code.");
problem_details.setCause("INTERNAL_ERROR");
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
}
if (res == status_code::OK) {
to_json(json_data, sm_policy_control);
} else {
to_json(json_data, problem_details);
}
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
void IndividualSMPolicyDocumentApiImpl::update_sm_policy(
const std::string& smPolicyId,
const SmPolicyUpdateContextData& smPolicyUpdateContextData,
Pistache::Http::ResponseWriter& response) {
Stefan Spettel
committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
ProblemDetails problem_details;
std::string problem_description = "";
std::string content_type = "application/problem+json";
nlohmann::json json_data;
int http_code = 0;
SmPolicyDecision decision_update;
status_code res = m_smpc_service->update_sm_policy_handler(
smPolicyId, smPolicyUpdateContextData, decision_update,
problem_description);
problem_details.setDetail(problem_description);
switch (res) {
case status_code::OK:
content_type = "application/json";
http_code = HTTP_STATUS_CODE_200_OK;
break;
case status_code::INVALID_PARAMETERS:
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause("ERROR_INITIAL_PARAMETERS");
break;
case status_code::CONTEXT_DENIED:
// should map to 403 but not defined in standard for this request
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause("ERROR_INITIAL_PARAMETERS");
break;
case status_code::NOT_FOUND:
// TODO This is not defined in the standard, but this scenario is missig
// we could map it to the 400 Bad request but that is somehow misleading
problem_details.setCause("SM_POLICY_ID_NOT_FOUND");
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
break;
default:
problem_details.setCause("INTERNAL_ERROR");
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
}
if (res == status_code::OK) {
to_json(json_data, decision_update);
} else {
to_json(json_data, problem_details);
}
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
} // namespace api
} // namespace pcf
} // namespace oai