/** * 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 "SMPoliciesCollectionApiImpl.h" #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; using namespace oai::pcf::app; using namespace oai::pcf::app::sm_policy; using namespace oai::model::common; SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl( 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) { 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"; status_code res = smpc_service->create_sm_policy_handler( smPolicyContextData, decision, association_id, details_string); nlohmann::json json_data; switch (res) { case status_code::CREATED: http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED; location = m_address + base + "/sm-policies/" + association_id; content_type = "application/json"; break; case status_code::USER_UNKOWN: problem_details.setCause("USER_UNKOWN"); problem_details.setDetail(details_string); http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; break; case status_code::INVALID_PARAMETERS: problem_details.setCause("ERROR_INITIAL_PARAMETERS"); problem_details.setDetail(details_string); http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST; break; case status_code::CONTEXT_DENIED: problem_details.setCause("POLICY_CONTEXT_DENIED"); problem_details.setDetail(details_string); 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."); } 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