Skip to content
Snippets Groups Projects
SMPoliciesCollectionApiImpl.cpp 3.26 KiB
Newer Older
Rohan's avatar
Rohan committed
/**
 * 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.
 */
Rohan's avatar
Rohan committed

#include "SMPoliciesCollectionApiImpl.h"
#include "3gpp_29.500.h"
#include "logger.hpp"
Rohan's avatar
Rohan committed

namespace oai {
namespace pcf {
namespace api {

using namespace oai::pcf::model;
using namespace oai::pcf::app::sm_policy;
Rohan's avatar
Rohan committed

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;
}
Rohan's avatar
Rohan committed

void SMPoliciesCollectionApiImpl::create_sm_policy(
    const SmPolicyContextData& smPolicyContextData,
    Pistache::Http::ResponseWriter& response) {
  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);
      http_code    = http_status_code_e::HTTP_STATUS_CODE_201_CREATED;
      location     = m_address + base + "/sm-policies/" + association_id;
      content_type = "application/json";
      problem_details.setCause("USER_UNKOWN");
      problem_details.setDetail(details_string);
      http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST;
      problem_details.setCause("ERROR_INITIAL_PARAMETERS");
      problem_details.setDetail(details_string);
      http_code = http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST;
      problem_details.setCause("POLICY_CONTEXT_DENIED");
      problem_details.setDetail(details_string);
      http_code = http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN;
    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());
Rohan's avatar
Rohan committed
}

}  // namespace api
}  // namespace pcf
}  // namespace oai