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.
*/
Stefan Spettel
committed
#include "sm_policy/pcf_smpc_status_code.hpp"
#include "3gpp_29.500.h"
#include "logger.hpp"
namespace oai {
namespace pcf {
namespace api {
using namespace oai::pcf::model;
Stefan Spettel
committed
using namespace oai::pcf::app;
using namespace oai::pcf::app::sm_policy;
Stefan Spettel
committed
using namespace oai::model::common;
SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl(
Stefan Spettel
committed
const std::shared_ptr<Pistache::Rest::Router>& rtr,
const std::shared_ptr<pcf_smpc> smpc_service, std::string address)
: SMPoliciesCollectionApi(rtr) {
this->m_address = address;
this->smpc_service = smpc_service;
}
void SMPoliciesCollectionApiImpl::create_sm_policy(
const SmPolicyContextData& smPolicyContextData,
Pistache::Http::ResponseWriter& response) {
Stefan Spettel
committed
http_status_code_e http_code;
std::string cause;
ProblemDetails problem_details;
SmPolicyDecision decision;
std::string details_string = "";
std::string association_id = "";
std::string location = "";
std::string content_type = "application/problem+json";
Stefan Spettel
committed
status_code res = smpc_service->create_sm_policy_handler(
smPolicyContextData, decision, association_id, details_string);
nlohmann::json json_data;
switch (res) {
Stefan Spettel
committed
case status_code::CREATED:
Stefan Spettel
committed
http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED;
location = m_address + base + "/sm-policies/" + association_id;
content_type = "application/json";
break;
Stefan Spettel
committed
case status_code::USER_UNKOWN:
problem_details.setCause("USER_UNKOWN");
problem_details.setDetail(details_string);
Stefan Spettel
committed
http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST;
break;
Stefan Spettel
committed
case status_code::INVALID_PARAMETERS:
problem_details.setCause("ERROR_INITIAL_PARAMETERS");
problem_details.setDetail(details_string);
Stefan Spettel
committed
http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST;
break;
Stefan Spettel
committed
case status_code::CONTEXT_DENIED:
problem_details.setCause("POLICY_CONTEXT_DENIED");
problem_details.setDetail(details_string);
Stefan Spettel
committed
http_code = http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN;
break;
default:
Logger::pcf_app().error("Unknown error code");
http_code =
http_status_code_e::HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
problem_details.setCause("INTERNAL_ERROR");
problem_details.setDetail("Internal Service Error: Unknown return code.");
}
Stefan Spettel
committed
if (http_code != http_status_code_e::HTTP_STATUS_CODE_201_CREATED) {
to_json(json_data, problem_details);
} else {
to_json(json_data, decision);
response.headers().add<Pistache::Http::Header::Location>(location);
}
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